X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fkmsg-syslogd.c;h=7fd69f858428f79380f047aa448d5bfb463b3014;hb=66ccd0387e528567dff92239e85c962d2f140ef1;hp=a2715ae0fa1b960ae68f2b7702bfc41180ddd48a;hpb=3351dc07213d17c2d5443c40d7fe100c0c4dce9a;p=elogind.git diff --git a/src/kmsg-syslogd.c b/src/kmsg-syslogd.c index a2715ae0f..7fd69f858 100644 --- a/src/kmsg-syslogd.c +++ b/src/kmsg-syslogd.c @@ -39,7 +39,6 @@ #include "fdset.h" #define SERVER_FD_MAX 16 -#define TIMEOUT ((int) (5*MSEC_PER_MINUTE)) typedef struct Stream Stream; @@ -92,7 +91,7 @@ static int server_init(Server *s, unsigned n_sockets) { } for (i = 0; i < n_sockets; i++) { - int fd, one = 1; + int fd; fd = SD_LISTEN_FDS_START+i; @@ -107,9 +106,6 @@ static int server_init(Server *s, unsigned n_sockets) { goto fail; } - if (setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0) - log_error("SO_PASSCRED failed: %m"); - zero(ev); ev.events = EPOLLIN; ev.data.fd = fd; @@ -155,50 +151,6 @@ fail: return r; } -static int read_priority(const char **buf) { - int priority; - size_t n; - const char *p; - int a, b, c; - - assert(buf); - assert(*buf); - - p = *buf; - n = strlen(p); - - if (n < 3 || p[0] != '<') - goto fail; - - if (p[2] == '>') { - a = b = 0; - c = undecchar(p[1]); - p += 3; - } else if (n >= 4 && p[3] == '>') { - a = 0; - b = undecchar(p[1]); - c = undecchar(p[2]); - p += 4; - } else if (n >= 5 && p[4] == '>') { - a = undecchar(p[1]); - b = undecchar(p[2]); - c = undecchar(p[3]); - p += 5; - } else - goto fail; - - if (a < 0 || b < 0 || c < 0) - goto fail; - - *buf = p; - - priority = 100*a + 10*b + c; - return LOG_PRI(priority); - -fail: - return LOG_INFO; -} - static void skip_date(const char **buf) { enum { LETTER, @@ -335,17 +287,26 @@ static void skip_pid(const char **buf) { static int write_message(Server *s, const char *buf, struct ucred *ucred) { ssize_t k; - char priority[4], pid[16]; + char priority[6], pid[16]; struct iovec iovec[5]; unsigned i = 0; char *process = NULL; int r = 0; + int prio = LOG_USER | LOG_INFO; assert(s); assert(buf); + parse_syslog_priority((char**) &buf, &prio); + + if (*buf == 0) + return 0; + + if ((prio & LOG_FACMASK) == 0) + prio = LOG_USER | LOG_PRI(prio); + /* First, set priority field */ - snprintf(priority, sizeof(priority), "<%i>", read_priority(&buf)); + snprintf(priority, sizeof(priority), "<%i>", prio); char_array_0(priority); IOVEC_SET_STRING(iovec[i++], priority); @@ -355,7 +316,9 @@ static int write_message(Server *s, const char *buf, struct ucred *ucred) { /* Then, add process if set */ if (read_process(&buf, &iovec[i]) > 0) i++; - else if (ucred && get_process_name(ucred->pid, &process) >= 0) + else if (ucred && + ucred->pid > 0 && + get_process_name(ucred->pid, &process) >= 0) IOVEC_SET_STRING(iovec[i++], process); /* Skip the stored PID if we have a better one */ @@ -413,7 +376,7 @@ static int process_event(Server *s, struct epoll_event *ev) { return -errno; } - log_debug("Received SIG%s", strna(signal_to_string(sfsi.ssi_signo))); + log_debug("Received SIG%s", signal_to_string(sfsi.ssi_signo)); return 0; } else { @@ -489,6 +452,8 @@ int main(int argc, char *argv[]) { log_parse_environment(); log_open(); + umask(0022); + if ((n = sd_listen_fds(true)) < 0) { log_error("Failed to read listening file descriptors from environment: %s", strerror(-r)); return EXIT_FAILURE; @@ -512,7 +477,7 @@ int main(int argc, char *argv[]) { struct epoll_event event; int k; - if ((k = epoll_wait(server.epoll_fd, &event, 1, TIMEOUT)) < 0) { + if ((k = epoll_wait(server.epoll_fd, &event, 1, -1)) < 0) { if (errno == EINTR) continue;