]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/install.h
resolved: TCP fast open connections
[thirdparty/systemd.git] / src / shared / install.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
c2f1db8f 2#pragma once
83096483
LP
3
4/***
5 This file is part of systemd.
6
7 Copyright 2011 Lennart Poettering
83096483
LP
8***/
9
cab6235f
LP
10typedef enum UnitFileScope UnitFileScope;
11typedef enum UnitFileState UnitFileState;
12typedef enum UnitFilePresetMode UnitFilePresetMode;
13typedef enum UnitFileChangeType UnitFileChangeType;
b3796dd8 14typedef enum UnitFileFlags UnitFileFlags;
0ec0deaa 15typedef enum UnitFileType UnitFileType;
cab6235f
LP
16typedef struct UnitFileChange UnitFileChange;
17typedef struct UnitFileList UnitFileList;
18typedef struct UnitFileInstallInfo UnitFileInstallInfo;
19
a8fbdf54
TA
20#include <stdbool.h>
21
83096483 22#include "hashmap.h"
a8fbdf54 23#include "macro.h"
a8ffe6fb 24#include "path-lookup.h"
0ec0deaa
LP
25#include "strv.h"
26#include "unit-name.h"
83096483 27
cab6235f 28enum UnitFileScope {
83096483
LP
29 UNIT_FILE_SYSTEM,
30 UNIT_FILE_GLOBAL,
31 UNIT_FILE_USER,
32 _UNIT_FILE_SCOPE_MAX,
33 _UNIT_FILE_SCOPE_INVALID = -1
cab6235f 34};
83096483 35
cab6235f 36enum UnitFileState {
83096483
LP
37 UNIT_FILE_ENABLED,
38 UNIT_FILE_ENABLED_RUNTIME,
39 UNIT_FILE_LINKED,
40 UNIT_FILE_LINKED_RUNTIME,
41 UNIT_FILE_MASKED,
42 UNIT_FILE_MASKED_RUNTIME,
43 UNIT_FILE_STATIC,
44 UNIT_FILE_DISABLED,
aedd4012 45 UNIT_FILE_INDIRECT,
f4139308 46 UNIT_FILE_GENERATED,
e4fca67f 47 UNIT_FILE_TRANSIENT,
0ec0deaa 48 UNIT_FILE_BAD,
83096483
LP
49 _UNIT_FILE_STATE_MAX,
50 _UNIT_FILE_STATE_INVALID = -1
cab6235f 51};
83096483 52
cab6235f 53enum UnitFilePresetMode {
d309c1c3
LP
54 UNIT_FILE_PRESET_FULL,
55 UNIT_FILE_PRESET_ENABLE_ONLY,
56 UNIT_FILE_PRESET_DISABLE_ONLY,
86bbe5bf 57 _UNIT_FILE_PRESET_MAX,
d309c1c3 58 _UNIT_FILE_PRESET_INVALID = -1
cab6235f 59};
d309c1c3 60
cab6235f 61enum UnitFileChangeType {
83096483
LP
62 UNIT_FILE_SYMLINK,
63 UNIT_FILE_UNLINK,
9a0a413a 64 UNIT_FILE_IS_MASKED,
893275df 65 UNIT_FILE_IS_DANGLING,
83096483 66 _UNIT_FILE_CHANGE_TYPE_MAX,
42ce5f75 67 _UNIT_FILE_CHANGE_TYPE_INVALID = INT_MIN
cab6235f 68};
83096483 69
b3796dd8 70enum UnitFileFlags {
42ce5f75
LP
71 UNIT_FILE_RUNTIME = 1U << 0,
72 UNIT_FILE_FORCE = 1U << 1,
73 UNIT_FILE_DRY_RUN = 1U << 2,
b3796dd8
JS
74};
75
af3d8113
ZJS
76/* type can either one of the UnitFileChangeTypes listed above, or a negative error.
77 * If source is specified, it should be the contents of the path symlink.
78 * In case of an error, source should be the existing symlink contents or NULL
79 */
cab6235f 80struct UnitFileChange {
af3d8113 81 int type; /* UnitFileChangeType or bust */
83096483
LP
82 char *path;
83 char *source;
cab6235f 84};
83096483 85
da6053d0
LP
86static inline bool unit_file_changes_have_modification(const UnitFileChange* changes, size_t n_changes) {
87 size_t i;
795ff6d5
ZJS
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;
19539807 117 char *symlink_target;
0ec0deaa
LP
118
119 UnitFileType type;
19539807 120 bool auxiliary;
cab6235f 121};
7584d236 122
8a993b61 123bool unit_type_may_alias(UnitType type) _const_;
ce99c68a 124bool unit_type_may_template(UnitType type) _const_;
8a993b61 125
596fc263
ZJS
126int unit_file_enable(
127 UnitFileScope scope,
b3796dd8 128 UnitFileFlags flags,
596fc263
ZJS
129 const char *root_dir,
130 char **files,
596fc263 131 UnitFileChange **changes,
da6053d0 132 size_t *n_changes);
596fc263
ZJS
133int unit_file_disable(
134 UnitFileScope scope,
b3796dd8 135 UnitFileFlags flags,
596fc263
ZJS
136 const char *root_dir,
137 char **files,
138 UnitFileChange **changes,
da6053d0 139 size_t *n_changes);
596fc263
ZJS
140int unit_file_reenable(
141 UnitFileScope scope,
b3796dd8 142 UnitFileFlags flags,
596fc263
ZJS
143 const char *root_dir,
144 char **files,
596fc263 145 UnitFileChange **changes,
da6053d0 146 size_t *n_changes);
596fc263
ZJS
147int unit_file_preset(
148 UnitFileScope scope,
b3796dd8 149 UnitFileFlags flags,
596fc263
ZJS
150 const char *root_dir,
151 char **files,
152 UnitFilePresetMode mode,
596fc263 153 UnitFileChange **changes,
da6053d0 154 size_t *n_changes);
596fc263
ZJS
155int unit_file_preset_all(
156 UnitFileScope scope,
b3796dd8 157 UnitFileFlags flags,
596fc263
ZJS
158 const char *root_dir,
159 UnitFilePresetMode mode,
596fc263 160 UnitFileChange **changes,
da6053d0 161 size_t *n_changes);
596fc263
ZJS
162int unit_file_mask(
163 UnitFileScope scope,
b3796dd8 164 UnitFileFlags flags,
596fc263
ZJS
165 const char *root_dir,
166 char **files,
596fc263 167 UnitFileChange **changes,
da6053d0 168 size_t *n_changes);
596fc263
ZJS
169int unit_file_unmask(
170 UnitFileScope scope,
b3796dd8 171 UnitFileFlags flags,
596fc263
ZJS
172 const char *root_dir,
173 char **files,
174 UnitFileChange **changes,
da6053d0 175 size_t *n_changes);
596fc263
ZJS
176int unit_file_link(
177 UnitFileScope scope,
b3796dd8 178 UnitFileFlags flags,
596fc263
ZJS
179 const char *root_dir,
180 char **files,
596fc263 181 UnitFileChange **changes,
da6053d0 182 size_t *n_changes);
596fc263
ZJS
183int unit_file_revert(
184 UnitFileScope scope,
185 const char *root_dir,
186 char **files,
187 UnitFileChange **changes,
da6053d0 188 size_t *n_changes);
596fc263
ZJS
189int unit_file_set_default(
190 UnitFileScope scope,
b3796dd8 191 UnitFileFlags flags,
596fc263
ZJS
192 const char *root_dir,
193 const char *file,
596fc263 194 UnitFileChange **changes,
da6053d0 195 size_t *n_changes);
596fc263
ZJS
196int unit_file_get_default(
197 UnitFileScope scope,
198 const char *root_dir,
199 char **name);
200int unit_file_add_dependency(
201 UnitFileScope scope,
b3796dd8 202 UnitFileFlags flags,
596fc263
ZJS
203 const char *root_dir,
204 char **files,
205 const char *target,
206 UnitDependency dep,
596fc263 207 UnitFileChange **changes,
da6053d0 208 size_t *n_changes);
83096483 209
d6d98276
LP
210int unit_file_lookup_state(
211 UnitFileScope scope,
212 const LookupPaths *paths,
213 const char *name,
214 UnitFileState *ret);
215
0ec0deaa 216int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret);
e735decc 217int unit_file_exists(UnitFileScope scope, const LookupPaths *paths, const char *name);
83096483 218
313fe66f 219int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns);
0ec0deaa 220Hashmap* unit_file_list_free(Hashmap *h);
83096483 221
da6053d0
LP
222int unit_file_changes_add(UnitFileChange **changes, size_t *n_changes, UnitFileChangeType type, const char *path, const char *source);
223void unit_file_changes_free(UnitFileChange *changes, size_t n_changes);
224void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, size_t n_changes, bool quiet);
83096483 225
c2a8d7b0 226int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name);
83096483 227
44a6b1b6
ZJS
228const char *unit_file_state_to_string(UnitFileState s) _const_;
229UnitFileState unit_file_state_from_string(const char *s) _pure_;
1fa03360 230/* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */
83096483 231
44a6b1b6
ZJS
232const char *unit_file_change_type_to_string(UnitFileChangeType s) _const_;
233UnitFileChangeType unit_file_change_type_from_string(const char *s) _pure_;
d309c1c3
LP
234
235const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_;
236UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_;