chiark / gitweb /
journal: default ImportKernel=no until we make use of structured logging
[elogind.git] / src / journal / journald.c
index 98a155bdefa231ddec553e2dd184b86c9854a517..8d1b10d270aacbacfb5f2bd0ff053d329acd5c35 100644 (file)
@@ -111,6 +111,16 @@ struct StdoutStream {
         LIST_FIELDS(StdoutStream, stdout_stream);
 };
 
+static const char* const storage_table[] = {
+        [STORAGE_AUTO] = "auto",
+        [STORAGE_VOLATILE] = "volatile",
+        [STORAGE_PERMANENT] = "permanent",
+        [STORAGE_NONE] = "none"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(storage, Storage);
+DEFINE_CONFIG_PARSE_ENUM(config_parse_storage, storage, Storage, "Failed to parse storage setting");
+
 static int server_flush_to_var(Server *s);
 
 static uint64_t available_space(Server *s) {
@@ -397,7 +407,6 @@ static void server_vacuum(Server *s) {
                 free(p);
         }
 
-
         if (s->runtime_journal) {
                 if (asprintf(&p, "/run/log/journal/%s", ids) < 0) {
                         log_error("Out of memory.");
@@ -625,9 +634,7 @@ static void dispatch_message_real(
 
 retry:
         f = find_journal(s, realuid == 0 ? 0 : loginuid);
-        if (!f)
-                log_warning("Dropping message, as we can't find a place to store the data.");
-        else {
+        if (f) {
                 r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
 
                 if ((r == -E2BIG || /* hit limit */
@@ -1955,12 +1962,23 @@ static int system_journal_open(Server *s) {
 
         sd_id128_to_string(machine, ids);
 
-        if (!s->system_journal) {
+        if (!s->system_journal &&
+            (s->storage == STORAGE_PERMANENT ||
+             s->storage == STORAGE_AUTO)) {
+
+                /* If in auto mode: first try to create the machine
+                 * path, but not the prefix.
+                 *
+                 * If in permanent mode: create /var/log/journal and
+                 * the machine path */
+
+                if (s->storage & STORAGE_PERMANENT)
+                        (void) mkdir("/var/log/journal/", 0755);
 
-                /* First try to create the machine path, but not the prefix */
                 fn = strappend("/var/log/journal/", ids);
                 if (!fn)
                         return -ENOMEM;
+
                 (void) mkdir(fn, 0755);
                 free(fn);
 
@@ -1988,7 +2006,8 @@ static int system_journal_open(Server *s) {
                 }
         }
 
-        if (!s->runtime_journal) {
+        if (!s->runtime_journal &&
+            (s->storage != STORAGE_NONE)) {
 
                 fn = join("/run/log/journal/", ids, "/system.journal", NULL);
                 if (!fn)
@@ -2048,6 +2067,10 @@ static int server_flush_to_var(Server *s) {
 
         assert(s);
 
+        if (s->storage != STORAGE_AUTO &&
+            s->storage != STORAGE_PERMANENT)
+                return 0;
+
         if (!s->runtime_journal)
                 return 0;
 
@@ -2125,6 +2148,10 @@ static int server_read_proc_kmsg(Server *s) {
         assert(s->proc_kmsg_fd >= 0);
 
         l = read(s->proc_kmsg_fd, s->proc_kmsg_buffer + s->proc_kmsg_length, sizeof(s->proc_kmsg_buffer) - 1 - s->proc_kmsg_length);
+        if (l == 0) /* the kernel is stupid and in some race
+                     * conditions returns 0 in the middle of the
+                     * stream. */
+                return 0;
         if (l < 0) {
 
                 if (errno == EAGAIN || errno == EINTR)
@@ -2648,7 +2675,8 @@ static int server_parse_proc_cmdline(Server *s) {
                                 log_warning("Failed to parse forward to console switch %s. Ignoring.", word + 36);
                         else
                                 s->forward_to_console = r;
-                }
+                } else if (startswith(word, "systemd.journald"))
+                        log_warning("Invalid systemd.journald parameter. Ignoring.");
 
                 free(word);
         }
@@ -2699,7 +2727,6 @@ static int server_init(Server *s) {
         s->rate_limit_burst = DEFAULT_RATE_LIMIT_BURST;
 
         s->forward_to_syslog = true;
-        s->import_proc_kmsg = true;
 
         s->max_level_store = LOG_DEBUG;
         s->max_level_syslog = LOG_DEBUG;