diff options
Diffstat (limited to 'src/core/manager.h')
-rw-r--r-- | src/core/manager.h | 92 |
1 files changed, 64 insertions, 28 deletions
diff --git a/src/core/manager.h b/src/core/manager.h index ea5d425030..bce8020cfd 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -5,6 +5,7 @@ #include <stdio.h> #include "sd-bus.h" +#include "sd-device.h" #include "sd-event.h" #include "cgroup-util.h" @@ -22,6 +23,8 @@ typedef struct Unit Unit; typedef struct Manager Manager; +/* An externally visible state. We don't actually maintain this as state variable, but derive it from various fields + * when requested */ typedef enum ManagerState { MANAGER_INITIALIZING, MANAGER_STARTING, @@ -33,7 +36,7 @@ typedef enum ManagerState { _MANAGER_STATE_INVALID = -1 } ManagerState; -typedef enum ManagerExitCode { +typedef enum ManagerObjective { MANAGER_OK, MANAGER_EXIT, MANAGER_RELOAD, @@ -43,9 +46,9 @@ typedef enum ManagerExitCode { MANAGER_HALT, MANAGER_KEXEC, MANAGER_SWITCH_ROOT, - _MANAGER_EXIT_CODE_MAX, - _MANAGER_EXIT_CODE_INVALID = -1 -} ManagerExitCode; + _MANAGER_OBJECTIVE_MAX, + _MANAGER_OBJECTIVE_INVALID = -1 +} ManagerObjective; typedef enum StatusType { STATUS_TYPE_EPHEMERAL, @@ -53,6 +56,27 @@ typedef enum StatusType { STATUS_TYPE_EMERGENCY, } StatusType; +/* Notes: + * 1. TIMESTAMP_FIRMWARE, TIMESTAMP_LOADER, TIMESTAMP_KERNEL, TIMESTAMP_INITRD, + * TIMESTAMP_SECURITY_START, and TIMESTAMP_SECURITY_FINISH are set only when + * the manager is system and not running under container environment. + * + * 2. The monotonic timestamp of TIMESTAMP_KERNEL is always zero. + * + * 3. The realtime timestamp of TIMESTAMP_KERNEL will be unset if the system does not + * have RTC. + * + * 4. TIMESTAMP_FIRMWARE and TIMESTAMP_LOADER will be unset if the system does not + * have RTC, or systemd is built without EFI support. + * + * 5. The monotonic timestamps of TIMESTAMP_FIRMWARE and TIMESTAMP_LOADER are stored as + * negative of the actual value. + * + * 6. TIMESTAMP_USERSPACE is the timestamp of when the manager was started. + * + * 7. TIMESTAMP_INITRD_* are set only when the system is booted with an initrd. + */ + typedef enum ManagerTimestamp { MANAGER_TIMESTAMP_FIRMWARE, MANAGER_TIMESTAMP_LOADER, @@ -67,6 +91,13 @@ typedef enum ManagerTimestamp { MANAGER_TIMESTAMP_GENERATORS_FINISH, MANAGER_TIMESTAMP_UNITS_LOAD_START, MANAGER_TIMESTAMP_UNITS_LOAD_FINISH, + + MANAGER_TIMESTAMP_INITRD_SECURITY_START, + MANAGER_TIMESTAMP_INITRD_SECURITY_FINISH, + MANAGER_TIMESTAMP_INITRD_GENERATORS_START, + MANAGER_TIMESTAMP_INITRD_GENERATORS_FINISH, + MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_START, + MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_FINISH, _MANAGER_TIMESTAMP_MAX, _MANAGER_TIMESTAMP_INVALID = -1, } ManagerTimestamp; @@ -77,14 +108,15 @@ typedef enum ManagerTimestamp { #include "show-status.h" #include "unit-name.h" -enum { - /* 0 = run normally */ - MANAGER_TEST_RUN_MINIMAL = 1 << 1, /* create basic data structures */ - MANAGER_TEST_RUN_BASIC = 1 << 2, /* interact with the environment */ - MANAGER_TEST_RUN_ENV_GENERATORS = 1 << 3, /* also run env generators */ - MANAGER_TEST_RUN_GENERATORS = 1 << 4, /* also run unit generators */ +typedef enum ManagerTestRunFlags { + MANAGER_TEST_NORMAL = 0, /* run normally */ + MANAGER_TEST_RUN_MINIMAL = 1 << 0, /* create basic data structures */ + MANAGER_TEST_RUN_BASIC = 1 << 1, /* interact with the environment */ + MANAGER_TEST_RUN_ENV_GENERATORS = 1 << 2, /* also run env generators */ + MANAGER_TEST_RUN_GENERATORS = 1 << 3, /* also run unit generators */ MANAGER_TEST_FULL = MANAGER_TEST_RUN_BASIC | MANAGER_TEST_RUN_ENV_GENERATORS | MANAGER_TEST_RUN_GENERATORS, -}; +} ManagerTestRunFlags; + assert_cc((MANAGER_TEST_FULL & UINT8_MAX) == MANAGER_TEST_FULL); struct Manager { @@ -130,6 +162,9 @@ struct Manager { /* Target units whose default target dependencies haven't been set yet */ LIST_HEAD(Unit, target_deps_queue); + /* Units that might be subject to StopWhenUnneeded= clean-up */ + LIST_HEAD(Unit, stop_when_unneeded_queue); + sd_event *event; /* This maps PIDs we care about to units that are interested in. We allow multiple units to he interested in @@ -177,18 +212,16 @@ struct Manager { LookupPaths lookup_paths; Set *unit_path_cache; - char **environment; + char **transient_environment; /* The environment, as determined from config files, kernel cmdline and environment generators */ + char **client_environment; /* Environment variables created by clients through the bus API */ usec_t runtime_watchdog; usec_t shutdown_watchdog; dual_timestamp timestamps[_MANAGER_TIMESTAMP_MAX]; - struct udev* udev; - /* Data specific to the device subsystem */ - struct udev_monitor* udev_monitor; - sd_event_source *udev_event_source; + sd_device_monitor *device_monitor; Hashmap *devices_by_sysfs; /* Data specific to the mount subsystem */ @@ -215,7 +248,7 @@ struct Manager { /* This is used during reloading: before the reload we queue * the reply message here, and afterwards we send it */ - sd_bus_message *queued_message; + sd_bus_message *pending_reload_message; Hashmap *watch_bus; /* D-Bus names => Unit object n:1 */ @@ -250,11 +283,10 @@ struct Manager { usec_t etc_localtime_mtime; bool etc_localtime_accessible:1; - /* Flags */ - ManagerExitCode exit_code:5; + ManagerObjective objective:5; + /* Flags */ bool dispatching_load_queue:1; - bool dispatching_dbus_queue:1; bool taint_usr:1; @@ -267,7 +299,7 @@ struct Manager { /* Have we ever changed the "kernel.pid_max" sysctl? */ bool sysctl_pid_max_changed:1; - unsigned test_run_flags:8; + ManagerTestRunFlags test_run_flags:8; /* If non-zero, exit with the following value when the systemd * process terminate. Useful for containers: systemd-nspawn could get @@ -305,9 +337,6 @@ struct Manager { /* non-zero if we are reloading or reexecuting, */ int n_reloading; - /* A set which contains all jobs that started before reload and finished - * during it */ - Set *pending_finished_jobs; unsigned n_installed_jobs; unsigned n_failed_jobs; @@ -375,10 +404,12 @@ struct Manager { #define MANAGER_IS_FINISHED(m) (dual_timestamp_is_set((m)->timestamps + MANAGER_TIMESTAMP_FINISH)) -/* The exit code is set to OK as soon as we enter the main loop, and set otherwise as soon as we are done with it */ -#define MANAGER_IS_RUNNING(m) ((m)->exit_code == MANAGER_OK) +/* The objective is set to OK as soon as we enter the main loop, and set otherwise as soon as we are done with it */ +#define MANAGER_IS_RUNNING(m) ((m)->objective == MANAGER_OK) -int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **m); +#define MANAGER_IS_TEST_RUN(m) ((m)->test_run_flags != 0) + +int manager_new(UnitFileScope scope, ManagerTestRunFlags test_run_flags, Manager **m); Manager* manager_free(Manager *m); DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); @@ -408,7 +439,11 @@ void manager_clear_jobs(Manager *m); unsigned manager_dispatch_load_queue(Manager *m); -int manager_environment_add(Manager *m, char **minus, char **plus); +int manager_default_environment(Manager *m); +int manager_transient_environment_add(Manager *m, char **plus); +int manager_client_environment_modify(Manager *m, char **minus, char **plus); +int manager_get_effective_environment(Manager *m, char ***ret); + int manager_set_default_rlimits(Manager *m, struct rlimit **default_rlimit); int manager_loop(Manager *m); @@ -479,3 +514,4 @@ void manager_disable_confirm_spawn(void); const char *manager_timestamp_to_string(ManagerTimestamp m) _const_; ManagerTimestamp manager_timestamp_from_string(const char *s) _pure_; +ManagerTimestamp manager_timestamp_initrd_mangle(ManagerTimestamp s); |