1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 typedef enum UnitFileScope UnitFileScope
;
5 typedef enum UnitFileState UnitFileState
;
6 typedef enum UnitFilePresetMode UnitFilePresetMode
;
7 typedef enum UnitFileChangeType UnitFileChangeType
;
8 typedef enum UnitFileFlags UnitFileFlags
;
9 typedef enum UnitFileType UnitFileType
;
10 typedef struct UnitFileChange UnitFileChange
;
11 typedef struct UnitFileList UnitFileList
;
12 typedef struct UnitFileInstallInfo UnitFileInstallInfo
;
18 #include "path-lookup.h"
20 #include "unit-name.h"
27 _UNIT_FILE_SCOPE_INVALID
= -1
32 UNIT_FILE_ENABLED_RUNTIME
,
34 UNIT_FILE_LINKED_RUNTIME
,
36 UNIT_FILE_MASKED_RUNTIME
,
44 _UNIT_FILE_STATE_INVALID
= -1
47 enum UnitFilePresetMode
{
48 UNIT_FILE_PRESET_FULL
,
49 UNIT_FILE_PRESET_ENABLE_ONLY
,
50 UNIT_FILE_PRESET_DISABLE_ONLY
,
51 _UNIT_FILE_PRESET_MAX
,
52 _UNIT_FILE_PRESET_INVALID
= -1
55 enum UnitFileChangeType
{
59 UNIT_FILE_IS_DANGLING
,
60 _UNIT_FILE_CHANGE_TYPE_MAX
,
61 _UNIT_FILE_CHANGE_TYPE_INVALID
= INT_MIN
65 UNIT_FILE_RUNTIME
= 1 << 0,
66 UNIT_FILE_FORCE
= 1 << 1,
67 UNIT_FILE_DRY_RUN
= 1 << 2,
70 /* type can either one of the UnitFileChangeTypes listed above, or a negative error.
71 * If source is specified, it should be the contents of the path symlink.
72 * In case of an error, source should be the existing symlink contents or NULL
74 struct UnitFileChange
{
75 int type
; /* UnitFileChangeType or bust */
80 static inline bool unit_file_changes_have_modification(const UnitFileChange
* changes
, size_t n_changes
) {
82 for (i
= 0; i
< n_changes
; i
++)
83 if (IN_SET(changes
[i
].type
, UNIT_FILE_SYMLINK
, UNIT_FILE_UNLINK
))
94 UNIT_FILE_TYPE_REGULAR
,
95 UNIT_FILE_TYPE_SYMLINK
,
96 UNIT_FILE_TYPE_MASKED
,
98 _UNIT_FILE_TYPE_INVALID
= -1,
101 struct UnitFileInstallInfo
{
110 char *default_instance
;
111 char *symlink_target
;
117 bool unit_type_may_alias(UnitType type
) _const_
;
118 bool unit_type_may_template(UnitType type
) _const_
;
120 int unit_file_enable(
123 const char *root_dir
,
125 UnitFileChange
**changes
,
127 int unit_file_disable(
130 const char *root_dir
,
132 UnitFileChange
**changes
,
134 int unit_file_reenable(
137 const char *root_dir
,
139 UnitFileChange
**changes
,
141 int unit_file_preset(
144 const char *root_dir
,
146 UnitFilePresetMode mode
,
147 UnitFileChange
**changes
,
149 int unit_file_preset_all(
152 const char *root_dir
,
153 UnitFilePresetMode mode
,
154 UnitFileChange
**changes
,
159 const char *root_dir
,
161 UnitFileChange
**changes
,
163 int unit_file_unmask(
166 const char *root_dir
,
168 UnitFileChange
**changes
,
173 const char *root_dir
,
175 UnitFileChange
**changes
,
177 int unit_file_revert(
179 const char *root_dir
,
181 UnitFileChange
**changes
,
183 int unit_file_set_default(
186 const char *root_dir
,
188 UnitFileChange
**changes
,
190 int unit_file_get_default(
192 const char *root_dir
,
194 int unit_file_add_dependency(
197 const char *root_dir
,
201 UnitFileChange
**changes
,
204 int unit_file_lookup_state(
206 const LookupPaths
*paths
,
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
, size_t *n_changes
, UnitFileChangeType type
, const char *path
, const char *source
);
217 void unit_file_changes_free(UnitFileChange
*changes
, size_t n_changes
);
218 void unit_file_dump_changes(int r
, const char *verb
, const UnitFileChange
*changes
, size_t 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_
;