journald-server.c revision 66518acd40fbd99a87e553b2d0904c37c8929fb2
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering This file is part of systemd.
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering Copyright 2011 Lennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering systemd is free software; you can redistribute it and/or modify it
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering under the terms of the GNU Lesser General Public License as published by
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering (at your option) any later version.
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering systemd is distributed in the hope that it will be useful, but
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering Lesser General Public License for more details.
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering You should have received a copy of the GNU Lesser General Public License
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering#define DEFAULT_SYNC_INTERVAL_USEC (5*USEC_PER_MINUTE)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering#define DEFAULT_RATE_LIMIT_INTERVAL (30*USEC_PER_SEC)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering#define DEFAULT_MAX_FILE_USEC USEC_PER_MONTH
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering#define RECHECK_AVAILABLE_SPACE_USEC (30*USEC_PER_SEC)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic const char* const storage_table[_STORAGE_MAX] = {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart PoetteringDEFINE_STRING_TABLE_LOOKUP(storage, Storage);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart PoetteringDEFINE_CONFIG_PARSE_ENUM(config_parse_storage, storage, Storage, "Failed to parse storage setting");
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic const char* const split_mode_table[_SPLIT_MAX] = {
599659860c770058f2eb04d578c521c16e0b1853Lennart PoetteringDEFINE_STRING_TABLE_LOOKUP(split_mode, SplitMode);
599659860c770058f2eb04d578c521c16e0b1853Lennart PoetteringDEFINE_CONFIG_PARSE_ENUM(config_parse_split_mode, split_mode, SplitMode, "Failed to parse split mode setting");
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic uint64_t available_space(Server *s, bool verbose) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering uint64_t sum = 0, ss_avail = 0, avail = 0;
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering const char *f;
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (s->cached_available_space_timestamp + RECHECK_AVAILABLE_SPACE_USEC > ts
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering p = strappend(f, sd_id128_to_string(machine, ids));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering /* If we reached a high mark, we will always allow this much
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering * again, unless usage goes above max_use. This watermark
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering * value is cached so that we don't give up space on pressure,
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering * but hover below the maximum usage. */
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering s->cached_available_space = LESS_BY(MIN(m->max_use, avail), sum);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering s->cached_available_space_timestamp = ts;
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering char fb1[FORMAT_BYTES_MAX], fb2[FORMAT_BYTES_MAX], fb3[FORMAT_BYTES_MAX],
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering fb4[FORMAT_BYTES_MAX], fb5[FORMAT_BYTES_MAX];
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering server_driver_message(s, SD_MESSAGE_JOURNAL_USAGE,
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering "%s journal is using %s (max allowed %s, "
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering "trying to leave %s free of %s available → current limit %s).",
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering s->system_journal ? "Permanent" : "Runtime",
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering format_bytes(fb2, sizeof(fb2), m->max_use),
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering format_bytes(fb3, sizeof(fb3), m->keep_free),
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering format_bytes(fb4, sizeof(fb4), ss_avail),
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering format_bytes(fb5, sizeof(fb5), s->cached_available_space + sum));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringvoid server_fix_perms(Server *s, JournalFile *f, uid_t uid) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_warning_errno(r, "Failed to fix access mode on %s, ignoring: %m", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_warning_errno(errno, "Failed to read ACL on %s, ignoring: %m", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (acl_create_entry(&acl, &entry) < 0 ||
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_warning_errno(errno, "Failed to patch ACL on %s, ignoring: %m", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering /* We do not recalculate the mask unconditionally here,
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering * so that the fchmod() mask above stays intact. */
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (acl_get_permset(entry, &permset) < 0 ||
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_warning_errno(errno, "Failed to patch ACL on %s, ignoring: %m", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_warning_errno(errno, "Failed to set ACL on %s, ignoring: %m", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic JournalFile* find_journal(Server *s, uid_t uid) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering /* We split up user logs only on /var, not on /run. If the
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering * runtime file is open, we write to it exclusively, in order
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering * to guarantee proper order as soon as we flush /run to
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering * /var and close the runtime file. */
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering f = ordered_hashmap_get(s->user_journals, UINT32_TO_PTR(uid));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (asprintf(&p, "/var/log/journal/" SD_ID128_FORMAT_STR "/user-"UID_FMT".journal",
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering while (ordered_hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering /* Too many open? Then let's close one */
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering f = ordered_hashmap_steal_first(s->user_journals);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = journal_file_open_reliably(p, O_RDWR|O_CREAT, 0640, s->compress, s->seal, &s->system_metrics, s->mmap, NULL, &f);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = ordered_hashmap_put(s->user_journals, UINT32_TO_PTR(uid), f);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = journal_file_rotate(f, s->compress, seal);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error_errno(r, "Failed to rotate %s: %m", (*f)->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error_errno(r, "Failed to create new %s journal: %m", name);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering do_rotate(s, &s->runtime_journal, "runtime", false, 0);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering do_rotate(s, &s->system_journal, "system", s->seal, 0);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering ORDERED_HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = do_rotate(s, &f, "user", s->seal, PTR_TO_UINT32(k));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering ordered_hashmap_replace(s->user_journals, k, f);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering /* Old file has been closed and deallocated */
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering ordered_hashmap_remove(s->user_journals, k);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = journal_file_set_offline(s->system_journal);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error_errno(r, "Failed to sync system journal: %m");
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering ORDERED_HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
f75cb30bf97f623417cc7ee4b1bcc5c36cdbeb20Dave Reisner log_error_errno(r, "Failed to sync user journal: %m");
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = sd_event_source_set_enabled(s->sync_event_source, SD_EVENT_OFF);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error_errno(r, "Failed to disable sync timer source: %m");
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering const char *p;
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = journal_directory_vacuum(p, metrics->max_use, s->max_retention_usec, &s->oldest_file_usec, false);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (r < 0 && r != -ENOENT)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error_errno(r, "Failed to vacuum %s: %m", p);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error_errno(r, "Failed to get machine ID: %m");
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering do_vacuum(s, ids, s->system_journal, "/var/log/journal/", &s->system_metrics);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering do_vacuum(s, ids, s->runtime_journal, "/run/log/journal/", &s->runtime_metrics);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic void server_cache_machine_id(Server *s) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sd_id128_to_string(id, stpcpy(s->machine_id_field, "_MACHINE_ID="));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic void server_cache_boot_id(Server *s) {
c978343015c787713651dff571acb5207367f5f2Lennart Poettering sd_id128_to_string(id, stpcpy(s->boot_id_field, "_BOOT_ID="));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic void server_cache_hostname(Server *s) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic bool shall_try_append_again(JournalFile *f, int r) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering /* -E2BIG Hit configured limit
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering -EFBIG Hit fs limit
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering -EDQUOT Quota limit hit
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering -ENOSPC Disk full
c978343015c787713651dff571acb5207367f5f2Lennart Poettering -EIO I/O error of some kind (mmap)
c978343015c787713651dff571acb5207367f5f2Lennart Poettering -EHOSTDOWN Other machine
c978343015c787713651dff571acb5207367f5f2Lennart Poettering -EBUSY Unclean shutdown
c978343015c787713651dff571acb5207367f5f2Lennart Poettering -EPROTONOSUPPORT Unsupported feature
c978343015c787713651dff571acb5207367f5f2Lennart Poettering -EBADMSG Corrupted
c978343015c787713651dff571acb5207367f5f2Lennart Poettering -ENODATA Truncated
c978343015c787713651dff571acb5207367f5f2Lennart Poettering -ESHUTDOWN Already archived
c978343015c787713651dff571acb5207367f5f2Lennart Poettering -EIDRM Journal file has been deleted */
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (r == -E2BIG || r == -EFBIG || r == -EDQUOT || r == -ENOSPC)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_debug("%s: Allocation limit reached, rotating.", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering else if (r == -EHOSTDOWN)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_info("%s: Journal file from other machine, rotating.", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering else if (r == -EBUSY)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_info("%s: Unclean shutdown, rotating.", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_info("%s: Unsupported feature, rotating.", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering else if (r == -EBADMSG || r == -ENODATA || r == ESHUTDOWN)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_warning("%s: Journal file corrupted, rotating.", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering else if (r == -EIO)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_warning("%s: IO error, rotating.", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering else if (r == -EIDRM)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_warning("%s: Journal file has been deleted, rotating.", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned n, int priority) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (journal_file_rotate_suggested(f, s->max_file_usec)) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_debug("%s: Journal header limits reached or header out-of-date, rotating.", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (vacuumed || !shall_try_append_again(f, r)) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error_errno(r, "Failed to write entry (%d items, %zu bytes), ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error_errno(r, "Failed to write entry (%d items, %zu bytes) despite vacuuming, ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering struct iovec *iovec, unsigned n, unsigned m,
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering char pid[sizeof("_PID=") + DECIMAL_STR_MAX(pid_t)],
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering uid[sizeof("_UID=") + DECIMAL_STR_MAX(uid_t)],
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering gid[sizeof("_GID=") + DECIMAL_STR_MAX(gid_t)],
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering owner_uid[sizeof("_SYSTEMD_OWNER_UID=") + DECIMAL_STR_MAX(uid_t)],
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering source_time[sizeof("_SOURCE_REALTIME_TIMESTAMP=") + DECIMAL_STR_MAX(usec_t)],
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering o_uid[sizeof("OBJECT_UID=") + DECIMAL_STR_MAX(uid_t)],
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering o_gid[sizeof("OBJECT_GID=") + DECIMAL_STR_MAX(gid_t)],
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering o_owner_uid[sizeof("OBJECT_SYSTEMD_OWNER_UID=") + DECIMAL_STR_MAX(uid_t)];
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering uid_t realuid = 0, owner = 0, journal_uid;
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering char audit_session[sizeof("_AUDIT_SESSION=") + DECIMAL_STR_MAX(uint32_t)],
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering audit_loginuid[sizeof("_AUDIT_LOGINUID=") + DECIMAL_STR_MAX(uid_t)],
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering o_audit_session[sizeof("OBJECT_AUDIT_SESSION=") + DECIMAL_STR_MAX(uint32_t)],
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering o_audit_loginuid[sizeof("OBJECT_AUDIT_LOGINUID=") + DECIMAL_STR_MAX(uid_t)];
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering assert(n + N_IOVEC_META_FIELDS + (object_pid ? N_IOVEC_OBJECT_FIELDS : 0) <= m);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sprintf(pid, "_PID="PID_FMT, ucred->pid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sprintf(uid, "_UID="UID_FMT, ucred->uid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sprintf(gid, "_GID="GID_FMT, ucred->gid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = get_process_cmdline(ucred->pid, 0, false, &t);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = audit_session_from_pid(ucred->pid, &audit);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sprintf(audit_session, "_AUDIT_SESSION=%"PRIu32, audit);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering IOVEC_SET_STRING(iovec[n++], audit_session);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = audit_loginuid_from_pid(ucred->pid, &loginuid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sprintf(audit_loginuid, "_AUDIT_LOGINUID="UID_FMT, loginuid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering IOVEC_SET_STRING(iovec[n++], audit_loginuid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = cg_pid_get_path_shifted(ucred->pid, s->cgroup_root, &c);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering session = strappenda("_SYSTEMD_SESSION=", t);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (cg_path_get_owner_uid(c, &owner) >= 0) {
owner_valid = true;
if (cg_path_get_unit(c, &t) >= 0) {
free(t);
if (cg_path_get_user_unit(c, &t) >= 0) {
free(t);
if (cg_path_get_slice(c, &t) >= 0) {
free(t);
free(c);
} else if (unit_id) {
#ifdef HAVE_SELINUX
if (mac_selinux_use()) {
if (label) {
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;
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)