chiark / gitweb /
synchronize logger socket with what we use in the code
[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 #include <dbus/dbus.h>
11
12 typedef struct Manager Manager;
13 typedef enum WatchType WatchType;
14 typedef struct Watch Watch;
15
16 enum WatchType {
17         WATCH_INVALID,
18         WATCH_SIGNAL,
19         WATCH_FD,
20         WATCH_TIMER,
21         WATCH_MOUNT,
22         WATCH_UDEV,
23         WATCH_DBUS_WATCH,
24         WATCH_DBUS_TIMEOUT
25 };
26
27 struct Watch {
28         int fd;
29         WatchType type;
30         bool fd_is_dupped;
31         union {
32                 union Unit *unit;
33                 DBusWatch *bus_watch;
34                 DBusTimeout *bus_timeout;
35         } data;
36 };
37
38 #include "unit.h"
39 #include "job.h"
40 #include "hashmap.h"
41 #include "list.h"
42 #include "set.h"
43 #include "dbus.h"
44
45 #define SPECIAL_DEFAULT_TARGET "default.target"
46 #define SPECIAL_SYSLOG_SERVICE "syslog.service"
47 #define SPECIAL_DBUS_SERVICE "messagebus.service"
48 #define SPECIAL_LOGGER_SOCKET "systemd-logger.socket"
49 #define SPECIAL_KBREQUEST_TARGET "kbrequest.target"
50 #define SPECIAL_CTRL_ALT_DEL_TARGET "ctrl-alt-del.target"
51
52 struct Manager {
53         uint32_t current_job_id;
54
55         /* Note that the set of units we know of is allowed to be
56          * incosistent. However the subset of it that is loaded may
57          * not, and the list of jobs may neither. */
58
59         /* Active jobs and units */
60         Hashmap *units;  /* name string => Unit object n:1 */
61         Hashmap *jobs;   /* job id => Job object 1:1 */
62
63         /* To make it easy to iterate through the units of a specific
64          * type we maintain a per type linked list */
65         LIST_HEAD(Meta, units_per_type[_UNIT_TYPE_MAX]);
66
67         /* Units that need to be loaded */
68         LIST_HEAD(Meta, load_queue); /* this is actually more a stack than a queue, but uh. */
69
70         /* Jobs that need to be run */
71         LIST_HEAD(Job, run_queue);   /* more a stack than a queue, too */
72
73         /* Jobs to be added */
74         Hashmap *transaction_jobs;      /* Unit object => Job object list 1:1 */
75         JobDependency *transaction_anchor;
76
77         bool dispatching_load_queue:1;
78         bool dispatching_run_queue:1;
79
80         bool is_init:1;
81
82         bool request_bus_dispatch:1;
83
84         Hashmap *watch_pids;  /* pid => Unit object n:1 */
85
86         int epoll_fd;
87
88         Watch signal_watch;
89
90         /* Data specific to the device subsystem */
91         struct udev* udev;
92         struct udev_monitor* udev_monitor;
93         Watch udev_watch;
94
95         /* Data specific to the mount subsystem */
96         FILE *proc_self_mountinfo;
97         Watch mount_watch;
98
99         /* Data specific to the D-Bus subsystem */
100         DBusConnection *bus;
101 };
102
103 Manager* manager_new(void);
104 void manager_free(Manager *m);
105
106 int manager_coldplug(Manager *m);
107
108 Job *manager_get_job(Manager *m, uint32_t id);
109 Unit *manager_get_unit(Manager *m, const char *name);
110
111 int manager_get_unit_from_dbus_path(Manager *m, const char *s, Unit **_u);
112
113 int manager_load_unit(Manager *m, const char *path_or_name, Unit **_ret);
114 int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, Job **_ret);
115
116 void manager_dump_units(Manager *s, FILE *f, const char *prefix);
117 void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
118
119 void manager_transaction_unlink_job(Manager *m, Job *j);
120
121 void manager_clear_jobs(Manager *m);
122
123 void manager_dispatch_load_queue(Manager *m);
124 void manager_dispatch_run_queue(Manager *m);
125
126 int manager_loop(Manager *m);
127
128 #endif