]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal/kmsg: drop old kernels (<3.6) support 37137/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 14 Apr 2025 20:09:28 +0000 (05:09 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 14 Apr 2025 21:19:07 +0000 (06:19 +0900)
The flags field was added by kernel v3.6:
https://github.com/torvalds/linux/commit/d39f3d77c9b1fe7cc33a14beb4a4849af0a4ac22

Now our baseline on the kernel is v5.4, so we can assume there exists
the flags field after the monotonic timestamp.

This also adds several short comments.

src/journal/journald-kmsg.c

index cae91cfb72a3c3c159781375bdd3ce4f74a19af9..d2942315ef5d0f5e91b149a83647508fe3e4a276 100644 (file)
@@ -104,7 +104,7 @@ void dev_kmsg_record(Server *s, char *p, size_t l) {
         unsigned long long usec;
         size_t n = 0, z = 0, j;
         int priority, r;
-        char *e, *f, *k;
+        char *e, *k;
         uint64_t serial;
         size_t pl;
         int saved_log_max_level = INT_MAX;
@@ -116,6 +116,7 @@ void dev_kmsg_record(Server *s, char *p, size_t l) {
         if (l <= 0)
                 return;
 
+        /* syslog prefix including priority and facility */
         e = memchr(p, ',', l);
         if (!e)
                 return;
@@ -128,6 +129,7 @@ void dev_kmsg_record(Server *s, char *p, size_t l) {
         if (s->forward_to_kmsg && LOG_FAC(priority) != LOG_KERN)
                 return;
 
+        /* seqnum */
         l -= (e - p) + 1;
         p = e + 1;
         e = memchr(p, ',', l);
@@ -158,23 +160,28 @@ void dev_kmsg_record(Server *s, char *p, size_t l) {
                 *s->kernel_seqnum = serial + 1;
         }
 
+        /* monotonic timestamp */
         l -= (e - p) + 1;
         p = e + 1;
-        f = memchr(p, ';', l);
-        if (!f)
-                return;
-        /* Kernel 3.6 has the flags field, kernel 3.5 lacks that */
         e = memchr(p, ',', l);
-        if (!e || f < e)
-                e = f;
+        if (!e)
+                return;
         *e = 0;
 
         r = safe_atollu(p, &usec);
         if (r < 0)
                 return;
 
-        l -= (f - p) + 1;
-        p = f + 1;
+        /* ignore flags and any other fields, and find the beginning of the message */
+        l -= (e - p) + 1;
+        p = e + 1;
+        e = memchr(p, ';', l);
+        if (!e)
+                return;
+
+        /* find the end of the message */
+        l -= (e - p) + 1;
+        p = e + 1;
         e = memchr(p, '\n', l);
         if (!e)
                 return;