1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
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
;
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
= -EINVAL
,
28 /* This enum type is anonymous, since we usually store it in an 'int', as we overload it with negative errno
34 UNIT_FILE_IS_DANGLING
,
35 UNIT_FILE_DESTINATION_NOT_PRESENT
,
36 UNIT_FILE_AUXILIARY_FAILED
,
37 _UNIT_FILE_CHANGE_TYPE_MAX
,
38 _UNIT_FILE_CHANGE_TYPE_INVALID
= -EINVAL
,
42 UNIT_FILE_RUNTIME
= 1 << 0, /* Public API via DBUS, do not change */
43 UNIT_FILE_FORCE
= 1 << 1, /* Public API via DBUS, do not change */
44 UNIT_FILE_PORTABLE
= 1 << 2, /* Public API via DBUS, do not change */
45 UNIT_FILE_DRY_RUN
= 1 << 3,
46 UNIT_FILE_IGNORE_AUXILIARY_FAILURE
= 1 << 4,
47 _UNIT_FILE_FLAGS_MASK_PUBLIC
= UNIT_FILE_RUNTIME
|UNIT_FILE_PORTABLE
|UNIT_FILE_FORCE
,
50 /* type can either one of the UNIT_FILE_SYMLINK, UNIT_FILE_UNLINK, … listed above, or a negative errno value.
51 * If source is specified, it should be the contents of the path symlink. In case of an error, source should
52 * be the existing symlink contents or NULL. */
53 struct UnitFileChange
{
54 int type_or_errno
; /* UNIT_FILE_SYMLINK, … if positive, errno if negative */
59 static inline bool unit_file_changes_have_modification(const UnitFileChange
* changes
, size_t n_changes
) {
60 for (size_t i
= 0; i
< n_changes
; i
++)
61 if (IN_SET(changes
[i
].type_or_errno
, UNIT_FILE_SYMLINK
, UNIT_FILE_UNLINK
))
72 UNIT_FILE_TYPE_REGULAR
,
73 UNIT_FILE_TYPE_SYMLINK
,
74 UNIT_FILE_TYPE_MASKED
,
76 _UNIT_FILE_TYPE_INVALID
= -EINVAL
,
79 struct UnitFileInstallInfo
{
89 char *default_instance
;
101 UnitFileChange
**changes
,
103 int unit_file_disable(
106 const char *root_dir
,
108 UnitFileChange
**changes
,
110 int unit_file_reenable(
113 const char *root_dir
,
115 UnitFileChange
**changes
,
117 int unit_file_preset(
120 const char *root_dir
,
122 UnitFilePresetMode mode
,
123 UnitFileChange
**changes
,
125 int unit_file_preset_all(
128 const char *root_dir
,
129 UnitFilePresetMode mode
,
130 UnitFileChange
**changes
,
135 const char *root_dir
,
137 UnitFileChange
**changes
,
139 int unit_file_unmask(
142 const char *root_dir
,
144 UnitFileChange
**changes
,
149 const char *root_dir
,
151 UnitFileChange
**changes
,
153 int unit_file_revert(
155 const char *root_dir
,
157 UnitFileChange
**changes
,
159 int unit_file_set_default(
162 const char *root_dir
,
164 UnitFileChange
**changes
,
166 int unit_file_get_default(
168 const char *root_dir
,
170 int unit_file_add_dependency(
173 const char *root_dir
,
177 UnitFileChange
**changes
,
180 int unit_file_lookup_state(
182 const LookupPaths
*paths
,
186 int unit_file_get_state(UnitFileScope scope
, const char *root_dir
, const char *filename
, UnitFileState
*ret
);
187 int unit_file_exists(UnitFileScope scope
, const LookupPaths
*paths
, const char *name
);
189 int unit_file_get_list(UnitFileScope scope
, const char *root_dir
, Hashmap
*h
, char **states
, char **patterns
);
190 Hashmap
* unit_file_list_free(Hashmap
*h
);
192 int unit_file_changes_add(UnitFileChange
**changes
, size_t *n_changes
, int type
, const char *path
, const char *source
);
193 void unit_file_changes_free(UnitFileChange
*changes
, size_t n_changes
);
194 void unit_file_dump_changes(int r
, const char *verb
, const UnitFileChange
*changes
, size_t n_changes
, bool quiet
);
196 int unit_file_verify_alias(const UnitFileInstallInfo
*i
, const char *dst
, char **ret_dst
);
198 typedef struct UnitFilePresetRule UnitFilePresetRule
;
201 UnitFilePresetRule
*rules
;
206 void unit_file_presets_freep(UnitFilePresets
*p
);
207 int unit_file_query_preset(UnitFileScope scope
, const char *root_dir
, const char *name
, UnitFilePresets
*cached
);
209 const char *unit_file_state_to_string(UnitFileState s
) _const_
;
210 UnitFileState
unit_file_state_from_string(const char *s
) _pure_
;
211 /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */
213 const char *unit_file_change_type_to_string(int s
) _const_
;
214 int unit_file_change_type_from_string(const char *s
) _pure_
;
216 const char *unit_file_preset_mode_to_string(UnitFilePresetMode m
) _const_
;
217 UnitFilePresetMode
unit_file_preset_mode_from_string(const char *s
) _pure_
;