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