chiark / gitweb /
logger: when passing on PID info, fall back to our own if originating process is...
[elogind.git] / src / logger.c
index 9d67ab6bd82074d407957cbda87ffdc44b90340c..482ec41244502298a1b12b877367a00b37a77ece 100644 (file)
@@ -174,7 +174,7 @@ static int stream_log(Stream *s, char *p, usec_t ts) {
                 IOVEC_SET_STRING(iovec[3], header_pid);
                 IOVEC_SET_STRING(iovec[4], p);
 
-                /* When using syslog via SOCK_STREAM seperate the messages by NUL chars */
+                /* When using syslog via SOCK_STREAM separate the messages by NUL chars */
                 if (s->server->syslog_is_stream)
                         iovec[4].iov_len++;
 
@@ -187,8 +187,28 @@ static int stream_log(Stream *s, char *p, usec_t ts) {
                 for (;;) {
                         ssize_t n;
 
-                        if ((n = sendmsg(s->server->syslog_fd, &msghdr, MSG_NOSIGNAL)) < 0)
+                        if ((n = sendmsg(s->server->syslog_fd, &msghdr, MSG_NOSIGNAL)) < 0) {
+
+                                if (errno == ESRCH) {
+                                        pid_t our_pid;
+
+                                        /* Hmm, maybe the process this
+                                         * line originates from is
+                                         * dead? Then let's patch in
+                                         * our own pid and retry,
+                                         * since we have nothing
+                                         * better */
+
+                                        our_pid = getpid();
+
+                                        if (ucred->pid != our_pid) {
+                                                ucred->pid = our_pid;
+                                                continue;
+                                        }
+                                }
+
                                 return -errno;
+                        }
 
                         if (!s->server->syslog_is_stream ||
                             (size_t) n >= IOVEC_TOTAL_SIZE(iovec, ELEMENTSOF(iovec)))
@@ -318,7 +338,7 @@ static int stream_process(Stream *s, usec_t ts) {
                         return 0;
 
                 log_warning("Failed to read from stream: %m");
-                return -1;
+                return -errno;
         }