1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 This file is part of systemd.
7 Copyright 2011 Lennart Poettering
10 typedef enum UnitFileScope UnitFileScope
;
11 typedef enum UnitFileState UnitFileState
;
12 typedef enum UnitFilePresetMode UnitFilePresetMode
;
13 typedef enum UnitFileChangeType UnitFileChangeType
;
14 typedef enum UnitFileFlags UnitFileFlags
;
15 typedef enum UnitFileType UnitFileType
;
16 typedef struct UnitFileChange UnitFileChange
;
17 typedef struct UnitFileList UnitFileList
;
18 typedef struct UnitFileInstallInfo UnitFileInstallInfo
;
24 #include "path-lookup.h"
26 #include "unit-name.h"
33 _UNIT_FILE_SCOPE_INVALID
= -1
38 UNIT_FILE_ENABLED_RUNTIME
,
40 UNIT_FILE_LINKED_RUNTIME
,
42 UNIT_FILE_MASKED_RUNTIME
,
50 _UNIT_FILE_STATE_INVALID
= -1
53 enum UnitFilePresetMode
{
54 UNIT_FILE_PRESET_FULL
,
55 UNIT_FILE_PRESET_ENABLE_ONLY
,
56 UNIT_FILE_PRESET_DISABLE_ONLY
,
57 _UNIT_FILE_PRESET_MAX
,
58 _UNIT_FILE_PRESET_INVALID
= -1
61 enum UnitFileChangeType
{
65 UNIT_FILE_IS_DANGLING
,
66 _UNIT_FILE_CHANGE_TYPE_MAX
,
67 _UNIT_FILE_CHANGE_TYPE_INVALID
= INT_MIN
71 UNIT_FILE_RUNTIME
= 1U << 0,
72 UNIT_FILE_FORCE
= 1U << 1,
73 UNIT_FILE_DRY_RUN
= 1U << 2,
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
80 struct UnitFileChange
{
81 int type
; /* UnitFileChangeType or bust */
86 static inline bool unit_file_changes_have_modification(const UnitFileChange
* changes
, unsigned n_changes
) {
88 for (i
= 0; i
< n_changes
; i
++)
89 if (IN_SET(changes
[i
].type
, UNIT_FILE_SYMLINK
, UNIT_FILE_UNLINK
))
100 UNIT_FILE_TYPE_REGULAR
,
101 UNIT_FILE_TYPE_SYMLINK
,
102 UNIT_FILE_TYPE_MASKED
,
104 _UNIT_FILE_TYPE_INVALID
= -1,
107 struct UnitFileInstallInfo
{
116 char *default_instance
;
117 char *symlink_target
;
123 bool unit_type_may_alias(UnitType type
) _const_
;
124 bool unit_type_may_template(UnitType type
) _const_
;
126 int unit_file_enable(
129 const char *root_dir
,
131 UnitFileChange
**changes
,
132 unsigned *n_changes
);
133 int unit_file_disable(
136 const char *root_dir
,
138 UnitFileChange
**changes
,
139 unsigned *n_changes
);
140 int unit_file_reenable(
143 const char *root_dir
,
145 UnitFileChange
**changes
,
146 unsigned *n_changes
);
147 int unit_file_preset(
150 const char *root_dir
,
152 UnitFilePresetMode mode
,
153 UnitFileChange
**changes
,
154 unsigned *n_changes
);
155 int unit_file_preset_all(
158 const char *root_dir
,
159 UnitFilePresetMode mode
,
160 UnitFileChange
**changes
,
161 unsigned *n_changes
);
165 const char *root_dir
,
167 UnitFileChange
**changes
,
168 unsigned *n_changes
);
169 int unit_file_unmask(
172 const char *root_dir
,
174 UnitFileChange
**changes
,
175 unsigned *n_changes
);
179 const char *root_dir
,
181 UnitFileChange
**changes
,
182 unsigned *n_changes
);
183 int unit_file_revert(
185 const char *root_dir
,
187 UnitFileChange
**changes
,
188 unsigned *n_changes
);
189 int unit_file_set_default(
192 const char *root_dir
,
194 UnitFileChange
**changes
,
195 unsigned *n_changes
);
196 int unit_file_get_default(
198 const char *root_dir
,
200 int unit_file_add_dependency(
203 const char *root_dir
,
207 UnitFileChange
**changes
,
208 unsigned *n_changes
);
210 int unit_file_get_state(UnitFileScope scope
, const char *root_dir
, const char *filename
, UnitFileState
*ret
);
211 int unit_file_exists(UnitFileScope scope
, const LookupPaths
*paths
, const char *name
);
213 int unit_file_get_list(UnitFileScope scope
, const char *root_dir
, Hashmap
*h
, char **states
, char **patterns
);
214 Hashmap
* unit_file_list_free(Hashmap
*h
);
216 int unit_file_changes_add(UnitFileChange
**changes
, unsigned *n_changes
, UnitFileChangeType type
, const char *path
, const char *source
);
217 void unit_file_changes_free(UnitFileChange
*changes
, unsigned n_changes
);
218 void unit_file_dump_changes(int r
, const char *verb
, const UnitFileChange
*changes
, unsigned n_changes
, bool quiet
);
220 int unit_file_query_preset(UnitFileScope scope
, const char *root_dir
, const char *name
);
222 const char *unit_file_state_to_string(UnitFileState s
) _const_
;
223 UnitFileState
unit_file_state_from_string(const char *s
) _pure_
;
224 /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */
226 const char *unit_file_change_type_to_string(UnitFileChangeType s
) _const_
;
227 UnitFileChangeType
unit_file_change_type_from_string(const char *s
) _pure_
;
229 const char *unit_file_preset_mode_to_string(UnitFilePresetMode m
) _const_
;
230 UnitFilePresetMode
unit_file_preset_mode_from_string(const char *s
) _pure_
;