]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/install.h
shared/install: add helper function unit_file_changes_have_modification()
[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
LP
76 _UNIT_FILE_CHANGE_TYPE_MAX,
77 _UNIT_FILE_CHANGE_TYPE_INVALID = -1
cab6235f 78};
83096483 79
cab6235f 80struct UnitFileChange {
83096483
LP
81 UnitFileChangeType type;
82 char *path;
83 char *source;
cab6235f 84};
83096483 85
795ff6d5
ZJS
86static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, unsigned n_changes) {
87 unsigned i;
88 for (i = 0; i < n_changes; i++)
89 if (IN_SET(changes[i].type, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK))
90 return true;
91 return false;
92}
93
cab6235f 94struct UnitFileList {
83096483
LP
95 char *path;
96 UnitFileState state;
cab6235f 97};
83096483 98
0ec0deaa
LP
99enum UnitFileType {
100 UNIT_FILE_TYPE_REGULAR,
101 UNIT_FILE_TYPE_SYMLINK,
102 UNIT_FILE_TYPE_MASKED,
103 _UNIT_FILE_TYPE_MAX,
104 _UNIT_FILE_TYPE_INVALID = -1,
105};
106
cab6235f 107struct UnitFileInstallInfo {
7584d236
ZJS
108 char *name;
109 char *path;
110
111 char **aliases;
112 char **wanted_by;
113 char **required_by;
aedd4012 114 char **also;
d54c4993
LP
115
116 char *default_instance;
0ec0deaa
LP
117
118 UnitFileType type;
119
120 char *symlink_target;
cab6235f 121};
7584d236 122
0ec0deaa
LP
123static inline bool UNIT_FILE_INSTALL_INFO_HAS_RULES(UnitFileInstallInfo *i) {
124 assert(i);
125
126 return !strv_isempty(i->aliases) ||
127 !strv_isempty(i->wanted_by) ||
128 !strv_isempty(i->required_by);
129}
130
131static inline bool UNIT_FILE_INSTALL_INFO_HAS_ALSO(UnitFileInstallInfo *i) {
132 assert(i);
133
134 return !strv_isempty(i->also);
135}
136
596fc263
ZJS
137int unit_file_enable(
138 UnitFileScope scope,
139 bool runtime,
140 const char *root_dir,
141 char **files,
142 bool force,
143 UnitFileChange **changes,
144 unsigned *n_changes);
145int unit_file_disable(
146 UnitFileScope scope,
147 bool runtime,
148 const char *root_dir,
149 char **files,
150 UnitFileChange **changes,
151 unsigned *n_changes);
152int unit_file_reenable(
153 UnitFileScope scope,
154 bool runtime,
155 const char *root_dir,
156 char **files,
157 bool force,
158 UnitFileChange **changes,
159 unsigned *n_changes);
160int unit_file_preset(
161 UnitFileScope scope,
162 bool runtime,
163 const char *root_dir,
164 char **files,
165 UnitFilePresetMode mode,
166 bool force,
167 UnitFileChange **changes,
168 unsigned *n_changes);
169int unit_file_preset_all(
170 UnitFileScope scope,
171 bool runtime,
172 const char *root_dir,
173 UnitFilePresetMode mode,
174 bool force,
175 UnitFileChange **changes,
176 unsigned *n_changes);
177int unit_file_mask(
178 UnitFileScope scope,
179 bool runtime,
180 const char *root_dir,
181 char **files,
182 bool force,
183 UnitFileChange **changes,
184 unsigned *n_changes);
185int unit_file_unmask(
186 UnitFileScope scope,
187 bool runtime,
188 const char *root_dir,
189 char **files,
190 UnitFileChange **changes,
191 unsigned *n_changes);
192int unit_file_link(
193 UnitFileScope scope,
194 bool runtime,
195 const char *root_dir,
196 char **files,
197 bool force,
198 UnitFileChange **changes,
199 unsigned *n_changes);
200int unit_file_revert(
201 UnitFileScope scope,
202 const char *root_dir,
203 char **files,
204 UnitFileChange **changes,
205 unsigned *n_changes);
206int unit_file_set_default(
207 UnitFileScope scope,
208 const char *root_dir,
209 const char *file,
210 bool force,
211 UnitFileChange **changes,
212 unsigned *n_changes);
213int unit_file_get_default(
214 UnitFileScope scope,
215 const char *root_dir,
216 char **name);
217int unit_file_add_dependency(
218 UnitFileScope scope,
219 bool runtime,
220 const char *root_dir,
221 char **files,
222 const char *target,
223 UnitDependency dep,
224 bool force,
225 UnitFileChange **changes,
226 unsigned *n_changes);
83096483 227
0ec0deaa 228int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret);
e735decc 229int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name);
83096483
LP
230
231int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h);
0ec0deaa 232Hashmap* unit_file_list_free(Hashmap *h);
83096483 233
57ab2eab 234int unit_file_changes_add(UnitFileChange **changes, unsigned *n_changes, UnitFileChangeType type, const char *path, const char *source);
83096483
LP
235void unit_file_changes_free(UnitFileChange *changes, unsigned n_changes);
236
c2a8d7b0 237int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name);
83096483 238
44a6b1b6
ZJS
239const char *unit_file_state_to_string(UnitFileState s) _const_;
240UnitFileState unit_file_state_from_string(const char *s) _pure_;
83096483 241
44a6b1b6
ZJS
242const char *unit_file_change_type_to_string(UnitFileChangeType s) _const_;
243UnitFileChangeType unit_file_change_type_from_string(const char *s) _pure_;
d309c1c3
LP
244
245const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_;
246UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_;