]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/install.h
install: make UnitFileChangeType enum anonymous
[thirdparty/systemd.git] / src / shared / install.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 typedef enum UnitFilePresetMode UnitFilePresetMode;
5 typedef enum UnitFileChangeType UnitFileChangeType;
6 typedef enum UnitFileFlags UnitFileFlags;
7 typedef enum UnitFileType UnitFileType;
8 typedef struct UnitFileChange UnitFileChange;
9 typedef struct UnitFileList UnitFileList;
10 typedef struct UnitFileInstallInfo UnitFileInstallInfo;
11
12 #include <stdbool.h>
13
14 #include "hashmap.h"
15 #include "macro.h"
16 #include "path-lookup.h"
17 #include "strv.h"
18 #include "unit-name.h"
19
20 enum UnitFilePresetMode {
21 UNIT_FILE_PRESET_FULL,
22 UNIT_FILE_PRESET_ENABLE_ONLY,
23 UNIT_FILE_PRESET_DISABLE_ONLY,
24 _UNIT_FILE_PRESET_MAX,
25 _UNIT_FILE_PRESET_INVALID = -EINVAL,
26 };
27
28 /* This enum type is anonymous, since we usually store it in an 'int', as we overload it with negative errno
29 * values. */
30 enum {
31 UNIT_FILE_SYMLINK,
32 UNIT_FILE_UNLINK,
33 UNIT_FILE_IS_MASKED,
34 UNIT_FILE_IS_DANGLING,
35 _UNIT_FILE_CHANGE_TYPE_MAX,
36 _UNIT_FILE_CHANGE_TYPE_INVALID = -EINVAL,
37 };
38
39 enum UnitFileFlags {
40 UNIT_FILE_RUNTIME = 1 << 0, /* Public API via DBUS, do not change */
41 UNIT_FILE_FORCE = 1 << 1, /* Public API via DBUS, do not change */
42 UNIT_FILE_PORTABLE = 1 << 2, /* Public API via DBUS, do not change */
43 UNIT_FILE_DRY_RUN = 1 << 3,
44 _UNIT_FILE_FLAGS_MASK_PUBLIC = UNIT_FILE_RUNTIME|UNIT_FILE_PORTABLE|UNIT_FILE_FORCE,
45 };
46
47 /* type can either one of the UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK, … listed above, or a negative errno value.
48 * If source is specified, it should be the contents of the path symlink. In case of an error, source should
49 * be the existing symlink contents or NULL. */
50 struct UnitFileChange {
51 int type_or_errno; /* UNIT_FILE_SYMLINK, … if positive, errno if negative */
52 char *path;
53 char *source;
54 };
55
56 static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, size_t n_changes) {
57 for (size_t i = 0; i < n_changes; i++)
58 if (IN_SET(changes[i].type_or_errno, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK))
59 return true;
60 return false;
61 }
62
63 struct UnitFileList {
64 char *path;
65 UnitFileState state;
66 };
67
68 enum UnitFileType {
69 UNIT_FILE_TYPE_REGULAR,
70 UNIT_FILE_TYPE_SYMLINK,
71 UNIT_FILE_TYPE_MASKED,
72 _UNIT_FILE_TYPE_MAX,
73 _UNIT_FILE_TYPE_INVALID = -EINVAL,
74 };
75
76 struct UnitFileInstallInfo {
77 char *name;
78 char *path;
79
80 char **aliases;
81 char **wanted_by;
82 char **required_by;
83 char **also;
84
85 char *default_instance;
86 char *symlink_target;
87
88 UnitFileType type;
89 bool auxiliary;
90 };
91
92 int unit_file_enable(
93 UnitFileScope scope,
94 UnitFileFlags flags,
95 const char *root_dir,
96 char **files,
97 UnitFileChange **changes,
98 size_t *n_changes);
99 int unit_file_disable(
100 UnitFileScope scope,
101 UnitFileFlags flags,
102 const char *root_dir,
103 char **files,
104 UnitFileChange **changes,
105 size_t *n_changes);
106 int unit_file_reenable(
107 UnitFileScope scope,
108 UnitFileFlags flags,
109 const char *root_dir,
110 char **files,
111 UnitFileChange **changes,
112 size_t *n_changes);
113 int unit_file_preset(
114 UnitFileScope scope,
115 UnitFileFlags flags,
116 const char *root_dir,
117 char **files,
118 UnitFilePresetMode mode,
119 UnitFileChange **changes,
120 size_t *n_changes);
121 int unit_file_preset_all(
122 UnitFileScope scope,
123 UnitFileFlags flags,
124 const char *root_dir,
125 UnitFilePresetMode mode,
126 UnitFileChange **changes,
127 size_t *n_changes);
128 int unit_file_mask(
129 UnitFileScope scope,
130 UnitFileFlags flags,
131 const char *root_dir,
132 char **files,
133 UnitFileChange **changes,
134 size_t *n_changes);
135 int unit_file_unmask(
136 UnitFileScope scope,
137 UnitFileFlags flags,
138 const char *root_dir,
139 char **files,
140 UnitFileChange **changes,
141 size_t *n_changes);
142 int unit_file_link(
143 UnitFileScope scope,
144 UnitFileFlags flags,
145 const char *root_dir,
146 char **files,
147 UnitFileChange **changes,
148 size_t *n_changes);
149 int unit_file_revert(
150 UnitFileScope scope,
151 const char *root_dir,
152 char **files,
153 UnitFileChange **changes,
154 size_t *n_changes);
155 int unit_file_set_default(
156 UnitFileScope scope,
157 UnitFileFlags flags,
158 const char *root_dir,
159 const char *file,
160 UnitFileChange **changes,
161 size_t *n_changes);
162 int unit_file_get_default(
163 UnitFileScope scope,
164 const char *root_dir,
165 char **name);
166 int unit_file_add_dependency(
167 UnitFileScope scope,
168 UnitFileFlags flags,
169 const char *root_dir,
170 char **files,
171 const char *target,
172 UnitDependency dep,
173 UnitFileChange **changes,
174 size_t *n_changes);
175
176 int unit_file_lookup_state(
177 UnitFileScope scope,
178 const LookupPaths *paths,
179 const char *name,
180 UnitFileState *ret);
181
182 int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret);
183 int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name);
184
185 int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns);
186 Hashmap* unit_file_list_free(Hashmap *h);
187
188 int unit_file_changes_add(UnitFileChange **changes, size_t *n_changes, int type, const char *path, const char *source);
189 void unit_file_changes_free(UnitFileChange *changes, size_t n_changes);
190 void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, size_t n_changes, bool quiet);
191
192 int unit_file_verify_alias(const UnitFileInstallInfo *i, const char *dst, char **ret_dst);
193
194 typedef struct UnitFilePresetRule UnitFilePresetRule;
195
196 typedef struct {
197 UnitFilePresetRule *rules;
198 size_t n_rules;
199 bool initialized;
200 } UnitFilePresets;
201
202 void unit_file_presets_freep(UnitFilePresets *p);
203 int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name, UnitFilePresets *cached);
204
205 const char *unit_file_state_to_string(UnitFileState s) _const_;
206 UnitFileState unit_file_state_from_string(const char *s) _pure_;
207 /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */
208
209 const char *unit_file_change_type_to_string(int s) _const_;
210 int unit_file_change_type_from_string(const char *s) _pure_;
211
212 const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_;
213 UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_;