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 UnitFileType UnitFileType
;
27 typedef struct UnitFileChange UnitFileChange
;
28 typedef struct UnitFileList UnitFileList
;
29 typedef struct UnitFileInstallInfo UnitFileInstallInfo
;
35 #include "path-lookup.h"
37 #include "unit-name.h"
44 _UNIT_FILE_SCOPE_INVALID
= -1
49 UNIT_FILE_ENABLED_RUNTIME
,
51 UNIT_FILE_LINKED_RUNTIME
,
53 UNIT_FILE_MASKED_RUNTIME
,
61 _UNIT_FILE_STATE_INVALID
= -1
64 enum UnitFilePresetMode
{
65 UNIT_FILE_PRESET_FULL
,
66 UNIT_FILE_PRESET_ENABLE_ONLY
,
67 UNIT_FILE_PRESET_DISABLE_ONLY
,
68 _UNIT_FILE_PRESET_MAX
,
69 _UNIT_FILE_PRESET_INVALID
= -1
72 enum UnitFileChangeType
{
76 UNIT_FILE_IS_DANGLING
,
77 _UNIT_FILE_CHANGE_TYPE_MAX
,
78 _UNIT_FILE_CHANGE_INVALID
= INT_MIN
81 /* type can either one of the UnitFileChangeTypes listed above, or a negative error.
82 * If source is specified, it should be the contents of the path symlink.
83 * In case of an error, source should be the existing symlink contents or NULL
85 struct UnitFileChange
{
86 int type
; /* UnitFileChangeType or bust */
91 static inline bool unit_file_changes_have_modification(const UnitFileChange
* changes
, unsigned n_changes
) {
93 for (i
= 0; i
< n_changes
; i
++)
94 if (IN_SET(changes
[i
].type
, UNIT_FILE_SYMLINK
, UNIT_FILE_UNLINK
))
105 UNIT_FILE_TYPE_REGULAR
,
106 UNIT_FILE_TYPE_SYMLINK
,
107 UNIT_FILE_TYPE_MASKED
,
109 _UNIT_FILE_TYPE_INVALID
= -1,
112 struct UnitFileInstallInfo
{
121 char *default_instance
;
122 char *symlink_target
;
128 static inline bool UNIT_FILE_INSTALL_INFO_HAS_RULES(UnitFileInstallInfo
*i
) {
131 return !strv_isempty(i
->aliases
) ||
132 !strv_isempty(i
->wanted_by
) ||
133 !strv_isempty(i
->required_by
);
136 static inline bool UNIT_FILE_INSTALL_INFO_HAS_ALSO(UnitFileInstallInfo
*i
) {
139 return !strv_isempty(i
->also
);
142 bool unit_type_may_alias(UnitType type
) _const_
;
143 bool unit_type_may_template(UnitType type
) _const_
;
145 int unit_file_enable(
148 const char *root_dir
,
151 UnitFileChange
**changes
,
152 unsigned *n_changes
);
153 int unit_file_disable(
156 const char *root_dir
,
158 UnitFileChange
**changes
,
159 unsigned *n_changes
);
160 int unit_file_reenable(
163 const char *root_dir
,
166 UnitFileChange
**changes
,
167 unsigned *n_changes
);
168 int unit_file_preset(
171 const char *root_dir
,
173 UnitFilePresetMode mode
,
175 UnitFileChange
**changes
,
176 unsigned *n_changes
);
177 int unit_file_preset_all(
180 const char *root_dir
,
181 UnitFilePresetMode mode
,
183 UnitFileChange
**changes
,
184 unsigned *n_changes
);
188 const char *root_dir
,
191 UnitFileChange
**changes
,
192 unsigned *n_changes
);
193 int unit_file_unmask(
196 const char *root_dir
,
198 UnitFileChange
**changes
,
199 unsigned *n_changes
);
203 const char *root_dir
,
206 UnitFileChange
**changes
,
207 unsigned *n_changes
);
208 int unit_file_revert(
210 const char *root_dir
,
212 UnitFileChange
**changes
,
213 unsigned *n_changes
);
214 int unit_file_set_default(
216 const char *root_dir
,
219 UnitFileChange
**changes
,
220 unsigned *n_changes
);
221 int unit_file_get_default(
223 const char *root_dir
,
225 int unit_file_add_dependency(
228 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_
;