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