X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournald-server.c;h=ce419d48d89665afce9febb8ab4bf7378a3c69ed;hb=26fefda707e6511733f48da03b281a004dba6abf;hp=e03e413aeffba6fc337912d6d56bd77dfca5e9a4;hpb=2b98f75a63e6022bf74a7d678c47faa5208c794f;p=elogind.git diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index e03e413ae..ce419d48d 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -27,10 +27,10 @@ #include #include -#include -#include -#include +#include "sd-journal.h" +#include "sd-messages.h" +#include "sd-daemon.h" #include "fileio.h" #include "mkdir.h" #include "hashmap.h" @@ -38,19 +38,19 @@ #include "socket-util.h" #include "cgroup-util.h" #include "list.h" -#include "virt.h" #include "missing.h" #include "conf-parser.h" +#include "selinux-util.h" #include "journal-internal.h" #include "journal-vacuum.h" #include "journal-authenticate.h" -#include "journald-server.h" #include "journald-rate-limit.h" #include "journald-kmsg.h" #include "journald-syslog.h" #include "journald-stream.h" #include "journald-console.h" #include "journald-native.h" +#include "journald-server.h" #ifdef HAVE_ACL #include @@ -629,19 +629,21 @@ static void dispatch_message_real( } #ifdef HAVE_SELINUX - if (label) { - x = alloca(sizeof("_SELINUX_CONTEXT=") + label_len); + if (use_selinux()) { + if (label) { + x = alloca(sizeof("_SELINUX_CONTEXT=") + label_len); - *((char*) mempcpy(stpcpy(x, "_SELINUX_CONTEXT="), label, label_len)) = 0; - IOVEC_SET_STRING(iovec[n++], x); - } else { - security_context_t con; + *((char*) mempcpy(stpcpy(x, "_SELINUX_CONTEXT="), label, label_len)) = 0; + IOVEC_SET_STRING(iovec[n++], x); + } else { + security_context_t con; - if (getpidcon(ucred->pid, &con) >= 0) { - x = strappenda("_SELINUX_CONTEXT=", con); + if (getpidcon(ucred->pid, &con) >= 0) { + x = strappenda("_SELINUX_CONTEXT=", con); - freecon(con); - IOVEC_SET_STRING(iovec[n++], x); + freecon(con); + IOVEC_SET_STRING(iovec[n++], x); + } } } #endif @@ -1142,13 +1144,13 @@ int process_event(Server *s, struct epoll_event *ev) { } for (;;) { - struct msghdr msghdr; - struct iovec iovec; struct ucred *ucred = NULL; struct timeval *tv = NULL; struct cmsghdr *cmsg; char *label = NULL; size_t label_len = 0; + + struct iovec iovec; union { struct cmsghdr cmsghdr; @@ -1165,7 +1167,14 @@ int process_event(Server *s, struct epoll_event *ev) { CMSG_SPACE(sizeof(struct timeval)) + CMSG_SPACE(sizeof(int)) + /* fd */ CMSG_SPACE(NAME_MAX)]; /* selinux label */ - } control; + } control = {}; + struct msghdr msghdr = { + .msg_iov = &iovec, + .msg_iovlen = 1, + .msg_control = &control, + .msg_controllen = sizeof(control), + }; + ssize_t n; int v; int *fds = NULL; @@ -1176,36 +1185,14 @@ int process_event(Server *s, struct epoll_event *ev) { return -errno; } - if (s->buffer_size < (size_t) v) { - void *b; - size_t l; - - l = MAX(LINE_MAX + (size_t) v, s->buffer_size * 2); - b = realloc(s->buffer, l+1); + if (!GREEDY_REALLOC(s->buffer, s->buffer_size, LINE_MAX + (size_t) v)) + return log_oom(); - if (!b) { - log_error("Couldn't increase buffer."); - return -ENOMEM; - } - - s->buffer_size = l; - s->buffer = b; - } - - zero(iovec); iovec.iov_base = s->buffer; iovec.iov_len = s->buffer_size; - zero(control); - zero(msghdr); - msghdr.msg_iov = &iovec; - msghdr.msg_iovlen = 1; - msghdr.msg_control = &control; - msghdr.msg_controllen = sizeof(control); - n = recvmsg(ev->data.fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC); if (n < 0) { - if (errno == EINTR || errno == EAGAIN) return 1; @@ -1325,17 +1312,14 @@ static int open_signalfd(Server *s) { static int server_parse_proc_cmdline(Server *s) { _cleanup_free_ char *line = NULL; char *w, *state; - int r; size_t l; + int r; - if (detect_container(NULL) > 0) - return 0; - - r = read_one_line_file("/proc/cmdline", &line); - if (r < 0) { + r = proc_cmdline(&line); + if (r < 0) log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); + if (r <= 0) return 0; - } FOREACH_WORD_QUOTED(w, l, line, state) { _cleanup_free_ char *word;