HALF ECHO LEARN / REFERENCE COLLECTION

v262.2

src/core/manager.c

215,074 bytesGit mode 100644Download original fileLGPL-2.1-or-later

Git blob: e0aa34f4c11534f81d2a7e0a2a8c2aa218451eb3

Lines 5001–5689 of 5,689

        u = manager_get_unit(m, SPECIAL_SHUTDOWN_TARGET);
        if (u && unit_active_or_pending(u))
                return MANAGER_STOPPING;
 
        /* Did we ever finish booting? If not then we are still starting up */
        if (!MANAGER_IS_FINISHED(m)) {
 
                u = manager_get_unit(m, SPECIAL_BASIC_TARGET);
                if (!u || !UNIT_IS_ACTIVE_OR_RELOADING(unit_active_state(u)))
                        return MANAGER_INITIALIZING;
 
                return MANAGER_STARTING;
        }
 
        if (MANAGER_IS_SYSTEM(m)) {
                /* Are the rescue or emergency targets active or queued? If so we are in maintenance state */
                u = manager_get_unit(m, SPECIAL_RESCUE_TARGET);
                if (u && unit_active_or_pending(u))
                        return MANAGER_MAINTENANCE;
 
                u = manager_get_unit(m, SPECIAL_EMERGENCY_TARGET);
                if (u && unit_active_or_pending(u))
                        return MANAGER_MAINTENANCE;
        }
 
        /* Are there any failed units or ordering cycles? If so, we are in degraded mode */
        if (!set_isempty(m->failed_units) || !set_isempty(m->transactions_with_cycle))
                return MANAGER_DEGRADED;
 
        return MANAGER_RUNNING;
}
 
static void manager_unref_uid_internal(
                Hashmap *uid_refs,
                uid_t uid,
                bool destroy_now,
                int (*_clean_ipc)(uid_t uid)) {
 
        uint32_t c, n;
 
        assert(uid_is_valid(uid));
        assert(_clean_ipc);
 
        /* A generic implementation, covering both manager_unref_uid() and manager_unref_gid(), under the
         * assumption that uid_t and gid_t are actually defined the same way, with the same validity rules.
         *
         * We store a hashmap where the key is the UID/GID and the value is a 32-bit reference counter, whose
         * highest bit is used as flag for marking UIDs/GIDs whose IPC objects to remove when the last
         * reference to the UID/GID is dropped. The flag is set to on, once at least one reference from a
         * unit where RemoveIPC= is set is added on a UID/GID. It is reset when the UID's/GID's reference
         * counter drops to 0 again. */
 
        assert_cc(sizeof(uid_t) == sizeof(gid_t));
        assert_cc(UID_INVALID == (uid_t) GID_INVALID);
 
        if (uid == 0) /* We don't keep track of root, and will never destroy it */
                return;
 
        c = PTR_TO_UINT32(hashmap_get(uid_refs, UID_TO_PTR(uid)));
 
        n = c & ~DESTROY_IPC_FLAG;
        assert(n > 0);
        n--;
 
        if (destroy_now && n == 0) {
                hashmap_remove(uid_refs, UID_TO_PTR(uid));
 
                if (c & DESTROY_IPC_FLAG) {
                        log_debug("%s " UID_FMT " is no longer referenced, cleaning up its IPC.",
                                  _clean_ipc == clean_ipc_by_uid ? "UID" : "GID",
                                  uid);
                        (void) _clean_ipc(uid);
                }
        } else {
                c = n | (c & DESTROY_IPC_FLAG);
                assert_se(hashmap_update(uid_refs, UID_TO_PTR(uid), UINT32_TO_PTR(c)) >= 0);
        }
}
 
void manager_unref_uid(Manager *m, uid_t uid, bool destroy_now) {
        manager_unref_uid_internal(m->uid_refs, uid, destroy_now, clean_ipc_by_uid);
}
 
void manager_unref_gid(Manager *m, gid_t gid, bool destroy_now) {
        manager_unref_uid_internal(m->gid_refs, (uid_t) gid, destroy_now, clean_ipc_by_gid);
}
 
static int manager_ref_uid_internal(
                Hashmap **uid_refs,
                uid_t uid,
                bool clean_ipc) {
 
        uint32_t c, n;
        int r;
 
        assert(uid_refs);
        assert(uid_is_valid(uid));
 
        /* A generic implementation, covering both manager_ref_uid() and manager_ref_gid(), under the
         * assumption that uid_t and gid_t are actually defined the same way, with the same validity
         * rules. */
 
        assert_cc(sizeof(uid_t) == sizeof(gid_t));
        assert_cc(UID_INVALID == (uid_t) GID_INVALID);
 
        if (uid == 0) /* We don't keep track of root, and will never destroy it */
                return 0;
 
        r = hashmap_ensure_allocated(uid_refs, &trivial_hash_ops);
        if (r < 0)
                return r;
 
        c = PTR_TO_UINT32(hashmap_get(*uid_refs, UID_TO_PTR(uid)));
 
        n = c & ~DESTROY_IPC_FLAG;
        n++;
 
        if (n & DESTROY_IPC_FLAG) /* check for overflow */
                return -EOVERFLOW;
 
        c = n | (c & DESTROY_IPC_FLAG) | (clean_ipc ? DESTROY_IPC_FLAG : 0);
 
        return hashmap_replace(*uid_refs, UID_TO_PTR(uid), UINT32_TO_PTR(c));
}
 
int manager_ref_uid(Manager *m, uid_t uid, bool clean_ipc) {
        return manager_ref_uid_internal(&m->uid_refs, uid, clean_ipc);
}
 
int manager_ref_gid(Manager *m, gid_t gid, bool clean_ipc) {
        return manager_ref_uid_internal(&m->gid_refs, (uid_t) gid, clean_ipc);
}
 
static void manager_vacuum_uid_refs_internal(
                Hashmap *uid_refs,
                int (*_clean_ipc)(uid_t uid)) {
 
        void *p, *k;
 
        assert(_clean_ipc);
 
        HASHMAP_FOREACH_KEY(p, k, uid_refs) {
                uint32_t c, n;
                uid_t uid;
 
                uid = PTR_TO_UID(k);
                c = PTR_TO_UINT32(p);
 
                n = c & ~DESTROY_IPC_FLAG;
                if (n > 0)
                        continue;
 
                if (c & DESTROY_IPC_FLAG) {
                        log_debug("Found unreferenced %s " UID_FMT " after reload/reexec. Cleaning up.",
                                  _clean_ipc == clean_ipc_by_uid ? "UID" : "GID",
                                  uid);
                        (void) _clean_ipc(uid);
                }
 
                assert_se(hashmap_remove(uid_refs, k) == p);
        }
}
 
static void manager_vacuum_uid_refs(Manager *m) {
        manager_vacuum_uid_refs_internal(m->uid_refs, clean_ipc_by_uid);
}
 
static void manager_vacuum_gid_refs(Manager *m) {
        manager_vacuum_uid_refs_internal(m->gid_refs, clean_ipc_by_gid);
}
 
static void manager_vacuum(Manager *m) {
        assert(m);
 
        /* Release any dynamic users no longer referenced */
        dynamic_user_vacuum(m, true);
 
        /* Release any references to UIDs/GIDs no longer referenced, and destroy any IPC owned by them */
        manager_vacuum_uid_refs(m);
        manager_vacuum_gid_refs(m);
 
        /* Release any runtimes no longer referenced */
        exec_shared_runtime_vacuum(m);
}
 
static int manager_dispatch_user_lookup_fd(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
        struct buffer {
                uid_t uid;
                gid_t gid;
                char unit_name[UNIT_NAME_MAX+1];
        } _packed_ buffer;
 
        Manager *m = ASSERT_PTR(userdata);
        ssize_t l;
        size_t n;
        Unit *u;
 
        assert(source);
 
        /* Invoked whenever a child process succeeded resolving its user/group to use and sent us the
         * resulting UID/GID in a datagram. We parse the datagram here and pass it off to the unit, so that
         * it can add a reference to the UID/GID so that it can destroy the UID/GID's IPC objects when the
         * reference counter drops to 0. */
 
        l = recv(fd, &buffer, sizeof(buffer), MSG_DONTWAIT);
        if (l < 0) {
                if (ERRNO_IS_TRANSIENT(errno))
                        return 0;
 
                return log_error_errno(errno, "Failed to read from user lookup fd: %m");
        }
 
        if ((size_t) l <= offsetof(struct buffer, unit_name)) {
                log_warning("Received too short user lookup message, ignoring.");
                return 0;
        }
 
        if ((size_t) l > offsetof(struct buffer, unit_name) + UNIT_NAME_MAX) {
                log_warning("Received too long user lookup message, ignoring.");
                return 0;
        }
 
        if (!uid_is_valid(buffer.uid) && !gid_is_valid(buffer.gid)) {
                log_warning("Got user lookup message with invalid UID/GID pair, ignoring.");
                return 0;
        }
 
        n = (size_t) l - offsetof(struct buffer, unit_name);
        if (memchr(buffer.unit_name, 0, n)) {
                log_warning("Received lookup message with embedded NUL character, ignoring.");
                return 0;
        }
 
        buffer.unit_name[n] = 0;
        u = manager_get_unit(m, buffer.unit_name);
        if (!u) {
                log_debug("Got user lookup message but unit doesn't exist, ignoring.");
                return 0;
        }
 
        log_unit_debug(u, "User lookup succeeded: uid=" UID_FMT " gid=" GID_FMT, buffer.uid, buffer.gid);
 
        unit_notify_user_lookup(u, buffer.uid, buffer.gid);
        return 0;
}
 
static int manager_dispatch_handoff_timestamp_fd(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
        Manager *m = ASSERT_PTR(userdata);
        usec_t ts[2] = {};
        CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(struct ucred))) control;
        struct msghdr msghdr = {
                .msg_iov = &IOVEC_MAKE(ts, sizeof(ts)),
                .msg_iovlen = 1,
                .msg_control = &control,
                .msg_controllen = sizeof(control),
        };
        ssize_t n;
 
        assert(source);
 
        n = recvmsg_safe(m->handoff_timestamp_fds[0], &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC);
        if (ERRNO_IS_NEG_TRANSIENT(n))
                return 0; /* Spurious wakeup, try again */
        if (n == -ECHRNG) {
                log_warning_errno(n, "Got message with truncated control data (unexpected fds sent?), ignoring.");
                return 0;
        }
        if (n == -EXFULL) {
                log_warning_errno(n, "Got message with truncated payload data, ignoring.");
                return 0;
        }
        if (n < 0)
                return log_error_errno(n, "Failed to receive handoff timestamp message: %m");
 
        cmsg_close_all(&msghdr);
 
        if (n != sizeof(ts)) {
                log_warning("Got handoff timestamp message of unexpected size %zi (expected %zu), ignoring.", n, sizeof(ts));
                return 0;
        }
 
        struct ucred *ucred = CMSG_FIND_DATA(&msghdr, SOL_SOCKET, SCM_CREDENTIALS, struct ucred);
        if (!ucred || !pid_is_valid(ucred->pid)) {
                log_warning("Received handoff timestamp message without valid credentials. Ignoring.");
                return 0;
        }
 
        log_debug("Got handoff timestamp event for PID " PID_FMT ".", ucred->pid);
 
        _cleanup_free_ Unit **units = NULL;
        int n_units = manager_get_units_for_pidref(m, &PIDREF_MAKE_FROM_PID(ucred->pid), &units);
        if (n_units < 0) {
                log_warning_errno(n_units, "Unable to determine units for PID " PID_FMT ", ignoring: %m", ucred->pid);
                return 0;
        }
        if (n_units == 0) {
                log_debug("Got handoff timestamp for process " PID_FMT " we are not interested in, ignoring.", ucred->pid);
                return 0;
        }
 
        dual_timestamp dt = {
                .realtime = ts[0],
                .monotonic = ts[1],
        };
 
        FOREACH_ARRAY(u, units, n_units) {
                if (!UNIT_VTABLE(*u)->notify_handoff_timestamp)
                        continue;
 
                UNIT_VTABLE(*u)->notify_handoff_timestamp(*u, ucred, &dt);
        }
 
        return 0;
}
 
static int manager_dispatch_pidref_transport_fd(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
        Manager *m = ASSERT_PTR(userdata);
        _cleanup_(pidref_done) PidRef child_pidref = PIDREF_NULL, parent_pidref = PIDREF_NULL;
        _cleanup_close_ int child_pidfd = -EBADF, parent_pidfd = -EBADF;
        struct ucred *ucred = NULL;
        CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(struct ucred)) + CMSG_SPACE(sizeof(int)) * 2) control;
        pid_t child_pid = 0; /* silence false-positive warning by coverity */
        struct msghdr msghdr = {
                .msg_iov = &IOVEC_MAKE(&child_pid, sizeof(child_pid)),
                .msg_iovlen = 1,
                .msg_control = &control,
                .msg_controllen = sizeof(control),
        };
        struct cmsghdr *cmsg;
        ssize_t n;
        int r;
 
        assert(source);
 
        /* Server expects:
         * - Parent PID in ucreds enabled via SO_PASSCRED
         * - Parent PIDFD in SCM_PIDFD message enabled via SO_PASSPIDFD
         * - Child PIDFD in SCM_RIGHTS in message body
         * - Child PID in message IOV
         *
         * SO_PASSPIDFD may not be supported by the kernel (it is supported since v6.5) so we fall back to
         * using parent PID from ucreds and accept some raciness. */
        n = recvmsg_safe(m->pidref_transport_fds[0], &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC|MSG_TRUNC);
        if (ERRNO_IS_NEG_TRANSIENT(n))
                return 0; /* Spurious wakeup, try again */
        if (n == -ECHRNG) {
                log_warning_errno(n, "Got message with truncated control data (unexpected fds sent?), ignoring.");
                return 0;
        }
        if (n == -EXFULL) {
                log_warning_errno(n, "Got message with truncated payload data, ignoring.");
                return 0;
        }
        if (n < 0)
                return log_error_errno(n, "Failed to receive pidref message: %m");
 
        if (n != sizeof(child_pid)) {
                log_warning("Got pidref message of unexpected size %zi (expected %zu), ignoring.", n, sizeof(child_pid));
                cmsg_close_all(&msghdr);
                return 0;
        }
 
        CMSG_FOREACH(cmsg, &msghdr) {
                if (cmsg->cmsg_level != SOL_SOCKET)
                        continue;
 
                if (cmsg->cmsg_type == SCM_CREDENTIALS && cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred))) {
                        assert(!ucred);
                        ucred = CMSG_TYPED_DATA(cmsg, struct ucred);
                } else if (cmsg->cmsg_type == SCM_PIDFD) {
                        assert(parent_pidfd < 0);
                        parent_pidfd = *CMSG_TYPED_DATA(cmsg, int);
                } else if (cmsg->cmsg_type == SCM_RIGHTS) {
                        assert(child_pidfd < 0);
                        child_pidfd = *CMSG_TYPED_DATA(cmsg, int);
                }
        }
 
        /* From this point on, the fds are owned by our local variables. Call cmsg_close_all no more. */
 
        /* Verify and set parent pidref. */
        if (!ucred || !pid_is_valid(ucred->pid)) {
                log_warning("Received pidref message without valid credentials. Ignoring.");
                return 0;
        }
 
        /* Need to handle kernels without SO_PASSPIDFD where SCM_PIDFD will not be set. */
        if (parent_pidfd >= 0)
                r = pidref_set_pidfd_consume(&parent_pidref, TAKE_FD(parent_pidfd));
        else
                r = pidref_set_pid(&parent_pidref, ucred->pid);
        if (r < 0) {
                if (r == -ESRCH)
                        log_debug_errno(r, "PidRef child process died before message is processed. Ignoring.");
                else
                        log_warning_errno(r, "Failed to pin pidref child process, ignoring message: %m");
                return 0;
        }
 
        if (parent_pidref.pid != ucred->pid) {
                assert(parent_pidref.fd >= 0);
                log_warning("Got SCM_PIDFD for parent process " PID_FMT " but got SCM_CREDENTIALS for parent process " PID_FMT ". Ignoring.",
                            parent_pidref.pid, ucred->pid);
                return 0;
        }
 
        /* Verify and set child pidref. */
        if (!pid_is_valid(child_pid)) {
                log_warning("Received pidref message without valid child PID. Ignoring.");
                return 0;
        }
 
        /* Need to handle kernels without PIDFD support. */
        if (child_pidfd >= 0)
                r = pidref_set_pidfd_consume(&child_pidref, TAKE_FD(child_pidfd));
        else
                r = pidref_set_pid(&child_pidref, child_pid);
        if (r < 0) {
                if (r == -ESRCH)
                        log_debug_errno(r, "PidRef child process died before message is processed. Ignoring.");
                else
                        log_warning_errno(r, "Failed to pin pidref child process, ignoring message: %m");
                return 0;
        }
 
        if (child_pidref.pid != child_pid) {
                assert(child_pidref.fd >= 0);
                log_warning("Got SCM_RIGHTS for child process " PID_FMT " but PID in IOV message is " PID_FMT ". Ignoring.",
                            child_pidref.pid, child_pid);
                return 0;
        }
 
        log_debug("Got pidref event with parent PID " PID_FMT " and child PID " PID_FMT ".", parent_pidref.pid, child_pidref.pid);
 
        /* Try finding cgroup of parent process. But if parent process exited and we're not using PIDFD, this could return NULL.
         * Then fall back to finding cgroup of the child process. */
        Unit *u = manager_get_unit_by_pidref_cgroup(m, &parent_pidref);
        if (!u)
                u = manager_get_unit_by_pidref_cgroup(m, &child_pidref);
        if (!u) {
                log_debug("Got pidref for parent process " PID_FMT " and child process " PID_FMT " we are not interested in, ignoring.", parent_pidref.pid, child_pidref.pid);
                return 0;
        }
 
        if (!UNIT_VTABLE(u)->notify_pidref) {
                log_unit_warning(u, "Received pidref event from unexpected unit type '%s'.", unit_type_to_string(u->type));
                return 0;
        }
 
        UNIT_VTABLE(u)->notify_pidref(u, &parent_pidref, &child_pidref);
 
        return 0;
}
 
void manager_ref_console(Manager *m) {
        assert(m);
 
        m->n_on_console++;
}
 
void manager_unref_console(Manager *m) {
 
        assert(m->n_on_console > 0);
        m->n_on_console--;
 
        if (m->n_on_console == 0)
                m->no_console_output = false; /* unset no_console_output flag, since the console is definitely free now */
}
 
void manager_override_log_level(Manager *m, int level) {
        _cleanup_free_ char *s = NULL;
        assert(m);
 
        if (!m->log_level_overridden) {
                m->original_log_level = log_get_max_level();
                m->log_level_overridden = true;
        }
 
        (void) log_level_to_string_alloc(level, &s);
        log_info("Setting log level to %s.", strna(s));
 
        log_set_max_level(level);
}
 
void manager_restore_original_log_level(Manager *m) {
        _cleanup_free_ char *s = NULL;
        assert(m);
 
        if (!m->log_level_overridden)
                return;
 
        (void) log_level_to_string_alloc(m->original_log_level, &s);
        log_info("Restoring log level to original (%s).", strna(s));
 
        log_set_max_level(m->original_log_level);
        m->log_level_overridden = false;
}
 
void manager_override_log_target(Manager *m, LogTarget target) {
        assert(m);
 
        if (!m->log_target_overridden) {
                m->original_log_target = log_get_target();
                m->log_target_overridden = true;
        }
 
        log_info("Setting log target to %s.", log_target_to_string(target));
        log_set_target(target);
}
 
void manager_restore_original_log_target(Manager *m) {
        assert(m);
 
        if (!m->log_target_overridden)
                return;
 
        log_info("Restoring log target to original %s.", log_target_to_string(m->original_log_target));
 
        log_set_target(m->original_log_target);
        m->log_target_overridden = false;
}
 
ManagerTimestamp manager_timestamp_initrd_mangle(ManagerTimestamp s) {
        if (in_initrd() &&
            s >= MANAGER_TIMESTAMP_SECURITY_START &&
            s <= MANAGER_TIMESTAMP_UNITS_LOAD_FINISH)
                return s - MANAGER_TIMESTAMP_SECURITY_START + MANAGER_TIMESTAMP_INITRD_SECURITY_START;
        return s;
}
 
int manager_allocate_idle_pipe(Manager *m) {
        int r;
 
        assert(m);
 
        if (m->idle_pipe[0] >= 0) {
                assert(m->idle_pipe[1] >= 0);
                assert(m->idle_pipe[2] >= 0);
                assert(m->idle_pipe[3] >= 0);
                return 0;
        }
 
        assert(m->idle_pipe[1] < 0);
        assert(m->idle_pipe[2] < 0);
        assert(m->idle_pipe[3] < 0);
 
        r = RET_NERRNO(pipe2(m->idle_pipe + 0, O_NONBLOCK|O_CLOEXEC));
        if (r < 0)
                return r;
 
        r = RET_NERRNO(pipe2(m->idle_pipe + 2, O_NONBLOCK|O_CLOEXEC));
        if (r < 0) {
                safe_close_pair(m->idle_pipe + 0);
                return r;
        }
 
        return 1;
}
 
void unit_defaults_init(UnitDefaults *defaults, RuntimeScope scope) {
        assert(defaults);
        assert(scope >= 0);
        assert(scope < _RUNTIME_SCOPE_MAX);
 
        *defaults = (UnitDefaults) {
                .std_output = EXEC_OUTPUT_JOURNAL,
                .std_error = EXEC_OUTPUT_INHERIT,
                .restart_usec = DEFAULT_RESTART_USEC,
                .timeout_start_usec = manager_default_timeout(scope),
                .timeout_stop_usec = manager_default_timeout(scope),
                .timeout_abort_usec = manager_default_timeout(scope),
                .timeout_abort_set = false,
                .device_timeout_usec = manager_default_timeout(scope),
                .start_limit = { DEFAULT_START_LIMIT_INTERVAL, DEFAULT_START_LIMIT_BURST },
 
                .memory_accounting = MEMORY_ACCOUNTING_DEFAULT,
                .io_accounting = false,
                .tasks_accounting = true,
                .ip_accounting = false,
 
                .tasks_max = DEFAULT_TASKS_MAX,
                .timer_accuracy_usec = 1 * USEC_PER_MINUTE,
 
                .pressure = {
                        [PRESSURE_MEMORY] = { .watch = CGROUP_PRESSURE_WATCH_AUTO, .threshold_usec = PRESSURE_DEFAULT_THRESHOLD_USEC },
                        [PRESSURE_CPU]    = { .watch = CGROUP_PRESSURE_WATCH_AUTO, .threshold_usec = PRESSURE_DEFAULT_THRESHOLD_USEC },
                        [PRESSURE_IO]     = { .watch = CGROUP_PRESSURE_WATCH_AUTO, .threshold_usec = PRESSURE_DEFAULT_THRESHOLD_USEC },
                },
 
                .oom_policy = OOM_STOP,
                .oom_score_adjust_set = false,
 
                .memory_zswap_writeback = true,
        };
}
 
void unit_defaults_done(UnitDefaults *defaults) {
        assert(defaults);
 
        defaults->smack_process_label = mfree(defaults->smack_process_label);
        rlimit_free_all(defaults->rlimit);
}
 
LogTarget manager_get_executor_log_target(Manager *m) {
        assert(m);
 
        /* If journald is not available tell sd-executor to go to kmsg, as it might be starting journald */
        if (!MANAGER_IS_TEST_RUN(m) && !manager_journal_is_running(m))
                return LOG_TARGET_KMSG;
 
        return log_get_target();
}
 
void manager_log_caller(Manager *manager, PidRef *caller, const char *method) {
        _cleanup_free_ char *comm = NULL;
 
        assert(manager);
        assert(method);
 
        if (!pidref_is_set(caller)) {
                log_notice("%s requested from unknown client PID...", method);
                return;
        }
 
        (void) pidref_get_comm(caller, &comm);
        Unit *caller_unit = manager_get_unit_by_pidref(manager, caller);
 
        log_notice("%s requested from client PID " PID_FMT "%s%s%s%s%s%s...",
                   method, caller->pid,
                   comm ? " ('" : "", strempty(comm), comm ? "')" : "",
                   caller_unit ? " (unit " : "", caller_unit ? caller_unit->id : "", caller_unit ? ")" : "");
}
 
static const char* const manager_state_table[_MANAGER_STATE_MAX] = {
        [MANAGER_INITIALIZING] = "initializing",
        [MANAGER_STARTING]     = "starting",
        [MANAGER_RUNNING]      = "running",
        [MANAGER_DEGRADED]     = "degraded",
        [MANAGER_MAINTENANCE]  = "maintenance",
        [MANAGER_STOPPING]     = "stopping",
};
 
DEFINE_STRING_TABLE_LOOKUP(manager_state, ManagerState);
 
static const char* const manager_objective_table[_MANAGER_OBJECTIVE_MAX] = {
        [MANAGER_OK]          = "ok",
        [MANAGER_EXIT]        = "exit",
        [MANAGER_RELOAD]      = "reload",
        [MANAGER_REEXECUTE]   = "reexecute",
        [MANAGER_REBOOT]      = "reboot",
        [MANAGER_SOFT_REBOOT] = "soft-reboot",
        [MANAGER_POWEROFF]    = "poweroff",
        [MANAGER_HALT]        = "halt",
        [MANAGER_KEXEC]       = "kexec",
        [MANAGER_SWITCH_ROOT] = "switch-root",
};
 
DEFINE_STRING_TABLE_LOOKUP(manager_objective, ManagerObjective);
 
static const char* const manager_timestamp_table[_MANAGER_TIMESTAMP_MAX] = {
        [MANAGER_TIMESTAMP_FIRMWARE]                      = "firmware",
        [MANAGER_TIMESTAMP_LOADER]                        = "loader",
        [MANAGER_TIMESTAMP_KERNEL]                        = "kernel",
        [MANAGER_TIMESTAMP_INITRD]                        = "initrd",
        [MANAGER_TIMESTAMP_USERSPACE]                     = "userspace",
        [MANAGER_TIMESTAMP_FINISH]                        = "finish",
        [MANAGER_TIMESTAMP_SECURITY_START]                = "security-start",
        [MANAGER_TIMESTAMP_SECURITY_FINISH]               = "security-finish",
        [MANAGER_TIMESTAMP_GENERATORS_START]              = "generators-start",
        [MANAGER_TIMESTAMP_GENERATORS_FINISH]             = "generators-finish",
        [MANAGER_TIMESTAMP_UNITS_LOAD_START]              = "units-load-start",
        [MANAGER_TIMESTAMP_UNITS_LOAD_FINISH]             = "units-load-finish",
        [MANAGER_TIMESTAMP_UNITS_LOAD]                    = "units-load",
        [MANAGER_TIMESTAMP_INITRD_SECURITY_START]         = "initrd-security-start",
        [MANAGER_TIMESTAMP_INITRD_SECURITY_FINISH]        = "initrd-security-finish",
        [MANAGER_TIMESTAMP_INITRD_GENERATORS_START]       = "initrd-generators-start",
        [MANAGER_TIMESTAMP_INITRD_GENERATORS_FINISH]      = "initrd-generators-finish",
        [MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_START]       = "initrd-units-load-start",
        [MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_FINISH]      = "initrd-units-load-finish",
        [MANAGER_TIMESTAMP_SHUTDOWN_START]                = "shutdown-start",
        [MANAGER_TIMESTAMP_SHUTDOWN_FINISH]               = "shutdown-finish",
        [MANAGER_TIMESTAMP_PREVIOUS_SHUTDOWN_START]       = "previous-shutdown-start",
        [MANAGER_TIMESTAMP_PREVIOUS_SHUTDOWN_FINISH]      = "previous-shutdown-finish",
        [MANAGER_TIMESTAMP_PREVIOUS_SHUTDOWN_LATE_START]  = "previous-shutdown-late-start",
        [MANAGER_TIMESTAMP_PREVIOUS_SHUTDOWN_LATE_FINISH] = "previous-shutdown-late-finish",
};
 
DEFINE_STRING_TABLE_LOOKUP(manager_timestamp, ManagerTimestamp);