1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 typedef enum UnitFilePresetMode UnitFilePresetMode
;
5 typedef enum UnitFileChangeType UnitFileChangeType
;
6 typedef enum UnitFileFlags UnitFileFlags
;
7 typedef enum UnitFileType UnitFileType
;
8 typedef struct UnitFileChange UnitFileChange
;
9 typedef struct UnitFileList UnitFileList
;
10 typedef struct UnitFileInstallInfo UnitFileInstallInfo
;
16 #include "path-lookup.h"
18 #include "unit-name.h"
20 enum UnitFilePresetMode
{
21 UNIT_FILE_PRESET_FULL
,
22 UNIT_FILE_PRESET_ENABLE_ONLY
,
23 UNIT_FILE_PRESET_DISABLE_ONLY
,
24 _UNIT_FILE_PRESET_MAX
,
25 _UNIT_FILE_PRESET_INVALID
= -1
28 enum UnitFileChangeType
{
32 UNIT_FILE_IS_DANGLING
,
33 _UNIT_FILE_CHANGE_TYPE_MAX
,
34 _UNIT_FILE_CHANGE_TYPE_INVALID
= INT_MIN
38 UNIT_FILE_RUNTIME
= 1 << 0, /* Public API via DBUS, do not change */
39 UNIT_FILE_FORCE
= 1 << 1, /* Public API via DBUS, do not change */
40 UNIT_FILE_PORTABLE
= 1 << 2, /* Public API via DBUS, do not change */
41 UNIT_FILE_DRY_RUN
= 1 << 3,
42 _UNIT_FILE_FLAGS_MASK_PUBLIC
= UNIT_FILE_RUNTIME
|UNIT_FILE_PORTABLE
|UNIT_FILE_FORCE
,
45 /* type can either one of the UnitFileChangeTypes listed above, or a negative error.
46 * If source is specified, it should be the contents of the path symlink.
47 * In case of an error, source should be the existing symlink contents or NULL
49 struct UnitFileChange
{
50 int type
; /* UnitFileChangeType or bust */
55 static inline bool unit_file_changes_have_modification(const UnitFileChange
* changes
, size_t n_changes
) {
57 for (i
= 0; i
< n_changes
; i
++)
58 if (IN_SET(changes
[i
].type
, UNIT_FILE_SYMLINK
, UNIT_FILE_UNLINK
))
69 UNIT_FILE_TYPE_REGULAR
,
70 UNIT_FILE_TYPE_SYMLINK
,
71 UNIT_FILE_TYPE_MASKED
,
73 _UNIT_FILE_TYPE_INVALID
= -1,
76 struct UnitFileInstallInfo
{
85 char *default_instance
;
97 UnitFileChange
**changes
,
99 int unit_file_disable(
102 const char *root_dir
,
104 UnitFileChange
**changes
,
106 int unit_file_reenable(
109 const char *root_dir
,
111 UnitFileChange
**changes
,
113 int unit_file_preset(
116 const char *root_dir
,
118 UnitFilePresetMode mode
,
119 UnitFileChange
**changes
,
121 int unit_file_preset_all(
124 const char *root_dir
,
125 UnitFilePresetMode mode
,
126 UnitFileChange
**changes
,
131 const char *root_dir
,
133 UnitFileChange
**changes
,
135 int unit_file_unmask(
138 const char *root_dir
,
140 UnitFileChange
**changes
,
145 const char *root_dir
,
147 UnitFileChange
**changes
,
149 int unit_file_revert(
151 const char *root_dir
,
153 UnitFileChange
**changes
,
155 int unit_file_set_default(
158 const char *root_dir
,
160 UnitFileChange
**changes
,
162 int unit_file_get_default(
164 const char *root_dir
,
166 int unit_file_add_dependency(
169 const char *root_dir
,
173 UnitFileChange
**changes
,
176 int unit_file_lookup_state(
178 const LookupPaths
*paths
,
182 int unit_file_get_state(UnitFileScope scope
, const char *root_dir
, const char *filename
, UnitFileState
*ret
);
183 int unit_file_exists(UnitFileScope scope
, const LookupPaths
*paths
, const char *name
);
185 int unit_file_get_list(UnitFileScope scope
, const char *root_dir
, Hashmap
*h
, char **states
, char **patterns
);
186 Hashmap
* unit_file_list_free(Hashmap
*h
);
188 int unit_file_changes_add(UnitFileChange
**changes
, size_t *n_changes
, int type
, const char *path
, const char *source
);
189 void unit_file_changes_free(UnitFileChange
*changes
, size_t n_changes
);
190 void unit_file_dump_changes(int r
, const char *verb
, const UnitFileChange
*changes
, size_t n_changes
, bool quiet
);
192 int unit_file_verify_alias(const UnitFileInstallInfo
*i
, const char *dst
, char **ret_dst
);
194 typedef struct UnitFilePresetRule UnitFilePresetRule
;
197 UnitFilePresetRule
*rules
;
202 void unit_file_presets_freep(UnitFilePresets
*p
);
203 int unit_file_query_preset(UnitFileScope scope
, const char *root_dir
, const char *name
, UnitFilePresets
*cached
);
205 const char *unit_file_state_to_string(UnitFileState s
) _const_
;
206 UnitFileState
unit_file_state_from_string(const char *s
) _pure_
;
207 /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */
209 const char *unit_file_change_type_to_string(UnitFileChangeType s
) _const_
;
210 UnitFileChangeType
unit_file_change_type_from_string(const char *s
) _pure_
;
212 const char *unit_file_preset_mode_to_string(UnitFilePresetMode m
) _const_
;
213 UnitFilePresetMode
unit_file_preset_mode_from_string(const char *s
) _pure_
;