Debian Codegraph @

src/udev/udev-manager.h

raw
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #pragma once
3
4 #include "sd-event.h"
5
6 #include "list.h"
7 #include "udev-config.h"
8 #include "udev-forward.h"
9
10 /* This should have a higher priority than the device monitor and inotify watch, to make device monitor and
11 * inotify event source stopped as soon as possible when the signal is received. Otherwise, we may continue
12 * receive events that needs to be serialized anyway. */
13 #define EVENT_PRIORITY_SIGTERM (SD_EVENT_PRIORITY_NORMAL - 6)
14 /* This must have a higher priority than the inotify event source, to make 'remove' uevent received earlier
15 * than IN_IGNORED inotify event. */
16 #define EVENT_PRIORITY_DEVICE_MONITOR (SD_EVENT_PRIORITY_NORMAL - 5)
17 /* This must have a higher priority than the worker notification, to make IN_IGNORED event received earlier
18 * than notifications about requests of adding/removing inotify watches. */
19 #define EVENT_PRIORITY_INOTIFY_WATCH (SD_EVENT_PRIORITY_NORMAL - 4)
20 /* This must have a higher priority than the worker exit event, to make notifications about completions of
21 * processing events received before exit. */
22 #define EVENT_PRIORITY_WORKER_NOTIFY (SD_EVENT_PRIORITY_NORMAL - 3)
23 /* This should have a higher priority than timer events about killing long running worker processes or idle
24 * worker processes. */
25 #define EVENT_PRIORITY_WORKER_EXIT (SD_EVENT_PRIORITY_NORMAL - 2)
26 /* As said in the above, this should have a lower proority than the exit event source. */
27 #define EVENT_PRIORITY_WORKER_TIMER (SD_EVENT_PRIORITY_NORMAL - 1)
28 /* This should have a lower priority than most event sources, but let's process earlier than varlink and the
29 * legacy control socket. */
30 #define EVENT_PRIORITY_SIGHUP (SD_EVENT_PRIORITY_NORMAL + 1)
31 /* Let's not interrupt the service by any user process, even that requires privileges. */
32 #define EVENT_PRIORITY_VARLINK (SD_EVENT_PRIORITY_NORMAL + 2)
33 #define EVENT_PRIORITY_CONTROL (SD_EVENT_PRIORITY_NORMAL + 2)
34 /* The event is intended to trigger the post-event source, hence can be the lowest priority. */
35 #define EVENT_PRIORITY_REQUEUE_EVENT (SD_EVENT_PRIORITY_NORMAL + 3)
36
37 typedef struct Manager {
38 sd_event *event;
39 Hashmap *workers;
40 LIST_HEAD(Event, events);
41 Event *last_event;
42 char *cgroup;
43
44 UdevRules *rules;
45 Hashmap *properties;
46
47 sd_device_monitor *monitor;
48 UdevCtrl *ctrl;
49 sd_varlink_server *varlink_server;
50
51 char *worker_notify_socket_path;
52
53 /* used by udev-watch */
54 int inotify_fd;
55 sd_event_source *inotify_event;
56 Set *synthesize_change_child_event_sources;
57 Set *synthesized_events;
58 sd_event_source *synthesized_events_clear_event_source;
59
60 sd_event_source *kill_workers_event;
61
62 Hashmap *locked_events_by_disk;
63 Prioq *locked_events_by_time;
64 sd_event_source *requeue_locked_events_timer_event_source;
65
66 usec_t last_usec;
67
68 UdevConfig config_by_udev_conf;
69 UdevConfig config_by_command;
70 UdevConfig config_by_kernel;
71 UdevConfig config_by_control;
72 UdevConfig config;
73
74 bool queue_file_created;
75 bool stop_exec_queue;
76 bool exit;
77 } Manager;
78
79 Manager* manager_new(void);
80 Manager* manager_free(Manager *manager);
81 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
82
83 int manager_main(Manager *manager);
84 void manager_reload(Manager *manager, bool force);
85 void manager_revert(Manager *manager);
86 void manager_exit(Manager *manager);
87
88 void notify_ready(Manager *manager);
89
90 void manager_kill_workers(Manager *manager, int signo);
91 int manager_reset_kill_workers_timer(Manager *manager);
92
93 bool devpath_conflict(const char *a, const char *b);
94
95 int manager_requeue_locked_events_by_device(Manager *manager, sd_device *dev);
96
97 int manager_create_queue_file(Manager *manager);