]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
c2f1db8f | 2 | #pragma once |
83096483 | 3 | |
1b153a82 LP |
4 | #include <stdbool.h> |
5 | ||
cab6235f LP |
6 | typedef enum UnitFilePresetMode UnitFilePresetMode; |
7 | typedef enum UnitFileChangeType UnitFileChangeType; | |
b3796dd8 | 8 | typedef enum UnitFileFlags UnitFileFlags; |
0ec0deaa | 9 | typedef enum UnitFileType UnitFileType; |
cab6235f LP |
10 | typedef struct UnitFileChange UnitFileChange; |
11 | typedef struct UnitFileList UnitFileList; | |
12 | typedef struct UnitFileInstallInfo UnitFileInstallInfo; | |
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 | |
93419a96 LP |
28 | /* This enum type is anonymous, since we usually store it in an 'int', as we overload it with negative errno |
29 | * values. */ | |
30 | enum { | |
83096483 LP |
31 | UNIT_FILE_SYMLINK, |
32 | UNIT_FILE_UNLINK, | |
9a0a413a | 33 | UNIT_FILE_IS_MASKED, |
893275df | 34 | UNIT_FILE_IS_DANGLING, |
8ae27441 | 35 | UNIT_FILE_DESTINATION_NOT_PRESENT, |
3aa96361 | 36 | UNIT_FILE_AUXILIARY_FAILED, |
83096483 | 37 | _UNIT_FILE_CHANGE_TYPE_MAX, |
c1b48a7f | 38 | _UNIT_FILE_CHANGE_TYPE_INVALID = -EINVAL, |
cab6235f | 39 | }; |
83096483 | 40 | |
b3796dd8 | 41 | enum UnitFileFlags { |
ad5fdd39 ZJS |
42 | UNIT_FILE_RUNTIME = 1 << 0, /* Public API via DBUS, do not change */ |
43 | UNIT_FILE_FORCE = 1 << 1, /* Public API via DBUS, do not change */ | |
44 | UNIT_FILE_PORTABLE = 1 << 2, /* Public API via DBUS, do not change */ | |
45 | UNIT_FILE_DRY_RUN = 1 << 3, | |
46 | UNIT_FILE_IGNORE_AUXILIARY_FAILURE = 1 << 4, | |
83654007 | 47 | _UNIT_FILE_FLAGS_MASK_PUBLIC = UNIT_FILE_RUNTIME|UNIT_FILE_PORTABLE|UNIT_FILE_FORCE, |
b3796dd8 JS |
48 | }; |
49 | ||
93419a96 LP |
50 | /* type can either one of the UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK, … listed above, or a negative errno value. |
51 | * If source is specified, it should be the contents of the path symlink. In case of an error, source should | |
52 | * be the existing symlink contents or NULL. */ | |
cab6235f | 53 | struct UnitFileChange { |
93419a96 | 54 | int type_or_errno; /* UNIT_FILE_SYMLINK, … if positive, errno if negative */ |
83096483 LP |
55 | char *path; |
56 | char *source; | |
cab6235f | 57 | }; |
83096483 | 58 | |
da6053d0 | 59 | static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, size_t n_changes) { |
93419a96 LP |
60 | for (size_t i = 0; i < n_changes; i++) |
61 | if (IN_SET(changes[i].type_or_errno, UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK)) | |
795ff6d5 ZJS |
62 | return true; |
63 | return false; | |
64 | } | |
65 | ||
cab6235f | 66 | struct UnitFileList { |
83096483 LP |
67 | char *path; |
68 | UnitFileState state; | |
cab6235f | 69 | }; |
83096483 | 70 | |
0ec0deaa LP |
71 | enum UnitFileType { |
72 | UNIT_FILE_TYPE_REGULAR, | |
48ed75ad ZJS |
73 | UNIT_FILE_TYPE_LINKED, |
74 | UNIT_FILE_TYPE_ALIAS, | |
0ec0deaa LP |
75 | UNIT_FILE_TYPE_MASKED, |
76 | _UNIT_FILE_TYPE_MAX, | |
2d93c20e | 77 | _UNIT_FILE_TYPE_INVALID = -EINVAL, |
0ec0deaa LP |
78 | }; |
79 | ||
cab6235f | 80 | struct UnitFileInstallInfo { |
7584d236 ZJS |
81 | char *name; |
82 | char *path; | |
de61a04b | 83 | char *root; |
7584d236 ZJS |
84 | |
85 | char **aliases; | |
86 | char **wanted_by; | |
87 | char **required_by; | |
aedd4012 | 88 | char **also; |
d54c4993 LP |
89 | |
90 | char *default_instance; | |
19539807 | 91 | char *symlink_target; |
0ec0deaa LP |
92 | |
93 | UnitFileType type; | |
19539807 | 94 | bool auxiliary; |
cab6235f | 95 | }; |
7584d236 | 96 | |
596fc263 ZJS |
97 | int unit_file_enable( |
98 | UnitFileScope scope, | |
b3796dd8 | 99 | UnitFileFlags flags, |
596fc263 ZJS |
100 | const char *root_dir, |
101 | char **files, | |
596fc263 | 102 | UnitFileChange **changes, |
da6053d0 | 103 | size_t *n_changes); |
596fc263 ZJS |
104 | int unit_file_disable( |
105 | UnitFileScope scope, | |
b3796dd8 | 106 | UnitFileFlags flags, |
596fc263 ZJS |
107 | const char *root_dir, |
108 | char **files, | |
109 | UnitFileChange **changes, | |
da6053d0 | 110 | size_t *n_changes); |
596fc263 ZJS |
111 | int unit_file_reenable( |
112 | UnitFileScope scope, | |
b3796dd8 | 113 | UnitFileFlags flags, |
596fc263 | 114 | const char *root_dir, |
29a7c59a | 115 | char **names_or_paths, |
596fc263 | 116 | UnitFileChange **changes, |
da6053d0 | 117 | size_t *n_changes); |
596fc263 ZJS |
118 | int unit_file_preset( |
119 | UnitFileScope scope, | |
b3796dd8 | 120 | UnitFileFlags flags, |
596fc263 ZJS |
121 | const char *root_dir, |
122 | char **files, | |
123 | UnitFilePresetMode mode, | |
596fc263 | 124 | UnitFileChange **changes, |
da6053d0 | 125 | size_t *n_changes); |
596fc263 ZJS |
126 | int unit_file_preset_all( |
127 | UnitFileScope scope, | |
b3796dd8 | 128 | UnitFileFlags flags, |
596fc263 ZJS |
129 | const char *root_dir, |
130 | UnitFilePresetMode mode, | |
596fc263 | 131 | UnitFileChange **changes, |
da6053d0 | 132 | size_t *n_changes); |
596fc263 ZJS |
133 | int unit_file_mask( |
134 | UnitFileScope scope, | |
b3796dd8 | 135 | UnitFileFlags flags, |
596fc263 ZJS |
136 | const char *root_dir, |
137 | char **files, | |
596fc263 | 138 | UnitFileChange **changes, |
da6053d0 | 139 | size_t *n_changes); |
596fc263 ZJS |
140 | int unit_file_unmask( |
141 | UnitFileScope scope, | |
b3796dd8 | 142 | UnitFileFlags flags, |
596fc263 ZJS |
143 | const char *root_dir, |
144 | char **files, | |
145 | UnitFileChange **changes, | |
da6053d0 | 146 | size_t *n_changes); |
596fc263 ZJS |
147 | int unit_file_link( |
148 | UnitFileScope scope, | |
b3796dd8 | 149 | UnitFileFlags flags, |
596fc263 ZJS |
150 | const char *root_dir, |
151 | char **files, | |
596fc263 | 152 | UnitFileChange **changes, |
da6053d0 | 153 | size_t *n_changes); |
596fc263 ZJS |
154 | int unit_file_revert( |
155 | UnitFileScope scope, | |
156 | const char *root_dir, | |
157 | char **files, | |
158 | UnitFileChange **changes, | |
da6053d0 | 159 | size_t *n_changes); |
596fc263 ZJS |
160 | int unit_file_set_default( |
161 | UnitFileScope scope, | |
b3796dd8 | 162 | UnitFileFlags flags, |
596fc263 ZJS |
163 | const char *root_dir, |
164 | const char *file, | |
596fc263 | 165 | UnitFileChange **changes, |
da6053d0 | 166 | size_t *n_changes); |
596fc263 ZJS |
167 | int unit_file_get_default( |
168 | UnitFileScope scope, | |
169 | const char *root_dir, | |
170 | char **name); | |
171 | int unit_file_add_dependency( | |
172 | UnitFileScope scope, | |
b3796dd8 | 173 | UnitFileFlags flags, |
596fc263 ZJS |
174 | const char *root_dir, |
175 | char **files, | |
176 | const char *target, | |
177 | UnitDependency dep, | |
596fc263 | 178 | UnitFileChange **changes, |
da6053d0 | 179 | size_t *n_changes); |
83096483 | 180 | |
d6d98276 LP |
181 | int unit_file_lookup_state( |
182 | UnitFileScope scope, | |
183 | const LookupPaths *paths, | |
184 | const char *name, | |
185 | UnitFileState *ret); | |
186 | ||
0ec0deaa | 187 | int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret); |
e735decc | 188 | int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name); |
83096483 | 189 | |
313fe66f | 190 | int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns); |
0ec0deaa | 191 | Hashmap* unit_file_list_free(Hashmap *h); |
83096483 | 192 | |
76fb53c9 | 193 | int unit_file_changes_add(UnitFileChange **changes, size_t *n_changes, int type, const char *path, const char *source); |
da6053d0 LP |
194 | void unit_file_changes_free(UnitFileChange *changes, size_t n_changes); |
195 | void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, size_t n_changes, bool quiet); | |
83096483 | 196 | |
cbfdbffb ZJS |
197 | int unit_file_verify_alias( |
198 | const UnitFileInstallInfo *info, | |
199 | const char *dst, | |
200 | char **ret_dst, | |
201 | UnitFileChange **changes, | |
202 | size_t *n_changes); | |
aa0f357f | 203 | |
8f7b2566 ZJS |
204 | typedef struct UnitFilePresetRule UnitFilePresetRule; |
205 | ||
206 | typedef struct { | |
207 | UnitFilePresetRule *rules; | |
208 | size_t n_rules; | |
209 | bool initialized; | |
210 | } UnitFilePresets; | |
211 | ||
212 | void unit_file_presets_freep(UnitFilePresets *p); | |
213 | int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name, UnitFilePresets *cached); | |
83096483 | 214 | |
44a6b1b6 ZJS |
215 | const char *unit_file_state_to_string(UnitFileState s) _const_; |
216 | UnitFileState unit_file_state_from_string(const char *s) _pure_; | |
1fa03360 | 217 | /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */ |
83096483 | 218 | |
93419a96 LP |
219 | const char *unit_file_change_type_to_string(int s) _const_; |
220 | int unit_file_change_type_from_string(const char *s) _pure_; | |
d309c1c3 LP |
221 | |
222 | const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_; | |
223 | UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_; |