]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
c2f1db8f | 2 | #pragma once |
83096483 | 3 | |
1b153a82 LP |
4 | #include <stdbool.h> |
5 | ||
cab6235f | 6 | typedef enum UnitFilePresetMode UnitFilePresetMode; |
cd44ec5a | 7 | typedef enum InstallChangeType InstallChangeType; |
b3796dd8 | 8 | typedef enum UnitFileFlags UnitFileFlags; |
318031fd | 9 | typedef enum InstallMode InstallMode; |
cd44ec5a | 10 | typedef struct InstallChange InstallChange; |
cab6235f | 11 | typedef struct UnitFileList UnitFileList; |
0047d54d | 12 | typedef struct InstallInfo InstallInfo; |
cab6235f | 13 | |
83096483 | 14 | #include "hashmap.h" |
a8fbdf54 | 15 | #include "macro.h" |
a8ffe6fb | 16 | #include "path-lookup.h" |
0ec0deaa | 17 | #include "strv.h" |
b380b643 | 18 | #include "unit-file.h" |
0ec0deaa | 19 | #include "unit-name.h" |
83096483 | 20 | |
cab6235f | 21 | enum UnitFilePresetMode { |
d309c1c3 LP |
22 | UNIT_FILE_PRESET_FULL, |
23 | UNIT_FILE_PRESET_ENABLE_ONLY, | |
24 | UNIT_FILE_PRESET_DISABLE_ONLY, | |
b364c4de LP |
25 | _UNIT_FILE_PRESET_MODE_MAX, |
26 | _UNIT_FILE_PRESET_MODE_INVALID = -EINVAL, | |
cab6235f | 27 | }; |
d309c1c3 | 28 | |
f8662fee | 29 | enum InstallChangeType { |
1308f72e ZJS |
30 | INSTALL_CHANGE_SYMLINK, |
31 | INSTALL_CHANGE_UNLINK, | |
32 | INSTALL_CHANGE_IS_MASKED, | |
bf3b0d5f | 33 | INSTALL_CHANGE_IS_MASKED_GENERATOR, |
1308f72e ZJS |
34 | INSTALL_CHANGE_IS_DANGLING, |
35 | INSTALL_CHANGE_DESTINATION_NOT_PRESENT, | |
36 | INSTALL_CHANGE_AUXILIARY_FAILED, | |
f8662fee | 37 | _INSTALL_CHANGE_TYPE_MAX, |
1308f72e | 38 | _INSTALL_CHANGE_INVALID = -EINVAL, |
f8662fee | 39 | _INSTALL_CHANGE_ERRNO_MAX = -ERRNO_MAX, /* Ensure this type covers the whole negative errno range */ |
cab6235f | 40 | }; |
83096483 | 41 | |
f8662fee LP |
42 | static inline bool INSTALL_CHANGE_TYPE_VALID(InstallChangeType t) { |
43 | return t >= _INSTALL_CHANGE_ERRNO_MAX && t < _INSTALL_CHANGE_TYPE_MAX; | |
44 | } | |
45 | ||
b3796dd8 | 46 | enum UnitFileFlags { |
ad5fdd39 ZJS |
47 | UNIT_FILE_RUNTIME = 1 << 0, /* Public API via DBUS, do not change */ |
48 | UNIT_FILE_FORCE = 1 << 1, /* Public API via DBUS, do not change */ | |
49 | UNIT_FILE_PORTABLE = 1 << 2, /* Public API via DBUS, do not change */ | |
50 | UNIT_FILE_DRY_RUN = 1 << 3, | |
51 | UNIT_FILE_IGNORE_AUXILIARY_FAILURE = 1 << 4, | |
83654007 | 52 | _UNIT_FILE_FLAGS_MASK_PUBLIC = UNIT_FILE_RUNTIME|UNIT_FILE_PORTABLE|UNIT_FILE_FORCE, |
b3796dd8 JS |
53 | }; |
54 | ||
f8662fee LP |
55 | /* type can be either one of the INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK, … listed above, or a negative |
56 | * errno value. | |
1308f72e | 57 | * |
93419a96 LP |
58 | * If source is specified, it should be the contents of the path symlink. In case of an error, source should |
59 | * be the existing symlink contents or NULL. */ | |
cd44ec5a | 60 | struct InstallChange { |
f8662fee | 61 | int type; /* INSTALL_CHANGE_SYMLINK, … if positive, errno if negative */ |
83096483 LP |
62 | char *path; |
63 | char *source; | |
cab6235f | 64 | }; |
83096483 | 65 | |
cd44ec5a | 66 | static inline bool install_changes_have_modification(const InstallChange* changes, size_t n_changes) { |
93419a96 | 67 | for (size_t i = 0; i < n_changes; i++) |
f8662fee | 68 | if (IN_SET(changes[i].type, INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK)) |
795ff6d5 ZJS |
69 | return true; |
70 | return false; | |
71 | } | |
72 | ||
cab6235f | 73 | struct UnitFileList { |
83096483 LP |
74 | char *path; |
75 | UnitFileState state; | |
cab6235f | 76 | }; |
83096483 | 77 | |
318031fd ZJS |
78 | enum InstallMode { |
79 | INSTALL_MODE_REGULAR, | |
80 | INSTALL_MODE_LINKED, | |
81 | INSTALL_MODE_ALIAS, | |
82 | INSTALL_MODE_MASKED, | |
83 | _INSTALL_MODE_MAX, | |
84 | _INSTALL_MODE_INVALID = -EINVAL, | |
0ec0deaa LP |
85 | }; |
86 | ||
0047d54d | 87 | struct InstallInfo { |
7584d236 ZJS |
88 | char *name; |
89 | char *path; | |
de61a04b | 90 | char *root; |
7584d236 ZJS |
91 | |
92 | char **aliases; | |
93 | char **wanted_by; | |
94 | char **required_by; | |
38f90179 | 95 | char **upheld_by; |
aedd4012 | 96 | char **also; |
d54c4993 LP |
97 | |
98 | char *default_instance; | |
19539807 | 99 | char *symlink_target; |
0ec0deaa | 100 | |
91810c8f | 101 | InstallMode install_mode; |
19539807 | 102 | bool auxiliary; |
cab6235f | 103 | }; |
7584d236 | 104 | |
596fc263 | 105 | int unit_file_enable( |
4870133b | 106 | RuntimeScope scope, |
b3796dd8 | 107 | UnitFileFlags flags, |
596fc263 | 108 | const char *root_dir, |
0f87041f | 109 | char **names_or_paths, |
cd44ec5a | 110 | InstallChange **changes, |
da6053d0 | 111 | size_t *n_changes); |
596fc263 | 112 | int unit_file_disable( |
4870133b | 113 | RuntimeScope scope, |
b3796dd8 | 114 | UnitFileFlags flags, |
596fc263 | 115 | const char *root_dir, |
0f87041f | 116 | char **names, |
cd44ec5a | 117 | InstallChange **changes, |
da6053d0 | 118 | size_t *n_changes); |
596fc263 | 119 | int unit_file_reenable( |
4870133b | 120 | RuntimeScope scope, |
b3796dd8 | 121 | UnitFileFlags flags, |
596fc263 | 122 | const char *root_dir, |
29a7c59a | 123 | char **names_or_paths, |
cd44ec5a | 124 | InstallChange **changes, |
da6053d0 | 125 | size_t *n_changes); |
596fc263 | 126 | int unit_file_preset( |
4870133b | 127 | RuntimeScope scope, |
b3796dd8 | 128 | UnitFileFlags flags, |
596fc263 | 129 | const char *root_dir, |
0f87041f | 130 | char **names, |
596fc263 | 131 | UnitFilePresetMode mode, |
cd44ec5a | 132 | InstallChange **changes, |
da6053d0 | 133 | size_t *n_changes); |
596fc263 | 134 | int unit_file_preset_all( |
4870133b | 135 | RuntimeScope scope, |
b3796dd8 | 136 | UnitFileFlags flags, |
596fc263 ZJS |
137 | const char *root_dir, |
138 | UnitFilePresetMode mode, | |
cd44ec5a | 139 | InstallChange **changes, |
da6053d0 | 140 | size_t *n_changes); |
596fc263 | 141 | int unit_file_mask( |
4870133b | 142 | RuntimeScope scope, |
b3796dd8 | 143 | UnitFileFlags flags, |
596fc263 | 144 | const char *root_dir, |
0f87041f | 145 | char **names, |
cd44ec5a | 146 | InstallChange **changes, |
da6053d0 | 147 | size_t *n_changes); |
596fc263 | 148 | int unit_file_unmask( |
4870133b | 149 | RuntimeScope scope, |
b3796dd8 | 150 | UnitFileFlags flags, |
596fc263 | 151 | const char *root_dir, |
0f87041f | 152 | char **names, |
cd44ec5a | 153 | InstallChange **changes, |
da6053d0 | 154 | size_t *n_changes); |
596fc263 | 155 | int unit_file_link( |
4870133b | 156 | RuntimeScope scope, |
b3796dd8 | 157 | UnitFileFlags flags, |
596fc263 ZJS |
158 | const char *root_dir, |
159 | char **files, | |
cd44ec5a | 160 | InstallChange **changes, |
da6053d0 | 161 | size_t *n_changes); |
596fc263 | 162 | int unit_file_revert( |
4870133b | 163 | RuntimeScope scope, |
596fc263 | 164 | const char *root_dir, |
0f87041f | 165 | char **names, |
cd44ec5a | 166 | InstallChange **changes, |
da6053d0 | 167 | size_t *n_changes); |
596fc263 | 168 | int unit_file_set_default( |
4870133b | 169 | RuntimeScope scope, |
b3796dd8 | 170 | UnitFileFlags flags, |
596fc263 | 171 | const char *root_dir, |
0f87041f | 172 | const char *name, |
cd44ec5a | 173 | InstallChange **changes, |
da6053d0 | 174 | size_t *n_changes); |
596fc263 | 175 | int unit_file_get_default( |
4870133b | 176 | RuntimeScope scope, |
596fc263 | 177 | const char *root_dir, |
454318d3 | 178 | char **ret); |
596fc263 | 179 | int unit_file_add_dependency( |
4870133b | 180 | RuntimeScope scope, |
b3796dd8 | 181 | UnitFileFlags flags, |
596fc263 | 182 | const char *root_dir, |
0f87041f | 183 | char **names, |
596fc263 ZJS |
184 | const char *target, |
185 | UnitDependency dep, | |
cd44ec5a | 186 | InstallChange **changes, |
da6053d0 | 187 | size_t *n_changes); |
83096483 | 188 | |
d6d98276 | 189 | int unit_file_lookup_state( |
4870133b | 190 | RuntimeScope scope, |
d6d98276 LP |
191 | const LookupPaths *paths, |
192 | const char *name, | |
193 | UnitFileState *ret); | |
194 | ||
4870133b | 195 | int unit_file_get_state(RuntimeScope scope, const char *root_dir, const char *filename, UnitFileState *ret); |
e09c255d LP |
196 | |
197 | int unit_file_exists_full(RuntimeScope scope, const LookupPaths *paths, const char *name, char **ret_path); | |
198 | static inline int unit_file_exists(RuntimeScope scope, const LookupPaths *paths, const char *name) { | |
199 | return unit_file_exists_full(scope, paths, name, NULL); | |
200 | } | |
83096483 | 201 | |
4870133b | 202 | int unit_file_get_list(RuntimeScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns); |
27beea26 | 203 | |
c92899fd | 204 | extern const struct hash_ops unit_file_list_hash_ops_free; |
83096483 | 205 | |
9264db1a | 206 | InstallChangeType install_changes_add(InstallChange **changes, size_t *n_changes, InstallChangeType type, const char *path, const char *source); |
cd44ec5a | 207 | void install_changes_free(InstallChange *changes, size_t n_changes); |
d41f08bd MY |
208 | |
209 | int install_change_dump_error(const InstallChange *change, char **ret_errmsg, const char **ret_bus_error); | |
210 | void install_changes_dump( | |
211 | int error, | |
212 | const char *verb, | |
213 | const InstallChange *changes, | |
214 | size_t n_changes, | |
215 | bool quiet); | |
83096483 | 216 | |
cbfdbffb | 217 | int unit_file_verify_alias( |
0047d54d | 218 | const InstallInfo *info, |
cbfdbffb ZJS |
219 | const char *dst, |
220 | char **ret_dst, | |
cd44ec5a | 221 | InstallChange **changes, |
cbfdbffb | 222 | size_t *n_changes); |
aa0f357f | 223 | |
8f7b2566 ZJS |
224 | typedef struct UnitFilePresetRule UnitFilePresetRule; |
225 | ||
226 | typedef struct { | |
227 | UnitFilePresetRule *rules; | |
228 | size_t n_rules; | |
229 | bool initialized; | |
230 | } UnitFilePresets; | |
231 | ||
e77e07f6 DDM |
232 | typedef enum PresetAction { |
233 | PRESET_UNKNOWN, | |
234 | PRESET_ENABLE, | |
235 | PRESET_DISABLE, | |
236 | PRESET_IGNORE, | |
237 | _PRESET_ACTION_MAX, | |
238 | _PRESET_ACTION_INVALID = -EINVAL, | |
239 | _PRESET_ACTION_ERRNO_MAX = -ERRNO_MAX, /* Ensure this type covers the whole negative errno range */ | |
240 | } PresetAction; | |
241 | ||
242 | const char *preset_action_past_tense_to_string(PresetAction action); | |
243 | ||
05cdf6a7 | 244 | void unit_file_presets_done(UnitFilePresets *p); |
e77e07f6 | 245 | PresetAction unit_file_query_preset(RuntimeScope scope, const char *root_dir, const char *name, UnitFilePresets *cached); |
83096483 | 246 | |
44a6b1b6 ZJS |
247 | const char *unit_file_state_to_string(UnitFileState s) _const_; |
248 | UnitFileState unit_file_state_from_string(const char *s) _pure_; | |
1fa03360 | 249 | /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */ |
83096483 | 250 | |
f8662fee | 251 | const char *install_change_type_to_string(InstallChangeType t) _const_; |
9264db1a | 252 | InstallChangeType install_change_type_from_string(const char *s) _pure_; |
d309c1c3 LP |
253 | |
254 | const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_; | |
255 | UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_; |