]>
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 | |
83096483 LP |
8 | ***/ |
9 | ||
cab6235f LP |
10 | typedef enum UnitFileScope UnitFileScope; |
11 | typedef enum UnitFileState UnitFileState; | |
12 | typedef enum UnitFilePresetMode UnitFilePresetMode; | |
13 | typedef enum UnitFileChangeType UnitFileChangeType; | |
b3796dd8 | 14 | typedef enum UnitFileFlags UnitFileFlags; |
0ec0deaa | 15 | typedef enum UnitFileType UnitFileType; |
cab6235f LP |
16 | typedef struct UnitFileChange UnitFileChange; |
17 | typedef struct UnitFileList UnitFileList; | |
18 | typedef struct UnitFileInstallInfo UnitFileInstallInfo; | |
19 | ||
a8fbdf54 TA |
20 | #include <stdbool.h> |
21 | ||
83096483 | 22 | #include "hashmap.h" |
a8fbdf54 | 23 | #include "macro.h" |
a8ffe6fb | 24 | #include "path-lookup.h" |
0ec0deaa LP |
25 | #include "strv.h" |
26 | #include "unit-name.h" | |
83096483 | 27 | |
cab6235f | 28 | enum UnitFileScope { |
83096483 LP |
29 | UNIT_FILE_SYSTEM, |
30 | UNIT_FILE_GLOBAL, | |
31 | UNIT_FILE_USER, | |
32 | _UNIT_FILE_SCOPE_MAX, | |
33 | _UNIT_FILE_SCOPE_INVALID = -1 | |
cab6235f | 34 | }; |
83096483 | 35 | |
cab6235f | 36 | enum UnitFileState { |
83096483 LP |
37 | UNIT_FILE_ENABLED, |
38 | UNIT_FILE_ENABLED_RUNTIME, | |
39 | UNIT_FILE_LINKED, | |
40 | UNIT_FILE_LINKED_RUNTIME, | |
41 | UNIT_FILE_MASKED, | |
42 | UNIT_FILE_MASKED_RUNTIME, | |
43 | UNIT_FILE_STATIC, | |
44 | UNIT_FILE_DISABLED, | |
aedd4012 | 45 | UNIT_FILE_INDIRECT, |
f4139308 | 46 | UNIT_FILE_GENERATED, |
e4fca67f | 47 | UNIT_FILE_TRANSIENT, |
0ec0deaa | 48 | UNIT_FILE_BAD, |
83096483 LP |
49 | _UNIT_FILE_STATE_MAX, |
50 | _UNIT_FILE_STATE_INVALID = -1 | |
cab6235f | 51 | }; |
83096483 | 52 | |
cab6235f | 53 | enum UnitFilePresetMode { |
d309c1c3 LP |
54 | UNIT_FILE_PRESET_FULL, |
55 | UNIT_FILE_PRESET_ENABLE_ONLY, | |
56 | UNIT_FILE_PRESET_DISABLE_ONLY, | |
86bbe5bf | 57 | _UNIT_FILE_PRESET_MAX, |
d309c1c3 | 58 | _UNIT_FILE_PRESET_INVALID = -1 |
cab6235f | 59 | }; |
d309c1c3 | 60 | |
cab6235f | 61 | enum UnitFileChangeType { |
83096483 LP |
62 | UNIT_FILE_SYMLINK, |
63 | UNIT_FILE_UNLINK, | |
9a0a413a | 64 | UNIT_FILE_IS_MASKED, |
893275df | 65 | UNIT_FILE_IS_DANGLING, |
83096483 | 66 | _UNIT_FILE_CHANGE_TYPE_MAX, |
42ce5f75 | 67 | _UNIT_FILE_CHANGE_TYPE_INVALID = INT_MIN |
cab6235f | 68 | }; |
83096483 | 69 | |
b3796dd8 | 70 | enum UnitFileFlags { |
42ce5f75 LP |
71 | UNIT_FILE_RUNTIME = 1U << 0, |
72 | UNIT_FILE_FORCE = 1U << 1, | |
73 | UNIT_FILE_DRY_RUN = 1U << 2, | |
b3796dd8 JS |
74 | }; |
75 | ||
af3d8113 ZJS |
76 | /* type can either one of the UnitFileChangeTypes listed above, or a negative error. |
77 | * If source is specified, it should be the contents of the path symlink. | |
78 | * In case of an error, source should be the existing symlink contents or NULL | |
79 | */ | |
cab6235f | 80 | struct UnitFileChange { |
af3d8113 | 81 | int type; /* UnitFileChangeType or bust */ |
83096483 LP |
82 | char *path; |
83 | char *source; | |
cab6235f | 84 | }; |
83096483 | 85 | |
da6053d0 LP |
86 | static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, size_t n_changes) { |
87 | size_t i; | |
795ff6d5 ZJS |
88 | for (i = 0; i < n_changes; i++) |
89 | if (IN_SET(changes[i].type, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK)) | |
90 | return true; | |
91 | return false; | |
92 | } | |
93 | ||
cab6235f | 94 | struct UnitFileList { |
83096483 LP |
95 | char *path; |
96 | UnitFileState state; | |
cab6235f | 97 | }; |
83096483 | 98 | |
0ec0deaa LP |
99 | enum UnitFileType { |
100 | UNIT_FILE_TYPE_REGULAR, | |
101 | UNIT_FILE_TYPE_SYMLINK, | |
102 | UNIT_FILE_TYPE_MASKED, | |
103 | _UNIT_FILE_TYPE_MAX, | |
104 | _UNIT_FILE_TYPE_INVALID = -1, | |
105 | }; | |
106 | ||
cab6235f | 107 | struct UnitFileInstallInfo { |
7584d236 ZJS |
108 | char *name; |
109 | char *path; | |
110 | ||
111 | char **aliases; | |
112 | char **wanted_by; | |
113 | char **required_by; | |
aedd4012 | 114 | char **also; |
d54c4993 LP |
115 | |
116 | char *default_instance; | |
19539807 | 117 | char *symlink_target; |
0ec0deaa LP |
118 | |
119 | UnitFileType type; | |
19539807 | 120 | bool auxiliary; |
cab6235f | 121 | }; |
7584d236 | 122 | |
8a993b61 | 123 | bool unit_type_may_alias(UnitType type) _const_; |
ce99c68a | 124 | bool unit_type_may_template(UnitType type) _const_; |
8a993b61 | 125 | |
596fc263 ZJS |
126 | int unit_file_enable( |
127 | UnitFileScope scope, | |
b3796dd8 | 128 | UnitFileFlags flags, |
596fc263 ZJS |
129 | const char *root_dir, |
130 | char **files, | |
596fc263 | 131 | UnitFileChange **changes, |
da6053d0 | 132 | size_t *n_changes); |
596fc263 ZJS |
133 | int unit_file_disable( |
134 | UnitFileScope scope, | |
b3796dd8 | 135 | UnitFileFlags flags, |
596fc263 ZJS |
136 | const char *root_dir, |
137 | char **files, | |
138 | UnitFileChange **changes, | |
da6053d0 | 139 | size_t *n_changes); |
596fc263 ZJS |
140 | int unit_file_reenable( |
141 | UnitFileScope scope, | |
b3796dd8 | 142 | UnitFileFlags flags, |
596fc263 ZJS |
143 | const char *root_dir, |
144 | char **files, | |
596fc263 | 145 | UnitFileChange **changes, |
da6053d0 | 146 | size_t *n_changes); |
596fc263 ZJS |
147 | int unit_file_preset( |
148 | UnitFileScope scope, | |
b3796dd8 | 149 | UnitFileFlags flags, |
596fc263 ZJS |
150 | const char *root_dir, |
151 | char **files, | |
152 | UnitFilePresetMode mode, | |
596fc263 | 153 | UnitFileChange **changes, |
da6053d0 | 154 | size_t *n_changes); |
596fc263 ZJS |
155 | int unit_file_preset_all( |
156 | UnitFileScope scope, | |
b3796dd8 | 157 | UnitFileFlags flags, |
596fc263 ZJS |
158 | const char *root_dir, |
159 | UnitFilePresetMode mode, | |
596fc263 | 160 | UnitFileChange **changes, |
da6053d0 | 161 | size_t *n_changes); |
596fc263 ZJS |
162 | int unit_file_mask( |
163 | UnitFileScope scope, | |
b3796dd8 | 164 | UnitFileFlags flags, |
596fc263 ZJS |
165 | const char *root_dir, |
166 | char **files, | |
596fc263 | 167 | UnitFileChange **changes, |
da6053d0 | 168 | size_t *n_changes); |
596fc263 ZJS |
169 | int unit_file_unmask( |
170 | UnitFileScope scope, | |
b3796dd8 | 171 | UnitFileFlags flags, |
596fc263 ZJS |
172 | const char *root_dir, |
173 | char **files, | |
174 | UnitFileChange **changes, | |
da6053d0 | 175 | size_t *n_changes); |
596fc263 ZJS |
176 | int unit_file_link( |
177 | UnitFileScope scope, | |
b3796dd8 | 178 | UnitFileFlags flags, |
596fc263 ZJS |
179 | const char *root_dir, |
180 | char **files, | |
596fc263 | 181 | UnitFileChange **changes, |
da6053d0 | 182 | size_t *n_changes); |
596fc263 ZJS |
183 | int unit_file_revert( |
184 | UnitFileScope scope, | |
185 | const char *root_dir, | |
186 | char **files, | |
187 | UnitFileChange **changes, | |
da6053d0 | 188 | size_t *n_changes); |
596fc263 ZJS |
189 | int unit_file_set_default( |
190 | UnitFileScope scope, | |
b3796dd8 | 191 | UnitFileFlags flags, |
596fc263 ZJS |
192 | const char *root_dir, |
193 | const char *file, | |
596fc263 | 194 | UnitFileChange **changes, |
da6053d0 | 195 | size_t *n_changes); |
596fc263 ZJS |
196 | int unit_file_get_default( |
197 | UnitFileScope scope, | |
198 | const char *root_dir, | |
199 | char **name); | |
200 | int unit_file_add_dependency( | |
201 | UnitFileScope scope, | |
b3796dd8 | 202 | UnitFileFlags flags, |
596fc263 ZJS |
203 | const char *root_dir, |
204 | char **files, | |
205 | const char *target, | |
206 | UnitDependency dep, | |
596fc263 | 207 | UnitFileChange **changes, |
da6053d0 | 208 | size_t *n_changes); |
83096483 | 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_; |