/src/systemd/src/shared/install.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | | #pragma once |
3 | | |
4 | | typedef enum UnitFileScope UnitFileScope; |
5 | | typedef enum UnitFileState UnitFileState; |
6 | | typedef enum UnitFilePresetMode UnitFilePresetMode; |
7 | | typedef enum UnitFileChangeType UnitFileChangeType; |
8 | | typedef enum UnitFileFlags UnitFileFlags; |
9 | | typedef enum UnitFileType UnitFileType; |
10 | | typedef struct UnitFileChange UnitFileChange; |
11 | | typedef struct UnitFileList UnitFileList; |
12 | | typedef struct UnitFileInstallInfo UnitFileInstallInfo; |
13 | | |
14 | | #include <stdbool.h> |
15 | | |
16 | | #include "hashmap.h" |
17 | | #include "macro.h" |
18 | | #include "path-lookup.h" |
19 | | #include "strv.h" |
20 | | #include "unit-name.h" |
21 | | |
22 | | enum UnitFileScope { |
23 | | UNIT_FILE_SYSTEM, |
24 | | UNIT_FILE_GLOBAL, |
25 | | UNIT_FILE_USER, |
26 | | _UNIT_FILE_SCOPE_MAX, |
27 | | _UNIT_FILE_SCOPE_INVALID = -1 |
28 | | }; |
29 | | |
30 | | enum UnitFileState { |
31 | | UNIT_FILE_ENABLED, |
32 | | UNIT_FILE_ENABLED_RUNTIME, |
33 | | UNIT_FILE_LINKED, |
34 | | UNIT_FILE_LINKED_RUNTIME, |
35 | | UNIT_FILE_MASKED, |
36 | | UNIT_FILE_MASKED_RUNTIME, |
37 | | UNIT_FILE_STATIC, |
38 | | UNIT_FILE_DISABLED, |
39 | | UNIT_FILE_INDIRECT, |
40 | | UNIT_FILE_GENERATED, |
41 | | UNIT_FILE_TRANSIENT, |
42 | | UNIT_FILE_BAD, |
43 | | _UNIT_FILE_STATE_MAX, |
44 | | _UNIT_FILE_STATE_INVALID = -1 |
45 | | }; |
46 | | |
47 | | enum UnitFilePresetMode { |
48 | | UNIT_FILE_PRESET_FULL, |
49 | | UNIT_FILE_PRESET_ENABLE_ONLY, |
50 | | UNIT_FILE_PRESET_DISABLE_ONLY, |
51 | | _UNIT_FILE_PRESET_MAX, |
52 | | _UNIT_FILE_PRESET_INVALID = -1 |
53 | | }; |
54 | | |
55 | | enum UnitFileChangeType { |
56 | | UNIT_FILE_SYMLINK, |
57 | | UNIT_FILE_UNLINK, |
58 | | UNIT_FILE_IS_MASKED, |
59 | | UNIT_FILE_IS_DANGLING, |
60 | | _UNIT_FILE_CHANGE_TYPE_MAX, |
61 | | _UNIT_FILE_CHANGE_TYPE_INVALID = INT_MIN |
62 | | }; |
63 | | |
64 | | enum UnitFileFlags { |
65 | | UNIT_FILE_RUNTIME = 1 << 0, |
66 | | UNIT_FILE_FORCE = 1 << 1, |
67 | | UNIT_FILE_DRY_RUN = 1 << 2, |
68 | | }; |
69 | | |
70 | | /* type can either one of the UnitFileChangeTypes listed above, or a negative error. |
71 | | * If source is specified, it should be the contents of the path symlink. |
72 | | * In case of an error, source should be the existing symlink contents or NULL |
73 | | */ |
74 | | struct UnitFileChange { |
75 | | int type; /* UnitFileChangeType or bust */ |
76 | | char *path; |
77 | | char *source; |
78 | | }; |
79 | | |
80 | 0 | static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, size_t n_changes) { |
81 | 0 | size_t i; |
82 | 0 | for (i = 0; i < n_changes; i++) |
83 | 0 | if (IN_SET(changes[i].type, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK)) |
84 | 0 | return true; |
85 | 0 | return false; |
86 | 0 | } Unexecuted instantiation: fuzz-unit-file.c:unit_file_changes_have_modification Unexecuted instantiation: load-fragment-gperf.c:unit_file_changes_have_modification Unexecuted instantiation: ip-address-access.c:unit_file_changes_have_modification Unexecuted instantiation: load-fragment.c:unit_file_changes_have_modification Unexecuted instantiation: manager.c:unit_file_changes_have_modification Unexecuted instantiation: path.c:unit_file_changes_have_modification Unexecuted instantiation: service.c:unit_file_changes_have_modification Unexecuted instantiation: socket.c:unit_file_changes_have_modification Unexecuted instantiation: timer.c:unit_file_changes_have_modification Unexecuted instantiation: transaction.c:unit_file_changes_have_modification Unexecuted instantiation: unit-printf.c:unit_file_changes_have_modification Unexecuted instantiation: unit.c:unit_file_changes_have_modification Unexecuted instantiation: automount.c:unit_file_changes_have_modification Unexecuted instantiation: bpf-firewall.c:unit_file_changes_have_modification Unexecuted instantiation: cgroup.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-automount.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-job.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-manager.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-path.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-scope.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-service.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-socket.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-timer.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-unit.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-util.c:unit_file_changes_have_modification Unexecuted instantiation: dbus.c:unit_file_changes_have_modification Unexecuted instantiation: device.c:unit_file_changes_have_modification Unexecuted instantiation: dynamic-user.c:unit_file_changes_have_modification Unexecuted instantiation: emergency-action.c:unit_file_changes_have_modification Unexecuted instantiation: execute.c:unit_file_changes_have_modification Unexecuted instantiation: job.c:unit_file_changes_have_modification Unexecuted instantiation: load-dropin.c:unit_file_changes_have_modification Unexecuted instantiation: mount.c:unit_file_changes_have_modification Unexecuted instantiation: scope.c:unit_file_changes_have_modification Unexecuted instantiation: slice.c:unit_file_changes_have_modification Unexecuted instantiation: swap.c:unit_file_changes_have_modification Unexecuted instantiation: target.c:unit_file_changes_have_modification Unexecuted instantiation: bpf-devices.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-cgroup.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-device.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-execute.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-kill.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-mount.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-slice.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-swap.c:unit_file_changes_have_modification Unexecuted instantiation: dbus-target.c:unit_file_changes_have_modification Unexecuted instantiation: bus-unit-util.c:unit_file_changes_have_modification Unexecuted instantiation: install-printf.c:unit_file_changes_have_modification Unexecuted instantiation: install.c:unit_file_changes_have_modification Unexecuted instantiation: path-lookup.c:unit_file_changes_have_modification |
87 | | |
88 | | struct UnitFileList { |
89 | | char *path; |
90 | | UnitFileState state; |
91 | | }; |
92 | | |
93 | | enum UnitFileType { |
94 | | UNIT_FILE_TYPE_REGULAR, |
95 | | UNIT_FILE_TYPE_SYMLINK, |
96 | | UNIT_FILE_TYPE_MASKED, |
97 | | _UNIT_FILE_TYPE_MAX, |
98 | | _UNIT_FILE_TYPE_INVALID = -1, |
99 | | }; |
100 | | |
101 | | struct UnitFileInstallInfo { |
102 | | char *name; |
103 | | char *path; |
104 | | |
105 | | char **aliases; |
106 | | char **wanted_by; |
107 | | char **required_by; |
108 | | char **also; |
109 | | |
110 | | char *default_instance; |
111 | | char *symlink_target; |
112 | | |
113 | | UnitFileType type; |
114 | | bool auxiliary; |
115 | | }; |
116 | | |
117 | | bool unit_type_may_alias(UnitType type) _const_; |
118 | | bool unit_type_may_template(UnitType type) _const_; |
119 | | |
120 | | int unit_file_enable( |
121 | | UnitFileScope scope, |
122 | | UnitFileFlags flags, |
123 | | const char *root_dir, |
124 | | char **files, |
125 | | UnitFileChange **changes, |
126 | | size_t *n_changes); |
127 | | int unit_file_disable( |
128 | | UnitFileScope scope, |
129 | | UnitFileFlags flags, |
130 | | const char *root_dir, |
131 | | char **files, |
132 | | UnitFileChange **changes, |
133 | | size_t *n_changes); |
134 | | int unit_file_reenable( |
135 | | UnitFileScope scope, |
136 | | UnitFileFlags flags, |
137 | | const char *root_dir, |
138 | | char **files, |
139 | | UnitFileChange **changes, |
140 | | size_t *n_changes); |
141 | | int unit_file_preset( |
142 | | UnitFileScope scope, |
143 | | UnitFileFlags flags, |
144 | | const char *root_dir, |
145 | | char **files, |
146 | | UnitFilePresetMode mode, |
147 | | UnitFileChange **changes, |
148 | | size_t *n_changes); |
149 | | int unit_file_preset_all( |
150 | | UnitFileScope scope, |
151 | | UnitFileFlags flags, |
152 | | const char *root_dir, |
153 | | UnitFilePresetMode mode, |
154 | | UnitFileChange **changes, |
155 | | size_t *n_changes); |
156 | | int unit_file_mask( |
157 | | UnitFileScope scope, |
158 | | UnitFileFlags flags, |
159 | | const char *root_dir, |
160 | | char **files, |
161 | | UnitFileChange **changes, |
162 | | size_t *n_changes); |
163 | | int unit_file_unmask( |
164 | | UnitFileScope scope, |
165 | | UnitFileFlags flags, |
166 | | const char *root_dir, |
167 | | char **files, |
168 | | UnitFileChange **changes, |
169 | | size_t *n_changes); |
170 | | int unit_file_link( |
171 | | UnitFileScope scope, |
172 | | UnitFileFlags flags, |
173 | | const char *root_dir, |
174 | | char **files, |
175 | | UnitFileChange **changes, |
176 | | size_t *n_changes); |
177 | | int unit_file_revert( |
178 | | UnitFileScope scope, |
179 | | const char *root_dir, |
180 | | char **files, |
181 | | UnitFileChange **changes, |
182 | | size_t *n_changes); |
183 | | int unit_file_set_default( |
184 | | UnitFileScope scope, |
185 | | UnitFileFlags flags, |
186 | | const char *root_dir, |
187 | | const char *file, |
188 | | UnitFileChange **changes, |
189 | | size_t *n_changes); |
190 | | int unit_file_get_default( |
191 | | UnitFileScope scope, |
192 | | const char *root_dir, |
193 | | char **name); |
194 | | int unit_file_add_dependency( |
195 | | UnitFileScope scope, |
196 | | UnitFileFlags flags, |
197 | | const char *root_dir, |
198 | | char **files, |
199 | | const char *target, |
200 | | UnitDependency dep, |
201 | | UnitFileChange **changes, |
202 | | size_t *n_changes); |
203 | | |
204 | | int unit_file_lookup_state( |
205 | | UnitFileScope scope, |
206 | | const LookupPaths *paths, |
207 | | const char *name, |
208 | | UnitFileState *ret); |
209 | | |
210 | | int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret); |
211 | | int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name); |
212 | | |
213 | | int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns); |
214 | | Hashmap* unit_file_list_free(Hashmap *h); |
215 | | |
216 | | int unit_file_changes_add(UnitFileChange **changes, size_t *n_changes, UnitFileChangeType type, const char *path, const char *source); |
217 | | void unit_file_changes_free(UnitFileChange *changes, size_t n_changes); |
218 | | void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, size_t n_changes, bool quiet); |
219 | | |
220 | | int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name); |
221 | | |
222 | | const char *unit_file_state_to_string(UnitFileState s) _const_; |
223 | | UnitFileState unit_file_state_from_string(const char *s) _pure_; |
224 | | /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */ |
225 | | |
226 | | const char *unit_file_change_type_to_string(UnitFileChangeType s) _const_; |
227 | | UnitFileChangeType unit_file_change_type_from_string(const char *s) _pure_; |
228 | | |
229 | | const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_; |
230 | | UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_; |