]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
c2f1db8f | 2 | #pragma once |
83096483 | 3 | |
cab6235f LP |
4 | typedef enum UnitFilePresetMode UnitFilePresetMode; |
5 | typedef enum UnitFileChangeType UnitFileChangeType; | |
b3796dd8 | 6 | typedef enum UnitFileFlags UnitFileFlags; |
0ec0deaa | 7 | typedef enum UnitFileType UnitFileType; |
cab6235f LP |
8 | typedef struct UnitFileChange UnitFileChange; |
9 | typedef struct UnitFileList UnitFileList; | |
10 | typedef struct UnitFileInstallInfo UnitFileInstallInfo; | |
11 | ||
a8fbdf54 TA |
12 | #include <stdbool.h> |
13 | ||
83096483 | 14 | #include "hashmap.h" |
a8fbdf54 | 15 | #include "macro.h" |
a8ffe6fb | 16 | #include "path-lookup.h" |
0ec0deaa LP |
17 | #include "strv.h" |
18 | #include "unit-name.h" | |
83096483 | 19 | |
cab6235f | 20 | enum UnitFilePresetMode { |
d309c1c3 LP |
21 | UNIT_FILE_PRESET_FULL, |
22 | UNIT_FILE_PRESET_ENABLE_ONLY, | |
23 | UNIT_FILE_PRESET_DISABLE_ONLY, | |
86bbe5bf | 24 | _UNIT_FILE_PRESET_MAX, |
2d93c20e | 25 | _UNIT_FILE_PRESET_INVALID = -EINVAL, |
cab6235f | 26 | }; |
d309c1c3 | 27 | |
cab6235f | 28 | enum UnitFileChangeType { |
83096483 LP |
29 | UNIT_FILE_SYMLINK, |
30 | UNIT_FILE_UNLINK, | |
9a0a413a | 31 | UNIT_FILE_IS_MASKED, |
893275df | 32 | UNIT_FILE_IS_DANGLING, |
83096483 | 33 | _UNIT_FILE_CHANGE_TYPE_MAX, |
42ce5f75 | 34 | _UNIT_FILE_CHANGE_TYPE_INVALID = INT_MIN |
cab6235f | 35 | }; |
83096483 | 36 | |
b3796dd8 | 37 | enum UnitFileFlags { |
83654007 LB |
38 | UNIT_FILE_RUNTIME = 1 << 0, /* Public API via DBUS, do not change */ |
39 | UNIT_FILE_FORCE = 1 << 1, /* Public API via DBUS, do not change */ | |
40 | UNIT_FILE_PORTABLE = 1 << 2, /* Public API via DBUS, do not change */ | |
41 | UNIT_FILE_DRY_RUN = 1 << 3, | |
42 | _UNIT_FILE_FLAGS_MASK_PUBLIC = UNIT_FILE_RUNTIME|UNIT_FILE_PORTABLE|UNIT_FILE_FORCE, | |
b3796dd8 JS |
43 | }; |
44 | ||
af3d8113 ZJS |
45 | /* type can either one of the UnitFileChangeTypes listed above, or a negative error. |
46 | * If source is specified, it should be the contents of the path symlink. | |
47 | * In case of an error, source should be the existing symlink contents or NULL | |
48 | */ | |
cab6235f | 49 | struct UnitFileChange { |
af3d8113 | 50 | int type; /* UnitFileChangeType or bust */ |
83096483 LP |
51 | char *path; |
52 | char *source; | |
cab6235f | 53 | }; |
83096483 | 54 | |
da6053d0 LP |
55 | static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, size_t n_changes) { |
56 | size_t i; | |
795ff6d5 ZJS |
57 | for (i = 0; i < n_changes; i++) |
58 | if (IN_SET(changes[i].type, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK)) | |
59 | return true; | |
60 | return false; | |
61 | } | |
62 | ||
cab6235f | 63 | struct UnitFileList { |
83096483 LP |
64 | char *path; |
65 | UnitFileState state; | |
cab6235f | 66 | }; |
83096483 | 67 | |
0ec0deaa LP |
68 | enum UnitFileType { |
69 | UNIT_FILE_TYPE_REGULAR, | |
70 | UNIT_FILE_TYPE_SYMLINK, | |
71 | UNIT_FILE_TYPE_MASKED, | |
72 | _UNIT_FILE_TYPE_MAX, | |
2d93c20e | 73 | _UNIT_FILE_TYPE_INVALID = -EINVAL, |
0ec0deaa LP |
74 | }; |
75 | ||
cab6235f | 76 | struct UnitFileInstallInfo { |
7584d236 ZJS |
77 | char *name; |
78 | char *path; | |
79 | ||
80 | char **aliases; | |
81 | char **wanted_by; | |
82 | char **required_by; | |
aedd4012 | 83 | char **also; |
d54c4993 LP |
84 | |
85 | char *default_instance; | |
19539807 | 86 | char *symlink_target; |
0ec0deaa LP |
87 | |
88 | UnitFileType type; | |
19539807 | 89 | bool auxiliary; |
cab6235f | 90 | }; |
7584d236 | 91 | |
596fc263 ZJS |
92 | int unit_file_enable( |
93 | UnitFileScope scope, | |
b3796dd8 | 94 | UnitFileFlags flags, |
596fc263 ZJS |
95 | const char *root_dir, |
96 | char **files, | |
596fc263 | 97 | UnitFileChange **changes, |
da6053d0 | 98 | size_t *n_changes); |
596fc263 ZJS |
99 | int unit_file_disable( |
100 | UnitFileScope scope, | |
b3796dd8 | 101 | UnitFileFlags flags, |
596fc263 ZJS |
102 | const char *root_dir, |
103 | char **files, | |
104 | UnitFileChange **changes, | |
da6053d0 | 105 | size_t *n_changes); |
596fc263 ZJS |
106 | int unit_file_reenable( |
107 | UnitFileScope scope, | |
b3796dd8 | 108 | UnitFileFlags flags, |
596fc263 ZJS |
109 | const char *root_dir, |
110 | char **files, | |
596fc263 | 111 | UnitFileChange **changes, |
da6053d0 | 112 | size_t *n_changes); |
596fc263 ZJS |
113 | int unit_file_preset( |
114 | UnitFileScope scope, | |
b3796dd8 | 115 | UnitFileFlags flags, |
596fc263 ZJS |
116 | const char *root_dir, |
117 | char **files, | |
118 | UnitFilePresetMode mode, | |
596fc263 | 119 | UnitFileChange **changes, |
da6053d0 | 120 | size_t *n_changes); |
596fc263 ZJS |
121 | int unit_file_preset_all( |
122 | UnitFileScope scope, | |
b3796dd8 | 123 | UnitFileFlags flags, |
596fc263 ZJS |
124 | const char *root_dir, |
125 | UnitFilePresetMode mode, | |
596fc263 | 126 | UnitFileChange **changes, |
da6053d0 | 127 | size_t *n_changes); |
596fc263 ZJS |
128 | int unit_file_mask( |
129 | UnitFileScope scope, | |
b3796dd8 | 130 | UnitFileFlags flags, |
596fc263 ZJS |
131 | const char *root_dir, |
132 | char **files, | |
596fc263 | 133 | UnitFileChange **changes, |
da6053d0 | 134 | size_t *n_changes); |
596fc263 ZJS |
135 | int unit_file_unmask( |
136 | UnitFileScope scope, | |
b3796dd8 | 137 | UnitFileFlags flags, |
596fc263 ZJS |
138 | const char *root_dir, |
139 | char **files, | |
140 | UnitFileChange **changes, | |
da6053d0 | 141 | size_t *n_changes); |
596fc263 ZJS |
142 | int unit_file_link( |
143 | UnitFileScope scope, | |
b3796dd8 | 144 | UnitFileFlags flags, |
596fc263 ZJS |
145 | const char *root_dir, |
146 | char **files, | |
596fc263 | 147 | UnitFileChange **changes, |
da6053d0 | 148 | size_t *n_changes); |
596fc263 ZJS |
149 | int unit_file_revert( |
150 | UnitFileScope scope, | |
151 | const char *root_dir, | |
152 | char **files, | |
153 | UnitFileChange **changes, | |
da6053d0 | 154 | size_t *n_changes); |
596fc263 ZJS |
155 | int unit_file_set_default( |
156 | UnitFileScope scope, | |
b3796dd8 | 157 | UnitFileFlags flags, |
596fc263 ZJS |
158 | const char *root_dir, |
159 | const char *file, | |
596fc263 | 160 | UnitFileChange **changes, |
da6053d0 | 161 | size_t *n_changes); |
596fc263 ZJS |
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, | |
b3796dd8 | 168 | UnitFileFlags flags, |
596fc263 ZJS |
169 | const char *root_dir, |
170 | char **files, | |
171 | const char *target, | |
172 | UnitDependency dep, | |
596fc263 | 173 | UnitFileChange **changes, |
da6053d0 | 174 | size_t *n_changes); |
83096483 | 175 | |
d6d98276 LP |
176 | int unit_file_lookup_state( |
177 | UnitFileScope scope, | |
178 | const LookupPaths *paths, | |
179 | const char *name, | |
180 | UnitFileState *ret); | |
181 | ||
0ec0deaa | 182 | int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret); |
e735decc | 183 | int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name); |
83096483 | 184 | |
313fe66f | 185 | int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns); |
0ec0deaa | 186 | Hashmap* unit_file_list_free(Hashmap *h); |
83096483 | 187 | |
76fb53c9 | 188 | int unit_file_changes_add(UnitFileChange **changes, size_t *n_changes, int type, const char *path, const char *source); |
da6053d0 LP |
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); | |
83096483 | 191 | |
3f57bc22 | 192 | int unit_file_verify_alias(const UnitFileInstallInfo *i, const char *dst, char **ret_dst); |
aa0f357f | 193 | |
8f7b2566 ZJS |
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); | |
83096483 | 204 | |
44a6b1b6 ZJS |
205 | const char *unit_file_state_to_string(UnitFileState s) _const_; |
206 | UnitFileState unit_file_state_from_string(const char *s) _pure_; | |
1fa03360 | 207 | /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */ |
83096483 | 208 | |
44a6b1b6 ZJS |
209 | const char *unit_file_change_type_to_string(UnitFileChangeType s) _const_; |
210 | UnitFileChangeType unit_file_change_type_from_string(const char *s) _pure_; | |
d309c1c3 LP |
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_; |