]> git.ipfire.org Git - thirdparty/systemd.git/blob - name.h
make sure impact of transactions is minimized
[thirdparty/systemd.git] / name.h
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #ifndef foonamehfoo
4 #define foonamehfoo
5
6 #include <stdbool.h>
7 #include <stdlib.h>
8
9 typedef union Name Name;
10 typedef struct Meta Meta;
11 typedef struct Service Service;
12 typedef struct Timer Timer;
13 typedef struct Socket Socket;
14 typedef struct Milestone Milestone;
15 typedef struct Device Device;
16 typedef struct Mount Mount;
17 typedef struct Automount Automount;
18 typedef struct Snapshot Snapshot;
19
20 #include "job.h"
21 #include "manager.h"
22 #include "set.h"
23 #include "util.h"
24 #include "list.h"
25 #include "socket-util.h"
26
27 typedef enum NameType {
28 NAME_SERVICE = 0,
29 NAME_TIMER,
30 NAME_SOCKET,
31 NAME_MILESTONE,
32 NAME_DEVICE,
33 NAME_MOUNT,
34 NAME_AUTOMOUNT,
35 NAME_SNAPSHOT,
36 _NAME_TYPE_MAX,
37 _NAME_TYPE_INVALID = -1,
38 } NameType;
39
40 typedef enum NameState {
41 NAME_STUB,
42 NAME_LOADED,
43 NAME_FAILED,
44 _NAME_STATE_MAX
45 } NameState;
46
47 typedef enum NameDependency {
48 /* Positive dependencies */
49 NAME_REQUIRES,
50 NAME_SOFT_REQUIRES,
51 NAME_WANTS,
52 NAME_REQUISITE,
53 NAME_SOFT_REQUISITE,
54 NAME_REQUIRED_BY, /* inverse of 'requires' and 'requisite' is 'required_by' */
55 NAME_WANTED_BY, /* inverse of 'wants', 'soft_requires' and 'soft_requisite' is 'wanted_by' */
56
57 /* Negative dependencies */
58 NAME_CONFLICTS, /* inverse of 'conflicts' is 'conflicts' */
59
60 /* Order */
61 NAME_BEFORE, /* inverse of before is after and vice versa */
62 NAME_AFTER,
63 _NAME_DEPENDENCY_MAX
64 } NameDependency;
65
66 struct Meta {
67 Manager *manager;
68 NameType type;
69 NameState state;
70
71 Set *names;
72 Set *dependencies[_NAME_DEPENDENCY_MAX];
73
74 char *description;
75
76 /* If there is something to do with this name, then this is
77 * the job for it */
78 Job *job;
79
80 bool linked:1;
81
82 /* Load queue */
83 LIST_FIELDS(Meta);
84 };
85
86 typedef enum ServiceState {
87 SERVICE_DEAD,
88 SERVICE_BEFORE,
89 SERVICE_START_PRE,
90 SERVICE_START,
91 SERVICE_START_POST,
92 SERVICE_RUNNING,
93 SERVICE_RELOAD_PRE,
94 SERVICE_RELOAD,
95 SERVICE_RELOAD_POST,
96 SERVICE_STOP_PRE,
97 SERVICE_STOP,
98 SERVICE_SIGTERM,
99 SERVICE_SIGKILL,
100 SERVICE_STOP_POST,
101 SERVICE_HOLDOFF,
102 SERVICE_MAINTAINANCE
103 } ServiceState;
104
105 typedef enum ServiceMode {
106 SERVICE_ONCE,
107 SERVICE_RESTART
108 } ServiceMode;
109
110 struct Service {
111 Meta meta;
112
113 ServiceState state;
114 ServiceMode mode;
115 };
116
117 typedef enum TimerState {
118 TIMER_DEAD,
119 TIMER_BEFORE,
120 TIMER_START_PRE,
121 TIMER_START,
122 TIMER_START_POST,
123 TIMER_WAITING,
124 TIMER_RUNNING,
125 TIMER_STOP_PRE,
126 TIMER_STOP,
127 TIMER_STOP_POST
128 } TimerState;
129
130 struct Timer {
131 Meta meta;
132
133 TimerState state;
134 Service *subject;
135
136 clockid_t clock_id;
137 usec_t next_elapse;
138 };
139
140 typedef enum SocketState {
141 SOCKET_DEAD,
142 SOCKET_BEFORE,
143 SOCKET_START_PRE,
144 SOCKET_START,
145 SOCKET_START_POST,
146 SOCKET_LISTENING,
147 SOCKET_RUNNING,
148 SOCKET_STOP_PRE,
149 SOCKET_STOP,
150 SOCKET_STOP_POST,
151 SOCKET_MAINTAINANCE,
152 _SOCKET_STATE_MAX
153 } SocketState;
154
155 struct Socket {
156 Meta meta;
157
158 SocketState state;
159
160 Address address;
161 int *fds;
162 unsigned n_fds;
163
164 Service *subject;
165 };
166
167 typedef enum MilestoneState {
168 MILESTONE_DEAD,
169 MILESTONE_BEFORE,
170 MILESTONE_ACTIVE
171 } MilestoneState;
172
173 struct Milestone {
174 Meta meta;
175
176 MilestoneState state;
177 };
178
179 typedef enum DeviceState {
180 DEVICE_DEAD,
181 DEVICE_BEFORE,
182 DEVICE_AVAILABLE
183 } DeviceState;
184
185 struct Device {
186 Meta meta;
187
188 DeviceState state;
189 char *sysfs;
190 };
191
192 typedef enum MountState {
193 MOUNT_DEAD,
194 MOUNT_BEFORE,
195 MOUNT_MOUNTING,
196 MOUNT_MOUNTED,
197 MOUNT_UNMOUNTING,
198 MOUNT_SIGTERM, /* if the mount command hangs */
199 MOUNT_SIGKILL,
200 MOUNT_MAINTAINANCE
201 } MountState;
202
203 struct Mount {
204 Meta meta;
205
206 MountState state;
207 char *path;
208 };
209
210 typedef enum AutomountState {
211 AUTOMOUNT_DEAD,
212 AUTOMOUNT_BEFORE,
213 AUTOMOUNT_START_PRE,
214 AUTOMOUNT_START,
215 AUTOMOUNT_START_POST,
216 AUTOMOUNT_WAITING,
217 AUTOMOUNT_RUNNING,
218 AUTOMOUNT_STOP_PRE,
219 AUTOMOUNT_STOP,
220 AUTOMOUNT_STOP_POST,
221 AUTOMOUNT_MAINTAINANCE
222 } AutomountState;
223
224 struct Automount {
225 Meta meta;
226
227 AutomountState state;
228 char *path;
229 Mount *subject;
230 };
231
232 typedef enum SnapshotState {
233 SNAPSHOT_DEAD,
234 SNAPSHOT_BEFORE,
235 SNAPSHOT_ACTIVE
236 } SnapshotState;
237
238 struct Snapshot {
239 Meta meta;
240
241 SnapshotState state;
242 bool cleanup:1;
243 };
244
245 union Name {
246 Meta meta;
247 Service service;
248 Timer timer;
249 Socket socket;
250 Milestone milestone;
251 Device device;
252 Mount mount;
253 Automount automount;
254 Snapshot snapshot;
255 };
256
257 /* For casting a name into the various name types */
258
259 #define DEFINE_CAST(UPPERCASE, MixedCase, lowercase) \
260 static inline MixedCase* UPPERCASE(Name *name) { \
261 if (name->meta.type != NAME_##UPPERCASE) \
262 return NULL; \
263 \
264 return &name->lowercase; \
265 }
266
267 DEFINE_CAST(SERVICE, Service, service);
268 DEFINE_CAST(TIMER, Timer, timer);
269 DEFINE_CAST(SOCKET, Socket, socket);
270 DEFINE_CAST(MILESTONE, Milestone, milestone);
271 DEFINE_CAST(DEVICE, Device, device);
272 DEFINE_CAST(MOUNT, Mount, mount);
273 DEFINE_CAST(AUTOMOUNT, Automount, automount);
274 DEFINE_CAST(SNAPSHOT, Snapshot, snapshot);
275
276 /* For casting the various name types into a name */
277 #define NAME(o) ((Name*) (o))
278
279 bool name_is_running(Name *name);
280 bool name_is_dead(Name *name);
281
282 NameType name_type_from_string(const char *n);
283 bool name_is_valid(const char *n);
284
285 Name *name_new(Manager *m);
286 void name_free(Name *name);
287 int name_link(Name *name);
288 int name_link_names(Name *name, bool replace);
289 int name_merge(Name *name, Name *other);
290 int name_sanitize(Name *n);
291 int name_load(Name *name);
292 const char* name_id(Name *n);
293
294 void name_dump(Name *n, FILE *f, const char *prefix);
295
296 #endif