]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
c2f1db8f | 2 | #pragma once |
83096483 | 3 | |
cab6235f LP |
4 | typedef enum UnitFileScope UnitFileScope; |
5 | typedef enum UnitFileState UnitFileState; | |
6 | typedef enum UnitFilePresetMode UnitFilePresetMode; | |
7 | typedef enum UnitFileChangeType UnitFileChangeType; | |
b3796dd8 | 8 | typedef enum UnitFileFlags UnitFileFlags; |
0ec0deaa | 9 | typedef enum UnitFileType UnitFileType; |
cab6235f LP |
10 | typedef struct UnitFileChange UnitFileChange; |
11 | typedef struct UnitFileList UnitFileList; | |
12 | typedef struct UnitFileInstallInfo UnitFileInstallInfo; | |
13 | ||
a8fbdf54 TA |
14 | #include <stdbool.h> |
15 | ||
83096483 | 16 | #include "hashmap.h" |
a8fbdf54 | 17 | #include "macro.h" |
a8ffe6fb | 18 | #include "path-lookup.h" |
0ec0deaa LP |
19 | #include "strv.h" |
20 | #include "unit-name.h" | |
83096483 | 21 | |
cab6235f | 22 | enum UnitFileScope { |
83096483 LP |
23 | UNIT_FILE_SYSTEM, |
24 | UNIT_FILE_GLOBAL, | |
25 | UNIT_FILE_USER, | |
26 | _UNIT_FILE_SCOPE_MAX, | |
27 | _UNIT_FILE_SCOPE_INVALID = -1 | |
cab6235f | 28 | }; |
83096483 | 29 | |
cab6235f | 30 | enum UnitFileState { |
83096483 LP |
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, | |
aedd4012 | 39 | UNIT_FILE_INDIRECT, |
f4139308 | 40 | UNIT_FILE_GENERATED, |
e4fca67f | 41 | UNIT_FILE_TRANSIENT, |
0ec0deaa | 42 | UNIT_FILE_BAD, |
83096483 LP |
43 | _UNIT_FILE_STATE_MAX, |
44 | _UNIT_FILE_STATE_INVALID = -1 | |
cab6235f | 45 | }; |
83096483 | 46 | |
cab6235f | 47 | enum UnitFilePresetMode { |
d309c1c3 LP |
48 | UNIT_FILE_PRESET_FULL, |
49 | UNIT_FILE_PRESET_ENABLE_ONLY, | |
50 | UNIT_FILE_PRESET_DISABLE_ONLY, | |
86bbe5bf | 51 | _UNIT_FILE_PRESET_MAX, |
d309c1c3 | 52 | _UNIT_FILE_PRESET_INVALID = -1 |
cab6235f | 53 | }; |
d309c1c3 | 54 | |
cab6235f | 55 | enum UnitFileChangeType { |
83096483 LP |
56 | UNIT_FILE_SYMLINK, |
57 | UNIT_FILE_UNLINK, | |
9a0a413a | 58 | UNIT_FILE_IS_MASKED, |
893275df | 59 | UNIT_FILE_IS_DANGLING, |
83096483 | 60 | _UNIT_FILE_CHANGE_TYPE_MAX, |
42ce5f75 | 61 | _UNIT_FILE_CHANGE_TYPE_INVALID = INT_MIN |
cab6235f | 62 | }; |
83096483 | 63 | |
b3796dd8 | 64 | enum UnitFileFlags { |
ef31828d LP |
65 | UNIT_FILE_RUNTIME = 1 << 0, |
66 | UNIT_FILE_FORCE = 1 << 1, | |
67 | UNIT_FILE_DRY_RUN = 1 << 2, | |
b3796dd8 JS |
68 | }; |
69 | ||
af3d8113 ZJS |
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 | */ | |
cab6235f | 74 | struct UnitFileChange { |
af3d8113 | 75 | int type; /* UnitFileChangeType or bust */ |
83096483 LP |
76 | char *path; |
77 | char *source; | |
cab6235f | 78 | }; |
83096483 | 79 | |
da6053d0 LP |
80 | static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, size_t n_changes) { |
81 | size_t i; | |
795ff6d5 ZJS |
82 | for (i = 0; i < n_changes; i++) |
83 | if (IN_SET(changes[i].type, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK)) | |
84 | return true; | |
85 | return false; | |
86 | } | |
87 | ||
cab6235f | 88 | struct UnitFileList { |
83096483 LP |
89 | char *path; |
90 | UnitFileState state; | |
cab6235f | 91 | }; |
83096483 | 92 | |
0ec0deaa LP |
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 | ||
cab6235f | 101 | struct UnitFileInstallInfo { |
7584d236 ZJS |
102 | char *name; |
103 | char *path; | |
104 | ||
105 | char **aliases; | |
106 | char **wanted_by; | |
107 | char **required_by; | |
aedd4012 | 108 | char **also; |
d54c4993 LP |
109 | |
110 | char *default_instance; | |
19539807 | 111 | char *symlink_target; |
0ec0deaa LP |
112 | |
113 | UnitFileType type; | |
19539807 | 114 | bool auxiliary; |
cab6235f | 115 | }; |
7584d236 | 116 | |
8a993b61 | 117 | bool unit_type_may_alias(UnitType type) _const_; |
ce99c68a | 118 | bool unit_type_may_template(UnitType type) _const_; |
8a993b61 | 119 | |
596fc263 ZJS |
120 | int unit_file_enable( |
121 | UnitFileScope scope, | |
b3796dd8 | 122 | UnitFileFlags flags, |
596fc263 ZJS |
123 | const char *root_dir, |
124 | char **files, | |
596fc263 | 125 | UnitFileChange **changes, |
da6053d0 | 126 | size_t *n_changes); |
596fc263 ZJS |
127 | int unit_file_disable( |
128 | UnitFileScope scope, | |
b3796dd8 | 129 | UnitFileFlags flags, |
596fc263 ZJS |
130 | const char *root_dir, |
131 | char **files, | |
132 | UnitFileChange **changes, | |
da6053d0 | 133 | size_t *n_changes); |
596fc263 ZJS |
134 | int unit_file_reenable( |
135 | UnitFileScope scope, | |
b3796dd8 | 136 | UnitFileFlags flags, |
596fc263 ZJS |
137 | const char *root_dir, |
138 | char **files, | |
596fc263 | 139 | UnitFileChange **changes, |
da6053d0 | 140 | size_t *n_changes); |
596fc263 ZJS |
141 | int unit_file_preset( |
142 | UnitFileScope scope, | |
b3796dd8 | 143 | UnitFileFlags flags, |
596fc263 ZJS |
144 | const char *root_dir, |
145 | char **files, | |
146 | UnitFilePresetMode mode, | |
596fc263 | 147 | UnitFileChange **changes, |
da6053d0 | 148 | size_t *n_changes); |
596fc263 ZJS |
149 | int unit_file_preset_all( |
150 | UnitFileScope scope, | |
b3796dd8 | 151 | UnitFileFlags flags, |
596fc263 ZJS |
152 | const char *root_dir, |
153 | UnitFilePresetMode mode, | |
596fc263 | 154 | UnitFileChange **changes, |
da6053d0 | 155 | size_t *n_changes); |
596fc263 ZJS |
156 | int unit_file_mask( |
157 | UnitFileScope scope, | |
b3796dd8 | 158 | UnitFileFlags flags, |
596fc263 ZJS |
159 | const char *root_dir, |
160 | char **files, | |
596fc263 | 161 | UnitFileChange **changes, |
da6053d0 | 162 | size_t *n_changes); |
596fc263 ZJS |
163 | int unit_file_unmask( |
164 | UnitFileScope scope, | |
b3796dd8 | 165 | UnitFileFlags flags, |
596fc263 ZJS |
166 | const char *root_dir, |
167 | char **files, | |
168 | UnitFileChange **changes, | |
da6053d0 | 169 | size_t *n_changes); |
596fc263 ZJS |
170 | int unit_file_link( |
171 | UnitFileScope scope, | |
b3796dd8 | 172 | UnitFileFlags flags, |
596fc263 ZJS |
173 | const char *root_dir, |
174 | char **files, | |
596fc263 | 175 | UnitFileChange **changes, |
da6053d0 | 176 | size_t *n_changes); |
596fc263 ZJS |
177 | int unit_file_revert( |
178 | UnitFileScope scope, | |
179 | const char *root_dir, | |
180 | char **files, | |
181 | UnitFileChange **changes, | |
da6053d0 | 182 | size_t *n_changes); |
596fc263 ZJS |
183 | int unit_file_set_default( |
184 | UnitFileScope scope, | |
b3796dd8 | 185 | UnitFileFlags flags, |
596fc263 ZJS |
186 | const char *root_dir, |
187 | const char *file, | |
596fc263 | 188 | UnitFileChange **changes, |
da6053d0 | 189 | size_t *n_changes); |
596fc263 ZJS |
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, | |
b3796dd8 | 196 | UnitFileFlags flags, |
596fc263 ZJS |
197 | const char *root_dir, |
198 | char **files, | |
199 | const char *target, | |
200 | UnitDependency dep, | |
596fc263 | 201 | UnitFileChange **changes, |
da6053d0 | 202 | size_t *n_changes); |
83096483 | 203 | |
d6d98276 LP |
204 | int unit_file_lookup_state( |
205 | UnitFileScope scope, | |
206 | const LookupPaths *paths, | |
207 | const char *name, | |
208 | UnitFileState *ret); | |
209 | ||
0ec0deaa | 210 | int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret); |
e735decc | 211 | int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name); |
83096483 | 212 | |
313fe66f | 213 | int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns); |
0ec0deaa | 214 | Hashmap* unit_file_list_free(Hashmap *h); |
83096483 | 215 | |
da6053d0 LP |
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); | |
83096483 | 219 | |
c2a8d7b0 | 220 | int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name); |
83096483 | 221 | |
44a6b1b6 ZJS |
222 | const char *unit_file_state_to_string(UnitFileState s) _const_; |
223 | UnitFileState unit_file_state_from_string(const char *s) _pure_; | |
1fa03360 | 224 | /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */ |
83096483 | 225 | |
44a6b1b6 ZJS |
226 | const char *unit_file_change_type_to_string(UnitFileChangeType s) _const_; |
227 | UnitFileChangeType unit_file_change_type_from_string(const char *s) _pure_; | |
d309c1c3 LP |
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_; |