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