chiark / gitweb /
journal: Leave server_dispatch_message early when Storage is none
[elogind.git] / src / journal / journald-kmsg.c
index cc0080da19e5663dbf0be9a0b81c1ae4a52f9e1f..21649d06ce01e8f529a2a84d903af3f70ae95a2b 100644 (file)
 #include <sys/epoll.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#include <sys/socket.h>
 
 #include <systemd/sd-messages.h>
 #include <libudev.h>
 
-#include "journald.h"
+#include "journald-server.h"
 #include "journald-kmsg.h"
+#include "journald-syslog.h"
 
 void server_forward_kmsg(
         Server *s,
@@ -107,7 +109,7 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) {
         char *message = NULL, *syslog_priority = NULL, *syslog_pid = NULL, *syslog_facility = NULL, *syslog_identifier = NULL, *source_time = NULL;
         int priority, r;
         unsigned n = 0, z = 0, j;
-        usec_t usec;
+        unsigned long long usec;
         char *identifier = NULL, *pid = NULL, *e, *f, *k;
         uint64_t serial;
         size_t pl;
@@ -149,7 +151,8 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) {
 
                 /* Did we lose any? */
                 if (serial > *s->kernel_seqnum)
-                        server_driver_message(s, SD_MESSAGE_JOURNAL_MISSED, "Missed %llu kernel messages", (unsigned long long) serial - *s->kernel_seqnum - 1);
+                        server_driver_message(s, SD_MESSAGE_JOURNAL_MISSED, "Missed %"PRIu64" kernel messages",
+                                              serial - *s->kernel_seqnum - 1);
 
                 /* Make sure we never read this one again. Note that
                  * we always store the next message serial we expect
@@ -169,7 +172,7 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) {
                 e = f;
         *e = 0;
 
-        r = parse_usec(p, &usec);
+        r = safe_atollu(p, &usec);
         if (r < 0)
                 return;
 
@@ -248,10 +251,12 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) {
                                         break;
 
                                 g = udev_list_entry_get_name(ll);
-                                b = strappend("_UDEV_DEVLINK=", g);
                                 if (g) {
-                                        IOVEC_SET_STRING(iovec[n++], b);
-                                        z++;
+                                        b = strappend("_UDEV_DEVLINK=", g);
+                                        if (b) {
+                                                IOVEC_SET_STRING(iovec[n++], b);
+                                                z++;
+                                        }
                                 }
 
                                 j++;
@@ -261,8 +266,7 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) {
                 }
         }
 
-        if (asprintf(&source_time, "_SOURCE_MONOTONIC_TIMESTAMP=%llu",
-                     (unsigned long long) usec) >= 0)
+        if (asprintf(&source_time, "_SOURCE_MONOTONIC_TIMESTAMP=%llu", usec) >= 0)
                 IOVEC_SET_STRING(iovec[n++], source_time);
 
         IOVEC_SET_STRING(iovec[n++], "_TRANSPORT=kernel");
@@ -273,7 +277,7 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) {
         if ((priority & LOG_FACMASK) == LOG_KERN)
                 IOVEC_SET_STRING(iovec[n++], "SYSLOG_IDENTIFIER=kernel");
         else {
-                syslog_read_identifier((const char**) &p, &identifier, &pid);
+                pl -= syslog_parse_identifier((const char**) &p, &identifier, &pid);
 
                 /* Avoid any messages we generated ourselves via
                  * log_info() and friends. */
@@ -300,7 +304,7 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) {
         if (message)
                 IOVEC_SET_STRING(iovec[n++], message);
 
-        server_dispatch_message(s, iovec, n, ELEMENTSOF(iovec), NULL, NULL, NULL, 0, NULL, priority);
+        server_dispatch_message(s, iovec, n, ELEMENTSOF(iovec), NULL, NULL, NULL, 0, NULL, priority, 0);
 
 finish:
         for (j = 0; j < z; j++)
@@ -357,7 +361,7 @@ int server_flush_dev_kmsg(Server *s) {
         if (!s->dev_kmsg_readable)
                 return 0;
 
-        log_info("Flushing /dev/kmsg...");
+        log_debug("Flushing /dev/kmsg...");
 
         for (;;) {
                 r = server_read_dev_kmsg(s);
@@ -409,7 +413,7 @@ int server_open_kernel_seqnum(Server *s) {
 
         /* We store the seqnum we last read in an mmaped file. That
          * way we can just use it like a variable, but it is
-         * persistant and automatically flushed at reboot. */
+         * persistent and automatically flushed at reboot. */
 
         fd = open("/run/systemd/journal/kernel-seqnum", O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0644);
         if (fd < 0) {