]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/install.h
Merge pull request #14547 from keszybz/networkctl-matching
[thirdparty/systemd.git] / src / shared / install.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
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 = -1
26 };
27
28 enum UnitFileChangeType {
29 UNIT_FILE_SYMLINK,
30 UNIT_FILE_UNLINK,
31 UNIT_FILE_IS_MASKED,
32 UNIT_FILE_IS_DANGLING,
33 _UNIT_FILE_CHANGE_TYPE_MAX,
34 _UNIT_FILE_CHANGE_TYPE_INVALID = INT_MIN
35 };
36
37 enum UnitFileFlags {
38 UNIT_FILE_RUNTIME = 1 << 0,
39 UNIT_FILE_FORCE = 1 << 1,
40 UNIT_FILE_DRY_RUN = 1 << 2,
41 };
42
43 /* type can either one of the UnitFileChangeTypes listed above, or a negative error.
44 * If source is specified, it should be the contents of the path symlink.
45 * In case of an error, source should be the existing symlink contents or NULL
46 */
47 struct UnitFileChange {
48 int type; /* UnitFileChangeType or bust */
49 char *path;
50 char *source;
51 };
52
53 static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, size_t n_changes) {
54 size_t i;
55 for (i = 0; i < n_changes; i++)
56 if (IN_SET(changes[i].type, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK))
57 return true;
58 return false;
59 }
60
61 struct UnitFileList {
62 char *path;
63 UnitFileState state;
64 };
65
66 enum UnitFileType {
67 UNIT_FILE_TYPE_REGULAR,
68 UNIT_FILE_TYPE_SYMLINK,
69 UNIT_FILE_TYPE_MASKED,
70 _UNIT_FILE_TYPE_MAX,
71 _UNIT_FILE_TYPE_INVALID = -1,
72 };
73
74 struct UnitFileInstallInfo {
75 char *name;
76 char *path;
77
78 char **aliases;
79 char **wanted_by;
80 char **required_by;
81 char **also;
82
83 char *default_instance;
84 char *symlink_target;
85
86 UnitFileType type;
87 bool auxiliary;
88 };
89
90 int unit_file_enable(
91 UnitFileScope scope,
92 UnitFileFlags flags,
93 const char *root_dir,
94 char **files,
95 UnitFileChange **changes,
96 size_t *n_changes);
97 int unit_file_disable(
98 UnitFileScope scope,
99 UnitFileFlags flags,
100 const char *root_dir,
101 char **files,
102 UnitFileChange **changes,
103 size_t *n_changes);
104 int unit_file_reenable(
105 UnitFileScope scope,
106 UnitFileFlags flags,
107 const char *root_dir,
108 char **files,
109 UnitFileChange **changes,
110 size_t *n_changes);
111 int unit_file_preset(
112 UnitFileScope scope,
113 UnitFileFlags flags,
114 const char *root_dir,
115 char **files,
116 UnitFilePresetMode mode,
117 UnitFileChange **changes,
118 size_t *n_changes);
119 int unit_file_preset_all(
120 UnitFileScope scope,
121 UnitFileFlags flags,
122 const char *root_dir,
123 UnitFilePresetMode mode,
124 UnitFileChange **changes,
125 size_t *n_changes);
126 int unit_file_mask(
127 UnitFileScope scope,
128 UnitFileFlags flags,
129 const char *root_dir,
130 char **files,
131 UnitFileChange **changes,
132 size_t *n_changes);
133 int unit_file_unmask(
134 UnitFileScope scope,
135 UnitFileFlags flags,
136 const char *root_dir,
137 char **files,
138 UnitFileChange **changes,
139 size_t *n_changes);
140 int unit_file_link(
141 UnitFileScope scope,
142 UnitFileFlags flags,
143 const char *root_dir,
144 char **files,
145 UnitFileChange **changes,
146 size_t *n_changes);
147 int unit_file_revert(
148 UnitFileScope scope,
149 const char *root_dir,
150 char **files,
151 UnitFileChange **changes,
152 size_t *n_changes);
153 int unit_file_set_default(
154 UnitFileScope scope,
155 UnitFileFlags flags,
156 const char *root_dir,
157 const char *file,
158 UnitFileChange **changes,
159 size_t *n_changes);
160 int unit_file_get_default(
161 UnitFileScope scope,
162 const char *root_dir,
163 char **name);
164 int unit_file_add_dependency(
165 UnitFileScope scope,
166 UnitFileFlags flags,
167 const char *root_dir,
168 char **files,
169 const char *target,
170 UnitDependency dep,
171 UnitFileChange **changes,
172 size_t *n_changes);
173
174 int unit_file_lookup_state(
175 UnitFileScope scope,
176 const LookupPaths *paths,
177 const char *name,
178 UnitFileState *ret);
179
180 int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret);
181 int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name);
182
183 int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns);
184 Hashmap* unit_file_list_free(Hashmap *h);
185
186 int unit_file_changes_add(UnitFileChange **changes, size_t *n_changes, UnitFileChangeType type, const char *path, const char *source);
187 void unit_file_changes_free(UnitFileChange *changes, size_t n_changes);
188 void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, size_t n_changes, bool quiet);
189
190 int unit_file_verify_alias(const UnitFileInstallInfo *i, const char *dst, char **ret_dst);
191
192 int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name);
193
194 const char *unit_file_state_to_string(UnitFileState s) _const_;
195 UnitFileState unit_file_state_from_string(const char *s) _pure_;
196 /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */
197
198 const char *unit_file_change_type_to_string(UnitFileChangeType s) _const_;
199 UnitFileChangeType unit_file_change_type_from_string(const char *s) _pure_;
200
201 const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_;
202 UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_;