]> git.ipfire.org Git - thirdparty/systemd.git/blame_incremental - src/shared/install.h
io.systemd.Unit.List fix context/runtime split (#38172)
[thirdparty/systemd.git] / src / shared / install.h
... / ...
CommitLineData
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
8typedef 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
16typedef 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
29static inline bool INSTALL_CHANGE_TYPE_VALID(InstallChangeType t) {
30 return t >= _INSTALL_CHANGE_ERRNO_MAX && t < _INSTALL_CHANGE_TYPE_MAX;
31}
32
33typedef 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. */
47typedef struct InstallChange {
48 int type; /* INSTALL_CHANGE_SYMLINK, … if positive, errno if negative */
49 char *path;
50 char *source;
51} InstallChange;
52
53static 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
60typedef struct UnitFileList {
61 char *path;
62 UnitFileState state;
63} UnitFileList;
64
65typedef 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
74typedef 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
92int 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);
99int 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);
106int 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);
113int 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);
121int 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);
128int 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);
135int 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);
142int 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);
149int unit_file_revert(
150 RuntimeScope scope,
151 const char *root_dir,
152 char * const *names,
153 InstallChange **changes,
154 size_t *n_changes);
155int 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);
162int unit_file_get_default(
163 RuntimeScope scope,
164 const char *root_dir,
165 char **ret);
166int 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
176int unit_file_lookup_state(
177 RuntimeScope scope,
178 const LookupPaths *paths,
179 const char *name,
180 UnitFileState *ret);
181
182int unit_file_get_state(RuntimeScope scope, const char *root_dir, const char *filename, UnitFileState *ret);
183
184int unit_file_exists_full(RuntimeScope scope, const LookupPaths *paths, const char *name, char **ret_path);
185static 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
189int unit_file_get_list(RuntimeScope scope, const char *root_dir, char * const *states, char * const *patterns, Hashmap **ret);
190
191InstallChangeType install_changes_add(InstallChange **changes, size_t *n_changes, InstallChangeType type, const char *path, const char *source);
192void install_changes_free(InstallChange *changes, size_t n_changes);
193
194int install_change_dump_error(const InstallChange *change, char **ret_errmsg, const char **ret_bus_error);
195void install_changes_dump(
196 int error,
197 const char *verb,
198 const InstallChange *changes,
199 size_t n_changes,
200 bool quiet);
201
202int 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
209typedef struct UnitFilePresetRule UnitFilePresetRule;
210
211typedef struct {
212 UnitFilePresetRule *rules;
213 size_t n_rules;
214 bool initialized;
215} UnitFilePresets;
216
217typedef 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
227const char* preset_action_past_tense_to_string(PresetAction action);
228
229void unit_file_presets_done(UnitFilePresets *p);
230PresetAction unit_file_query_preset(RuntimeScope scope, const char *root_dir, const char *name, UnitFilePresets *cached);
231
232const char* unit_file_state_to_string(UnitFileState s) _const_;
233UnitFileState 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
236const char* install_change_type_to_string(InstallChangeType t) _const_;
237InstallChangeType install_change_type_from_string(const char *s) _pure_;
238
239const char* unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_;
240UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_;