]>
Commit | Line | Data |
---|---|---|
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 | 34 | typedef struct Manager Manager; |
acbb0225 LP |
35 | typedef enum WatchType WatchType; |
36 | typedef struct Watch Watch; | |
37 | ||
a16e1123 LP |
38 | typedef 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 |
52 | enum 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 LP |
63 | WATCH_DBUS_TIMEOUT, |
64 | WATCH_TIME_CHANGE | |
acbb0225 LP |
65 | }; |
66 | ||
67 | struct Watch { | |
68 | int fd; | |
69 | WatchType type; | |
ea430986 | 70 | union { |
ac155bb8 | 71 | struct Unit *unit; |
faf919f1 | 72 | struct Job *job; |
ea430986 LP |
73 | DBusWatch *bus_watch; |
74 | DBusTimeout *bus_timeout; | |
75 | } data; | |
cabab516 LP |
76 | bool fd_is_dupped:1; |
77 | bool socket_accept:1; | |
acbb0225 | 78 | }; |
60918275 | 79 | |
87f0e418 | 80 | #include "unit.h" |
60918275 LP |
81 | #include "job.h" |
82 | #include "hashmap.h" | |
83 | #include "list.h" | |
84 | #include "set.h" | |
ea430986 | 85 | #include "dbus.h" |
84e3543e | 86 | #include "path-lookup.h" |
60918275 LP |
87 | |
88 | struct Manager { | |
87f0e418 | 89 | /* Note that the set of units we know of is allowed to be |
35b8ca3a | 90 | * inconsistent. However the subset of it that is loaded may |
87d1515d LP |
91 | * not, and the list of jobs may neither. */ |
92 | ||
87f0e418 LP |
93 | /* Active jobs and units */ |
94 | Hashmap *units; /* name string => Unit object n:1 */ | |
60918275 LP |
95 | Hashmap *jobs; /* job id => Job object 1:1 */ |
96 | ||
ef734fd6 LP |
97 | /* To make it easy to iterate through the units of a specific |
98 | * type we maintain a per type linked list */ | |
ac155bb8 | 99 | LIST_HEAD(Unit, units_by_type[_UNIT_TYPE_MAX]); |
ef734fd6 | 100 | |
7c8fa05c LP |
101 | /* To optimize iteration of units that have requires_mounts_for set */ |
102 | LIST_HEAD(Unit, has_requires_mounts_for); | |
103 | ||
87f0e418 | 104 | /* Units that need to be loaded */ |
ac155bb8 | 105 | LIST_HEAD(Unit, load_queue); /* this is actually more a stack than a queue, but uh. */ |
60918275 | 106 | |
034c6ed7 LP |
107 | /* Jobs that need to be run */ |
108 | LIST_HEAD(Job, run_queue); /* more a stack than a queue, too */ | |
109 | ||
c1e1601e LP |
110 | /* Units and jobs that have not yet been announced via |
111 | * D-Bus. When something about a job changes it is added here | |
112 | * if it is not in there yet. This allows easy coalescing of | |
113 | * D-Bus change signals. */ | |
ac155bb8 | 114 | LIST_HEAD(Unit, dbus_unit_queue); |
c1e1601e LP |
115 | LIST_HEAD(Job, dbus_job_queue); |
116 | ||
701cc384 | 117 | /* Units to remove */ |
ac155bb8 | 118 | LIST_HEAD(Unit, cleanup_queue); |
23a177ef | 119 | |
701cc384 | 120 | /* Units to check when doing GC */ |
ac155bb8 | 121 | LIST_HEAD(Unit, gc_queue); |
701cc384 | 122 | |
87f0e418 | 123 | Hashmap *watch_pids; /* pid => Unit object n:1 */ |
9152c765 | 124 | |
c952c6ec LP |
125 | char *notify_socket; |
126 | ||
8c47c732 | 127 | Watch notify_watch; |
9d58f1db | 128 | Watch signal_watch; |
8742514c | 129 | Watch time_change_watch; |
9d58f1db | 130 | |
9152c765 | 131 | int epoll_fd; |
acbb0225 | 132 | |
9d58f1db | 133 | unsigned n_snapshots; |
ce578209 | 134 | |
84e3543e | 135 | LookupPaths lookup_paths; |
fe51822e | 136 | Set *unit_path_cache; |
036643a2 | 137 | |
1137a57c | 138 | char **environment; |
06d4c99a | 139 | char **default_controllers; |
1137a57c | 140 | |
e96d6be7 LP |
141 | usec_t runtime_watchdog; |
142 | usec_t shutdown_watchdog; | |
143 | ||
915b3753 LP |
144 | dual_timestamp firmware_timestamp; |
145 | dual_timestamp loader_timestamp; | |
146 | dual_timestamp kernel_timestamp; | |
e9ddabc2 | 147 | dual_timestamp initrd_timestamp; |
915b3753 | 148 | dual_timestamp userspace_timestamp; |
b0c918b9 | 149 | dual_timestamp finish_timestamp; |
8d567588 | 150 | |
5a1e9937 | 151 | char *generator_unit_path; |
07719a21 LP |
152 | char *generator_unit_path_early; |
153 | char *generator_unit_path_late; | |
b2bb3dbe | 154 | |
ef734fd6 | 155 | /* Data specific to the device subsystem */ |
25ac040b | 156 | struct udev* udev; |
f94ea366 LP |
157 | struct udev_monitor* udev_monitor; |
158 | Watch udev_watch; | |
8fe914ec | 159 | Hashmap *devices_by_sysfs; |
ef734fd6 LP |
160 | |
161 | /* Data specific to the mount subsystem */ | |
162 | FILE *proc_self_mountinfo; | |
163 | Watch mount_watch; | |
ea430986 | 164 | |
07b0b134 ML |
165 | /* Data specific to the swap filesystem */ |
166 | FILE *proc_swaps; | |
e04aad61 LP |
167 | Hashmap *swaps_by_proc_swaps; |
168 | bool request_reload; | |
4e434314 | 169 | Watch swap_watch; |
07b0b134 | 170 | |
ea430986 | 171 | /* Data specific to the D-Bus subsystem */ |
f278026d | 172 | DBusConnection *api_bus, *system_bus; |
5e8d1c9a LP |
173 | DBusServer *private_bus; |
174 | Set *bus_connections, *bus_connections_for_dispatch; | |
175 | ||
a16e1123 LP |
176 | DBusMessage *queued_message; /* This is used during reloading: |
177 | * before the reload we queue the | |
178 | * reply message here, and | |
179 | * afterwards we send it */ | |
7b97f477 | 180 | DBusConnection *queued_message_connection; /* The connection to send the queued message on */ |
8e274523 | 181 | |
05e343b7 LP |
182 | Hashmap *watch_bus; /* D-Bus names => Unit object n:1 */ |
183 | int32_t name_data_slot; | |
cbd37330 | 184 | int32_t conn_data_slot; |
a567261a | 185 | int32_t subscribed_data_slot; |
05e343b7 | 186 | |
7fab9d01 | 187 | uint32_t current_job_id; |
bacbccb7 | 188 | uint32_t default_unit_job_id; |
7fab9d01 | 189 | |
9d58f1db LP |
190 | /* Data specific to the Automount subsystem */ |
191 | int dev_autofs_fd; | |
192 | ||
8e274523 LP |
193 | /* Data specific to the cgroup subsystem */ |
194 | Hashmap *cgroup_bondings; /* path string => CGroupBonding object 1:n */ | |
8e274523 | 195 | char *cgroup_hierarchy; |
e537352b | 196 | |
701cc384 | 197 | usec_t gc_queue_timestamp; |
701cc384 LP |
198 | int gc_marker; |
199 | unsigned n_in_gc_queue; | |
200 | ||
35b8ca3a | 201 | /* Make sure the user cannot accidentally unmount our cgroup |
33be102a LP |
202 | * file system */ |
203 | int pin_cgroupfs_fd; | |
204 | ||
9d58f1db | 205 | /* Flags */ |
67445f4e | 206 | SystemdRunningAs running_as; |
b9080b03 | 207 | ManagerExitCode exit_code:5; |
41447faf | 208 | |
9d58f1db LP |
209 | bool dispatching_load_queue:1; |
210 | bool dispatching_run_queue:1; | |
211 | bool dispatching_dbus_queue:1; | |
212 | ||
72bc8d00 LP |
213 | bool taint_usr:1; |
214 | ||
9e58ff9c | 215 | bool show_status; |
f295f5c0 | 216 | bool confirm_spawn; |
d3689161 | 217 | |
0a494f1f LP |
218 | ExecOutput default_std_output, default_std_error; |
219 | ||
c93ff2e9 FC |
220 | struct rlimit *rlimit[RLIMIT_NLIMITS]; |
221 | ||
a7556052 LP |
222 | /* non-zero if we are reloading or reexecuting, */ |
223 | int n_reloading; | |
e409f875 LP |
224 | |
225 | unsigned n_installed_jobs; | |
76bf48b7 | 226 | unsigned n_failed_jobs; |
f2b68789 LP |
227 | |
228 | /* Type=idle pipes */ | |
229 | int idle_pipe[2]; | |
664f88a7 LP |
230 | |
231 | char *switch_root; | |
232 | char *switch_root_init; | |
60918275 LP |
233 | }; |
234 | ||
67445f4e | 235 | int manager_new(SystemdRunningAs running_as, Manager **m); |
60918275 LP |
236 | void manager_free(Manager *m); |
237 | ||
a16e1123 | 238 | int manager_enumerate(Manager *m); |
f50e0a01 | 239 | int manager_coldplug(Manager *m); |
a16e1123 | 240 | int manager_startup(Manager *m, FILE *serialization, FDSet *fds); |
f50e0a01 | 241 | |
60918275 | 242 | Job *manager_get_job(Manager *m, uint32_t id); |
87f0e418 | 243 | Unit *manager_get_unit(Manager *m, const char *name); |
60918275 | 244 | |
86fbf370 | 245 | int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j); |
ea430986 | 246 | |
398ef8ba LP |
247 | int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret); |
248 | int manager_load_unit(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret); | |
80fbf05e | 249 | int manager_load_unit_from_dbus_path(Manager *m, const char *s, DBusError *e, Unit **_u); |
28247076 | 250 | |
398ef8ba LP |
251 | int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, DBusError *e, Job **_ret); |
252 | int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool force, DBusError *e, Job **_ret); | |
60918275 | 253 | |
87f0e418 | 254 | void manager_dump_units(Manager *s, FILE *f, const char *prefix); |
cea8e32e | 255 | void manager_dump_jobs(Manager *s, FILE *f, const char *prefix); |
a66d02c3 | 256 | |
7fad411c LP |
257 | void manager_clear_jobs(Manager *m); |
258 | ||
c1e1601e LP |
259 | unsigned manager_dispatch_load_queue(Manager *m); |
260 | unsigned manager_dispatch_run_queue(Manager *m); | |
261 | unsigned manager_dispatch_dbus_queue(Manager *m); | |
f50e0a01 | 262 | |
06d4c99a | 263 | int manager_set_default_controllers(Manager *m, char **controllers); |
c93ff2e9 | 264 | int manager_set_default_rlimits(Manager *m, struct rlimit **default_rlimit); |
b2bb3dbe | 265 | |
9152c765 | 266 | int manager_loop(Manager *m); |
83c60c9f | 267 | |
05e343b7 LP |
268 | void manager_dispatch_bus_name_owner_changed(Manager *m, const char *name, const char* old_owner, const char *new_owner); |
269 | void manager_dispatch_bus_query_pid_done(Manager *m, const char *name, pid_t pid); | |
270 | ||
d8d5ab98 | 271 | int manager_open_serialization(Manager *m, FILE **_f); |
a16e1123 | 272 | |
6b78f9b4 | 273 | int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool serialize_jobs); |
a16e1123 LP |
274 | int manager_deserialize(Manager *m, FILE *f, FDSet *fds); |
275 | ||
276 | int manager_reload(Manager *m); | |
277 | ||
9e58ff9c LP |
278 | bool manager_is_booting_or_shutting_down(Manager *m); |
279 | ||
fdf20a31 | 280 | void manager_reset_failed(Manager *m); |
5632e374 | 281 | |
4927fcae | 282 | void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success); |
e983b760 | 283 | void manager_send_unit_plymouth(Manager *m, Unit *u); |
4927fcae | 284 | |
8f6df3fa LP |
285 | bool manager_unit_pending_inactive(Manager *m, const char *name); |
286 | ||
b0c918b9 LP |
287 | void manager_check_finished(Manager *m); |
288 | ||
5a1e9937 LP |
289 | void manager_run_generators(Manager *m); |
290 | void manager_undo_generators(Manager *m); | |
291 | ||
4cfa2c99 | 292 | void manager_recheck_journal(Manager *m); |
f1dd0c3f | 293 | |
27d340c7 LP |
294 | void manager_set_show_status(Manager *m, bool b); |
295 | bool manager_get_show_status(Manager *m); | |
68b29a9f LP |
296 | |
297 | void watch_init(Watch *w); |