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