diff options
author | Lennart Poettering <lennart@poettering.net> | 2011-02-15 01:27:53 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2011-02-15 01:27:53 +0100 |
commit | 28dbc1e80b0db09313f11e44f218138aefd646c8 (patch) | |
tree | 897f4bbc275cc773d20929deabeb8c16a51f2910 /src/logger.c | |
parent | 7b4bf06ba7f31ea8069fc8927729d70ab98b9b64 (diff) |
execute: optionally forward program output to /dev/console in addition to syslog/kmsg
Diffstat (limited to 'src/logger.c')
-rw-r--r-- | src/logger.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/logger.c b/src/logger.c index 482ec41244..342c307899 100644 --- a/src/logger.c +++ b/src/logger.c @@ -84,7 +84,8 @@ struct Stream { uid_t uid; gid_t gid; - bool prefix; + bool prefix:1; + bool tee_console:1; char buffer[LINE_MAX]; size_t length; @@ -228,6 +229,20 @@ static int stream_log(Stream *s, char *p, usec_t ts) { } 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; } @@ -242,9 +257,9 @@ static int stream_line(Stream *s, char *p, usec_t ts) { 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; @@ -256,6 +271,10 @@ static int stream_line(Stream *s, char *p, usec_t ts) { log_warning("Failed to parse log target line."); return -EBADMSG; } + + if (endswith(p, "+console")) + s->tee_console = true; + s->state = STREAM_PRIORITY; return 0; |