chiark / gitweb /
journald: ignore messages read from /proc/kmsg that we generated via /dev/kmsg
[elogind.git] / src / journal / journald.c
index 232457aa5b392dfbf77fd711379aef107b953d31..5ecb7f72d34a4e80742d51b78a82938bfd584022 100644 (file)
@@ -1692,8 +1692,8 @@ static int stdout_stream_new(Server *s) {
         }
 
 #ifdef HAVE_SELINUX
-        if (getpeercon(fd, &stream->security_context) < 0)
-                log_error("Failed to determine peer security context.");
+        if (getpeercon(fd, &stream->security_context) < 0 && errno != ENOPROTOOPT)
+                log_error("Failed to determine peer security context: %m");
 #endif
 
         if (shutdown(fd, SHUT_WR) < 0) {
@@ -1768,6 +1768,17 @@ static int parse_kernel_timestamp(char **_p, usec_t *t) {
         return 1;
 }
 
+static bool is_us(const char *pid) {
+        pid_t t;
+
+        assert(pid);
+
+        if (parse_pid(pid, &t) < 0)
+                return false;
+
+        return t == getpid();
+}
+
 static void proc_kmsg_line(Server *s, const char *p) {
         struct iovec iovec[N_IOVEC_META_FIELDS + 7];
         char *message = NULL, *syslog_priority = NULL, *syslog_pid = NULL, *syslog_facility = NULL, *syslog_identifier = NULL, *source_time = NULL;
@@ -1807,6 +1818,11 @@ static void proc_kmsg_line(Server *s, const char *p) {
         } else {
                 read_identifier(&p, &identifier, &pid);
 
+                /* Avoid any messages we generated ourselves via
+                 * log_info() and friends. */
+                if (is_us(pid))
+                        goto finish;
+
                 if (s->forward_to_syslog)
                         forward_syslog(s, priority, identifier, p, NULL, NULL);
 
@@ -1832,6 +1848,7 @@ static void proc_kmsg_line(Server *s, const char *p) {
 
         dispatch_message(s, iovec, n, ELEMENTSOF(iovec), NULL, NULL, NULL, 0, priority);
 
+finish:
         free(message);
         free(syslog_priority);
         free(syslog_identifier);
@@ -2774,7 +2791,7 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
-        log_set_target(LOG_TARGET_KMSG);
+        log_set_target(LOG_TARGET_SAFE);
         log_set_facility(LOG_SYSLOG);
         log_parse_environment();
         log_open();