From 632117b71fdd2d1b9da7418d00ec21c18d60dedd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 27 Jan 2012 18:14:06 +0100 Subject: [PATCH] log: never delay logging if the log server is stuck, always drop messages quickly --- src/journal/journald.c | 21 ++++++--------------- src/log.c | 18 +++--------------- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/src/journal/journald.c b/src/journal/journald.c index f63a12fa..73f8ed6a 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -66,8 +66,6 @@ #define RECHECK_VAR_AVAILABLE_USEC (30*USEC_PER_SEC) -#define SYSLOG_TIMEOUT_USEC (250*USEC_PER_MSEC) - #define N_IOVEC_META_FIELDS 17 #define ENTRY_SIZE_MAX (1024*1024*32) @@ -2220,7 +2218,6 @@ static int open_syslog_socket(Server *s) { union sockaddr_union sa; int one, r; struct epoll_event ev; - struct timeval tv; assert(s); @@ -2245,7 +2242,8 @@ static int open_syslog_socket(Server *s) { } chmod(sa.un.sun_path, 0666); - } + } else + fd_nonblock(s->syslog_fd, 1); one = 1; r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)); @@ -2261,15 +2259,6 @@ static int open_syslog_socket(Server *s) { return -errno; } - /* Since we use the same socket for forwarding this to some - * other syslog implementation, make sure we don't hang - * forever */ - timeval_store(&tv, SYSLOG_TIMEOUT_USEC); - if (setsockopt(s->syslog_fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) < 0) { - log_error("SO_SNDTIMEO failed: %m"); - return -errno; - } - zero(ev); ev.events = EPOLLIN; ev.data.fd = s->syslog_fd; @@ -2309,7 +2298,8 @@ static int open_native_socket(Server*s) { } chmod(sa.un.sun_path, 0666); - } + } else + fd_nonblock(s->native_fd, 1); one = 1; r = setsockopt(s->native_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)); @@ -2369,7 +2359,8 @@ static int open_stdout_socket(Server *s) { log_error("liste() failed: %m"); return -errno; } - } + } else + fd_nonblock(s->stdout_fd, 1); zero(ev); ev.events = EPOLLIN; diff --git a/src/log.c b/src/log.c index 1a6ea7e5..0594f7fd 100644 --- a/src/log.c +++ b/src/log.c @@ -33,8 +33,6 @@ #include "macro.h" #include "socket-util.h" -#define SOCKET_TIMEOUT_USEC (5*USEC_PER_SEC) - static LogTarget log_target = LOG_TARGET_CONSOLE; static int log_max_level = LOG_INFO; @@ -120,25 +118,15 @@ void log_close_syslog(void) { } static int create_log_socket(int type) { - struct timeval tv; int fd; - if (getpid() == 1) - /* systemd should not block on syslog */ - type |= SOCK_NONBLOCK; + /* All output to the syslog/journal fds we do asynchronously, + * and if the buffers are full we just drop the messages */ - fd = socket(AF_UNIX, type|SOCK_CLOEXEC, 0); + fd = socket(AF_UNIX, type|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); if (fd < 0) return -errno; - /* Make sure we don't block for more than 5s when talking to - * syslog */ - timeval_store(&tv, SOCKET_TIMEOUT_USEC); - if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) < 0) { - close_nointr_nofail(fd); - return -errno; - } - return fd; } -- 2.39.5