]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
c2f1db8f | 2 | #pragma once |
83096483 LP |
3 | |
4 | /*** | |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2011 Lennart Poettering | |
8 | ||
9 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
10 | under the terms of the GNU Lesser General Public License as published by |
11 | the Free Software Foundation; either version 2.1 of the License, or | |
83096483 LP |
12 | (at your option) any later version. |
13 | ||
14 | systemd is distributed in the hope that it will be useful, but | |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 17 | Lesser General Public License for more details. |
83096483 | 18 | |
5430f7f2 | 19 | You should have received a copy of the GNU Lesser General Public License |
83096483 LP |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
21 | ***/ | |
22 | ||
cab6235f LP |
23 | typedef enum UnitFileScope UnitFileScope; |
24 | typedef enum UnitFileState UnitFileState; | |
25 | typedef enum UnitFilePresetMode UnitFilePresetMode; | |
26 | typedef enum UnitFileChangeType UnitFileChangeType; | |
b3796dd8 | 27 | typedef enum UnitFileFlags UnitFileFlags; |
0ec0deaa | 28 | typedef enum UnitFileType UnitFileType; |
cab6235f LP |
29 | typedef struct UnitFileChange UnitFileChange; |
30 | typedef struct UnitFileList UnitFileList; | |
31 | typedef struct UnitFileInstallInfo UnitFileInstallInfo; | |
32 | ||
a8fbdf54 TA |
33 | #include <stdbool.h> |
34 | ||
83096483 | 35 | #include "hashmap.h" |
a8fbdf54 | 36 | #include "macro.h" |
a8ffe6fb | 37 | #include "path-lookup.h" |
0ec0deaa LP |
38 | #include "strv.h" |
39 | #include "unit-name.h" | |
83096483 | 40 | |
cab6235f | 41 | enum UnitFileScope { |
83096483 LP |
42 | UNIT_FILE_SYSTEM, |
43 | UNIT_FILE_GLOBAL, | |
44 | UNIT_FILE_USER, | |
45 | _UNIT_FILE_SCOPE_MAX, | |
46 | _UNIT_FILE_SCOPE_INVALID = -1 | |
cab6235f | 47 | }; |
83096483 | 48 | |
cab6235f | 49 | enum UnitFileState { |
83096483 LP |
50 | UNIT_FILE_ENABLED, |
51 | UNIT_FILE_ENABLED_RUNTIME, | |
52 | UNIT_FILE_LINKED, | |
53 | UNIT_FILE_LINKED_RUNTIME, | |
54 | UNIT_FILE_MASKED, | |
55 | UNIT_FILE_MASKED_RUNTIME, | |
56 | UNIT_FILE_STATIC, | |
57 | UNIT_FILE_DISABLED, | |
aedd4012 | 58 | UNIT_FILE_INDIRECT, |
f4139308 | 59 | UNIT_FILE_GENERATED, |
e4fca67f | 60 | UNIT_FILE_TRANSIENT, |
0ec0deaa | 61 | UNIT_FILE_BAD, |
83096483 LP |
62 | _UNIT_FILE_STATE_MAX, |
63 | _UNIT_FILE_STATE_INVALID = -1 | |
cab6235f | 64 | }; |
83096483 | 65 | |
cab6235f | 66 | enum UnitFilePresetMode { |
d309c1c3 LP |
67 | UNIT_FILE_PRESET_FULL, |
68 | UNIT_FILE_PRESET_ENABLE_ONLY, | |
69 | UNIT_FILE_PRESET_DISABLE_ONLY, | |
86bbe5bf | 70 | _UNIT_FILE_PRESET_MAX, |
d309c1c3 | 71 | _UNIT_FILE_PRESET_INVALID = -1 |
cab6235f | 72 | }; |
d309c1c3 | 73 | |
cab6235f | 74 | enum UnitFileChangeType { |
83096483 LP |
75 | UNIT_FILE_SYMLINK, |
76 | UNIT_FILE_UNLINK, | |
9a0a413a | 77 | UNIT_FILE_IS_MASKED, |
893275df | 78 | UNIT_FILE_IS_DANGLING, |
83096483 | 79 | _UNIT_FILE_CHANGE_TYPE_MAX, |
1fa03360 | 80 | _UNIT_FILE_CHANGE_INVALID = INT_MIN |
cab6235f | 81 | }; |
83096483 | 82 | |
b3796dd8 JS |
83 | enum UnitFileFlags { |
84 | UNIT_FILE_RUNTIME = 1, | |
85 | UNIT_FILE_FORCE = 1 << 1, | |
3b3557c4 | 86 | UNIT_FILE_DRY_RUN = 1 << 2, |
b3796dd8 JS |
87 | }; |
88 | ||
af3d8113 ZJS |
89 | /* type can either one of the UnitFileChangeTypes listed above, or a negative error. |
90 | * If source is specified, it should be the contents of the path symlink. | |
91 | * In case of an error, source should be the existing symlink contents or NULL | |
92 | */ | |
cab6235f | 93 | struct UnitFileChange { |
af3d8113 | 94 | int type; /* UnitFileChangeType or bust */ |
83096483 LP |
95 | char *path; |
96 | char *source; | |
cab6235f | 97 | }; |
83096483 | 98 | |
795ff6d5 ZJS |
99 | static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, unsigned n_changes) { |
100 | unsigned i; | |
101 | for (i = 0; i < n_changes; i++) | |
102 | if (IN_SET(changes[i].type, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK)) | |
103 | return true; | |
104 | return false; | |
105 | } | |
106 | ||
cab6235f | 107 | struct UnitFileList { |
83096483 LP |
108 | char *path; |
109 | UnitFileState state; | |
cab6235f | 110 | }; |
83096483 | 111 | |
0ec0deaa LP |
112 | enum UnitFileType { |
113 | UNIT_FILE_TYPE_REGULAR, | |
114 | UNIT_FILE_TYPE_SYMLINK, | |
115 | UNIT_FILE_TYPE_MASKED, | |
116 | _UNIT_FILE_TYPE_MAX, | |
117 | _UNIT_FILE_TYPE_INVALID = -1, | |
118 | }; | |
119 | ||
cab6235f | 120 | struct UnitFileInstallInfo { |
7584d236 ZJS |
121 | char *name; |
122 | char *path; | |
123 | ||
124 | char **aliases; | |
125 | char **wanted_by; | |
126 | char **required_by; | |
aedd4012 | 127 | char **also; |
d54c4993 LP |
128 | |
129 | char *default_instance; | |
19539807 | 130 | char *symlink_target; |
0ec0deaa LP |
131 | |
132 | UnitFileType type; | |
19539807 | 133 | bool auxiliary; |
cab6235f | 134 | }; |
7584d236 | 135 | |
8a993b61 | 136 | bool unit_type_may_alias(UnitType type) _const_; |
ce99c68a | 137 | bool unit_type_may_template(UnitType type) _const_; |
8a993b61 | 138 | |
596fc263 ZJS |
139 | int unit_file_enable( |
140 | UnitFileScope scope, | |
b3796dd8 | 141 | UnitFileFlags flags, |
596fc263 ZJS |
142 | const char *root_dir, |
143 | char **files, | |
596fc263 ZJS |
144 | UnitFileChange **changes, |
145 | unsigned *n_changes); | |
146 | int unit_file_disable( | |
147 | UnitFileScope scope, | |
b3796dd8 | 148 | UnitFileFlags flags, |
596fc263 ZJS |
149 | const char *root_dir, |
150 | char **files, | |
151 | UnitFileChange **changes, | |
152 | unsigned *n_changes); | |
153 | int unit_file_reenable( | |
154 | UnitFileScope scope, | |
b3796dd8 | 155 | UnitFileFlags flags, |
596fc263 ZJS |
156 | const char *root_dir, |
157 | char **files, | |
596fc263 ZJS |
158 | UnitFileChange **changes, |
159 | unsigned *n_changes); | |
160 | int unit_file_preset( | |
161 | UnitFileScope scope, | |
b3796dd8 | 162 | UnitFileFlags flags, |
596fc263 ZJS |
163 | const char *root_dir, |
164 | char **files, | |
165 | UnitFilePresetMode mode, | |
596fc263 ZJS |
166 | UnitFileChange **changes, |
167 | unsigned *n_changes); | |
168 | int unit_file_preset_all( | |
169 | UnitFileScope scope, | |
b3796dd8 | 170 | UnitFileFlags flags, |
596fc263 ZJS |
171 | const char *root_dir, |
172 | UnitFilePresetMode mode, | |
596fc263 ZJS |
173 | UnitFileChange **changes, |
174 | unsigned *n_changes); | |
175 | int unit_file_mask( | |
176 | UnitFileScope scope, | |
b3796dd8 | 177 | UnitFileFlags flags, |
596fc263 ZJS |
178 | const char *root_dir, |
179 | char **files, | |
596fc263 ZJS |
180 | UnitFileChange **changes, |
181 | unsigned *n_changes); | |
182 | int unit_file_unmask( | |
183 | UnitFileScope scope, | |
b3796dd8 | 184 | UnitFileFlags flags, |
596fc263 ZJS |
185 | const char *root_dir, |
186 | char **files, | |
187 | UnitFileChange **changes, | |
188 | unsigned *n_changes); | |
189 | int unit_file_link( | |
190 | UnitFileScope scope, | |
b3796dd8 | 191 | UnitFileFlags flags, |
596fc263 ZJS |
192 | const char *root_dir, |
193 | char **files, | |
596fc263 ZJS |
194 | UnitFileChange **changes, |
195 | unsigned *n_changes); | |
196 | int unit_file_revert( | |
197 | UnitFileScope scope, | |
198 | const char *root_dir, | |
199 | char **files, | |
200 | UnitFileChange **changes, | |
201 | unsigned *n_changes); | |
202 | int unit_file_set_default( | |
203 | UnitFileScope scope, | |
b3796dd8 | 204 | UnitFileFlags flags, |
596fc263 ZJS |
205 | const char *root_dir, |
206 | const char *file, | |
596fc263 ZJS |
207 | UnitFileChange **changes, |
208 | unsigned *n_changes); | |
209 | int unit_file_get_default( | |
210 | UnitFileScope scope, | |
211 | const char *root_dir, | |
212 | char **name); | |
213 | int unit_file_add_dependency( | |
214 | UnitFileScope scope, | |
b3796dd8 | 215 | UnitFileFlags flags, |
596fc263 ZJS |
216 | const char *root_dir, |
217 | char **files, | |
218 | const char *target, | |
219 | UnitDependency dep, | |
596fc263 ZJS |
220 | UnitFileChange **changes, |
221 | unsigned *n_changes); | |
83096483 | 222 | |
0ec0deaa | 223 | int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret); |
e735decc | 224 | int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name); |
83096483 | 225 | |
313fe66f | 226 | int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns); |
0ec0deaa | 227 | Hashmap* unit_file_list_free(Hashmap *h); |
83096483 | 228 | |
57ab2eab | 229 | int unit_file_changes_add(UnitFileChange **changes, unsigned *n_changes, UnitFileChangeType type, const char *path, const char *source); |
83096483 | 230 | void unit_file_changes_free(UnitFileChange *changes, unsigned n_changes); |
af3d8113 | 231 | void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, unsigned n_changes, bool quiet); |
83096483 | 232 | |
c2a8d7b0 | 233 | int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name); |
83096483 | 234 | |
44a6b1b6 ZJS |
235 | const char *unit_file_state_to_string(UnitFileState s) _const_; |
236 | UnitFileState unit_file_state_from_string(const char *s) _pure_; | |
1fa03360 | 237 | /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */ |
83096483 | 238 | |
44a6b1b6 ZJS |
239 | const char *unit_file_change_type_to_string(UnitFileChangeType s) _const_; |
240 | UnitFileChangeType unit_file_change_type_from_string(const char *s) _pure_; | |
d309c1c3 LP |
241 | |
242 | const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_; | |
243 | UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_; |