chiark / gitweb /
journal: rename priority_prefix to level_prefix, since that's how we call it in PID 1
[elogind.git] / src / journal / journald.c
index d7f0ed52b4ac742ac10c52560e105c2feba905f1..419ce26ada78491d47b9fb17e7dd0136f96042a4 100644 (file)
@@ -65,7 +65,7 @@
 typedef enum StdoutStreamState {
         STDOUT_STREAM_TAG,
         STDOUT_STREAM_PRIORITY,
-        STDOUT_STREAM_PRIORITY_PREFIX,
+        STDOUT_STREAM_LEVEL_PREFIX,
         STDOUT_STREAM_FORWARD_TO_SYSLOG,
         STDOUT_STREAM_FORWARD_TO_KMSG,
         STDOUT_STREAM_FORWARD_TO_CONSOLE,
@@ -82,7 +82,7 @@ struct StdoutStream {
 
         char *tag;
         int priority;
-        bool priority_prefix:1;
+        bool level_prefix:1;
         bool forward_to_syslog:1;
         bool forward_to_kmsg:1;
         bool forward_to_console:1;
@@ -578,7 +578,7 @@ retry:
 static void driver_message(Server *s, sd_id128_t message_id, const char *format, ...) {
         char mid[11 + 32 + 1];
         char buffer[16 + LINE_MAX + 1];
-        struct iovec iovec[N_IOVEC_META_FIELDS + 3];
+        struct iovec iovec[N_IOVEC_META_FIELDS + 4];
         int n = 0;
         va_list ap;
         struct ucred ucred;
@@ -587,6 +587,7 @@ static void driver_message(Server *s, sd_id128_t message_id, const char *format,
         assert(format);
 
         IOVEC_SET_STRING(iovec[n++], "PRIORITY=5");
+        IOVEC_SET_STRING(iovec[n++], "_TRANSPORT=driver");
 
         memcpy(buffer, "MESSAGE=", 8);
         va_start(ap, format);
@@ -680,7 +681,7 @@ static void forward_syslog_iovec(Server *s, const struct iovec *iovec, unsigned
 
         zero(sa);
         sa.un.sun_family = AF_UNIX;
-        strncpy(sa.un.sun_path, "/run/systemd/syslog", sizeof(sa.un.sun_path));
+        strncpy(sa.un.sun_path, "/run/systemd/journal/syslog", sizeof(sa.un.sun_path));
         msghdr.msg_name = &sa;
         msghdr.msg_namelen = offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path);
 
@@ -947,7 +948,7 @@ static void read_tag(const char **buf, char **tag) {
 
 static void process_syslog_message(Server *s, const char *buf, struct ucred *ucred, struct timeval *tv) {
         char *message = NULL, *syslog_priority = NULL, *syslog_facility = NULL, *syslog_tag = NULL;
-        struct iovec iovec[N_IOVEC_META_FIELDS + 4];
+        struct iovec iovec[N_IOVEC_META_FIELDS + 5];
         unsigned n = 0;
         int priority = LOG_USER | LOG_INFO;
         char *tag = NULL;
@@ -968,6 +969,8 @@ static void process_syslog_message(Server *s, const char *buf, struct ucred *ucr
         if (s->forward_to_console)
                 forward_console(s, tag, buf, ucred);
 
+        IOVEC_SET_STRING(iovec[n++], "_TRANSPORT=syslog");
+
         if (asprintf(&syslog_priority, "PRIORITY=%i", priority & LOG_PRIMASK) >= 0)
                 IOVEC_SET_STRING(iovec[n++], syslog_priority);
 
@@ -1031,7 +1034,7 @@ static bool valid_user_field(const char *p, size_t l) {
 
 static void process_native_message(Server *s, const void *buffer, size_t buffer_size, struct ucred *ucred, struct timeval *tv) {
         struct iovec *iovec = NULL;
-        unsigned n = 0, m = 0, j;
+        unsigned n = 0, m = 0, j, tn = (unsigned) -1;
         const char *p;
         size_t remaining;
         int priority = LOG_INFO;
@@ -1079,7 +1082,7 @@ static void process_native_message(Server *s, const void *buffer, size_t buffer_
                         struct iovec *c;
                         unsigned u;
 
-                        u = MAX((n+N_IOVEC_META_FIELDS) * 2U, 4U);
+                        u = MAX((n+N_IOVEC_META_FIELDS+1) * 2U, 4U);
                         c = realloc(iovec, u * sizeof(struct iovec));
                         if (!c) {
                                 log_error("Out of memory");
@@ -1188,6 +1191,12 @@ static void process_native_message(Server *s, const void *buffer, size_t buffer_
                 }
         }
 
+        if (n <= 0)
+                goto finish;
+
+        tn = n++;
+        IOVEC_SET_STRING(iovec[tn], "_TRANSPORT=journal");
+
         if (message) {
                 if (s->forward_to_syslog)
                         forward_syslog(s, priority, tag, message, ucred, tv);
@@ -1201,17 +1210,22 @@ static void process_native_message(Server *s, const void *buffer, size_t buffer_
 
         dispatch_message(s, iovec, n, m, ucred, tv, priority);
 
-        for (j = 0; j < n; j++)
+finish:
+        for (j = 0; j < n; j++)  {
+                if (j == tn)
+                        continue;
+
                 if (iovec[j].iov_base < buffer ||
                     (const uint8_t*) iovec[j].iov_base >= (const uint8_t*) buffer + buffer_size)
                         free(iovec[j].iov_base);
+        }
 
         free(tag);
         free(message);
 }
 
 static int stdout_stream_log(StdoutStream *s, const char *p) {
-        struct iovec iovec[N_IOVEC_META_FIELDS + 4];
+        struct iovec iovec[N_IOVEC_META_FIELDS + 5];
         char *message = NULL, *syslog_priority = NULL, *syslog_facility = NULL, *syslog_tag = NULL;
         unsigned n = 0;
         int priority;
@@ -1221,7 +1235,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
 
         priority = s->priority;
 
-        if (s->priority_prefix)
+        if (s->level_prefix)
                 parse_syslog_priority((char**) &p, &priority);
 
         if (s->forward_to_syslog || s->server->forward_to_syslog)
@@ -1233,6 +1247,8 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
         if (s->forward_to_console || s->server->forward_to_console)
                 forward_console(s->server, s->tag, p, &s->ucred);
 
+        IOVEC_SET_STRING(iovec[n++], "_TRANSPORT=stdout");
+
         if (asprintf(&syslog_priority, "PRIORITY=%i", priority & LOG_PRIMASK) >= 0)
                 IOVEC_SET_STRING(iovec[n++], syslog_priority);
 
@@ -1287,17 +1303,17 @@ static int stdout_stream_line(StdoutStream *s, char *p) {
                         return -EINVAL;
                 }
 
-                s->state = STDOUT_STREAM_PRIORITY_PREFIX;
+                s->state = STDOUT_STREAM_LEVEL_PREFIX;
                 return 0;
 
-        case STDOUT_STREAM_PRIORITY_PREFIX:
+        case STDOUT_STREAM_LEVEL_PREFIX:
                 r = parse_boolean(p);
                 if (r < 0) {
-                        log_warning("Failed to parse priority prefix line.");
+                        log_warning("Failed to parse level prefix line.");
                         return -EINVAL;
                 }
 
-                s->priority_prefix = !!r;
+                s->level_prefix = !!r;
                 s->state = STDOUT_STREAM_FORWARD_TO_SYSLOG;
                 return 0;
 
@@ -1929,7 +1945,7 @@ static int open_native_socket(Server*s) {
 
                 zero(sa);
                 sa.un.sun_family = AF_UNIX;
-                strncpy(sa.un.sun_path, "/run/systemd/journal", sizeof(sa.un.sun_path));
+                strncpy(sa.un.sun_path, "/run/systemd/journal/socket", sizeof(sa.un.sun_path));
 
                 unlink(sa.un.sun_path);
 
@@ -1984,7 +2000,7 @@ static int open_stdout_socket(Server *s) {
 
                 zero(sa);
                 sa.un.sun_family = AF_UNIX;
-                strncpy(sa.un.sun_path, "/run/systemd/stdout", sizeof(sa.un.sun_path));
+                strncpy(sa.un.sun_path, "/run/systemd/journal/stdout", sizeof(sa.un.sun_path));
 
                 unlink(sa.un.sun_path);
 
@@ -2106,7 +2122,7 @@ static int server_init(Server *s) {
 
         for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) {
 
-                if (sd_is_socket_unix(fd, SOCK_DGRAM, -1, "/run/systemd/native", 0) > 0) {
+                if (sd_is_socket_unix(fd, SOCK_DGRAM, -1, "/run/systemd/journal/socket", 0) > 0) {
 
                         if (s->native_fd >= 0) {
                                 log_error("Too many native sockets passed.");
@@ -2115,7 +2131,7 @@ static int server_init(Server *s) {
 
                         s->native_fd = fd;
 
-                } else if (sd_is_socket_unix(fd, SOCK_STREAM, 1, "/run/systemd/stdout", 0) > 0) {
+                } else if (sd_is_socket_unix(fd, SOCK_STREAM, 1, "/run/systemd/journal/stdout", 0) > 0) {
 
                         if (s->stdout_fd >= 0) {
                                 log_error("Too many stdout sockets passed.");