4 This file is part of systemd.
6 Copyright 2011 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 typedef enum UnitFileScope UnitFileScope
;
23 typedef enum UnitFileState UnitFileState
;
24 typedef enum UnitFilePresetMode UnitFilePresetMode
;
25 typedef enum UnitFileChangeType UnitFileChangeType
;
26 typedef enum UnitFileFlags UnitFileFlags
;
27 typedef enum UnitFileType UnitFileType
;
28 typedef struct UnitFileChange UnitFileChange
;
29 typedef struct UnitFileList UnitFileList
;
30 typedef struct UnitFileInstallInfo UnitFileInstallInfo
;
36 #include "path-lookup.h"
38 #include "unit-name.h"
45 _UNIT_FILE_SCOPE_INVALID
= -1
50 UNIT_FILE_ENABLED_RUNTIME
,
52 UNIT_FILE_LINKED_RUNTIME
,
54 UNIT_FILE_MASKED_RUNTIME
,
62 _UNIT_FILE_STATE_INVALID
= -1
65 enum UnitFilePresetMode
{
66 UNIT_FILE_PRESET_FULL
,
67 UNIT_FILE_PRESET_ENABLE_ONLY
,
68 UNIT_FILE_PRESET_DISABLE_ONLY
,
69 _UNIT_FILE_PRESET_MAX
,
70 _UNIT_FILE_PRESET_INVALID
= -1
73 enum UnitFileChangeType
{
77 UNIT_FILE_IS_DANGLING
,
78 _UNIT_FILE_CHANGE_TYPE_MAX
,
79 _UNIT_FILE_CHANGE_INVALID
= INT_MIN
83 UNIT_FILE_RUNTIME
= 1,
84 UNIT_FILE_FORCE
= 1 << 1,
85 UNIT_FILE_DRY_RUN
= 1 << 2,
88 /* type can either one of the UnitFileChangeTypes listed above, or a negative error.
89 * If source is specified, it should be the contents of the path symlink.
90 * In case of an error, source should be the existing symlink contents or NULL
92 struct UnitFileChange
{
93 int type
; /* UnitFileChangeType or bust */
98 static inline bool unit_file_changes_have_modification(const UnitFileChange
* changes
, unsigned n_changes
) {
100 for (i
= 0; i
< n_changes
; i
++)
101 if (IN_SET(changes
[i
].type
, UNIT_FILE_SYMLINK
, UNIT_FILE_UNLINK
))
106 struct UnitFileList
{
112 UNIT_FILE_TYPE_REGULAR
,
113 UNIT_FILE_TYPE_SYMLINK
,
114 UNIT_FILE_TYPE_MASKED
,
116 _UNIT_FILE_TYPE_INVALID
= -1,
119 struct UnitFileInstallInfo
{
128 char *default_instance
;
129 char *symlink_target
;
135 static inline bool UNIT_FILE_INSTALL_INFO_HAS_RULES(UnitFileInstallInfo
*i
) {
138 return !strv_isempty(i
->aliases
) ||
139 !strv_isempty(i
->wanted_by
) ||
140 !strv_isempty(i
->required_by
);
143 static inline bool UNIT_FILE_INSTALL_INFO_HAS_ALSO(UnitFileInstallInfo
*i
) {
146 return !strv_isempty(i
->also
);
149 bool unit_type_may_alias(UnitType type
) _const_
;
150 bool unit_type_may_template(UnitType type
) _const_
;
152 int unit_file_enable(
155 const char *root_dir
,
157 UnitFileChange
**changes
,
158 unsigned *n_changes
);
159 int unit_file_disable(
162 const char *root_dir
,
164 UnitFileChange
**changes
,
165 unsigned *n_changes
);
166 int unit_file_reenable(
169 const char *root_dir
,
171 UnitFileChange
**changes
,
172 unsigned *n_changes
);
173 int unit_file_preset(
176 const char *root_dir
,
178 UnitFilePresetMode mode
,
179 UnitFileChange
**changes
,
180 unsigned *n_changes
);
181 int unit_file_preset_all(
184 const char *root_dir
,
185 UnitFilePresetMode mode
,
186 UnitFileChange
**changes
,
187 unsigned *n_changes
);
191 const char *root_dir
,
193 UnitFileChange
**changes
,
194 unsigned *n_changes
);
195 int unit_file_unmask(
198 const char *root_dir
,
200 UnitFileChange
**changes
,
201 unsigned *n_changes
);
205 const char *root_dir
,
207 UnitFileChange
**changes
,
208 unsigned *n_changes
);
209 int unit_file_revert(
211 const char *root_dir
,
213 UnitFileChange
**changes
,
214 unsigned *n_changes
);
215 int unit_file_set_default(
218 const char *root_dir
,
220 UnitFileChange
**changes
,
221 unsigned *n_changes
);
222 int unit_file_get_default(
224 const char *root_dir
,
226 int unit_file_add_dependency(
229 const char *root_dir
,
233 UnitFileChange
**changes
,
234 unsigned *n_changes
);
236 int unit_file_get_state(UnitFileScope scope
, const char *root_dir
, const char *filename
, UnitFileState
*ret
);
237 int unit_file_exists(UnitFileScope scope
, const LookupPaths
*paths
, const char *name
);
239 int unit_file_get_list(UnitFileScope scope
, const char *root_dir
, Hashmap
*h
, char **states
, char **patterns
);
240 Hashmap
* unit_file_list_free(Hashmap
*h
);
242 int unit_file_changes_add(UnitFileChange
**changes
, unsigned *n_changes
, UnitFileChangeType type
, const char *path
, const char *source
);
243 void unit_file_changes_free(UnitFileChange
*changes
, unsigned n_changes
);
244 void unit_file_dump_changes(int r
, const char *verb
, const UnitFileChange
*changes
, unsigned n_changes
, bool quiet
);
246 int unit_file_query_preset(UnitFileScope scope
, const char *root_dir
, const char *name
);
248 const char *unit_file_state_to_string(UnitFileState s
) _const_
;
249 UnitFileState
unit_file_state_from_string(const char *s
) _pure_
;
250 /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */
252 const char *unit_file_change_type_to_string(UnitFileChangeType s
) _const_
;
253 UnitFileChangeType
unit_file_change_type_from_string(const char *s
) _pure_
;
255 const char *unit_file_preset_mode_to_string(UnitFilePresetMode m
) _const_
;
256 UnitFilePresetMode
unit_file_preset_mode_from_string(const char *s
) _pure_
;