chiark / gitweb /
journal: simplify match_free_if_empty
[elogind.git] / src / journal / journald-server.c
index 4134e9fc67440a1b16eb9a9909090c486d0b616f..0bf557c809e3dbc056e24a0a5db330d04fdc6c63 100644 (file)
@@ -227,9 +227,11 @@ void server_fix_perms(Server *s, JournalFile *f, uid_t uid) {
                 }
         }
 
+        /* We do not recalculate the mask unconditionally here,
+         * so that the fchmod() mask above stays intact. */
         if (acl_get_permset(entry, &permset) < 0 ||
             acl_add_perm(permset, ACL_READ) < 0 ||
-            acl_calc_mask(&acl) < 0) {
+            calc_acl_mask_if_needed(&acl) < 0) {
                 log_warning("Failed to patch ACL on %s, ignoring: %m", f->path);
                 goto finish;
         }
@@ -508,7 +510,7 @@ static void dispatch_message_real(
                 source_time[sizeof("_SOURCE_REALTIME_TIMESTAMP=") + DECIMAL_STR_MAX(usec_t)],
                 boot_id[sizeof("_BOOT_ID=") + 32] = "_BOOT_ID=",
                 machine_id[sizeof("_MACHINE_ID=") + 32] = "_MACHINE_ID=";
-        char *comm, *exe, *cmdline, *cgroup, *session, *unit, *selinux_context, *hostname;
+        char *comm, *exe, *cmdline, *cgroup, *session, *unit, *hostname;
         sd_id128_t id;
         int r;
         char *t, *c;
@@ -615,7 +617,7 @@ static void dispatch_message_real(
 
 #ifdef HAVE_SELINUX
                 if (label) {
-                        selinux_context = alloca(sizeof("_SELINUX_CONTEXT=") + label_len);
+                        char *selinux_context = alloca(sizeof("_SELINUX_CONTEXT=") + label_len);
 
                         *((char*) mempcpy(stpcpy(selinux_context, "_SELINUX_CONTEXT="), label, label_len)) = 0;
                         IOVEC_SET_STRING(iovec[n++], selinux_context);
@@ -623,7 +625,8 @@ static void dispatch_message_real(
                         security_context_t con;
 
                         if (getpidcon(ucred->pid, &con) >= 0) {
-                                selinux_context = strappenda("_SELINUX_CONTEXT=", con);
+                                char *selinux_context = strappenda("_SELINUX_CONTEXT=", con);
+
                                 freecon(con);
                                 IOVEC_SET_STRING(iovec[n++], selinux_context);
                         }
@@ -777,6 +780,9 @@ static int system_journal_open(Server *s) {
         char *fn;
         sd_id128_t machine;
         char ids[33];
+        uint64_t avail;
+
+        avail = available_space(s);
 
         r = sd_id128_get_machine(&machine);
         if (r < 0)
@@ -818,6 +824,10 @@ static int system_journal_open(Server *s) {
                         server_driver_message(s, SD_ID128_NULL, "Allowing system journal files to grow to %s.",
                                               format_bytes(fb, sizeof(fb), s->system_metrics.max_use));
 
+                        if (s->system_metrics.max_use > avail)
+                               server_driver_message(s, SD_ID128_NULL, "Journal size currently limited to %s due to SystemKeepFree.",
+                                                     format_bytes(fb, sizeof(fb), avail));
+
                 } else if (r < 0) {
 
                         if (r != -ENOENT && r != -EROFS)
@@ -871,6 +881,10 @@ static int system_journal_open(Server *s) {
                         server_fix_perms(s, s->runtime_journal, 0);
                         server_driver_message(s, SD_ID128_NULL, "Allowing runtime journal files to grow to %s.",
                                               format_bytes(fb, sizeof(fb), s->runtime_metrics.max_use));
+
+                        if (s->system_metrics.max_use > avail)
+                               server_driver_message(s, SD_ID128_NULL, "Journal size currently limited to %s due to RuntimeKeepFree.",
+                                                     format_bytes(fb, sizeof(fb), avail));
                 }
         }
 
@@ -937,6 +951,12 @@ int server_flush_to_var(Server *s) {
                 server_rotate(s);
                 server_vacuum(s);
 
+                if (!s->system_journal) {
+                        log_notice("Didn't flush runtime journal since rotation of system journal wasn't successful.");
+                        r = -EIO;
+                        goto finish;
+                }
+
                 log_debug("Retrying write.");
                 r = journal_file_copy_entry(f, s->system_journal, o, f->current_offset, NULL, NULL, NULL);
                 if (r < 0) {
@@ -1270,7 +1290,7 @@ static int server_parse_proc_cmdline(Server *s) {
 }
 
 static int server_parse_config_file(Server *s) {
-        static const char *fn = "/etc/systemd/journald.conf";
+        static const char fn[] = "/etc/systemd/journald.conf";
         _cleanup_fclose_ FILE *f = NULL;
         int r;
 
@@ -1286,7 +1306,7 @@ static int server_parse_config_file(Server *s) {
         }
 
         r = config_parse(NULL, fn, f, "Journal\0", config_item_perf_lookup,
-                         (void*) journald_gperf_lookup, false, s);
+                         (void*) journald_gperf_lookup, false, false, s);
         if (r < 0)
                 log_warning("Failed to parse configuration file: %s", strerror(-r));
 
@@ -1325,10 +1345,9 @@ int server_schedule_sync(Server *s) {
                 return 0;
 
         if (s->sync_interval_usec) {
-                struct itimerspec sync_timer_enable = {
-                        .it_value.tv_sec = s->sync_interval_usec / USEC_PER_SEC,
-                        .it_value.tv_nsec = s->sync_interval_usec % MSEC_PER_SEC,
-                };
+                struct itimerspec sync_timer_enable = {};
+
+                timespec_store(&sync_timer_enable.it_value, s->sync_interval_usec);
 
                 r = timerfd_settime(s->sync_timer_fd, 0, &sync_timer_enable, NULL);
                 if (r < 0)