1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <stdbool.h>
5
6 #include "sd-bus.h"
7 #include "sd-event.h"
8
9 typedef struct Manager Manager;
10
11 #include "hashmap.h"
12 #include "image-dbus.h"
13 #include "list.h"
14 #include "machine-dbus.h"
15 #include "machine.h"
16 #include "operation.h"
17 #include "varlink.h"
18
19 struct Manager {
20 sd_event *event;
21 sd_bus *bus;
22
23 Hashmap *machines;
24 Hashmap *machine_units;
25 Hashmap *machine_leaders;
26
27 Hashmap *polkit_registry;
28
29 Hashmap *image_cache;
30 sd_event_source *image_cache_defer_event;
31
32 LIST_HEAD(Machine, machine_gc_queue);
33
34 Machine *host_machine;
35
36 LIST_HEAD(Operation, operations);
37 unsigned n_operations;
38
39 #if ENABLE_NSCD
40 sd_event_source *nscd_cache_flush_event;
41 #endif
42
43 VarlinkServer *varlink_server;
44 };
45
46 int manager_add_machine(Manager *m, const char *name, Machine **_machine);
47 int manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine);
48
49 extern const BusObjectImplementation manager_object;
50
51 int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error);
52 int match_unit_removed(sd_bus_message *message, void *userdata, sd_bus_error *error);
53 int match_properties_changed(sd_bus_message *message, void *userdata, sd_bus_error *error);
54 int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *error);
55
56 int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
57 int manager_kill_unit(Manager *manager, const char *unit, int signo, sd_bus_error *error);
58 int manager_unref_unit(Manager *m, const char *unit, sd_bus_error *error);
59 int manager_unit_is_active(Manager *manager, const char *unit);
60 int manager_job_is_active(Manager *manager, const char *path);
61
62 #if ENABLE_NSCD
63 int manager_enqueue_nscd_cache_flush(Manager *m);
64 #else
manager_enqueue_nscd_cache_flush(Manager * m)65 static inline void manager_enqueue_nscd_cache_flush(Manager *m) {}
66 #endif
67
68 int manager_find_machine_for_uid(Manager *m, uid_t host_uid, Machine **ret_machine, uid_t *ret_internal_uid);
69 int manager_find_machine_for_gid(Manager *m, gid_t host_gid, Machine **ret_machine, gid_t *ret_internal_gid);
70