X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flog.c;h=949936762a14c91830bd917029afeca91a205b47;hp=1a6ea7e5a84fbb2b97303f2b2775ce4e62bfde80;hb=568b679f2a5db6a23c795363091b94ad804f24f6;hpb=a3f914b2a21decb0c4bd7a763ddd3ace215091cb diff --git a/src/log.c b/src/log.c index 1a6ea7e5a..949936762 100644 --- a/src/log.c +++ b/src/log.c @@ -33,7 +33,7 @@ #include "macro.h" #include "socket-util.h" -#define SOCKET_TIMEOUT_USEC (5*USEC_PER_SEC) +#define SNDBUF_SIZE (8*1024*1024) static LogTarget log_target = LOG_TARGET_CONSOLE; static int log_max_level = LOG_INFO; @@ -120,24 +120,16 @@ 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; - } + fd_inc_sndbuf(fd, SNDBUF_SIZE); return fd; } @@ -590,26 +582,22 @@ int log_dump_internal( return r; } -int log_meta( +int log_metav( int level, const char*file, int line, const char *func, - const char *format, ...) { + const char *format, + va_list ap) { char buffer[LINE_MAX]; int saved_errno, r; - va_list ap; if (_likely_(LOG_PRI(level) > log_max_level)) return 0; saved_errno = errno; - - va_start(ap, format); vsnprintf(buffer, sizeof(buffer), format, ap); - va_end(ap); - char_array_0(buffer); r = log_dispatch(level, file, line, func, buffer); @@ -618,6 +606,23 @@ int log_meta( return r; } +int log_meta( + int level, + const char*file, + int line, + const char *func, + const char *format, ...) { + + int r; + va_list ap; + + va_start(ap, format); + r = log_metav(level, file, line, func, format, ap); + va_end(ap); + + return r; +} + #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" _noreturn_ static void log_assert(const char *text, const char *file, int line, const char *func, const char *format) { @@ -633,11 +638,11 @@ _noreturn_ static void log_assert(const char *text, const char *file, int line, } #pragma GCC diagnostic pop -void log_assert_failed(const char *text, const char *file, int line, const char *func) { +_noreturn_ void log_assert_failed(const char *text, const char *file, int line, const char *func) { log_assert(text, file, line, func, "Assertion '%s' failed at %s:%u, function %s(). Aborting."); } -void log_assert_failed_unreachable(const char *text, const char *file, int line, const char *func) { +_noreturn_ void log_assert_failed_unreachable(const char *text, const char *file, int line, const char *func) { log_assert(text, file, line, func, "Code should not be reached '%s' at %s:%u, function %s(). Aborting."); }