]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/manager.h
manager: add DefaultEnvironment option
[thirdparty/systemd.git] / src / core / manager.h
CommitLineData
03467c88 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
60918275 2
c2f1db8f 3#pragma once
60918275 4
a7334b09
LP
5/***
6 This file is part of systemd.
7
8 Copyright 2010 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
a7334b09
LP
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 18 Lesser General Public License for more details.
a7334b09 19
5430f7f2 20 You should have received a copy of the GNU Lesser General Public License
a7334b09
LP
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22***/
23
60918275
LP
24#include <stdbool.h>
25#include <inttypes.h>
a66d02c3 26#include <stdio.h>
ea430986
LP
27#include <dbus/dbus.h>
28
a16e1123
LP
29#include "fdset.h"
30
4f0f902f 31/* Enforce upper limit how many names we allow */
59d1a833 32#define MANAGER_MAX_NAMES 131072 /* 128K */
4f0f902f 33
60918275 34typedef struct Manager Manager;
acbb0225
LP
35typedef enum WatchType WatchType;
36typedef struct Watch Watch;
37
a16e1123
LP
38typedef enum ManagerExitCode {
39 MANAGER_RUNNING,
40 MANAGER_EXIT,
41 MANAGER_RELOAD,
42 MANAGER_REEXECUTE,
b9080b03
FF
43 MANAGER_REBOOT,
44 MANAGER_POWEROFF,
45 MANAGER_HALT,
46 MANAGER_KEXEC,
664f88a7 47 MANAGER_SWITCH_ROOT,
a16e1123
LP
48 _MANAGER_EXIT_CODE_MAX,
49 _MANAGER_EXIT_CODE_INVALID = -1
50} ManagerExitCode;
51
acbb0225
LP
52enum WatchType {
53 WATCH_INVALID,
ef734fd6 54 WATCH_SIGNAL,
8c47c732 55 WATCH_NOTIFY,
acbb0225 56 WATCH_FD,
faf919f1
LP
57 WATCH_UNIT_TIMER,
58 WATCH_JOB_TIMER,
f94ea366 59 WATCH_MOUNT,
4e434314 60 WATCH_SWAP,
ea430986
LP
61 WATCH_UDEV,
62 WATCH_DBUS_WATCH,
8742514c 63 WATCH_DBUS_TIMEOUT,
03b717a3
MS
64 WATCH_TIME_CHANGE,
65 WATCH_JOBS_IN_PROGRESS
acbb0225
LP
66};
67
68struct Watch {
69 int fd;
70 WatchType type;
ea430986 71 union {
ac155bb8 72 struct Unit *unit;
faf919f1 73 struct Job *job;
ea430986
LP
74 DBusWatch *bus_watch;
75 DBusTimeout *bus_timeout;
76 } data;
cabab516
LP
77 bool fd_is_dupped:1;
78 bool socket_accept:1;
acbb0225 79};
60918275 80
87f0e418 81#include "unit.h"
60918275
LP
82#include "job.h"
83#include "hashmap.h"
84#include "list.h"
85#include "set.h"
ea430986 86#include "dbus.h"
84e3543e 87#include "path-lookup.h"
c17ec25e 88#include "execute.h"
60918275
LP
89
90struct Manager {
87f0e418 91 /* Note that the set of units we know of is allowed to be
35b8ca3a 92 * inconsistent. However the subset of it that is loaded may
87d1515d
LP
93 * not, and the list of jobs may neither. */
94
87f0e418
LP
95 /* Active jobs and units */
96 Hashmap *units; /* name string => Unit object n:1 */
60918275
LP
97 Hashmap *jobs; /* job id => Job object 1:1 */
98
ef734fd6
LP
99 /* To make it easy to iterate through the units of a specific
100 * type we maintain a per type linked list */
ac155bb8 101 LIST_HEAD(Unit, units_by_type[_UNIT_TYPE_MAX]);
ef734fd6 102
7c8fa05c
LP
103 /* To optimize iteration of units that have requires_mounts_for set */
104 LIST_HEAD(Unit, has_requires_mounts_for);
105
87f0e418 106 /* Units that need to be loaded */
ac155bb8 107 LIST_HEAD(Unit, load_queue); /* this is actually more a stack than a queue, but uh. */
60918275 108
034c6ed7
LP
109 /* Jobs that need to be run */
110 LIST_HEAD(Job, run_queue); /* more a stack than a queue, too */
111
c1e1601e
LP
112 /* Units and jobs that have not yet been announced via
113 * D-Bus. When something about a job changes it is added here
114 * if it is not in there yet. This allows easy coalescing of
115 * D-Bus change signals. */
ac155bb8 116 LIST_HEAD(Unit, dbus_unit_queue);
c1e1601e
LP
117 LIST_HEAD(Job, dbus_job_queue);
118
701cc384 119 /* Units to remove */
ac155bb8 120 LIST_HEAD(Unit, cleanup_queue);
23a177ef 121
701cc384 122 /* Units to check when doing GC */
ac155bb8 123 LIST_HEAD(Unit, gc_queue);
701cc384 124
87f0e418 125 Hashmap *watch_pids; /* pid => Unit object n:1 */
9152c765 126
c952c6ec
LP
127 char *notify_socket;
128
8c47c732 129 Watch notify_watch;
9d58f1db 130 Watch signal_watch;
8742514c 131 Watch time_change_watch;
03b717a3 132 Watch jobs_in_progress_watch;
9d58f1db 133
9152c765 134 int epoll_fd;
acbb0225 135
9d58f1db 136 unsigned n_snapshots;
ce578209 137
84e3543e 138 LookupPaths lookup_paths;
fe51822e 139 Set *unit_path_cache;
036643a2 140
1137a57c 141 char **environment;
06d4c99a 142 char **default_controllers;
1137a57c 143
e96d6be7
LP
144 usec_t runtime_watchdog;
145 usec_t shutdown_watchdog;
146
915b3753
LP
147 dual_timestamp firmware_timestamp;
148 dual_timestamp loader_timestamp;
149 dual_timestamp kernel_timestamp;
e9ddabc2 150 dual_timestamp initrd_timestamp;
915b3753 151 dual_timestamp userspace_timestamp;
b0c918b9 152 dual_timestamp finish_timestamp;
518d10e9
UTL
153 dual_timestamp generators_start_timestamp;
154 dual_timestamp generators_finish_timestamp;
d9acfb71
TA
155 dual_timestamp unitsload_start_timestamp;
156 dual_timestamp unitsload_finish_timestamp;
8d567588 157
5a1e9937 158 char *generator_unit_path;
07719a21
LP
159 char *generator_unit_path_early;
160 char *generator_unit_path_late;
b2bb3dbe 161
ef734fd6 162 /* Data specific to the device subsystem */
25ac040b 163 struct udev* udev;
f94ea366
LP
164 struct udev_monitor* udev_monitor;
165 Watch udev_watch;
8fe914ec 166 Hashmap *devices_by_sysfs;
ef734fd6
LP
167
168 /* Data specific to the mount subsystem */
169 FILE *proc_self_mountinfo;
170 Watch mount_watch;
ea430986 171
07b0b134
ML
172 /* Data specific to the swap filesystem */
173 FILE *proc_swaps;
e04aad61
LP
174 Hashmap *swaps_by_proc_swaps;
175 bool request_reload;
4e434314 176 Watch swap_watch;
07b0b134 177
ea430986 178 /* Data specific to the D-Bus subsystem */
f278026d 179 DBusConnection *api_bus, *system_bus;
5e8d1c9a
LP
180 DBusServer *private_bus;
181 Set *bus_connections, *bus_connections_for_dispatch;
182
a16e1123
LP
183 DBusMessage *queued_message; /* This is used during reloading:
184 * before the reload we queue the
185 * reply message here, and
186 * afterwards we send it */
7b97f477 187 DBusConnection *queued_message_connection; /* The connection to send the queued message on */
8e274523 188
05e343b7
LP
189 Hashmap *watch_bus; /* D-Bus names => Unit object n:1 */
190 int32_t name_data_slot;
cbd37330 191 int32_t conn_data_slot;
a567261a 192 int32_t subscribed_data_slot;
05e343b7 193
7fab9d01 194 uint32_t current_job_id;
bacbccb7 195 uint32_t default_unit_job_id;
7fab9d01 196
9d58f1db
LP
197 /* Data specific to the Automount subsystem */
198 int dev_autofs_fd;
199
8e274523
LP
200 /* Data specific to the cgroup subsystem */
201 Hashmap *cgroup_bondings; /* path string => CGroupBonding object 1:n */
9444b1f2 202 char *cgroup_root;
e537352b 203
701cc384 204 usec_t gc_queue_timestamp;
701cc384
LP
205 int gc_marker;
206 unsigned n_in_gc_queue;
207
35b8ca3a 208 /* Make sure the user cannot accidentally unmount our cgroup
33be102a
LP
209 * file system */
210 int pin_cgroupfs_fd;
211
9d58f1db 212 /* Flags */
67445f4e 213 SystemdRunningAs running_as;
b9080b03 214 ManagerExitCode exit_code:5;
41447faf 215
9d58f1db
LP
216 bool dispatching_load_queue:1;
217 bool dispatching_run_queue:1;
218 bool dispatching_dbus_queue:1;
219
72bc8d00
LP
220 bool taint_usr:1;
221
9e58ff9c 222 bool show_status;
f295f5c0 223 bool confirm_spawn;
d3689161 224
0a494f1f
LP
225 ExecOutput default_std_output, default_std_error;
226
c93ff2e9
FC
227 struct rlimit *rlimit[RLIMIT_NLIMITS];
228
a7556052
LP
229 /* non-zero if we are reloading or reexecuting, */
230 int n_reloading;
e409f875
LP
231
232 unsigned n_installed_jobs;
76bf48b7 233 unsigned n_failed_jobs;
f2b68789 234
03b717a3 235 /* Jobs in progress watching */
637f8b8e 236 unsigned n_running_jobs;
7ed9f6cd 237 unsigned n_on_console;
03b717a3 238 unsigned jobs_in_progress_iteration;
637f8b8e 239
f2b68789
LP
240 /* Type=idle pipes */
241 int idle_pipe[2];
664f88a7
LP
242
243 char *switch_root;
244 char *switch_root_init;
60918275
LP
245};
246
67445f4e 247int manager_new(SystemdRunningAs running_as, Manager **m);
60918275
LP
248void manager_free(Manager *m);
249
a16e1123 250int manager_enumerate(Manager *m);
f50e0a01 251int manager_coldplug(Manager *m);
a16e1123 252int manager_startup(Manager *m, FILE *serialization, FDSet *fds);
f50e0a01 253
60918275 254Job *manager_get_job(Manager *m, uint32_t id);
87f0e418 255Unit *manager_get_unit(Manager *m, const char *name);
60918275 256
86fbf370 257int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j);
ea430986 258
398ef8ba
LP
259int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret);
260int manager_load_unit(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret);
80fbf05e 261int manager_load_unit_from_dbus_path(Manager *m, const char *s, DBusError *e, Unit **_u);
28247076 262
398ef8ba
LP
263int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, DBusError *e, Job **_ret);
264int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool force, DBusError *e, Job **_ret);
60918275 265
87f0e418 266void manager_dump_units(Manager *s, FILE *f, const char *prefix);
cea8e32e 267void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
a66d02c3 268
7fad411c
LP
269void manager_clear_jobs(Manager *m);
270
c1e1601e
LP
271unsigned manager_dispatch_load_queue(Manager *m);
272unsigned manager_dispatch_run_queue(Manager *m);
273unsigned manager_dispatch_dbus_queue(Manager *m);
f50e0a01 274
97d0e5f8 275int manager_set_default_environment(Manager *m, char **environment);
06d4c99a 276int manager_set_default_controllers(Manager *m, char **controllers);
c93ff2e9 277int manager_set_default_rlimits(Manager *m, struct rlimit **default_rlimit);
b2bb3dbe 278
9152c765 279int manager_loop(Manager *m);
83c60c9f 280
05e343b7
LP
281void manager_dispatch_bus_name_owner_changed(Manager *m, const char *name, const char* old_owner, const char *new_owner);
282void manager_dispatch_bus_query_pid_done(Manager *m, const char *name, pid_t pid);
283
d8d5ab98 284int manager_open_serialization(Manager *m, FILE **_f);
a16e1123 285
b3680f49 286int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root);
a16e1123 287int manager_deserialize(Manager *m, FILE *f, FDSet *fds);
01e10de3 288int manager_distribute_fds(Manager *m, FDSet *fds);
a16e1123
LP
289
290int manager_reload(Manager *m);
291
44a6b1b6 292bool manager_is_reloading_or_reexecuting(Manager *m) _pure_;
c17ec25e 293
fdf20a31 294void manager_reset_failed(Manager *m);
5632e374 295
4927fcae 296void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success);
e983b760 297void manager_send_unit_plymouth(Manager *m, Unit *u);
4927fcae 298
31afa0a4 299bool manager_unit_inactive_or_pending(Manager *m, const char *name);
8f6df3fa 300
b0c918b9
LP
301void manager_check_finished(Manager *m);
302
5a1e9937
LP
303void manager_run_generators(Manager *m);
304void manager_undo_generators(Manager *m);
305
4cfa2c99 306void manager_recheck_journal(Manager *m);
f1dd0c3f 307
27d340c7 308void manager_set_show_status(Manager *m, bool b);
b1e2b33c 309void manager_status_printf(Manager *m, bool ephemeral, const char *status, const char *format, ...) _printf_attr_(4,5);
68b29a9f
LP
310
311void watch_init(Watch *w);