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
This commit is contained in:
Evgeny Vereshchagin 2018-10-18 05:47:26 +00:00 committed by Lennart Poettering
parent 6ab1853953
commit 2ac1ff68f2

View file

@ -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;