journald-server.c revision 608c3dc5693177d9c297753a63349135a8edd76f
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)
1a5613266a93ddb197bbae137cd61fae25600718Lennart Poettering#define RECHECK_AVAILABLE_SPACE_USEC (30*USEC_PER_SEC)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringstatic const char* const storage_table[] = {
b92bea5d2a9481de69bb627a7b442a9f58fca43dZbigniew Jędrzejewski-Szmek [STORAGE_VOLATILE] = "volatile",
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[] = {
2311eb2ff0c3ff80ec3645b02c97170c9a565454Kay SieversDEFINE_STRING_TABLE_LOOKUP(split_mode, SplitMode);
2311eb2ff0c3ff80ec3645b02c97170c9a565454Kay SieversDEFINE_CONFIG_PARSE_ENUM(config_parse_split_mode, split_mode, SplitMode, "Failed to parse split mode setting");
2311eb2ff0c3ff80ec3645b02c97170c9a565454Kay Sieversstatic uint64_t available_space(Server *s, bool verbose) {
2311eb2ff0c3ff80ec3645b02c97170c9a565454Kay Sievers const char *f;
2311eb2ff0c3ff80ec3645b02c97170c9a565454Kay Sievers 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)
f18ca9dcdeda247e208f7143e834fd2fb2070d80Kay Sievers avail = ss_avail > m->keep_free ? ss_avail - m->keep_free : 0;
e2fd5e5ba281a22886fa3797dc6265cca670448bKay Sievers s->cached_available_space = MIN(m->max_use, avail) > sum ? MIN(m->max_use, avail) - sum : 0;
f18ca9dcdeda247e208f7143e834fd2fb2070d80Kay Sievers char fb1[FORMAT_BYTES_MAX], fb2[FORMAT_BYTES_MAX], fb3[FORMAT_BYTES_MAX],
2af32104c47dadf426f2e7697cd7382520476fc5Lennart Poettering server_driver_message(s, SD_MESSAGE_JOURNAL_USAGE,
f18ca9dcdeda247e208f7143e834fd2fb2070d80Kay Sievers "%s journal is using %s (max %s, leaving %s of free %s, current limit %s).",
2af32104c47dadf426f2e7697cd7382520476fc5Lennart Poettering format_bytes(fb2, sizeof(fb2), m->max_use),
3062c15117ab6eac5e8b3a3ceb5351ec22ea4481Lennart Poettering format_bytes(fb4, sizeof(fb4), ss_avail),
f18ca9dcdeda247e208f7143e834fd2fb2070d80Kay Sievers format_bytes(fb5, sizeof(fb5), MIN(m->max_use, avail)));
2af32104c47dadf426f2e7697cd7382520476fc5Lennart Poetteringstatic void server_read_file_gid(Server *s) {
f18ca9dcdeda247e208f7143e834fd2fb2070d80Kay Sievers const char *g = "systemd-journal";
f18ca9dcdeda247e208f7143e834fd2fb2070d80Kay Sievers log_warning("Failed to resolve '%s' group: %s", g, strerror(-r));
f18ca9dcdeda247e208f7143e834fd2fb2070d80Kay Sievers /* if we couldn't read the gid, then it will be 0, but that's
f18ca9dcdeda247e208f7143e834fd2fb2070d80Kay Sievers * fine and we shouldn't try to resolve the group again, so
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering * let's just pretend it worked right-away. */
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringvoid server_fix_perms(Server *s, JournalFile *f, uid_t uid) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = fchmod_and_fchown(f->fd, 0640, 0, s->file_gid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_warning("Failed to fix access mode/rights on %s, ignoring: %s", f->path, strerror(-r));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_warning("Failed to read ACL on %s, ignoring: %m", f->path);
1a5613266a93ddb197bbae137cd61fae25600718Lennart Poettering if (acl_create_entry(&acl, &entry) < 0 ||
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_warning("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 ||
b92bea5d2a9481de69bb627a7b442a9f58fca43dZbigniew Jędrzejewski-Szmek log_warning("Failed to patch ACL on %s, ignoring: %m", f->path);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_warning("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 = hashmap_get(s->user_journals, UINT32_TO_PTR(uid));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (asprintf(&p, "/var/log/journal/" SD_ID128_FORMAT_STR "/user-%lu.journal",
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering SD_ID128_FORMAT_VAL(machine), (unsigned long) uid) < 0)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering while (hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering /* Too many open? Then let's close one */
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering f = 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 = hashmap_put(s->user_journals, UINT32_TO_PTR(uid), f);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = journal_file_rotate(&s->runtime_journal, s->compress, false);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to rotate %s: %s", s->runtime_journal->path, strerror(-r));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to create new runtime journal: %s", strerror(-r));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering server_fix_perms(s, s->runtime_journal, 0);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = journal_file_rotate(&s->system_journal, s->compress, s->seal);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to rotate %s: %s", s->system_journal->path, strerror(-r));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to create new system journal: %s", strerror(-r));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering server_fix_perms(s, s->system_journal, 0);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
546158bc6f46f8004cc11e81d19d223e0da56730Jan Janssen r = journal_file_rotate(&f, s->compress, s->seal);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to rotate %s: %s", f->path, strerror(-r));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to create user journal: %s", strerror(-r));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering server_fix_perms(s, f, PTR_TO_UINT32(k));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering static const struct itimerspec sync_timer_disable = {};
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = journal_file_set_offline(s->system_journal);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to sync system journal: %s", strerror(-r));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to sync user journal: %s", strerror(-r));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = timerfd_settime(s->sync_timer_fd, 0, &sync_timer_disable, NULL);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to disable max timer: %m");
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to get machine ID: %s", strerror(-r));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering char *p = strappenda("/var/log/journal/", ids);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = journal_directory_vacuum(p, s->system_metrics.max_use, s->system_metrics.keep_free, s->max_retention_usec, &s->oldest_file_usec);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (r < 0 && r != -ENOENT)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to vacuum %s: %s", p, strerror(-r));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering char *p = strappenda("/run/log/journal/", ids);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = journal_directory_vacuum(p, s->runtime_metrics.max_use, s->runtime_metrics.keep_free, s->max_retention_usec, &s->oldest_file_usec);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (r < 0 && r != -ENOENT)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to vacuum %s: %s", p, strerror(-r));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringbool 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
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering -EHOSTDOWN Other machine
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering -EBUSY Unclean shutdown
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering -EPROTONOSUPPORT Unsupported feature
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering -EBADMSG Corrupted
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering -ENODATA Truncated
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering -ESHUTDOWN Already archived */
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 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 for (i = 0; i < n; i++)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to write entry (%d items, %zu bytes), ignoring: %s", n, size, strerror(-r));
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = journal_file_append_entry(f, NULL, iovec, n, &s->seqnum, NULL, NULL);
7591abd48079edc1f2adbd922e4b83eb73abeabeLennart Poettering for (i = 0; i < n; i++)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering log_error("Failed to write entry (%d items, %zu bytes) despite vacuuming, ignoring: %s", n, size, strerror(-r));
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 boot_id[sizeof("_BOOT_ID=") + 32] = "_BOOT_ID=",
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering machine_id[sizeof("_MACHINE_ID=") + 32] = "_MACHINE_ID=",
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering o_uid[sizeof("OBJECT_UID=") + DECIMAL_STR_MAX(uid_t)],
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering o_gid[sizeof("OBJECT_GID=") + DECIMAL_STR_MAX(gid_t)],
c978343015c787713651dff571acb5207367f5f2Lennart Poettering o_owner_uid[sizeof("OBJECT_SYSTEMD_OWNER_UID=") + DECIMAL_STR_MAX(uid_t)];
c978343015c787713651dff571acb5207367f5f2Lennart Poettering uid_t realuid = 0, owner = 0, journal_uid;
c978343015c787713651dff571acb5207367f5f2Lennart Poettering char audit_session[sizeof("_AUDIT_SESSION=") + DECIMAL_STR_MAX(uint32_t)],
c978343015c787713651dff571acb5207367f5f2Lennart Poettering audit_loginuid[sizeof("_AUDIT_LOGINUID=") + DECIMAL_STR_MAX(uid_t)],
c978343015c787713651dff571acb5207367f5f2Lennart 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=%lu", (unsigned long) ucred->pid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sprintf(uid, "_UID=%lu", (unsigned long) ucred->uid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sprintf(gid, "_GID=%lu", (unsigned long) ucred->gid);
546158bc6f46f8004cc11e81d19d223e0da56730Jan Janssen if (r >= 0) {
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=%lu", (unsigned long) 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=%lu", (unsigned long) loginuid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering IOVEC_SET_STRING(iovec[n++], audit_loginuid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = cg_pid_get_path_shifted(ucred->pid, NULL, &c);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering session = strappenda("_SYSTEMD_SESSION=", t);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (cg_path_get_owner_uid(c, &owner) >= 0) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sprintf(owner_uid, "_SYSTEMD_OWNER_UID=%lu", (unsigned long) owner);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (cg_path_get_unit(c, &t) >= 0) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering x = strappenda("_SYSTEMD_UNIT=", unit_id);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if (cg_path_get_user_unit(c, &t) >= 0) {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering x = strappenda("_SYSTEMD_USER_UNIT=", t);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering x = strappenda("_SYSTEMD_USER_UNIT=", unit_id);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering x = alloca(sizeof("_SELINUX_CONTEXT=") + label_len);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering *((char*) mempcpy(stpcpy(x, "_SELINUX_CONTEXT="), label, label_len)) = 0;
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering x = strappenda("_SELINUX_CONTEXT=", con);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = get_process_uid(object_pid, &object_uid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sprintf(o_uid, "OBJECT_UID=%lu", (unsigned long) object_uid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = get_process_gid(object_pid, &object_gid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sprintf(o_gid, "OBJECT_GID=%lu", (unsigned long) object_gid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = get_process_cmdline(object_pid, 0, false, &t);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = audit_session_from_pid(object_pid, &audit);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sprintf(o_audit_session, "OBJECT_AUDIT_SESSION=%lu", (unsigned long) audit);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering IOVEC_SET_STRING(iovec[n++], o_audit_session);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = audit_loginuid_from_pid(object_pid, &loginuid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering sprintf(o_audit_loginuid, "OBJECT_AUDIT_LOGINUID=%lu", (unsigned long) loginuid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering IOVEC_SET_STRING(iovec[n++], o_audit_loginuid);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering r = cg_pid_get_path_shifted(object_pid, NULL, &c);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering x = strappenda("OBJECT_SYSTEMD_CGROUP=", c);
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering x = strappenda("OBJECT_SYSTEMD_SESSION=", 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) {
t = gethostname_malloc();
free(t);
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)
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);
assert(s);
ssize_t n;
return -EIO;
if (n != sizeof(sfsi)) {
return -EIO;
return -errno;
server_sync(s);
server_rotate(s);
server_vacuum(s);
uint64_t t;
server_sync(s);
return -EIO;
r = server_read_dev_kmsg(s);
return -EIO;
} control;
ssize_t n;
unsigned n_fds = 0;
return -errno;
size_t l;
return -ENOMEM;
s->buffer_size = l;
s->buffer = b;
return -errno;
if (n > 0 && n_fds == 0) {
s->buffer[n] = 0;
} else if (n_fds > 0)
if (n > 0 && n_fds == 0)
else if (n_fds > 0)
return -EIO;
return -EIO;
assert(s);
if (s->signal_fd < 0) {
return -errno;
return -errno;
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;
assert(s);
return -errno;
(void*) journald_gperf_lookup, false, false, s);
assert(s);
if (s->sync_timer_fd < 0)
return -errno;
return -errno;
assert(s);
server_sync(s);
if (s->sync_scheduled)
if (s->sync_interval_usec) {
return -errno;
s->sync_scheduled = true;
int n, r, fd;
assert(s);
zero(*s);
s->compress = true;
s->seal = true;
s->sync_scheduled = false;
s->forward_to_syslog = true;
(long long unsigned) s->rate_limit_interval,
s->rate_limit_burst);
if (!s->user_journals)
return log_oom();
if (!s->mmap)
return log_oom();
if (s->epoll_fd < 0) {
return -errno;
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;
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_kernel_seqnum(s);
r = server_open_sync_timer(s);
r = open_signalfd(s);
if (!s->udev)
return -ENOMEM;
s->rate_limit_burst);
if (!s->rate_limit)
return -ENOMEM;
r = system_journal_open(s);
#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->epoll_fd >= 0)
if (s->signal_fd >= 0)
if (s->syslog_fd >= 0)
if (s->native_fd >= 0)
if (s->stdout_fd >= 0)
if (s->dev_kmsg_fd >= 0)
if (s->sync_timer_fd >= 0)
if (s->rate_limit)
if (s->kernel_seqnum)
if (s->mmap)
if (s->udev)