1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
5 #include "runtime-scope.h"
8 typedef enum UnitFilePresetMode
{
10 UNIT_FILE_PRESET_ENABLE_ONLY
,
11 UNIT_FILE_PRESET_DISABLE_ONLY
,
12 _UNIT_FILE_PRESET_MODE_MAX
,
13 _UNIT_FILE_PRESET_MODE_INVALID
= -EINVAL
,
16 typedef enum InstallChangeType
{
17 INSTALL_CHANGE_SYMLINK
,
18 INSTALL_CHANGE_UNLINK
,
19 INSTALL_CHANGE_IS_MASKED
,
20 INSTALL_CHANGE_IS_MASKED_GENERATOR
,
21 INSTALL_CHANGE_IS_DANGLING
,
22 INSTALL_CHANGE_DESTINATION_NOT_PRESENT
,
23 INSTALL_CHANGE_AUXILIARY_FAILED
,
24 _INSTALL_CHANGE_TYPE_MAX
,
25 _INSTALL_CHANGE_INVALID
= -EINVAL
,
26 _INSTALL_CHANGE_ERRNO_MAX
= -ERRNO_MAX
, /* Ensure this type covers the whole negative errno range */
29 static inline bool INSTALL_CHANGE_TYPE_VALID(InstallChangeType t
) {
30 return t
>= _INSTALL_CHANGE_ERRNO_MAX
&& t
< _INSTALL_CHANGE_TYPE_MAX
;
33 typedef enum UnitFileFlags
{
34 UNIT_FILE_RUNTIME
= 1 << 0, /* Public API via DBUS, do not change */
35 UNIT_FILE_FORCE
= 1 << 1, /* Public API via DBUS, do not change */
36 UNIT_FILE_PORTABLE
= 1 << 2, /* Public API via DBUS, do not change */
37 UNIT_FILE_DRY_RUN
= 1 << 3,
38 UNIT_FILE_IGNORE_AUXILIARY_FAILURE
= 1 << 4,
39 _UNIT_FILE_FLAGS_MASK_PUBLIC
= UNIT_FILE_RUNTIME
|UNIT_FILE_PORTABLE
|UNIT_FILE_FORCE
,
42 /* type can be either one of the INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK, … listed above, or a negative
45 * If source is specified, it should be the contents of the path symlink. In case of an error, source should
46 * be the existing symlink contents or NULL. */
47 typedef struct InstallChange
{
48 int type
; /* INSTALL_CHANGE_SYMLINK, … if positive, errno if negative */
53 static inline bool install_changes_have_modification(const InstallChange
*changes
, size_t n_changes
) {
54 FOREACH_ARRAY(i
, changes
, n_changes
)
55 if (IN_SET(i
->type
, INSTALL_CHANGE_SYMLINK
, INSTALL_CHANGE_UNLINK
))
60 typedef struct UnitFileList
{
65 typedef enum InstallMode
{
71 _INSTALL_MODE_INVALID
= -EINVAL
,
74 typedef struct InstallInfo
{
85 char *default_instance
;
88 InstallMode install_mode
;
96 char * const *names_or_paths
,
97 InstallChange
**changes
,
99 int unit_file_disable(
102 const char *root_dir
,
104 InstallChange
**changes
,
106 int unit_file_reenable(
109 const char *root_dir
,
110 char * const *names_or_paths
,
111 InstallChange
**changes
,
113 int unit_file_preset(
115 UnitFileFlags file_flags
,
116 const char *root_dir
,
118 UnitFilePresetMode mode
,
119 InstallChange
**changes
,
121 int unit_file_preset_all(
123 UnitFileFlags file_flags
,
124 const char *root_dir
,
125 UnitFilePresetMode mode
,
126 InstallChange
**changes
,
131 const char *root_dir
,
133 InstallChange
**changes
,
135 int unit_file_unmask(
138 const char *root_dir
,
140 InstallChange
**changes
,
145 const char *root_dir
,
147 InstallChange
**changes
,
149 int unit_file_revert(
151 const char *root_dir
,
153 InstallChange
**changes
,
155 int unit_file_set_default(
158 const char *root_dir
,
160 InstallChange
**changes
,
162 int unit_file_get_default(
164 const char *root_dir
,
166 int unit_file_add_dependency(
169 const char *root_dir
,
173 InstallChange
**changes
,
176 int unit_file_lookup_state(
178 const LookupPaths
*paths
,
182 int unit_file_get_state(RuntimeScope scope
, const char *root_dir
, const char *filename
, UnitFileState
*ret
);
184 int unit_file_exists_full(RuntimeScope scope
, const LookupPaths
*paths
, const char *name
, char **ret_path
);
185 static inline int unit_file_exists(RuntimeScope scope
, const LookupPaths
*paths
, const char *name
) {
186 return unit_file_exists_full(scope
, paths
, name
, NULL
);
189 int unit_file_get_list(RuntimeScope scope
, const char *root_dir
, char * const *states
, char * const *patterns
, Hashmap
**ret
);
191 InstallChangeType
install_changes_add(InstallChange
**changes
, size_t *n_changes
, InstallChangeType type
, const char *path
, const char *source
);
192 void install_changes_free(InstallChange
*changes
, size_t n_changes
);
194 int install_change_dump_error(const InstallChange
*change
, char **ret_errmsg
, const char **ret_bus_error
);
195 void install_changes_dump(
198 const InstallChange
*changes
,
202 int unit_file_verify_alias(
203 const InstallInfo
*info
,
206 InstallChange
**changes
,
209 typedef struct UnitFilePresetRule UnitFilePresetRule
;
212 UnitFilePresetRule
*rules
;
217 typedef enum PresetAction
{
223 _PRESET_ACTION_INVALID
= -EINVAL
,
224 _PRESET_ACTION_ERRNO_MAX
= -ERRNO_MAX
, /* Ensure this type covers the whole negative errno range */
227 const char* preset_action_past_tense_to_string(PresetAction action
);
229 void unit_file_presets_done(UnitFilePresets
*p
);
230 PresetAction
unit_file_query_preset(RuntimeScope scope
, const char *root_dir
, const char *name
, UnitFilePresets
*cached
);
232 const char* unit_file_state_to_string(UnitFileState s
) _const_
;
233 UnitFileState
unit_file_state_from_string(const char *s
) _pure_
;
234 /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */
236 const char* install_change_type_to_string(InstallChangeType t
) _const_
;
237 InstallChangeType
install_change_type_from_string(const char *s
) _pure_
;
239 const char* unit_file_preset_mode_to_string(UnitFilePresetMode m
) _const_
;
240 UnitFilePresetMode
unit_file_preset_mode_from_string(const char *s
) _pure_
;