X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Flog.c;h=8f4995a0c8834f3cb5c4e95cc9071705994758da;hb=edcfd89ad0996686488c02ee0062d913fa0ba483;hp=876f22dfc5535af48c10255c553324dc04302f5a;hpb=b92bea5d2a9481de69bb627a7b442a9f58fca43d;p=elogind.git diff --git a/src/shared/log.c b/src/shared/log.c index 876f22dfc..8f4995a0c 100644 --- a/src/shared/log.c +++ b/src/shared/log.c @@ -115,16 +115,20 @@ void log_close_syslog(void) { static int create_log_socket(int type) { int fd; + struct timeval tv; - /* 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|SOCK_NONBLOCK, 0); + fd = socket(AF_UNIX, type|SOCK_CLOEXEC, 0); if (fd < 0) return -errno; fd_inc_sndbuf(fd, SNDBUF_SIZE); + /* We need a blocking fd here since we'd otherwise lose + messages way too early. However, let's not hang forever in the + unlikely case of a deadlock. */ + timeval_store(&tv, 1*USEC_PER_MINUTE); + setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); + return fd; } @@ -737,7 +741,9 @@ int log_struct_internal( char header[LINE_MAX]; struct iovec iovec[17] = {}; unsigned n = 0, i; - struct msghdr mh; + struct msghdr mh = { + .msg_iov = iovec, + }; static const char nl = '\n'; /* If the journal is available do structured logging */ @@ -775,8 +781,6 @@ int log_struct_internal( format = va_arg(ap, char *); } - zero(mh); - mh.msg_iov = iovec; mh.msg_iovlen = n; if (sendmsg(journal_fd, &mh, MSG_NOSIGNAL) < 0)