chiark / gitweb /
log: don't strip facility when writing to kmsg
authorLennart Poettering <lennart@poettering.net>
Thu, 31 Mar 2011 17:49:04 +0000 (19:49 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 31 Mar 2011 17:49:04 +0000 (19:49 +0200)
TODO
src/log.c
src/logger.c

diff --git a/TODO b/TODO
index 1152927cacdacfcd70dbb0fdb60ce5af94dabc58..c1cdf1c6c35365bfdfe513118d0f50b8b2eec7ea 100644 (file)
--- a/TODO
+++ b/TODO
@@ -19,18 +19,10 @@ F15:
 
 * NM should pull in network.target, ntpd should pull in rtc-set.target.
 
-* kernel patch wegen kmsg prio nach f15
-
-* selinux issue http://people.gnome.org/~cosimoc/selinux.jpg
-
 * fix alsa mixer restore to not print error when no config is stored
 
-* ply should do mkdir before writing pid file
-
 * ConditionDirectoryNotEmpty= needs to be documented
 
-* add /etc/modules-load.d to rpm
-
 Features:
 
 * tmpfiles should allow two identical lines
@@ -40,8 +32,6 @@ Features:
 
 * document default dependencies
 
-* LOG_DAEMON/LOG_USER für kmsg messages schreiben
-
 * Find a way to replace /var/run, /var/lock directories with
   symlinks during an RPM package upgrade (filesystem.rpm or systemd.rpm).
   We soon want to get rid of var-run.mount var-lock.mount units.
index b6d4bf9c1b80a4f47eb592b2dfb0e4d5011da83f..4ec6b73888279217f1dd316b12965863753cc55f 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -289,7 +289,7 @@ static int write_to_syslog(
         if (syslog_fd < 0)
                 return 0;
 
-        snprintf(header_priority, sizeof(header_priority), "<%i>", LOG_MAKEPRI(LOG_DAEMON, LOG_PRI(level)));
+        snprintf(header_priority, sizeof(header_priority), "<%i>", level);
         char_array_0(header_priority);
 
         t = (time_t) (now(CLOCK_REALTIME) / USEC_PER_SEC);
@@ -346,7 +346,7 @@ static int write_to_kmsg(
         if (kmsg_fd < 0)
                 return 0;
 
-        snprintf(header_priority, sizeof(header_priority), "<%i>", LOG_PRI(level));
+        snprintf(header_priority, sizeof(header_priority), "<%i>", level);
         char_array_0(header_priority);
 
         snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) getpid());
@@ -377,6 +377,10 @@ static int log_dispatch(
         if (log_target == LOG_TARGET_NULL)
                 return 0;
 
+        /* Patch in LOG_DAEMON facility if necessary */
+        if (LOG_FAC(level) == 0)
+                level = LOG_MAKEPRI(LOG_DAEMON, LOG_PRI(level));
+
         do {
                 char *e;
                 int k = 0;
index 104d7c385b757d5e63e484577f06d3ff16425874..710dfed33bc9b12a0e0a6bfef38e41aef6507ff8 100644 (file)
@@ -93,6 +93,42 @@ struct Stream {
         LIST_FIELDS(Stream, stream);
 };
 
+static void parse_priority(char **p, int *priority) {
+        int a = 0, b = 0, c = 0;
+        int k;
+
+        assert(p);
+        assert(*p);
+        assert(priority);
+
+        if ((*p)[0] != '<')
+                return;
+
+        if (!strchr(*p, '>'))
+                return;
+
+        if ((*p)[2] == '>') {
+                c = undecchar((*p)[1]);
+                k = 3;
+        } else if ((*p)[3] == '>') {
+                b = undecchar((*p)[1]);
+                c = undecchar((*p)[2]);
+                k = 4;
+        } else if ((*p)[4] == '>') {
+                a = undecchar((*p)[1]);
+                b = undecchar((*p)[2]);
+                c = undecchar((*p)[3]);
+                k = 5;
+        } else
+                return;
+
+        if (a < 0 || b < 0 || c < 0)
+                return;
+
+        *priority = a*100+b*10+c;
+        *p += k;
+}
+
 static int stream_log(Stream *s, char *p, usec_t ts) {
 
         char header_priority[16], header_time[64], header_pid[16];
@@ -104,6 +140,9 @@ static int stream_log(Stream *s, char *p, usec_t ts) {
 
         priority = s->priority;
 
+        if (s->prefix)
+                parse_priority(&p, &priority);
+
         if (s->prefix &&
             p[0] == '<' &&
             p[1] >= '0' && p[1] <= '7' &&
@@ -118,6 +157,10 @@ static int stream_log(Stream *s, char *p, usec_t ts) {
         if (*p == 0)
                 return 0;
 
+        /* Patch in LOG_USER facility if necessary */
+        if (LOG_FAC(priority) == 0)
+                priority = LOG_MAKEPRI(LOG_USER, LOG_PRI(priority));
+
         /*
          * The format glibc uses to talk to the syslog daemon is:
          *
@@ -130,8 +173,7 @@ static int stream_log(Stream *s, char *p, usec_t ts) {
          *  We extend the latter to include the process name and pid.
          */
 
-        snprintf(header_priority, sizeof(header_priority), "<%i>",
-                 s->target == STREAM_SYSLOG ? priority : LOG_PRI(priority));
+        snprintf(header_priority, sizeof(header_priority), "<%i>", priority);
         char_array_0(header_priority);
 
         if (s->target == STREAM_SYSLOG) {