X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournald-server.c;h=80c97364209405da735e70e40d31730eda8e7e81;hb=8ee8e53648bf45854d92b60e1e70c17a0cec3c3d;hp=cd4843c9862ed78973cb6f8fce69260830ad63cd;hpb=3d82301321afdcc4f2f8786883bd15b1a64c6e83;p=elogind.git diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index cd4843c98..80c973642 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -204,7 +204,7 @@ void server_fix_perms(Server *s, JournalFile *f, uid_t uid) { r = fchmod(f->fd, 0640); if (r < 0) - log_warning("Failed to fix access mode on %s, ignoring: %s", f->path, strerror(-r)); + log_warning_errno(r, "Failed to fix access mode on %s, ignoring: %m", f->path); #ifdef HAVE_ACL if (uid <= SYSTEM_UID_MAX) @@ -212,7 +212,7 @@ void server_fix_perms(Server *s, JournalFile *f, uid_t uid) { acl = acl_get_fd(f->fd); if (!acl) { - log_warning("Failed to read ACL on %s, ignoring: %m", f->path); + log_warning_errno(errno, "Failed to read ACL on %s, ignoring: %m", f->path); return; } @@ -222,7 +222,7 @@ void server_fix_perms(Server *s, JournalFile *f, uid_t uid) { if (acl_create_entry(&acl, &entry) < 0 || acl_set_tag_type(entry, ACL_USER) < 0 || acl_set_qualifier(entry, &uid) < 0) { - log_warning("Failed to patch ACL on %s, ignoring: %m", f->path); + log_warning_errno(errno, "Failed to patch ACL on %s, ignoring: %m", f->path); goto finish; } } @@ -232,12 +232,12 @@ void server_fix_perms(Server *s, JournalFile *f, uid_t uid) { if (acl_get_permset(entry, &permset) < 0 || acl_add_perm(permset, ACL_READ) < 0 || calc_acl_mask_if_needed(&acl) < 0) { - log_warning("Failed to patch ACL on %s, ignoring: %m", f->path); + log_warning_errno(errno, "Failed to patch ACL on %s, ignoring: %m", f->path); goto finish; } if (acl_set_fd(f->fd, acl) < 0) - log_warning("Failed to set ACL on %s, ignoring: %m", f->path); + log_warning_errno(errno, "Failed to set ACL on %s, ignoring: %m", f->path); finish: acl_free(acl); @@ -308,11 +308,11 @@ static int do_rotate(Server *s, JournalFile **f, const char* name, r = journal_file_rotate(f, s->compress, seal); if (r < 0) if (*f) - log_error("Failed to rotate %s: %s", - (*f)->path, strerror(-r)); + log_error_errno(r, "Failed to rotate %s: %m", + (*f)->path); else - log_error("Failed to create new %s journal: %s", - name, strerror(-r)); + log_error_errno(r, "Failed to create new %s journal: %m", + name); else server_fix_perms(s, *f, uid); return r; @@ -348,19 +348,19 @@ void server_sync(Server *s) { if (s->system_journal) { r = journal_file_set_offline(s->system_journal); if (r < 0) - log_error("Failed to sync system journal: %s", strerror(-r)); + log_error_errno(r, "Failed to sync system journal: %m"); } ORDERED_HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) { r = journal_file_set_offline(f); if (r < 0) - log_error("Failed to sync user journal: %s", strerror(-r)); + log_error_errno(r, "Failed to sync user journal: %m"); } if (s->sync_event_source) { r = sd_event_source_set_enabled(s->sync_event_source, SD_EVENT_OFF); if (r < 0) - log_error("Failed to disable sync timer source: %s", strerror(-r)); + log_error_errno(r, "Failed to disable sync timer source: %m"); } s->sync_scheduled = false; @@ -377,7 +377,7 @@ static void do_vacuum(Server *s, char *ids, JournalFile *f, const char* path, p = strappenda(path, ids); r = journal_directory_vacuum(p, metrics->max_use, s->max_retention_usec, &s->oldest_file_usec, false); if (r < 0 && r != -ENOENT) - log_error("Failed to vacuum %s: %s", p, strerror(-r)); + log_error_errno(r, "Failed to vacuum %s: %m", p); } void server_vacuum(Server *s) { @@ -391,7 +391,7 @@ void server_vacuum(Server *s) { r = sd_id128_get_machine(&machine); if (r < 0) { - log_error("Failed to get machine ID: %s", strerror(-r)); + log_error_errno(r, "Failed to get machine ID: %m"); return; } sd_id128_to_string(machine, ids); @@ -511,7 +511,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned for (i = 0; i < n; i++) size += iovec[i].iov_len; - log_error("Failed to write entry (%d items, %zu bytes), ignoring: %s", n, size, strerror(-r)); + log_error_errno(r, "Failed to write entry (%d items, %zu bytes), ignoring: %m", n, size); return; } @@ -530,7 +530,7 @@ static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned for (i = 0; i < n; i++) size += iovec[i].iov_len; - log_error("Failed to write entry (%d items, %zu bytes) despite vacuuming, ignoring: %s", n, size, strerror(-r)); + log_error_errno(r, "Failed to write entry (%d items, %zu bytes) despite vacuuming, ignoring: %m", n, size); } else server_schedule_sync(s, priority); } @@ -841,7 +841,7 @@ void server_driver_message(Server *s, sd_id128_t message_id, const char *format, IOVEC_SET_STRING(iovec[n++], buffer); if (!sd_id128_equal(message_id, SD_ID128_NULL)) { - snprintf(mid, sizeof(mid), MESSAGE_ID(message_id)); + snprintf(mid, sizeof(mid), LOG_MESSAGE_ID(message_id)); char_array_0(mid); IOVEC_SET_STRING(iovec[n++], mid); } @@ -927,10 +927,8 @@ static int system_journal_open(Server *s, bool flush_requested) { char ids[33]; r = sd_id128_get_machine(&machine); - if (r < 0) { - log_error("Failed to get machine id: %s", strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to get machine id: %m"); sd_id128_to_string(machine, ids); @@ -958,7 +956,7 @@ static int system_journal_open(Server *s, bool flush_requested) { server_fix_perms(s, s->system_journal, 0); else if (r < 0) { if (r != -ENOENT && r != -EROFS) - log_warning("Failed to open system journal: %s", strerror(-r)); + log_warning_errno(r, "Failed to open system journal: %m"); r = 0; } @@ -982,7 +980,7 @@ static int system_journal_open(Server *s, bool flush_requested) { if (r < 0) { if (r != -ENOENT) - log_warning("Failed to open runtime journal: %s", strerror(-r)); + log_warning_errno(r, "Failed to open runtime journal: %m"); r = 0; } @@ -999,10 +997,8 @@ static int system_journal_open(Server *s, bool flush_requested) { r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, s->compress, false, &s->runtime_metrics, s->mmap, NULL, &s->runtime_journal); free(fn); - if (r < 0) { - log_error("Failed to open runtime journal: %s", strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to open runtime journal: %m"); } if (s->runtime_journal) @@ -1045,10 +1041,8 @@ int server_flush_to_var(Server *s) { return r; r = sd_journal_open(&j, SD_JOURNAL_RUNTIME_ONLY); - if (r < 0) { - log_error("Failed to read runtime journal: %s", strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to read runtime journal: %m"); sd_journal_set_data_threshold(j, 0); @@ -1063,7 +1057,7 @@ int server_flush_to_var(Server *s) { r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o); if (r < 0) { - log_error("Can't read entry: %s", strerror(-r)); + log_error_errno(r, "Can't read entry: %m"); goto finish; } @@ -1072,7 +1066,7 @@ int server_flush_to_var(Server *s) { continue; if (!shall_try_append_again(s->system_journal, r)) { - log_error("Can't write entry: %s", strerror(-r)); + log_error_errno(r, "Can't write entry: %m"); goto finish; } @@ -1088,7 +1082,7 @@ int server_flush_to_var(Server *s) { log_debug("Retrying write."); r = journal_file_copy_entry(f, s->system_journal, o, f->current_offset, NULL, NULL, NULL); if (r < 0) { - log_error("Can't write entry: %s", strerror(-r)); + log_error_errno(r, "Can't write entry: %m"); goto finish; } } @@ -1180,7 +1174,7 @@ int process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userda if (errno == EINTR || errno == EAGAIN) return 0; - log_error("recvmsg() failed: %m"); + log_error_errno(errno, "recvmsg() failed: %m"); return -errno; } @@ -1311,7 +1305,7 @@ static int server_parse_proc_cmdline(Server *s) { r = proc_cmdline(&line); if (r < 0) { - log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); + log_warning_errno(r, "Failed to read /proc/cmdline, ignoring: %m"); return 0; } @@ -1357,10 +1351,11 @@ static int server_parse_proc_cmdline(Server *s) { static int server_parse_config_file(Server *s) { assert(s); - return config_parse(NULL, "/etc/systemd/journald.conf", NULL, - "Journal\0", - config_item_perf_lookup, journald_gperf_lookup, - false, false, true, s); + return config_parse_many("/etc/systemd/journald.conf", + CONF_DIRS_NULSTR("systemd/journald.conf"), + "Journal\0", + config_item_perf_lookup, journald_gperf_lookup, + false, s); } static int server_dispatch_sync(sd_event_source *es, usec_t t, void *userdata) { @@ -1437,10 +1432,8 @@ static int server_open_hostname(Server *s) { assert(s); s->hostname_fd = open("/proc/sys/kernel/hostname", O_RDONLY|O_CLOEXEC|O_NDELAY|O_NOCTTY); - if (s->hostname_fd < 0) { - log_error("Failed to open /proc/sys/kernel/hostname: %m"); - return -errno; - } + if (s->hostname_fd < 0) + return log_error_errno(errno, "Failed to open /proc/sys/kernel/hostname: %m"); r = sd_event_add_io(s->event, &s->hostname_event_source, s->hostname_fd, 0, dispatch_hostname_change, s); if (r < 0) { @@ -1453,15 +1446,12 @@ static int server_open_hostname(Server *s) { return 0; } - log_error("Failed to register hostname fd in event loop: %s", strerror(-r)); - return r; + return log_error_errno(r, "Failed to register hostname fd in event loop: %m"); } r = sd_event_source_set_priority(s->hostname_event_source, SD_EVENT_PRIORITY_IMPORTANT-10); - if (r < 0) { - log_error("Failed to adjust priority of host name event source: %s", strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to adjust priority of host name event source: %m"); return 0; } @@ -1514,18 +1504,14 @@ int server_init(Server *s) { return log_oom(); r = sd_event_default(&s->event); - if (r < 0) { - log_error("Failed to create event loop: %s", strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to create event loop: %m"); sd_event_set_watchdog(s->event, true); n = sd_listen_fds(true); - if (n < 0) { - log_error("Failed to read listening file descriptors from environment: %s", strerror(-n)); - return n; - } + if (n < 0) + return log_error_errno(n, "Failed to read listening file descriptors from environment: %m"); for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) { @@ -1566,8 +1552,16 @@ int server_init(Server *s) { s->audit_fd = fd; - } else - log_error("Unknown socket passed as file descriptor %d, ignoring.", fd); + } else { + log_warning("Unknown socket passed as file descriptor %d, ignoring.", fd); + + /* Let's close the fd, better be safe than + sorry. The fd might reference some resource + that we really want to release if we don't + make use of it. */ + + safe_close(fd); + } } r = server_open_syslog_socket(s);