]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #2424 from keszybz/journald-disk-usage
authorLennart Poettering <lennart@poettering.net>
Tue, 26 Jan 2016 13:20:45 +0000 (14:20 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 26 Jan 2016 13:20:45 +0000 (14:20 +0100)
Journald disk usage

1  2 
catalog/systemd.catalog
src/journal/journald-server.c

diff --combined catalog/systemd.catalog
index 696f4ed6181830f361bfe1ee6edc47c05d3fe298,2ca9beb04537c0ba3391cf63e83acc9728b7fa78..10255906810c015aa8e154e542f8e2ce1ce6770c
@@@ -1,4 -1,3 +1,4 @@@
 +# -*- fill-column: 79; indent-tabs-mode: nil -*-
  #  This file is part of systemd.
  #
  #  Copyright 2012 Lennart Poettering
@@@ -39,6 -38,21 +39,21 @@@ Support: http://lists.freedesktop.org/m
  The system journal process has shut down and closed all currently
  active journal files.
  
+ -- ec387f577b844b8fa948f33cad9a75e6
+ Subject: Disk space used by the journal
+ Defined-By: systemd
+ Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
+ @JOURNAL_NAME@ (@JOURNAL_PATH@) is currently using @CURRENT_USE_PRETTY@.
+ Maximum allowed usage is set to @MAX_USE_PRETTY@.
+ Leaving at least @DISK_KEEP_FREE_PRETTY@ free (of currently available @DISK_AVAILABLE_PRETTY@ of disk space).
+ Enforced usage limit is thus @LIMIT_PRETTY@, of which @AVAILABLE_PRETTY@ are still available.
+ The limits controlling how much disk space is used by the journal may
+ be configured with SystemMaxUse=, SystemKeepFree=, SystemMaxFileSize=,
+ RuntimeMaxUse=, RuntimeKeepFree=, RuntimeMaxFileSize= settings in
+ /etc/systemd/journald.conf. See journald.conf(5) for details.
  -- a596d6fe7bfa4994828e72309e95d61e
  Subject: Messages from a service have been suppressed
  Defined-By: systemd
@@@ -279,42 -293,3 +294,42 @@@ Support: http://lists.freedesktop.org/m
  
  The virtual machine @NAME@ with its leader PID @LEADER@ has been
  shut down.
 +
 +-- 36db2dfa5a9045e1bd4af5f93e1cf057
 +Subject: DNSSEC mode has been turned off, as server doesn't support it
 +Defined-By: systemd
 +Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
 +Documentation: man:systemd-resolved.service(8) resolved.conf(5)
 +
 +The resolver service (systemd-resolved.service) has detected that the
 +configured DNS server does not support DNSSEC, and DNSSEC validation has been
 +turned off as result.
 +
 +This event will take place if DNSSEC=allow-downgrade is configured in
 +resolved.conf and the configured DNS server is incompatible with DNSSEC. Note
 +that using this mode permits DNSSEC downgrade attacks, as an attacker might be
 +able turn off DNSSEC validation on the system by inserting DNS replies in the
 +communication channel that result in a downgrade like this.
 +
 +This event might be indication that the DNS server is indeed incompatible with
 +DNSSEC or that an attacker has successfully managed to stage such a downgrade
 +attack.
 +
 +-- 1675d7f172174098b1108bf8c7dc8f5d
 +Subject: DNSSEC validation failed
 +Defined-By: systemd
 +Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
 +Documentation: man:systemd-resolved.service(8)
 +
 +A DNS query or resource record set failed DNSSEC validation. This is usually
 +indication that the communication channel used was tampered with.
 +
 +-- 4d4408cfd0d144859184d1e65d7c8a65
 +Subject: A DNSSEC trust anchor has been revoked
 +Defined-By: systemd
 +Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
 +Documentation: man:systemd-resolved.service(8)
 +
 +A DNSSEC trust anchor has been revoked. A new trust anchor has to be
 +configured, or the operating system needs to be updated, to provide an updated
 +DNSSEC trust anchor.
index c3add87ed10b5fcdb16d04f1cc3f861809698b75,f55e46382dbb3273f61dedcc5b2b185a83fe845b..8c1b064e8664a8a447a7e074d8e074c07d2fc2cc
  #include "selinux-util.h"
  #include "signal-util.h"
  #include "socket-util.h"
+ #include "stdio-util.h"
  #include "string-table.h"
  #include "string-util.h"
  #include "user-util.h"
+ #include "log.h"
  
  #define USER_JOURNALS_MAX 1024
  
@@@ -82,9 -84,6 +84,9 @@@
  
  #define NOTIFY_SNDBUF_SIZE (8*1024*1024)
  
 +/* The period to insert between posting changes for coalescing */
 +#define POST_CHANGE_TIMER_INTERVAL_USEC (250*USEC_PER_MSEC)
 +
  static int determine_space_for(
                  Server *s,
                  JournalMetrics *metrics,
                  sum += (uint64_t) st.st_blocks * 512UL;
          }
  
-         /* If request, then let's bump the min_use limit to the
+         /* If requested, then let's bump the min_use limit to the
           * current usage on disk. We do this when starting up and
           * first opening the journal files. This way sudden spikes in
           * disk usage will not cause journald to vacuum files without
          if (verbose) {
                  char    fb1[FORMAT_BYTES_MAX], fb2[FORMAT_BYTES_MAX], fb3[FORMAT_BYTES_MAX],
                          fb4[FORMAT_BYTES_MAX], fb5[FORMAT_BYTES_MAX], fb6[FORMAT_BYTES_MAX];
+                 format_bytes(fb1, sizeof(fb1), sum);
+                 format_bytes(fb2, sizeof(fb2), metrics->max_use);
+                 format_bytes(fb3, sizeof(fb3), metrics->keep_free);
+                 format_bytes(fb4, sizeof(fb4), ss_avail);
+                 format_bytes(fb5, sizeof(fb5), s->cached_space_limit);
+                 format_bytes(fb6, sizeof(fb6), s->cached_space_available);
  
                  server_driver_message(s, SD_MESSAGE_JOURNAL_USAGE,
-                                       "%s (%s) is currently using %s.\n"
-                                       "Maximum allowed usage is set to %s.\n"
-                                       "Leaving at least %s free (of currently available %s of space).\n"
-                                       "Enforced usage limit is thus %s, of which %s are still available.",
-                                       name, path,
-                                       format_bytes(fb1, sizeof(fb1), sum),
-                                       format_bytes(fb2, sizeof(fb2), metrics->max_use),
-                                       format_bytes(fb3, sizeof(fb3), metrics->keep_free),
-                                       format_bytes(fb4, sizeof(fb4), ss_avail),
-                                       format_bytes(fb5, sizeof(fb5), s->cached_space_limit),
-                                       format_bytes(fb6, sizeof(fb6), s->cached_space_available));
+                                       LOG_MESSAGE("%s (%s) is %s, max %s, %s free.",
+                                                   name, path, fb1, fb5, fb6),
+                                       "JOURNAL_NAME=%s", name,
+                                       "JOURNAL_PATH=%s", path,
+                                       "CURRENT_USE=%"PRIu64, sum,
+                                       "CURRENT_USE_PRETTY=%s", fb1,
+                                       "MAX_USE=%"PRIu64, metrics->max_use,
+                                       "MAX_USE_PRETTY=%s", fb2,
+                                       "DISK_KEEP_FREE=%"PRIu64, metrics->keep_free,
+                                       "DISK_KEEP_FREE_PRETTY=%s", fb3,
+                                       "DISK_AVAILABLE=%"PRIu64, ss_avail,
+                                       "DISK_AVAILABLE_PRETTY=%s", fb4,
+                                       "LIMIT=%"PRIu64, s->cached_space_limit,
+                                       "LIMIT_PRETTY=%s", fb5,
+                                       "AVAILABLE=%"PRIu64, s->cached_space_available,
+                                       "AVAILABLE_PRETTY=%s", fb6,
+                                       NULL);
          }
  
          if (available)
@@@ -223,38 -234,6 +237,38 @@@ static void server_add_acls(JournalFil
  #endif
  }
  
 +static int open_journal(
 +                Server *s,
 +                bool reliably,
 +                const char *fname,
 +                int flags,
 +                bool seal,
 +                JournalMetrics *metrics,
 +                JournalFile *template,
 +                JournalFile **ret) {
 +        int r;
 +
 +        assert(s);
 +        assert(fname);
 +        assert(ret);
 +
 +        if (reliably)
 +                r = journal_file_open_reliably(fname, flags, 0640, s->compress, seal, metrics, s->mmap, template, ret);
 +        else
 +                r = journal_file_open(fname, flags, 0640, s->compress, seal, metrics, s->mmap, template, ret);
 +
 +        if (r < 0)
 +                return r;
 +
 +        r = journal_file_enable_post_change_timer(*ret, s->event, POST_CHANGE_TIMER_INTERVAL_USEC);
 +        if (r < 0) {
 +                *ret = journal_file_close(*ret);
 +                return r;
 +        }
 +
 +        return r;
 +}
 +
  static JournalFile* find_journal(Server *s, uid_t uid) {
          _cleanup_free_ char *p = NULL;
          int r;
                  journal_file_close(f);
          }
  
 -        r = journal_file_open_reliably(p, O_RDWR|O_CREAT, 0640, s->compress, s->seal, &s->system_metrics, s->mmap, NULL, &f);
 +        r = open_journal(s, true, p, O_RDWR|O_CREAT, s->seal, &s->system_metrics, NULL, &f);
          if (r < 0)
                  return s->system_journal;
  
@@@ -843,9 -822,9 +857,9 @@@ static void dispatch_message_real
  
  void server_driver_message(Server *s, sd_id128_t message_id, const char *format, ...) {
          char mid[11 + 32 + 1];
-         char buffer[16 + LINE_MAX + 1];
-         struct iovec iovec[N_IOVEC_META_FIELDS + 6];
-         int n = 0;
+         struct iovec iovec[N_IOVEC_META_FIELDS + 5 + N_IOVEC_PAYLOAD_FIELDS];
+         unsigned n = 0, m;
+         int r;
          va_list ap;
          struct ucred ucred = {};
  
          IOVEC_SET_STRING(iovec[n++], "SYSLOG_FACILITY=3");
          IOVEC_SET_STRING(iovec[n++], "SYSLOG_IDENTIFIER=systemd-journald");
  
-         IOVEC_SET_STRING(iovec[n++], "PRIORITY=6");
          IOVEC_SET_STRING(iovec[n++], "_TRANSPORT=driver");
-         memcpy(buffer, "MESSAGE=", 8);
-         va_start(ap, format);
-         vsnprintf(buffer + 8, sizeof(buffer) - 8, format, ap);
-         va_end(ap);
-         IOVEC_SET_STRING(iovec[n++], buffer);
+         IOVEC_SET_STRING(iovec[n++], "PRIORITY=6");
  
          if (!sd_id128_equal(message_id, SD_ID128_NULL)) {
                  snprintf(mid, sizeof(mid), LOG_MESSAGE_ID(message_id));
                  IOVEC_SET_STRING(iovec[n++], mid);
          }
  
+         m = n;
+         va_start(ap, format);
+         r = log_format_iovec(iovec, ELEMENTSOF(iovec), &n, false, 0, format, ap);
+         /* Error handling below */
+         va_end(ap);
          ucred.pid = getpid();
          ucred.uid = getuid();
          ucred.gid = getgid();
  
-         dispatch_message_real(s, iovec, n, ELEMENTSOF(iovec), &ucred, NULL, NULL, 0, NULL, LOG_INFO, 0);
+         if (r >= 0)
+                 dispatch_message_real(s, iovec, n, ELEMENTSOF(iovec), &ucred, NULL, NULL, 0, NULL, LOG_INFO, 0);
+         while (m < n)
+                 free(iovec[m++].iov_base);
+         if (r < 0) {
+                 /* We failed to format the message. Emit a warning instead. */
+                 char buf[LINE_MAX];
+                 xsprintf(buf, "MESSAGE=Entry printing failed: %s", strerror(-r));
+                 n = 3;
+                 IOVEC_SET_STRING(iovec[n++], "PRIORITY=4");
+                 IOVEC_SET_STRING(iovec[n++], buf);
+                 dispatch_message_real(s, iovec, n, ELEMENTSOF(iovec), &ucred, NULL, NULL, 0, NULL, LOG_INFO, 0);
+         }
  }
  
  void server_dispatch_message(
          /* Write a suppression message if we suppressed something */
          if (rl > 1)
                  server_driver_message(s, SD_MESSAGE_JOURNAL_DROPPED,
-                                       "Suppressed %u messages from %s", rl - 1, path);
+                                       LOG_MESSAGE("Suppressed %u messages from %s", rl - 1, path),
+                                       NULL);
  
  finish:
          dispatch_message_real(s, iovec, n, m, ucred, tv, label, label_len, unit_id, priority, object_pid);
@@@ -965,7 -962,7 +997,7 @@@ static int system_journal_open(Server *
                  (void) mkdir(fn, 0755);
  
                  fn = strjoina(fn, "/system.journal");
 -                r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, s->compress, s->seal, &s->system_metrics, s->mmap, NULL, &s->system_journal);
 +                r = open_journal(s, true, fn, O_RDWR|O_CREAT, s->seal, &s->system_metrics, NULL, &s->system_journal);
                  if (r >= 0) {
                          server_add_acls(s->system_journal, 0);
                          (void) determine_space_for(s, &s->system_metrics, "/var/log/journal/", "System journal", true, true, NULL, NULL);
                           * if it already exists, so that we can flush
                           * it into the system journal */
  
 -                        r = journal_file_open(fn, O_RDWR, 0640, s->compress, false, &s->runtime_metrics, s->mmap, NULL, &s->runtime_journal);
 +                        r = open_journal(s, false, fn, O_RDWR, false, &s->runtime_metrics, NULL, &s->runtime_journal);
                          if (r < 0) {
                                  if (r != -ENOENT)
                                          log_warning_errno(r, "Failed to open runtime journal: %m");
                          (void) mkdir("/run/log/journal", 0755);
                          (void) mkdir_parents(fn, 0750);
  
 -                        r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, s->compress, false, &s->runtime_metrics, s->mmap, NULL, &s->runtime_journal);
 +                        r = open_journal(s, true, fn, O_RDWR|O_CREAT, false, &s->runtime_metrics, NULL, &s->runtime_journal);
                          if (r < 0)
                                  return log_error_errno(r, "Failed to open runtime journal: %m");
                  }
@@@ -1108,7 -1105,11 +1140,11 @@@ finish
  
          sd_journal_close(j);
  
-         server_driver_message(s, SD_ID128_NULL, "Time spent on flushing to /var is %s for %u entries.", format_timespan(ts, sizeof(ts), now(CLOCK_MONOTONIC) - start, 0), n);
+         server_driver_message(s, SD_ID128_NULL,
+                               LOG_MESSAGE("Time spent on flushing to /var is %s for %u entries.",
+                                           format_timespan(ts, sizeof(ts), now(CLOCK_MONOTONIC) - start, 0),
+                                           n),
+                               NULL);
  
          return r;
  }