1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-06 08:26:52 +03:00

journald: simplify context handling

By using our homegrown function we can dispense with all the iffdefery.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2015-06-06 21:36:52 -04:00
parent c4e6556c46
commit 2de56f7094

View File

@ -59,10 +59,7 @@ struct StdoutStream {
int fd; int fd;
struct ucred ucred; struct ucred ucred;
#ifdef HAVE_SELINUX char *label;
security_context_t security_context;
#endif
char *identifier; char *identifier;
char *unit_id; char *unit_id;
int priority; int priority;
@ -99,12 +96,7 @@ void stdout_stream_free(StdoutStream *s) {
} }
safe_close(s->fd); safe_close(s->fd);
free(s->label);
#ifdef HAVE_SELINUX
if (s->security_context)
freecon(s->security_context);
#endif
free(s->identifier); free(s->identifier);
free(s->unit_id); free(s->unit_id);
free(s->state_file); free(s->state_file);
@ -225,8 +217,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
char syslog_facility[sizeof("SYSLOG_FACILITY=")-1 + DECIMAL_STR_MAX(int) + 1]; char syslog_facility[sizeof("SYSLOG_FACILITY=")-1 + DECIMAL_STR_MAX(int) + 1];
_cleanup_free_ char *message = NULL, *syslog_identifier = NULL; _cleanup_free_ char *message = NULL, *syslog_identifier = NULL;
unsigned n = 0; unsigned n = 0;
char *label = NULL; size_t label_len;
size_t label_len = 0;
assert(s); assert(s);
assert(p); assert(p);
@ -271,14 +262,8 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
if (message) if (message)
IOVEC_SET_STRING(iovec[n++], message); IOVEC_SET_STRING(iovec[n++], message);
#ifdef HAVE_SELINUX label_len = s->label ? strlen(s->label) : 0;
if (s->security_context) { server_dispatch_message(s->server, iovec, n, ELEMENTSOF(iovec), &s->ucred, NULL, s->label, label_len, s->unit_id, priority, 0);
label = (char*) s->security_context;
label_len = strlen((char*) s->security_context);
}
#endif
server_dispatch_message(s->server, iovec, n, ELEMENTSOF(iovec), &s->ucred, NULL, label, label_len, s->unit_id, priority, 0);
return 0; return 0;
} }
@ -489,12 +474,11 @@ static int stdout_stream_install(Server *s, int fd, StdoutStream **ret) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to determine peer credentials: %m"); return log_error_errno(r, "Failed to determine peer credentials: %m");
#ifdef HAVE_SELINUX
if (mac_selinux_use()) { if (mac_selinux_use()) {
if (getpeercon(fd, &stream->security_context) < 0 && errno != ENOPROTOOPT) r = getpeersec(fd, &stream->label);
log_error_errno(errno, "Failed to determine peer security context: %m"); if (r < 0 && r != -EOPNOTSUPP)
(void) log_warning_errno(r, "Failed to determine peer security context: %m");
} }
#endif
(void) shutdown(fd, SHUT_WR); (void) shutdown(fd, SHUT_WR);