From 2ac1ff68f25374dd1274aba41aaef69b404fca94 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Thu, 18 Oct 2018 05:47:26 +0000 Subject: [PATCH] core: stop ignoring errors in connect_logger_as When journald reaches the maximum number of active streams, it, basically, starts to decline new connections. On the client side it can be detected by getting EPIPE and, if the writing process isn't lucky enough, getting SIGPIPE soon afterwards. systemd has always ignored EPIPE, which makes it very hard to keep track of services losing logs. This patch should make it easier to detect such services by just staring at the logs carefully. In case anyone is interested, the following one-liner run as any user can be used to paralyze all the stream logging on a machine: for i in {1..4096}; do systemd-cat -t HEY-$i & done --- src/core/execute.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core/execute.c b/src/core/execute.c index 60c4c0375e..f561bfe11a 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -324,7 +324,8 @@ static int connect_logger_as( uid_t uid, gid_t gid) { - int fd, r; + _cleanup_close_ int fd = -1; + int r; assert(context); assert(params); @@ -340,14 +341,12 @@ static int connect_logger_as( if (r < 0) return r; - if (shutdown(fd, SHUT_RD) < 0) { - safe_close(fd); + if (shutdown(fd, SHUT_RD) < 0) return -errno; - } (void) fd_inc_sndbuf(fd, SNDBUF_SIZE); - dprintf(fd, + if (dprintf(fd, "%s\n" "%s\n" "%i\n" @@ -361,10 +360,12 @@ static int connect_logger_as( !!context->syslog_level_prefix, is_syslog_output(output), is_kmsg_output(output), - is_terminal_output(output)); + is_terminal_output(output)) < 0) + return -errno; - return move_fd(fd, nfd, false); + return move_fd(TAKE_FD(fd), nfd, false); } + static int open_terminal_as(const char *path, int flags, int nfd) { int fd;