journald-server.c revision a9edaeff8481573764288ccf7e433a95b6dc7c03
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek This file is part of systemd.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek Copyright 2011 Lennart Poettering
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek (at your option) any later version.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek#include "journal-authenticate.h"
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek#define DEFAULT_SYNC_INTERVAL_USEC (5*USEC_PER_MINUTE)
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek#define DEFAULT_RATE_LIMIT_INTERVAL (30*USEC_PER_SEC)
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek#define DEFAULT_RATE_LIMIT_BURST 1000
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek#define DEFAULT_MAX_FILE_USEC USEC_PER_MONTH
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek#define RECHECK_AVAILABLE_SPACE_USEC (30*USEC_PER_SEC)
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic const char* const storage_table[_STORAGE_MAX] = {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek [STORAGE_VOLATILE] = "volatile",
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek [STORAGE_PERSISTENT] = "persistent",
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-SzmekDEFINE_STRING_TABLE_LOOKUP(storage, Storage);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-SzmekDEFINE_CONFIG_PARSE_ENUM(config_parse_storage, storage, Storage, "Failed to parse storage setting");
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekstatic const char* const split_mode_table[_SPLIT_MAX] = {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-SzmekDEFINE_STRING_TABLE_LOOKUP(split_mode, SplitMode);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-SzmekDEFINE_CONFIG_PARSE_ENUM(config_parse_split_mode, split_mode, SplitMode, "Failed to parse split mode setting");
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekstatic uint64_t available_space(Server *s, bool verbose) {
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek uint64_t sum = 0, ss_avail = 0, avail = 0;
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek _cleanup_closedir_ DIR *d = NULL;
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek if (s->cached_available_space_timestamp + RECHECK_AVAILABLE_SPACE_USEC > ts
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek return s->cached_available_space;
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek r = sd_id128_get_machine(&machine);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek p = strappend(f, sd_id128_to_string(machine, ids));
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek if (fstatvfs(dirfd(d), &ss) < 0)
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek if (!endswith(de->d_name, ".journal") &&
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek !endswith(de->d_name, ".journal~"))
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0)
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek sum += (uint64_t) st.st_blocks * 512UL;
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek ss_avail = ss.f_bsize * ss.f_bavail;
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek /* If we reached a high mark, we will always allow this much
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek * again, unless usage goes above max_use. This watermark
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek * value is cached so that we don't give up space on pressure,
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek * but hover below the maximum usage. */
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek avail = LESS_BY(ss_avail, m->keep_free);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek s->cached_available_space = LESS_BY(MIN(m->max_use, avail), sum);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek s->cached_available_space_timestamp = ts;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek char fb1[FORMAT_BYTES_MAX], fb2[FORMAT_BYTES_MAX], fb3[FORMAT_BYTES_MAX],
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek fb4[FORMAT_BYTES_MAX], fb5[FORMAT_BYTES_MAX];
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek server_driver_message(s, SD_MESSAGE_JOURNAL_USAGE,
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "%s journal is using %s (max allowed %s, "
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "trying to leave %s free of %s available → current limit %s).",
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek s->system_journal ? "Permanent" : "Runtime",
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek format_bytes(fb1, sizeof(fb1), sum),
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek format_bytes(fb2, sizeof(fb2), m->max_use),
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek format_bytes(fb3, sizeof(fb3), m->keep_free),
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek format_bytes(fb4, sizeof(fb4), ss_avail),
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek format_bytes(fb5, sizeof(fb5), s->cached_available_space + sum));
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek return s->cached_available_space;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekvoid server_fix_perms(Server *s, JournalFile *f, uid_t uid) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_warning_errno(r, "Failed to fix access mode on %s, ignoring: %m", f->path);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_warning_errno(errno, "Failed to read ACL on %s, ignoring: %m", f->path);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = acl_find_uid(acl, uid, &entry);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek acl_set_tag_type(entry, ACL_USER) < 0 ||
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek acl_set_qualifier(entry, &uid) < 0) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_warning_errno(errno, "Failed to patch ACL on %s, ignoring: %m", f->path);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek /* We do not recalculate the mask unconditionally here,
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek * so that the fchmod() mask above stays intact. */
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (acl_get_permset(entry, &permset) < 0 ||
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek acl_add_perm(permset, ACL_READ) < 0 ||
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek calc_acl_mask_if_needed(&acl) < 0) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_warning_errno(errno, "Failed to patch ACL on %s, ignoring: %m", f->path);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_warning_errno(errno, "Failed to set ACL on %s, ignoring: %m", f->path);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic JournalFile* find_journal(Server *s, uid_t uid) {
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek /* We split up user logs only on /var, not on /run. If the
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek * runtime file is open, we write to it exclusively, in order
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek * to guarantee proper order as soon as we flush /run to
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek * /var and close the runtime file. */
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek r = sd_id128_get_machine(&machine);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek f = ordered_hashmap_get(s->user_journals, UINT32_TO_PTR(uid));
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (asprintf(&p, "/var/log/journal/" SD_ID128_FORMAT_STR "/user-"UID_FMT".journal",
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek SD_ID128_FORMAT_VAL(machine), uid) < 0)
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek while (ordered_hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek /* Too many open? Then let's close one */
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek f = ordered_hashmap_steal_first(s->user_journals);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = journal_file_open_reliably(p, O_RDWR|O_CREAT, 0640, s->compress, s->seal, &s->system_metrics, s->mmap, NULL, &f);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = ordered_hashmap_put(s->user_journals, UINT32_TO_PTR(uid), f);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic int do_rotate(Server *s, JournalFile **f, const char* name,
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = journal_file_rotate(f, s->compress, seal);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_error_errno(r, "Failed to rotate %s: %m",
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_error_errno(r, "Failed to create new %s journal: %m",
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek do_rotate(s, &s->runtime_journal, "runtime", false, 0);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek do_rotate(s, &s->system_journal, "system", s->seal, 0);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek ORDERED_HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
8201af08fa09c2bd0f005fbe262f27e2c5bd2d86Zbigniew Jędrzejewski-Szmek r = do_rotate(s, &f, "user", s->seal, PTR_TO_UINT32(k));
8201af08fa09c2bd0f005fbe262f27e2c5bd2d86Zbigniew Jędrzejewski-Szmek ordered_hashmap_replace(s->user_journals, k, f);
8201af08fa09c2bd0f005fbe262f27e2c5bd2d86Zbigniew Jędrzejewski-Szmek /* Old file has been closed and deallocated */
8201af08fa09c2bd0f005fbe262f27e2c5bd2d86Zbigniew Jędrzejewski-Szmek ordered_hashmap_remove(s->user_journals, k);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = journal_file_set_offline(s->system_journal);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_error_errno(r, "Failed to sync system journal: %m");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek ORDERED_HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = journal_file_set_offline(f);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_error_errno(r, "Failed to sync user journal: %m");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = sd_event_source_set_enabled(s->sync_event_source, SD_EVENT_OFF);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_error_errno(r, "Failed to disable sync timer source: %m");
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekstatic void do_vacuum(Server *s, char *ids, JournalFile *f, const char* path,
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek r = journal_directory_vacuum(p, metrics->max_use, s->max_retention_usec, &s->oldest_file_usec, false);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (r < 0 && r != -ENOENT)
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_error_errno(r, "Failed to vacuum %s: %m", p);
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek r = sd_id128_get_machine(&machine);
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek log_error_errno(r, "Failed to get machine ID: %m");
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek sd_id128_to_string(machine, ids);
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek do_vacuum(s, ids, s->system_journal, "/var/log/journal/", &s->system_metrics);
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek do_vacuum(s, ids, s->runtime_journal, "/run/log/journal/", &s->runtime_metrics);
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek s->cached_available_space_timestamp = 0;
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmekstatic void server_cache_machine_id(Server *s) {
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek sd_id128_to_string(id, stpcpy(s->machine_id_field, "_MACHINE_ID="));
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmekstatic void server_cache_boot_id(Server *s) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek sd_id128_to_string(id, stpcpy(s->boot_id_field, "_BOOT_ID="));
50a0b0717563d08c027a16a896bff8d7754eab9eZbigniew Jędrzejewski-Szmekstatic void server_cache_hostname(Server *s) {
5bc891206dd8eb4e4df58f502b0184b8426caf22Zbigniew Jędrzejewski-Szmekbool shall_try_append_again(JournalFile *f, int r) {
5bc891206dd8eb4e4df58f502b0184b8426caf22Zbigniew Jędrzejewski-Szmek /* -E2BIG Hit configured limit
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek -EFBIG Hit fs limit
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek -EDQUOT Quota limit hit
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek -ENOSPC Disk full
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek -EHOSTDOWN Other machine
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek -EBUSY Unclean shutdown
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek -EPROTONOSUPPORT Unsupported feature
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek -EBADMSG Corrupted
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek -ENODATA Truncated
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek -ESHUTDOWN Already archived */
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek if (r == -E2BIG || r == -EFBIG || r == -EDQUOT || r == -ENOSPC)
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek log_debug("%s: Allocation limit reached, rotating.", f->path);
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek log_info("%s: Journal file from other machine, rotating.", f->path);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_info("%s: Unclean shutdown, rotating.", f->path);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_info("%s: Unsupported feature, rotating.", f->path);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek else if (r == -EBADMSG || r == -ENODATA || r == ESHUTDOWN)
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_warning("%s: Journal file corrupted, rotating.", f->path);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, unsigned n, int priority) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (journal_file_rotate_suggested(f, s->max_file_usec)) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_debug("%s: Journal header limits reached or header out-of-date, rotating.", f->path);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek server_schedule_sync(s, priority);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (vacuumed || !shall_try_append_again(f, r)) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek for (i = 0; i < n; i++)
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_error_errno(r, "Failed to write entry (%d items, %zu bytes), ignoring: %m", n, size);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek for (i = 0; i < n; i++)
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek log_error_errno(r, "Failed to write entry (%d items, %zu bytes) despite vacuuming, ignoring: %m", n, size);
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek server_schedule_sync(s, priority);
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmekstatic void dispatch_message_real(
36f822c4bd077f9121757e24b6516e5c7ada63b5Zbigniew Jędrzejewski-Szmek struct iovec *iovec, unsigned n, unsigned m,
36f822c4bd077f9121757e24b6516e5c7ada63b5Zbigniew Jędrzejewski-Szmek const char *label, size_t label_len,
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek char pid[sizeof("_PID=") + DECIMAL_STR_MAX(pid_t)],
dad29dff1925a114e20d4eb7b47fca23c4f25fd7Lennart Poettering uid[sizeof("_UID=") + DECIMAL_STR_MAX(uid_t)],
dad29dff1925a114e20d4eb7b47fca23c4f25fd7Lennart Poettering gid[sizeof("_GID=") + DECIMAL_STR_MAX(gid_t)],
50a0b0717563d08c027a16a896bff8d7754eab9eZbigniew Jędrzejewski-Szmek owner_uid[sizeof("_SYSTEMD_OWNER_UID=") + DECIMAL_STR_MAX(uid_t)],
50a0b0717563d08c027a16a896bff8d7754eab9eZbigniew Jędrzejewski-Szmek source_time[sizeof("_SOURCE_REALTIME_TIMESTAMP=") + DECIMAL_STR_MAX(usec_t)],
1af719edc5958c01c19204fb68d6fc45c9eea85cZbigniew Jędrzejewski-Szmek o_uid[sizeof("OBJECT_UID=") + DECIMAL_STR_MAX(uid_t)],
1af719edc5958c01c19204fb68d6fc45c9eea85cZbigniew Jędrzejewski-Szmek o_gid[sizeof("OBJECT_GID=") + DECIMAL_STR_MAX(gid_t)],
1af719edc5958c01c19204fb68d6fc45c9eea85cZbigniew Jędrzejewski-Szmek o_owner_uid[sizeof("OBJECT_SYSTEMD_OWNER_UID=") + DECIMAL_STR_MAX(uid_t)];
dad29dff1925a114e20d4eb7b47fca23c4f25fd7Lennart Poettering uid_t realuid = 0, owner = 0, journal_uid;
dad29dff1925a114e20d4eb7b47fca23c4f25fd7Lennart Poettering char audit_session[sizeof("_AUDIT_SESSION=") + DECIMAL_STR_MAX(uint32_t)],
dad29dff1925a114e20d4eb7b47fca23c4f25fd7Lennart Poettering audit_loginuid[sizeof("_AUDIT_LOGINUID=") + DECIMAL_STR_MAX(uid_t)],
dad29dff1925a114e20d4eb7b47fca23c4f25fd7Lennart Poettering o_audit_session[sizeof("OBJECT_AUDIT_SESSION=") + DECIMAL_STR_MAX(uint32_t)],
dad29dff1925a114e20d4eb7b47fca23c4f25fd7Lennart Poettering o_audit_loginuid[sizeof("OBJECT_AUDIT_LOGINUID=") + DECIMAL_STR_MAX(uid_t)];
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek assert(n + N_IOVEC_META_FIELDS + (object_pid ? N_IOVEC_OBJECT_FIELDS : 0) <= m);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek sprintf(pid, "_PID="PID_FMT, ucred->pid);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], pid);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek sprintf(uid, "_UID="UID_FMT, ucred->uid);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], uid);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek sprintf(gid, "_GID="GID_FMT, ucred->gid);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], gid);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = get_process_comm(ucred->pid, &t);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek r = get_process_exe(ucred->pid, &t);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek r = get_process_cmdline(ucred->pid, 0, false, &t);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = get_process_capeff(ucred->pid, &t);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek x = strappenda("_CAP_EFFECTIVE=", t);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = audit_session_from_pid(ucred->pid, &audit);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek sprintf(audit_session, "_AUDIT_SESSION=%"PRIu32, audit);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], audit_session);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = audit_loginuid_from_pid(ucred->pid, &loginuid);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek sprintf(audit_loginuid, "_AUDIT_LOGINUID="UID_FMT, loginuid);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], audit_loginuid);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = cg_pid_get_path_shifted(ucred->pid, s->cgroup_root, &c);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek x = strappenda("_SYSTEMD_CGROUP=", c);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek session = strappenda("_SYSTEMD_SESSION=", t);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], session);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek if (cg_path_get_owner_uid(c, &owner) >= 0) {
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek sprintf(owner_uid, "_SYSTEMD_OWNER_UID="UID_FMT, owner);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], owner_uid);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek if (cg_path_get_unit(c, &t) >= 0) {
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek x = strappenda("_SYSTEMD_UNIT=", t);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek } else if (unit_id && !session) {
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek x = strappenda("_SYSTEMD_UNIT=", unit_id);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek if (cg_path_get_user_unit(c, &t) >= 0) {
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek x = strappenda("_SYSTEMD_USER_UNIT=", t);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek } else if (unit_id && session) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek x = strappenda("_SYSTEMD_USER_UNIT=", unit_id);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (cg_path_get_slice(c, &t) >= 0) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek x = strappenda("_SYSTEMD_SLICE=", t);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek x = strappenda("_SYSTEMD_UNIT=", unit_id);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek x = alloca(strlen("_SELINUX_CONTEXT=") + label_len + 1);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek *((char*) mempcpy(stpcpy(x, "_SELINUX_CONTEXT="), label, label_len)) = 0;
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (getpidcon(ucred->pid, &con) >= 0) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek x = strappenda("_SELINUX_CONTEXT=", con);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek r = get_process_uid(object_pid, &object_uid);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek sprintf(o_uid, "OBJECT_UID="UID_FMT, object_uid);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], o_uid);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek r = get_process_gid(object_pid, &object_gid);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek sprintf(o_gid, "OBJECT_GID="GID_FMT, object_gid);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], o_gid);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek r = get_process_comm(object_pid, &t);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek x = strappenda("OBJECT_COMM=", t);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek r = get_process_cmdline(object_pid, 0, false, &t);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek x = strappenda("OBJECT_CMDLINE=", t);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = audit_session_from_pid(object_pid, &audit);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek sprintf(o_audit_session, "OBJECT_AUDIT_SESSION=%"PRIu32, audit);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], o_audit_session);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = audit_loginuid_from_pid(object_pid, &loginuid);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek sprintf(o_audit_loginuid, "OBJECT_AUDIT_LOGINUID="UID_FMT, loginuid);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], o_audit_loginuid);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = cg_pid_get_path_shifted(object_pid, s->cgroup_root, &c);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek x = strappenda("OBJECT_SYSTEMD_CGROUP=", c);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek x = strappenda("OBJECT_SYSTEMD_SESSION=", t);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (cg_path_get_owner_uid(c, &owner) >= 0) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek sprintf(o_owner_uid, "OBJECT_SYSTEMD_OWNER_UID="UID_FMT, owner);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], o_owner_uid);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (cg_path_get_unit(c, &t) >= 0) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek x = strappenda("OBJECT_SYSTEMD_UNIT=", t);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (cg_path_get_user_unit(c, &t) >= 0) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek x = strappenda("OBJECT_SYSTEMD_USER_UNIT=", t);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], x);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek sprintf(source_time, "_SOURCE_REALTIME_TIMESTAMP=%llu", (unsigned long long) timeval_load(tv));
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], source_time);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek /* Note that strictly speaking storing the boot id here is
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek * redundant since the entry includes this in-line
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek * anyway. However, we need this indexed, too. */
4015ac5c321f34784f73bd91ae9d7855ed663e5eLennart Poettering IOVEC_SET_STRING(iovec[n++], s->boot_id_field);
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek if (!isempty(s->machine_id_field))
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], s->machine_id_field);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (!isempty(s->hostname_field))
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], s->hostname_field);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (s->split_mode == SPLIT_UID && realuid > 0)
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek /* Split up strictly by any UID */
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek else if (s->split_mode == SPLIT_LOGIN && realuid > 0 && owner_valid && owner > 0)
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek /* Split up by login UIDs. We do this only if the
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek * realuid is not root, in order not to accidentally
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek * leak privileged information to the user that is
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek * logged by a privileged process that is part of an
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek * unprivileged session.*/
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek write_to_journal(s, journal_uid, iovec, n, priority);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekvoid server_driver_message(Server *s, sd_id128_t message_id, const char *format, ...) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek struct iovec iovec[N_IOVEC_META_FIELDS + 4];
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], "PRIORITY=6");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], "_TRANSPORT=driver");
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek vsnprintf(buffer + 8, sizeof(buffer) - 8, format, ap);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], buffer);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (!sd_id128_equal(message_id, SD_ID128_NULL)) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek snprintf(mid, sizeof(mid), LOG_MESSAGE_ID(message_id));
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek IOVEC_SET_STRING(iovec[n++], mid);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek dispatch_message_real(s, iovec, n, ELEMENTSOF(iovec), &ucred, NULL, NULL, 0, NULL, LOG_INFO, 0);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek struct iovec *iovec, unsigned n, unsigned m,
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek const char *label, size_t label_len,
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek _cleanup_free_ char *path = NULL;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (LOG_PRI(priority) > s->max_level_store)
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;
r = server_open_syslog_socket(s);
r = server_open_native_socket(s);
r = server_open_stdout_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)