chiark / gitweb /
journald: log when we fail to forward messages to syslog
[elogind.git] / src / journal / journald.c
index 9d3f4260c757dbdd1c3208539751988c3a40906b..74c80f5a085a8b0b765656cfcb8c0ce4ca525127 100644 (file)
 #include "virt.h"
 #include "missing.h"
 #include "conf-parser.h"
-#include "journal-rate-limit.h"
 #include "journal-internal.h"
 #include "journal-vacuum.h"
 #include "journal-authenticate.h"
 #include "journald.h"
+#include "journald-rate-limit.h"
 #include "journald-kmsg.h"
 #include "journald-syslog.h"
 #include "journald-stream.h"
@@ -87,6 +87,15 @@ static const char* const storage_table[] = {
 DEFINE_STRING_TABLE_LOOKUP(storage, Storage);
 DEFINE_CONFIG_PARSE_ENUM(config_parse_storage, storage, Storage, "Failed to parse storage setting");
 
+static const char* const split_mode_table[] = {
+        [SPLIT_NONE] = "none",
+        [SPLIT_UID] = "uid",
+        [SPLIT_LOGIN] = "login"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(split_mode, SplitMode);
+DEFINE_CONFIG_PARSE_ENUM(config_parse_split_mode, split_mode, SplitMode, "Failed to parse split mode setting");
+
 static uint64_t available_space(Server *s) {
         char ids[33], *p;
         const char *f;
@@ -304,7 +313,7 @@ static void server_rotate(Server *s) {
         Iterator i;
         int r;
 
-        log_info("Rotating...");
+        log_debug("Rotating...");
 
         if (s->runtime_journal) {
                 r = journal_file_rotate(&s->runtime_journal, s->compress, false);
@@ -338,7 +347,7 @@ static void server_rotate(Server *s) {
                                 log_error("Failed to create user journal: %s", strerror(-r));
                 else {
                         hashmap_replace(s->user_journals, k, f);
-                        server_fix_perms(s, s->system_journal, PTR_TO_UINT32(k));
+                        server_fix_perms(s, f, PTR_TO_UINT32(k));
                 }
         }
 }
@@ -349,7 +358,7 @@ static void server_vacuum(Server *s) {
         sd_id128_t machine;
         int r;
 
-        log_info("Vacuuming...");
+        log_debug("Vacuuming...");
 
         r = sd_id128_get_machine(&machine);
         if (r < 0) {
@@ -360,7 +369,8 @@ static void server_vacuum(Server *s) {
         sd_id128_to_string(machine, ids);
 
         if (s->system_journal) {
-                if (asprintf(&p, "/var/log/journal/%s", ids) < 0) {
+                p = strappend("/var/log/journal/", ids);
+                if (!p) {
                         log_oom();
                         return;
                 }
@@ -372,7 +382,8 @@ static void server_vacuum(Server *s) {
         }
 
         if (s->runtime_journal) {
-                if (asprintf(&p, "/run/log/journal/%s", ids) < 0) {
+                p = strappend("/run/log/journal/", ids);
+                if (!p) {
                         log_oom();
                         return;
                 }
@@ -442,7 +453,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned
                 return;
 
         if (journal_file_rotate_suggested(f)) {
-                log_info("Journal header limits reached or header out-of-date, rotating.");
+                log_debug("Journal header limits reached or header out-of-date, rotating.");
                 server_rotate(s);
                 server_vacuum(s);
                 vacuumed = true;
@@ -473,11 +484,11 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned
                 }
 
                 if (r == -E2BIG || r == -EFBIG || r == EDQUOT || r == ENOSPC)
-                        log_info("Allocation limit reached, rotating.");
+                        log_debug("Allocation limit reached, rotating.");
                 else if (r == -EHOSTDOWN)
                         log_info("Journal file from other machine, rotating.");
                 else if (r == -EBUSY)
-                        log_info("Unlcean shutdown, rotating.");
+                        log_info("Unclean shutdown, rotating.");
                 else
                         log_warning("Journal file corrupted, rotating.");
 
@@ -489,7 +500,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned
                 if (!f)
                         return;
 
-                log_info("Retrying write.");
+                log_debug("Retrying write.");
         }
 }
 
@@ -657,7 +668,10 @@ static void dispatch_message_real(
 
         assert(n <= m);
 
-        write_to_journal(s, realuid == 0 ? 0 : loginuid, iovec, n);
+        write_to_journal(s,
+                         s->split_mode == SPLIT_NONE ? 0 :
+                         (s->split_mode == SPLIT_UID ? realuid :
+                          (realuid == 0 ? 0 : loginuid)), iovec, n);
 
         free(pid);
         free(uid);
@@ -888,7 +902,7 @@ static int server_flush_to_var(Server *s) {
         if (!s->system_journal)
                 return 0;
 
-        log_info("Flushing to /var...");
+        log_debug("Flushing to /var...");
 
         r = sd_id128_get_machine(&machine);
         if (r < 0) {
@@ -916,7 +930,7 @@ static int server_flush_to_var(Server *s) {
 
                 r = journal_file_copy_entry(f, s->system_journal, o, f->current_offset, NULL, NULL, NULL);
                 if (r == -E2BIG) {
-                        log_info("Allocation limit reached.");
+                        log_debug("Allocation limit reached.");
 
                         journal_file_post_change(s->system_journal);
                         server_rotate(s);
@@ -952,7 +966,7 @@ static int process_event(Server *s, struct epoll_event *ev) {
                 ssize_t n;
 
                 if (ev->events != EPOLLIN) {
-                        log_info("Got invalid event from epoll.");
+                        log_error("Got invalid event from epoll.");
                         return -EIO;
                 }
 
@@ -988,7 +1002,7 @@ static int process_event(Server *s, struct epoll_event *ev) {
                 int r;
 
                 if (ev->events != EPOLLIN) {
-                        log_info("Got invalid event from epoll.");
+                        log_error("Got invalid event from epoll.");
                         return -EIO;
                 }
 
@@ -1002,7 +1016,7 @@ static int process_event(Server *s, struct epoll_event *ev) {
                    ev->data.fd == s->syslog_fd) {
 
                 if (ev->events != EPOLLIN) {
-                        log_info("Got invalid event from epoll.");
+                        log_error("Got invalid event from epoll.");
                         return -EIO;
                 }
 
@@ -1130,7 +1144,7 @@ static int process_event(Server *s, struct epoll_event *ev) {
         } else if (ev->data.fd == s->stdout_fd) {
 
                 if (ev->events != EPOLLIN) {
-                        log_info("Got invalid event from epoll.");
+                        log_error("Got invalid event from epoll.");
                         return -EIO;
                 }
 
@@ -1141,7 +1155,7 @@ static int process_event(Server *s, struct epoll_event *ev) {
                 StdoutStream *stream;
 
                 if ((ev->events|EPOLLIN|EPOLLHUP) != (EPOLLIN|EPOLLHUP)) {
-                        log_info("Got invalid event from epoll.");
+                        log_error("Got invalid event from epoll.");
                         return -EIO;
                 }
 
@@ -1394,7 +1408,7 @@ static int server_init(Server *s) {
         return 0;
 }
 
-static void maybe_append_tags(Server *s) {
+static void server_maybe_append_tags(Server *s) {
 #ifdef HAVE_GCRYPT
         JournalFile *f;
         Iterator i;
@@ -1478,7 +1492,6 @@ int main(int argc, char *argv[]) {
 
         log_set_target(LOG_TARGET_SAFE);
         log_set_facility(LOG_SYSLOG);
-        log_set_max_level(LOG_DEBUG);
         log_parse_environment();
         log_open();
 
@@ -1539,7 +1552,8 @@ int main(int argc, char *argv[]) {
                                 break;
                 }
 
-                maybe_append_tags(&server);
+                server_maybe_append_tags(&server);
+                server_maybe_warn_forward_syslog_missed(&server);
         }
 
         log_debug("systemd-journald stopped as pid %lu", (unsigned long) getpid());