1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 This file is part of systemd.
7 Copyright 2011 Lennart Poettering
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 typedef enum UnitFileScope UnitFileScope
;
24 typedef enum UnitFileState UnitFileState
;
25 typedef enum UnitFilePresetMode UnitFilePresetMode
;
26 typedef enum UnitFileChangeType UnitFileChangeType
;
27 typedef enum UnitFileFlags UnitFileFlags
;
28 typedef enum UnitFileType UnitFileType
;
29 typedef struct UnitFileChange UnitFileChange
;
30 typedef struct UnitFileList UnitFileList
;
31 typedef struct UnitFileInstallInfo UnitFileInstallInfo
;
37 #include "path-lookup.h"
39 #include "unit-name.h"
46 _UNIT_FILE_SCOPE_INVALID
= -1
51 UNIT_FILE_ENABLED_RUNTIME
,
53 UNIT_FILE_LINKED_RUNTIME
,
55 UNIT_FILE_MASKED_RUNTIME
,
63 _UNIT_FILE_STATE_INVALID
= -1
66 enum UnitFilePresetMode
{
67 UNIT_FILE_PRESET_FULL
,
68 UNIT_FILE_PRESET_ENABLE_ONLY
,
69 UNIT_FILE_PRESET_DISABLE_ONLY
,
70 _UNIT_FILE_PRESET_MAX
,
71 _UNIT_FILE_PRESET_INVALID
= -1
74 enum UnitFileChangeType
{
78 UNIT_FILE_IS_DANGLING
,
79 _UNIT_FILE_CHANGE_TYPE_MAX
,
80 _UNIT_FILE_CHANGE_INVALID
= INT_MIN
84 UNIT_FILE_RUNTIME
= 1,
85 UNIT_FILE_FORCE
= 1 << 1,
86 UNIT_FILE_DRY_RUN
= 1 << 2,
89 /* type can either one of the UnitFileChangeTypes listed above, or a negative error.
90 * If source is specified, it should be the contents of the path symlink.
91 * In case of an error, source should be the existing symlink contents or NULL
93 struct UnitFileChange
{
94 int type
; /* UnitFileChangeType or bust */
99 static inline bool unit_file_changes_have_modification(const UnitFileChange
* changes
, unsigned n_changes
) {
101 for (i
= 0; i
< n_changes
; i
++)
102 if (IN_SET(changes
[i
].type
, UNIT_FILE_SYMLINK
, UNIT_FILE_UNLINK
))
107 struct UnitFileList
{
113 UNIT_FILE_TYPE_REGULAR
,
114 UNIT_FILE_TYPE_SYMLINK
,
115 UNIT_FILE_TYPE_MASKED
,
117 _UNIT_FILE_TYPE_INVALID
= -1,
120 struct UnitFileInstallInfo
{
129 char *default_instance
;
130 char *symlink_target
;
136 bool unit_type_may_alias(UnitType type
) _const_
;
137 bool unit_type_may_template(UnitType type
) _const_
;
139 int unit_file_enable(
142 const char *root_dir
,
144 UnitFileChange
**changes
,
145 unsigned *n_changes
);
146 int unit_file_disable(
149 const char *root_dir
,
151 UnitFileChange
**changes
,
152 unsigned *n_changes
);
153 int unit_file_reenable(
156 const char *root_dir
,
158 UnitFileChange
**changes
,
159 unsigned *n_changes
);
160 int unit_file_preset(
163 const char *root_dir
,
165 UnitFilePresetMode mode
,
166 UnitFileChange
**changes
,
167 unsigned *n_changes
);
168 int unit_file_preset_all(
171 const char *root_dir
,
172 UnitFilePresetMode mode
,
173 UnitFileChange
**changes
,
174 unsigned *n_changes
);
178 const char *root_dir
,
180 UnitFileChange
**changes
,
181 unsigned *n_changes
);
182 int unit_file_unmask(
185 const char *root_dir
,
187 UnitFileChange
**changes
,
188 unsigned *n_changes
);
192 const char *root_dir
,
194 UnitFileChange
**changes
,
195 unsigned *n_changes
);
196 int unit_file_revert(
198 const char *root_dir
,
200 UnitFileChange
**changes
,
201 unsigned *n_changes
);
202 int unit_file_set_default(
205 const char *root_dir
,
207 UnitFileChange
**changes
,
208 unsigned *n_changes
);
209 int unit_file_get_default(
211 const char *root_dir
,
213 int unit_file_add_dependency(
216 const char *root_dir
,
220 UnitFileChange
**changes
,
221 unsigned *n_changes
);
223 int unit_file_get_state(UnitFileScope scope
, const char *root_dir
, const char *filename
, UnitFileState
*ret
);
224 int unit_file_exists(UnitFileScope scope
, const LookupPaths
*paths
, const char *name
);
226 int unit_file_get_list(UnitFileScope scope
, const char *root_dir
, Hashmap
*h
, char **states
, char **patterns
);
227 Hashmap
* unit_file_list_free(Hashmap
*h
);
229 int unit_file_changes_add(UnitFileChange
**changes
, unsigned *n_changes
, UnitFileChangeType type
, const char *path
, const char *source
);
230 void unit_file_changes_free(UnitFileChange
*changes
, unsigned n_changes
);
231 void unit_file_dump_changes(int r
, const char *verb
, const UnitFileChange
*changes
, unsigned n_changes
, bool quiet
);
233 int unit_file_query_preset(UnitFileScope scope
, const char *root_dir
, const char *name
);
235 const char *unit_file_state_to_string(UnitFileState s
) _const_
;
236 UnitFileState
unit_file_state_from_string(const char *s
) _pure_
;
237 /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */
239 const char *unit_file_change_type_to_string(UnitFileChangeType s
) _const_
;
240 UnitFileChangeType
unit_file_change_type_from_string(const char *s
) _pure_
;
242 const char *unit_file_preset_mode_to_string(UnitFilePresetMode m
) _const_
;
243 UnitFilePresetMode
unit_file_preset_mode_from_string(const char *s
) _pure_
;