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