]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/install.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / shared / install.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2011 Lennart Poettering
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 typedef enum UnitFileScope UnitFileScope;
24 typedef enum UnitFileState UnitFileState;
25 typedef enum UnitFilePresetMode UnitFilePresetMode;
26 typedef enum UnitFileChangeType UnitFileChangeType;
27 typedef enum UnitFileFlags UnitFileFlags;
28 typedef enum UnitFileType UnitFileType;
29 typedef struct UnitFileChange UnitFileChange;
30 typedef struct UnitFileList UnitFileList;
31 typedef struct UnitFileInstallInfo UnitFileInstallInfo;
32
33 #include <stdbool.h>
34
35 #include "hashmap.h"
36 #include "macro.h"
37 #include "path-lookup.h"
38 #include "strv.h"
39 #include "unit-name.h"
40
41 enum UnitFileScope {
42 UNIT_FILE_SYSTEM,
43 UNIT_FILE_GLOBAL,
44 UNIT_FILE_USER,
45 _UNIT_FILE_SCOPE_MAX,
46 _UNIT_FILE_SCOPE_INVALID = -1
47 };
48
49 enum UnitFileState {
50 UNIT_FILE_ENABLED,
51 UNIT_FILE_ENABLED_RUNTIME,
52 UNIT_FILE_LINKED,
53 UNIT_FILE_LINKED_RUNTIME,
54 UNIT_FILE_MASKED,
55 UNIT_FILE_MASKED_RUNTIME,
56 UNIT_FILE_STATIC,
57 UNIT_FILE_DISABLED,
58 UNIT_FILE_INDIRECT,
59 UNIT_FILE_GENERATED,
60 UNIT_FILE_TRANSIENT,
61 UNIT_FILE_BAD,
62 _UNIT_FILE_STATE_MAX,
63 _UNIT_FILE_STATE_INVALID = -1
64 };
65
66 enum UnitFilePresetMode {
67 UNIT_FILE_PRESET_FULL,
68 UNIT_FILE_PRESET_ENABLE_ONLY,
69 UNIT_FILE_PRESET_DISABLE_ONLY,
70 _UNIT_FILE_PRESET_MAX,
71 _UNIT_FILE_PRESET_INVALID = -1
72 };
73
74 enum UnitFileChangeType {
75 UNIT_FILE_SYMLINK,
76 UNIT_FILE_UNLINK,
77 UNIT_FILE_IS_MASKED,
78 UNIT_FILE_IS_DANGLING,
79 _UNIT_FILE_CHANGE_TYPE_MAX,
80 _UNIT_FILE_CHANGE_INVALID = INT_MIN
81 };
82
83 enum UnitFileFlags {
84 UNIT_FILE_RUNTIME = 1,
85 UNIT_FILE_FORCE = 1 << 1,
86 UNIT_FILE_DRY_RUN = 1 << 2,
87 };
88
89 /* type can either one of the UnitFileChangeTypes listed above, or a negative error.
90 * If source is specified, it should be the contents of the path symlink.
91 * In case of an error, source should be the existing symlink contents or NULL
92 */
93 struct UnitFileChange {
94 int type; /* UnitFileChangeType or bust */
95 char *path;
96 char *source;
97 };
98
99 static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, unsigned n_changes) {
100 unsigned i;
101 for (i = 0; i < n_changes; i++)
102 if (IN_SET(changes[i].type, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK))
103 return true;
104 return false;
105 }
106
107 struct UnitFileList {
108 char *path;
109 UnitFileState state;
110 };
111
112 enum UnitFileType {
113 UNIT_FILE_TYPE_REGULAR,
114 UNIT_FILE_TYPE_SYMLINK,
115 UNIT_FILE_TYPE_MASKED,
116 _UNIT_FILE_TYPE_MAX,
117 _UNIT_FILE_TYPE_INVALID = -1,
118 };
119
120 struct UnitFileInstallInfo {
121 char *name;
122 char *path;
123
124 char **aliases;
125 char **wanted_by;
126 char **required_by;
127 char **also;
128
129 char *default_instance;
130 char *symlink_target;
131
132 UnitFileType type;
133 bool auxiliary;
134 };
135
136 bool unit_type_may_alias(UnitType type) _const_;
137 bool unit_type_may_template(UnitType type) _const_;
138
139 int unit_file_enable(
140 UnitFileScope scope,
141 UnitFileFlags flags,
142 const char *root_dir,
143 char **files,
144 UnitFileChange **changes,
145 unsigned *n_changes);
146 int unit_file_disable(
147 UnitFileScope scope,
148 UnitFileFlags flags,
149 const char *root_dir,
150 char **files,
151 UnitFileChange **changes,
152 unsigned *n_changes);
153 int unit_file_reenable(
154 UnitFileScope scope,
155 UnitFileFlags flags,
156 const char *root_dir,
157 char **files,
158 UnitFileChange **changes,
159 unsigned *n_changes);
160 int unit_file_preset(
161 UnitFileScope scope,
162 UnitFileFlags flags,
163 const char *root_dir,
164 char **files,
165 UnitFilePresetMode mode,
166 UnitFileChange **changes,
167 unsigned *n_changes);
168 int unit_file_preset_all(
169 UnitFileScope scope,
170 UnitFileFlags flags,
171 const char *root_dir,
172 UnitFilePresetMode mode,
173 UnitFileChange **changes,
174 unsigned *n_changes);
175 int unit_file_mask(
176 UnitFileScope scope,
177 UnitFileFlags flags,
178 const char *root_dir,
179 char **files,
180 UnitFileChange **changes,
181 unsigned *n_changes);
182 int unit_file_unmask(
183 UnitFileScope scope,
184 UnitFileFlags flags,
185 const char *root_dir,
186 char **files,
187 UnitFileChange **changes,
188 unsigned *n_changes);
189 int unit_file_link(
190 UnitFileScope scope,
191 UnitFileFlags flags,
192 const char *root_dir,
193 char **files,
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 UnitFileFlags flags,
205 const char *root_dir,
206 const char *file,
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 UnitFileFlags flags,
216 const char *root_dir,
217 char **files,
218 const char *target,
219 UnitDependency dep,
220 UnitFileChange **changes,
221 unsigned *n_changes);
222
223 int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret);
224 int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name);
225
226 int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns);
227 Hashmap* unit_file_list_free(Hashmap *h);
228
229 int unit_file_changes_add(UnitFileChange **changes, unsigned *n_changes, UnitFileChangeType type, const char *path, const char *source);
230 void unit_file_changes_free(UnitFileChange *changes, unsigned n_changes);
231 void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, unsigned n_changes, bool quiet);
232
233 int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name);
234
235 const char *unit_file_state_to_string(UnitFileState s) _const_;
236 UnitFileState unit_file_state_from_string(const char *s) _pure_;
237 /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */
238
239 const char *unit_file_change_type_to_string(UnitFileChangeType s) _const_;
240 UnitFileChangeType unit_file_change_type_from_string(const char *s) _pure_;
241
242 const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_;
243 UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_;