chiark / gitweb /
monitor udev for device changes
[elogind.git] / manager.h
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #ifndef foomanagerhfoo
4 #define foomanagerhfoo
5
6 #include <stdbool.h>
7 #include <inttypes.h>
8 #include <stdio.h>
9
10 typedef struct Manager Manager;
11 typedef enum WatchType WatchType;
12 typedef struct Watch Watch;
13
14 enum WatchType {
15         WATCH_INVALID,
16         WATCH_SIGNAL,
17         WATCH_FD,
18         WATCH_TIMER,
19         WATCH_MOUNT,
20         WATCH_UDEV
21 };
22
23 struct Watch {
24         int fd;
25         WatchType type;
26         union Unit *unit;
27 };
28
29 #include "unit.h"
30 #include "job.h"
31 #include "hashmap.h"
32 #include "list.h"
33 #include "set.h"
34
35 #define SPECIAL_DEFAULT_TARGET "default.target"
36 #define SPECIAL_SYSLOG_SERVICE "syslog.service"
37 #define SPECIAL_DBUS_SERVICE "messagebus.service"
38 #define SPECIAL_LOGGER_SOCKET "systemd-logger.socket"
39 #define SPECIAL_KBREQUEST_TARGET "kbrequest.target"
40 #define SPECIAL_CTRL_ALT_DEL_TARGET "ctrl-alt-del.target"
41
42 struct Manager {
43         uint32_t current_job_id;
44
45         /* Note that the set of units we know of is allowed to be
46          * incosistent. However the subset of it that is loaded may
47          * not, and the list of jobs may neither. */
48
49         /* Active jobs and units */
50         Hashmap *units;  /* name string => Unit object n:1 */
51         Hashmap *jobs;   /* job id => Job object 1:1 */
52
53         /* To make it easy to iterate through the units of a specific
54          * type we maintain a per type linked list */
55         LIST_HEAD(Meta, units_per_type[_UNIT_TYPE_MAX]);
56
57         /* Units that need to be loaded */
58         LIST_HEAD(Meta, load_queue); /* this is actually more a stack than a queue, but uh. */
59
60         /* Jobs that need to be run */
61         LIST_HEAD(Job, run_queue);   /* more a stack than a queue, too */
62
63         /* Jobs to be added */
64         Hashmap *transaction_jobs;      /* Unit object => Job object list 1:1 */
65         JobDependency *transaction_anchor;
66
67         bool dispatching_load_queue:1;
68         bool dispatching_run_queue:1;
69
70         Hashmap *watch_pids;  /* pid => Unit object n:1 */
71
72         int epoll_fd;
73
74         Watch signal_watch;
75
76         /* Data specific to the device subsystem */
77         struct udev* udev;
78         struct udev_monitor* udev_monitor;
79         Watch udev_watch;
80
81         /* Data specific to the mount subsystem */
82         FILE *proc_self_mountinfo;
83         Watch mount_watch;
84 };
85
86 Manager* manager_new(void);
87 void manager_free(Manager *m);
88
89 int manager_coldplug(Manager *m);
90
91 Job *manager_get_job(Manager *m, uint32_t id);
92 Unit *manager_get_unit(Manager *m, const char *name);
93
94 int manager_load_unit(Manager *m, const char *path_or_name, Unit **_ret);
95 int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, Job **_ret);
96
97 void manager_dump_units(Manager *s, FILE *f, const char *prefix);
98 void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
99
100 void manager_transaction_unlink_job(Manager *m, Job *j);
101
102 void manager_clear_jobs(Manager *m);
103
104 void manager_dispatch_load_queue(Manager *m);
105 void manager_dispatch_run_queue(Manager *m);
106
107 int manager_loop(Manager *m);
108
109 #endif