From e92d55e6cbffc4ed7b516d2d36525d7ceb8aa7ab Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 11 Oct 2017 12:35:24 +0200 Subject: [PATCH] logger: allow to reconnect on initial failed connect too The current code sets noact flag if unix socked connection failed. This is ugly. We want to reconnect always in all cases (well, except --socket-error=on). Signed-off-by: Karel Zak --- misc-utils/logger.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/misc-utils/logger.c b/misc-utils/logger.c index bf2db9c6c..ea4bcf0b3 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -139,6 +139,7 @@ struct logger_ctl { octet_count:1; /* use RFC6587 octet counting */ }; +#define is_connected(_ctl) ((_ctl)->fd >= 0) static void logger_reopen(struct logger_ctl *ctl); /* @@ -268,9 +269,7 @@ static int unix_socket(struct logger_ctl *ctl, const char *path, int *socket_typ if (ctl->unix_socket_errors) err(EXIT_FAILURE, _("socket %s"), path); - /* openlog(3) compatibility, socket errors are - * not reported, but ignored silently */ - ctl->noact = 1; + /* write_output() will try to reconnect */ return -1; } @@ -433,6 +432,10 @@ static void write_output(struct logger_ctl *ctl, const char *const msg) int iovlen = 0; char *octet = NULL; + /* initial connect failed? */ + if (!ctl->noact && !is_connected(ctl)) + logger_reopen(ctl); + /* 1) octen count */ if (ctl->octet_count) { size_t len = xasprintf(&octet, "%zu ", strlen(ctl->hdr) + strlen(msg)); @@ -445,7 +448,7 @@ static void write_output(struct logger_ctl *ctl, const char *const msg) /* 3) message */ iovec_add_string(iov, iovlen, msg, 0); - if (!ctl->noact) { + if (!ctl->noact && is_connected(ctl)) { struct msghdr message = { 0 }; #ifdef SCM_CREDENTIALS struct cmsghdr *cmhp;