uid_t uid;
gid_t gid;
- bool prefix;
+ bool prefix:1;
+ bool tee_console:1;
char buffer[LINE_MAX];
size_t length;
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)))
} else
assert_not_reached("Unknown log target");
+ if (s->tee_console) {
+ int console;
+
+ if ((console = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC)) >= 0) {
+ IOVEC_SET_STRING(iovec[0], s->process);
+ IOVEC_SET_STRING(iovec[1], header_pid);
+ IOVEC_SET_STRING(iovec[2], p);
+ IOVEC_SET_STRING(iovec[3], (char*) "\n");
+
+ writev(console, iovec, 4);
+ }
+
+ }
+
return 0;
}
switch (s->state) {
case STREAM_TARGET:
- if (streq(p, "syslog"))
+ if (streq(p, "syslog") || streq(p, "syslog+console"))
s->target = STREAM_SYSLOG;
- else if (streq(p, "kmsg")) {
+ else if (streq(p, "kmsg") || streq(p, "kmsg+console")) {
if (s->server->kmsg_fd >= 0 && s->uid == 0)
s->target = STREAM_KMSG;
log_warning("Failed to parse log target line.");
return -EBADMSG;
}
+
+ if (endswith(p, "+console"))
+ s->tee_console = true;
+
s->state = STREAM_PRIORITY;
return 0;