]>
Commit | Line | Data |
---|---|---|
60918275 LP |
1 | /*-*- Mode: C; c-basic-offset: 8 -*-*/ |
2 | ||
3 | #ifndef foomanagerhfoo | |
4 | #define foomanagerhfoo | |
5 | ||
a7334b09 LP |
6 | /*** |
7 | This file is part of systemd. | |
8 | ||
9 | Copyright 2010 Lennart Poettering | |
10 | ||
11 | systemd is free software; you can redistribute it and/or modify it | |
12 | under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 2 of the License, or | |
14 | (at your option) any later version. | |
15 | ||
16 | systemd is distributed in the hope that it will be useful, but | |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | General Public License for more details. | |
20 | ||
21 | You should have received a copy of the GNU General Public License | |
22 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
23 | ***/ | |
24 | ||
60918275 LP |
25 | #include <stdbool.h> |
26 | #include <inttypes.h> | |
a66d02c3 | 27 | #include <stdio.h> |
ea430986 LP |
28 | #include <dbus/dbus.h> |
29 | ||
a16e1123 LP |
30 | #include "fdset.h" |
31 | ||
4f0f902f LP |
32 | /* Enforce upper limit how many names we allow */ |
33 | #define MANAGER_MAX_NAMES 2048 | |
34 | ||
60918275 | 35 | typedef struct Manager Manager; |
acbb0225 LP |
36 | typedef enum WatchType WatchType; |
37 | typedef struct Watch Watch; | |
38 | ||
a16e1123 LP |
39 | typedef enum ManagerExitCode { |
40 | MANAGER_RUNNING, | |
41 | MANAGER_EXIT, | |
42 | MANAGER_RELOAD, | |
43 | MANAGER_REEXECUTE, | |
44 | _MANAGER_EXIT_CODE_MAX, | |
45 | _MANAGER_EXIT_CODE_INVALID = -1 | |
46 | } ManagerExitCode; | |
47 | ||
dfcd764e LP |
48 | typedef enum ManagerRunningAs { |
49 | MANAGER_INIT, /* root and pid=1 */ | |
50 | MANAGER_SYSTEM, /* root and pid!=1 */ | |
80876c20 | 51 | MANAGER_SESSION, /* non-root, for a session */ |
dfcd764e LP |
52 | _MANAGER_RUNNING_AS_MAX, |
53 | _MANAGER_RUNNING_AS_INVALID = -1 | |
54 | } ManagerRunningAs; | |
55 | ||
acbb0225 LP |
56 | enum WatchType { |
57 | WATCH_INVALID, | |
ef734fd6 | 58 | WATCH_SIGNAL, |
8c47c732 | 59 | WATCH_NOTIFY, |
acbb0225 | 60 | WATCH_FD, |
ef734fd6 | 61 | WATCH_TIMER, |
f94ea366 | 62 | WATCH_MOUNT, |
ea430986 LP |
63 | WATCH_UDEV, |
64 | WATCH_DBUS_WATCH, | |
65 | WATCH_DBUS_TIMEOUT | |
acbb0225 LP |
66 | }; |
67 | ||
68 | struct Watch { | |
69 | int fd; | |
70 | WatchType type; | |
ea430986 LP |
71 | union { |
72 | union Unit *unit; | |
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 { | |
89 | uint32_t current_job_id; | |
90 | ||
87f0e418 | 91 | /* Note that the set of units we know of is allowed to be |
87d1515d LP |
92 | * incosistent. However the subset of it that is loaded may |
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 */ | |
101 | LIST_HEAD(Meta, units_per_type[_UNIT_TYPE_MAX]); | |
102 | ||
87f0e418 | 103 | /* Units that need to be loaded */ |
60918275 LP |
104 | LIST_HEAD(Meta, load_queue); /* this is actually more a stack than a queue, but uh. */ |
105 | ||
034c6ed7 LP |
106 | /* Jobs that need to be run */ |
107 | LIST_HEAD(Job, run_queue); /* more a stack than a queue, too */ | |
108 | ||
c1e1601e LP |
109 | /* Units and jobs that have not yet been announced via |
110 | * D-Bus. When something about a job changes it is added here | |
111 | * if it is not in there yet. This allows easy coalescing of | |
112 | * D-Bus change signals. */ | |
113 | LIST_HEAD(Meta, dbus_unit_queue); | |
114 | LIST_HEAD(Job, dbus_job_queue); | |
115 | ||
701cc384 | 116 | /* Units to remove */ |
23a177ef LP |
117 | LIST_HEAD(Meta, cleanup_queue); |
118 | ||
701cc384 LP |
119 | /* Units to check when doing GC */ |
120 | LIST_HEAD(Meta, gc_queue); | |
121 | ||
e5b5ae50 | 122 | /* Jobs to be added */ |
87f0e418 | 123 | Hashmap *transaction_jobs; /* Unit object => Job object list 1:1 */ |
e5b5ae50 | 124 | JobDependency *transaction_anchor; |
223dabab | 125 | |
87f0e418 | 126 | Hashmap *watch_pids; /* pid => Unit object n:1 */ |
9152c765 | 127 | |
8c47c732 | 128 | Watch notify_watch; |
9d58f1db LP |
129 | Watch signal_watch; |
130 | ||
9152c765 | 131 | int epoll_fd; |
acbb0225 | 132 | |
9d58f1db | 133 | unsigned n_snapshots; |
ce578209 | 134 | |
84e3543e | 135 | LookupPaths lookup_paths; |
036643a2 | 136 | |
1137a57c LP |
137 | char **environment; |
138 | ||
871d7de4 | 139 | timestamp startup_timestamp; |
8d567588 | 140 | |
ef734fd6 | 141 | /* Data specific to the device subsystem */ |
25ac040b | 142 | struct udev* udev; |
f94ea366 LP |
143 | struct udev_monitor* udev_monitor; |
144 | Watch udev_watch; | |
ef734fd6 LP |
145 | |
146 | /* Data specific to the mount subsystem */ | |
147 | FILE *proc_self_mountinfo; | |
148 | Watch mount_watch; | |
ea430986 | 149 | |
07b0b134 ML |
150 | /* Data specific to the swap filesystem */ |
151 | FILE *proc_swaps; | |
152 | ||
ea430986 | 153 | /* Data specific to the D-Bus subsystem */ |
f278026d | 154 | DBusConnection *api_bus, *system_bus; |
c1e1601e | 155 | Set *subscribed; |
a16e1123 LP |
156 | DBusMessage *queued_message; /* This is used during reloading: |
157 | * before the reload we queue the | |
158 | * reply message here, and | |
159 | * afterwards we send it */ | |
8e274523 | 160 | |
05e343b7 LP |
161 | Hashmap *watch_bus; /* D-Bus names => Unit object n:1 */ |
162 | int32_t name_data_slot; | |
163 | ||
9d58f1db LP |
164 | /* Data specific to the Automount subsystem */ |
165 | int dev_autofs_fd; | |
166 | ||
8e274523 LP |
167 | /* Data specific to the cgroup subsystem */ |
168 | Hashmap *cgroup_bondings; /* path string => CGroupBonding object 1:n */ | |
169 | char *cgroup_controller; | |
170 | char *cgroup_hierarchy; | |
e537352b | 171 | |
701cc384 | 172 | usec_t gc_queue_timestamp; |
701cc384 LP |
173 | int gc_marker; |
174 | unsigned n_in_gc_queue; | |
175 | ||
9d58f1db LP |
176 | /* Flags */ |
177 | ManagerRunningAs running_as; | |
178 | ManagerExitCode exit_code:4; | |
41447faf | 179 | |
9d58f1db LP |
180 | bool dispatching_load_queue:1; |
181 | bool dispatching_run_queue:1; | |
182 | bool dispatching_dbus_queue:1; | |
183 | ||
184 | bool request_api_bus_dispatch:1; | |
185 | bool request_system_bus_dispatch:1; | |
186 | ||
187 | bool utmp_reboot_written:1; | |
188 | ||
189 | bool confirm_spawn:1; | |
60918275 LP |
190 | }; |
191 | ||
80876c20 | 192 | int manager_new(ManagerRunningAs running_as, bool confirm_spawn, Manager **m); |
60918275 LP |
193 | void manager_free(Manager *m); |
194 | ||
a16e1123 | 195 | int manager_enumerate(Manager *m); |
f50e0a01 | 196 | int manager_coldplug(Manager *m); |
a16e1123 | 197 | int manager_startup(Manager *m, FILE *serialization, FDSet *fds); |
f50e0a01 | 198 | |
60918275 | 199 | Job *manager_get_job(Manager *m, uint32_t id); |
87f0e418 | 200 | Unit *manager_get_unit(Manager *m, const char *name); |
60918275 | 201 | |
ea430986 | 202 | int manager_get_unit_from_dbus_path(Manager *m, const char *s, Unit **_u); |
86fbf370 | 203 | int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j); |
ea430986 | 204 | |
db06e3b6 | 205 | int manager_load_unit_prepare(Manager *m, const char *name, const char *path, Unit **_ret); |
9e2f7c11 | 206 | int manager_load_unit(Manager *m, const char *name, const char *path, Unit **_ret); |
28247076 | 207 | |
87f0e418 | 208 | int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, Job **_ret); |
28247076 | 209 | int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool force, Job **_ret); |
60918275 | 210 | |
87f0e418 | 211 | void manager_dump_units(Manager *s, FILE *f, const char *prefix); |
cea8e32e | 212 | void manager_dump_jobs(Manager *s, FILE *f, const char *prefix); |
a66d02c3 | 213 | |
23a177ef | 214 | void manager_transaction_unlink_job(Manager *m, Job *j, bool delete_dependencies); |
e5b5ae50 | 215 | |
7fad411c LP |
216 | void manager_clear_jobs(Manager *m); |
217 | ||
c1e1601e LP |
218 | unsigned manager_dispatch_load_queue(Manager *m); |
219 | unsigned manager_dispatch_run_queue(Manager *m); | |
220 | unsigned manager_dispatch_dbus_queue(Manager *m); | |
f50e0a01 | 221 | |
9152c765 | 222 | int manager_loop(Manager *m); |
83c60c9f | 223 | |
e537352b | 224 | void manager_write_utmp_reboot(Manager *m); |
e537352b LP |
225 | void manager_write_utmp_runlevel(Manager *m, Unit *t); |
226 | ||
05e343b7 LP |
227 | void manager_dispatch_bus_name_owner_changed(Manager *m, const char *name, const char* old_owner, const char *new_owner); |
228 | void manager_dispatch_bus_query_pid_done(Manager *m, const char *name, pid_t pid); | |
229 | ||
a16e1123 LP |
230 | int manager_open_serialization(FILE **_f); |
231 | ||
232 | int manager_serialize(Manager *m, FILE *f, FDSet *fds); | |
233 | int manager_deserialize(Manager *m, FILE *f, FDSet *fds); | |
234 | ||
235 | int manager_reload(Manager *m); | |
236 | ||
05e343b7 LP |
237 | const char *manager_running_as_to_string(ManagerRunningAs i); |
238 | ManagerRunningAs manager_running_as_from_string(const char *s); | |
239 | ||
60918275 | 240 | #endif |