journald-server.c revision 13790add4bf648fed816361794d8277a75253410
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff This file is part of systemd.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff Copyright 2011 Lennart Poettering
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff systemd is free software; you can redistribute it and/or modify it
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff under the terms of the GNU Lesser General Public License as published by
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff the Free Software Foundation; either version 2.1 of the License, or
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff (at your option) any later version.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff systemd is distributed in the hope that it will be useful, but
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff WITHOUT ANY WARRANTY; without even the implied warranty of
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff Lesser General Public License for more details.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff You should have received a copy of the GNU Lesser General Public License
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff along with systemd; If not, see <http://www.gnu.org/licenses/>.
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff#define DEFAULT_SYNC_INTERVAL_USEC (5*USEC_PER_MINUTE)
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff#define DEFAULT_RATE_LIMIT_INTERVAL (30*USEC_PER_SEC)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff#define RECHECK_AVAILABLE_SPACE_USEC (30*USEC_PER_SEC)
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffstatic const char* const storage_table[_STORAGE_MAX] = {
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael GraffDEFINE_CONFIG_PARSE_ENUM(config_parse_storage, storage, Storage, "Failed to parse storage setting");
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graffstatic const char* const split_mode_table[_SPLIT_MAX] = {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael GraffDEFINE_STRING_TABLE_LOOKUP(split_mode, SplitMode);
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael GraffDEFINE_CONFIG_PARSE_ENUM(config_parse_split_mode, split_mode, SplitMode, "Failed to parse split mode setting");
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graffstatic uint64_t available_space(Server *s, bool verbose) {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff const char *f;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff if (s->cached_available_space_timestamp + RECHECK_AVAILABLE_SPACE_USEC > ts
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff p = strappend(f, sd_id128_to_string(machine, ids));
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff /* If we reached a high mark, we will always allow this much
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * again, unless usage goes above max_use. This watermark
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * value is cached so that we don't give up space on pressure,
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * but hover below the maximum usage. */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff s->cached_available_space = LESS_BY(MIN(m->max_use, avail), sum);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff char fb1[FORMAT_BYTES_MAX], fb2[FORMAT_BYTES_MAX], fb3[FORMAT_BYTES_MAX],
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff server_driver_message(s, SD_MESSAGE_JOURNAL_USAGE,
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff "%s journal is using %s (max allowed %s, "
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff "trying to leave %s free of %s available → current limit %s).",
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff format_bytes(fb5, sizeof(fb5), s->cached_available_space + sum));
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffvoid server_fix_perms(Server *s, JournalFile *f, uid_t uid) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_warning_errno(r, "Failed to fix access mode on %s, ignoring: %m", f->path);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_warning_errno(errno, "Failed to read ACL on %s, ignoring: %m", f->path);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (r <= 0) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_warning_errno(errno, "Failed to patch ACL on %s, ignoring: %m", f->path);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff /* We do not recalculate the mask unconditionally here,
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * so that the fchmod() mask above stays intact. */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_warning_errno(errno, "Failed to patch ACL on %s, ignoring: %m", f->path);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_warning_errno(errno, "Failed to set ACL on %s, ignoring: %m", f->path);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffstatic JournalFile* find_journal(Server *s, uid_t uid) {
519b4a1a27c8b767a57a981dda69a3c6394bd49dMichael Graff /* We split up user logs only on /var, not on /run. If the
519b4a1a27c8b767a57a981dda69a3c6394bd49dMichael Graff * runtime file is open, we write to it exclusively, in order
519b4a1a27c8b767a57a981dda69a3c6394bd49dMichael Graff * to guarantee proper order as soon as we flush /run to
519b4a1a27c8b767a57a981dda69a3c6394bd49dMichael Graff * /var and close the runtime file. */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff f = ordered_hashmap_get(s->user_journals, UINT32_TO_PTR(uid));
519b4a1a27c8b767a57a981dda69a3c6394bd49dMichael Graff if (asprintf(&p, "/var/log/journal/" SD_ID128_FORMAT_STR "/user-"UID_FMT".journal",
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff while (ordered_hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff /* Too many open? Then let's close one */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff f = ordered_hashmap_steal_first(s->user_journals);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff r = journal_file_open_reliably(p, O_RDWR|O_CREAT, 0640, s->compress, s->seal, &s->system_metrics, s->mmap, NULL, &f);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff r = ordered_hashmap_put(s->user_journals, UINT32_TO_PTR(uid), f);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff r = journal_file_rotate(f, s->compress, seal);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_error_errno(r, "Failed to rotate %s: %m", (*f)->path);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_error_errno(r, "Failed to create new %s journal: %m", name);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff do_rotate(s, &s->runtime_journal, "runtime", false, 0);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff do_rotate(s, &s->system_journal, "system", s->seal, 0);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff ORDERED_HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff r = do_rotate(s, &f, "user", s->seal, PTR_TO_UINT32(k));
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff ordered_hashmap_replace(s->user_journals, k, f);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff /* Old file has been closed and deallocated */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff r = journal_file_set_offline(s->system_journal);
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff log_error_errno(r, "Failed to sync system journal: %m");
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff ORDERED_HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff log_error_errno(r, "Failed to sync user journal: %m");
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff r = sd_event_source_set_enabled(s->sync_event_source, SD_EVENT_OFF);
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff log_error_errno(r, "Failed to disable sync timer source: %m");
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff const char *id,
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff const char *p;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff r = journal_directory_vacuum(p, metrics->max_use, s->max_retention_usec, &s->oldest_file_usec, false);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff if (r < 0 && r != -ENOENT)
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff log_error_errno(r, "Failed to vacuum %s: %m", p);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_error_errno(r, "Failed to get machine ID: %m");
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff do_vacuum(s, ids, s->system_journal, "/var/log/journal/", &s->system_metrics);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff do_vacuum(s, ids, s->runtime_journal, "/run/log/journal/", &s->runtime_metrics);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffstatic void server_cache_machine_id(Server *s) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff sd_id128_to_string(id, stpcpy(s->machine_id_field, "_MACHINE_ID="));
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff sd_id128_to_string(id, stpcpy(s->boot_id_field, "_BOOT_ID="));
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffstatic bool shall_try_append_again(JournalFile *f, int r) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff /* -E2BIG Hit configured limit
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff -EFBIG Hit fs limit
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff -EDQUOT Quota limit hit
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff -ENOSPC Disk full
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff -EIO I/O error of some kind (mmap)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff -EHOSTDOWN Other machine
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff -EBUSY Unclean shutdown
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff -EPROTONOSUPPORT Unsupported feature
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff -EBADMSG Corrupted
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff -ENODATA Truncated
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff -ESHUTDOWN Already archived
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff -EIDRM Journal file has been deleted */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (r == -E2BIG || r == -EFBIG || r == -EDQUOT || r == -ENOSPC)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_debug("%s: Allocation limit reached, rotating.", f->path);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff else if (r == -EHOSTDOWN)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_info("%s: Journal file from other machine, rotating.", f->path);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff else if (r == -EBUSY)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_info("%s: Unclean shutdown, rotating.", f->path);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff else if (r == -EPROTONOSUPPORT)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_info("%s: Unsupported feature, rotating.", f->path);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff else if (r == -EBADMSG || r == -ENODATA || r == ESHUTDOWN)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_warning("%s: Journal file corrupted, rotating.", f->path);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff else if (r == -EIO)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_warning("%s: IO error, rotating.", f->path);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff else if (r == -EIDRM)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff log_warning("%s: Journal file has been deleted, rotating.", f->path);
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff return false;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffstatic void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned n, int priority) {
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff if (journal_file_rotate_suggested(f, s->max_file_usec)) {
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff log_debug("%s: Journal header limits reached or header out-of-date, rotating.", f->path);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff if (r >= 0) {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff if (vacuumed || !shall_try_append_again(f, r)) {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff log_error_errno(r, "Failed to write entry (%d items, %zu bytes), ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n));
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
50b5857f1ad137624a18ce67b26b9941e316b007Michael Graff log_error_errno(r, "Failed to write entry (%d items, %zu bytes) despite vacuuming, ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n));
3c5148c4d98af51d6dcb449c6dbd45fe8c645f61Michael Graff char pid[sizeof("_PID=") + DECIMAL_STR_MAX(pid_t)],
3c5148c4d98af51d6dcb449c6dbd45fe8c645f61Michael Graff uid[sizeof("_UID=") + DECIMAL_STR_MAX(uid_t)],
3c5148c4d98af51d6dcb449c6dbd45fe8c645f61Michael Graff gid[sizeof("_GID=") + DECIMAL_STR_MAX(gid_t)],
3c5148c4d98af51d6dcb449c6dbd45fe8c645f61Michael Graff owner_uid[sizeof("_SYSTEMD_OWNER_UID=") + DECIMAL_STR_MAX(uid_t)],
3c5148c4d98af51d6dcb449c6dbd45fe8c645f61Michael Graff source_time[sizeof("_SOURCE_REALTIME_TIMESTAMP=") + DECIMAL_STR_MAX(usec_t)],
3c5148c4d98af51d6dcb449c6dbd45fe8c645f61Michael Graff o_uid[sizeof("OBJECT_UID=") + DECIMAL_STR_MAX(uid_t)],
3c5148c4d98af51d6dcb449c6dbd45fe8c645f61Michael Graff o_gid[sizeof("OBJECT_GID=") + DECIMAL_STR_MAX(gid_t)],
3c5148c4d98af51d6dcb449c6dbd45fe8c645f61Michael Graff o_owner_uid[sizeof("OBJECT_SYSTEMD_OWNER_UID=") + DECIMAL_STR_MAX(uid_t)];
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff char audit_session[sizeof("_AUDIT_SESSION=") + DECIMAL_STR_MAX(uint32_t)],
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff audit_loginuid[sizeof("_AUDIT_LOGINUID=") + DECIMAL_STR_MAX(uid_t)],
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff o_audit_session[sizeof("OBJECT_AUDIT_SESSION=") + DECIMAL_STR_MAX(uint32_t)],
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff o_audit_loginuid[sizeof("OBJECT_AUDIT_LOGINUID=") + DECIMAL_STR_MAX(uid_t)];
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff assert(n + N_IOVEC_META_FIELDS + (object_pid ? N_IOVEC_OBJECT_FIELDS : 0) <= m);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (r >= 0) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (r >= 0) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff r = get_process_cmdline(ucred->pid, 0, false, &t);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (r >= 0) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (r >= 0) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff r = audit_session_from_pid(ucred->pid, &audit);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (r >= 0) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff sprintf(audit_session, "_AUDIT_SESSION=%"PRIu32, audit);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff r = audit_loginuid_from_pid(ucred->pid, &loginuid);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (r >= 0) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff sprintf(audit_loginuid, "_AUDIT_LOGINUID="UID_FMT, loginuid);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff r = cg_pid_get_path_shifted(ucred->pid, s->cgroup_root, &c);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (r >= 0) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (r >= 0) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff sprintf(owner_uid, "_SYSTEMD_OWNER_UID="UID_FMT, owner);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (cg_path_get_unit(c, &t) >= 0) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (cg_path_get_user_unit(c, &t) >= 0) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff x = strappenda("_SYSTEMD_USER_UNIT=", unit_id);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if (cg_path_get_slice(c, &t) >= 0) {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff } else if (unit_id) {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff x = alloca(strlen("_SELINUX_CONTEXT=") + label_len + 1);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff *((char*) mempcpy(stpcpy(x, "_SELINUX_CONTEXT="), label, label_len)) = 0;
assert(n <= m);
if (object_pid) {
free(t);
free(t);
free(t);
#ifdef HAVE_AUDIT
r = cg_path_get_session(c, &t);
free(t);
if (cg_path_get_unit(c, &t) >= 0) {
free(t);
if (cg_path_get_user_unit(c, &t) >= 0) {
free(t);
free(c);
assert(n <= m);
if (tv) {
assert(n <= m);
journal_uid = 0;
assert(s);
void server_dispatch_message(
Server *s,
const char *unit_id,
int priority,
int rl, r;
assert(s);
if (!ucred)
goto finish;
goto finish;
if (rl == 0)
char *fn;
if (!s->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);
if (!s->runtime_journal &&
if (!fn)
return -ENOMEM;
if (s->system_journal) {
r = journal_file_open(fn, O_RDWR, 0640, s->compress, false, &s->runtime_metrics, s->mmap, NULL, &s->runtime_journal);
if (r != -ENOENT)
r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, s->compress, false, &s->runtime_metrics, s->mmap, NULL, &s->runtime_journal);
if (s->runtime_journal)
available_space(s, true);
assert(s);
if (!s->runtime_journal)
system_journal_open(s, true);
if (!s->system_journal)
SD_JOURNAL_FOREACH(j) {
JournalFile *f;
f = j->current_file;
goto finish;
goto finish;
server_rotate(s);
server_vacuum(s);
if (!s->system_journal) {
r = -EIO;
goto finish;
goto 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);
assert(s);
return -EIO;
} control = {};
ssize_t n;
unsigned n_fds = 0;
size_t m;
return log_oom();
return -errno;
return -ECONNRESET;
s->buffer[n] = 0;
if (n > 0 && n_fds == 0)
else if (n_fds > 0)
if (n > 0 && n_fds == 0)
else if (n_fds > 0)
if (n > 0 && n_fds == 0)
else if (n_fds > 0)
static int dispatch_sigusr1(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
assert(s);
server_sync(s);
server_vacuum(s);
static int dispatch_sigusr2(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
assert(s);
server_rotate(s);
server_vacuum(s);
static int dispatch_sigterm(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
assert(s);
assert(s);
const char *w, *state;
size_t l;
if (!word)
return -ENOMEM;
s->forward_to_syslog = r;
s->forward_to_kmsg = r;
s->forward_to_console = r;
s->forward_to_wall = r;
assert(s);
assert(s);
server_sync(s);
assert(s);
server_sync(s);
if (s->sync_scheduled)
if (s->sync_interval_usec > 0) {
if (!s->sync_event_source) {
r = sd_event_add_time(
s->event,
&s->sync_event_source,
when, 0,
server_dispatch_sync, s);
s->sync_scheduled = true;
static int dispatch_hostname_change(sd_event_source *es, int fd, uint32_t revents, void *userdata) {
assert(s);
assert(s);
if (s->hostname_fd < 0)
r = sd_event_add_io(s->event, &s->hostname_event_source, s->hostname_fd, 0, dispatch_hostname_change, s);
if (r == -EPERM) {
strerror(-r));
int n, r, fd;
assert(s);
zero(*s);
s->compress = true;
s->seal = true;
s->sync_scheduled = false;
s->forward_to_wall = true;
if (!s->user_journals)
return log_oom();
if (!s->mmap)
return log_oom();
n = sd_listen_fds(true);
if (s->native_fd >= 0) {
return -EINVAL;
if (s->stdout_fd >= 0) {
return -EINVAL;
if (s->syslog_fd >= 0) {
return -EINVAL;
if (s->audit_fd >= 0) {
return -EINVAL;
if (!fds) {
if (!fds)
return log_oom();
return log_oom();
r = server_open_syslog_socket(s);
r = server_open_native_socket(s);
r = server_open_dev_kmsg(s);
r = server_open_audit(s);
r = server_open_kernel_seqnum(s);
r = server_open_hostname(s);
r = setup_signals(s);
if (!s->udev)
return -ENOMEM;
if (!s->rate_limit)
return -ENOMEM;
r = system_journal_open(s, false);
#ifdef HAVE_GCRYPT
JournalFile *f;
Iterator i;
usec_t n;
if (s->system_journal)
JournalFile *f;
assert(s);
while (s->stdout_streams)
if (s->system_journal)
if (s->runtime_journal)
if (s->rate_limit)
if (s->kernel_seqnum)
if (s->mmap)
if (s->udev)