]>
Commit | Line | Data |
---|---|---|
c2f1db8f | 1 | #pragma once |
83096483 LP |
2 | |
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2011 Lennart Poettering | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
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 | |
83096483 LP |
11 | (at your option) any later version. |
12 | ||
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 | |
5430f7f2 | 16 | Lesser General Public License for more details. |
83096483 | 17 | |
5430f7f2 | 18 | You should have received a copy of the GNU Lesser General Public License |
83096483 LP |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
20 | ***/ | |
21 | ||
cab6235f LP |
22 | typedef enum UnitFileScope UnitFileScope; |
23 | typedef enum UnitFileState UnitFileState; | |
24 | typedef enum UnitFilePresetMode UnitFilePresetMode; | |
25 | typedef enum UnitFileChangeType UnitFileChangeType; | |
0ec0deaa | 26 | typedef enum UnitFileType UnitFileType; |
cab6235f LP |
27 | typedef struct UnitFileChange UnitFileChange; |
28 | typedef struct UnitFileList UnitFileList; | |
29 | typedef struct UnitFileInstallInfo UnitFileInstallInfo; | |
30 | ||
a8fbdf54 TA |
31 | #include <stdbool.h> |
32 | ||
83096483 | 33 | #include "hashmap.h" |
a8fbdf54 | 34 | #include "macro.h" |
a8ffe6fb | 35 | #include "path-lookup.h" |
0ec0deaa LP |
36 | #include "strv.h" |
37 | #include "unit-name.h" | |
83096483 | 38 | |
cab6235f | 39 | enum UnitFileScope { |
83096483 LP |
40 | UNIT_FILE_SYSTEM, |
41 | UNIT_FILE_GLOBAL, | |
42 | UNIT_FILE_USER, | |
43 | _UNIT_FILE_SCOPE_MAX, | |
44 | _UNIT_FILE_SCOPE_INVALID = -1 | |
cab6235f | 45 | }; |
83096483 | 46 | |
cab6235f | 47 | enum UnitFileState { |
83096483 LP |
48 | UNIT_FILE_ENABLED, |
49 | UNIT_FILE_ENABLED_RUNTIME, | |
50 | UNIT_FILE_LINKED, | |
51 | UNIT_FILE_LINKED_RUNTIME, | |
52 | UNIT_FILE_MASKED, | |
53 | UNIT_FILE_MASKED_RUNTIME, | |
54 | UNIT_FILE_STATIC, | |
55 | UNIT_FILE_DISABLED, | |
aedd4012 | 56 | UNIT_FILE_INDIRECT, |
f4139308 | 57 | UNIT_FILE_GENERATED, |
0ec0deaa | 58 | UNIT_FILE_BAD, |
83096483 LP |
59 | _UNIT_FILE_STATE_MAX, |
60 | _UNIT_FILE_STATE_INVALID = -1 | |
cab6235f | 61 | }; |
83096483 | 62 | |
cab6235f | 63 | enum UnitFilePresetMode { |
d309c1c3 LP |
64 | UNIT_FILE_PRESET_FULL, |
65 | UNIT_FILE_PRESET_ENABLE_ONLY, | |
66 | UNIT_FILE_PRESET_DISABLE_ONLY, | |
86bbe5bf | 67 | _UNIT_FILE_PRESET_MAX, |
d309c1c3 | 68 | _UNIT_FILE_PRESET_INVALID = -1 |
cab6235f | 69 | }; |
d309c1c3 | 70 | |
cab6235f | 71 | enum UnitFileChangeType { |
83096483 LP |
72 | UNIT_FILE_SYMLINK, |
73 | UNIT_FILE_UNLINK, | |
74 | _UNIT_FILE_CHANGE_TYPE_MAX, | |
75 | _UNIT_FILE_CHANGE_TYPE_INVALID = -1 | |
cab6235f | 76 | }; |
83096483 | 77 | |
cab6235f | 78 | struct UnitFileChange { |
83096483 LP |
79 | UnitFileChangeType type; |
80 | char *path; | |
81 | char *source; | |
cab6235f | 82 | }; |
83096483 | 83 | |
cab6235f | 84 | struct UnitFileList { |
83096483 LP |
85 | char *path; |
86 | UnitFileState state; | |
cab6235f | 87 | }; |
83096483 | 88 | |
0ec0deaa LP |
89 | enum UnitFileType { |
90 | UNIT_FILE_TYPE_REGULAR, | |
91 | UNIT_FILE_TYPE_SYMLINK, | |
92 | UNIT_FILE_TYPE_MASKED, | |
93 | _UNIT_FILE_TYPE_MAX, | |
94 | _UNIT_FILE_TYPE_INVALID = -1, | |
95 | }; | |
96 | ||
cab6235f | 97 | struct UnitFileInstallInfo { |
7584d236 ZJS |
98 | char *name; |
99 | char *path; | |
100 | ||
101 | char **aliases; | |
102 | char **wanted_by; | |
103 | char **required_by; | |
aedd4012 | 104 | char **also; |
d54c4993 LP |
105 | |
106 | char *default_instance; | |
0ec0deaa LP |
107 | |
108 | UnitFileType type; | |
109 | ||
110 | char *symlink_target; | |
cab6235f | 111 | }; |
7584d236 | 112 | |
0ec0deaa LP |
113 | static inline bool UNIT_FILE_INSTALL_INFO_HAS_RULES(UnitFileInstallInfo *i) { |
114 | assert(i); | |
115 | ||
116 | return !strv_isempty(i->aliases) || | |
117 | !strv_isempty(i->wanted_by) || | |
118 | !strv_isempty(i->required_by); | |
119 | } | |
120 | ||
121 | static inline bool UNIT_FILE_INSTALL_INFO_HAS_ALSO(UnitFileInstallInfo *i) { | |
122 | assert(i); | |
123 | ||
124 | return !strv_isempty(i->also); | |
125 | } | |
126 | ||
7195aa42 ZJS |
127 | int unit_file_enable(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes); |
128 | int unit_file_disable(UnitFileScope scope, bool runtime, const char *root_dir, char **files, UnitFileChange **changes, unsigned *n_changes); | |
129 | int unit_file_reenable(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes); | |
130 | int unit_file_link(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes); | |
d309c1c3 LP |
131 | int unit_file_preset(UnitFileScope scope, bool runtime, const char *root_dir, char **files, UnitFilePresetMode mode, bool force, UnitFileChange **changes, unsigned *n_changes); |
132 | int unit_file_preset_all(UnitFileScope scope, bool runtime, const char *root_dir, UnitFilePresetMode mode, bool force, UnitFileChange **changes, unsigned *n_changes); | |
7195aa42 ZJS |
133 | int unit_file_mask(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes); |
134 | int unit_file_unmask(UnitFileScope scope, bool runtime, const char *root_dir, char **files, UnitFileChange **changes, unsigned *n_changes); | |
718db961 | 135 | int unit_file_set_default(UnitFileScope scope, const char *root_dir, const char *file, bool force, UnitFileChange **changes, unsigned *n_changes); |
99504dd4 | 136 | int unit_file_get_default(UnitFileScope scope, const char *root_dir, char **name); |
0ec0deaa | 137 | int unit_file_add_dependency(UnitFileScope scope, bool runtime, const char *root_dir, char **files, const char *target, UnitDependency dep, bool force, UnitFileChange **changes, unsigned *n_changes); |
83096483 | 138 | |
e4bb56c7 | 139 | int unit_file_lookup_state(UnitFileScope scope, const LookupPaths *paths, const char *name, UnitFileState *ret); |
0ec0deaa | 140 | int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret); |
83096483 LP |
141 | |
142 | int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h); | |
0ec0deaa | 143 | Hashmap* unit_file_list_free(Hashmap *h); |
83096483 | 144 | |
57ab2eab | 145 | int unit_file_changes_add(UnitFileChange **changes, unsigned *n_changes, UnitFileChangeType type, const char *path, const char *source); |
83096483 LP |
146 | void unit_file_changes_free(UnitFileChange *changes, unsigned n_changes); |
147 | ||
c2a8d7b0 | 148 | int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name); |
83096483 | 149 | |
44a6b1b6 ZJS |
150 | const char *unit_file_state_to_string(UnitFileState s) _const_; |
151 | UnitFileState unit_file_state_from_string(const char *s) _pure_; | |
83096483 | 152 | |
44a6b1b6 ZJS |
153 | const char *unit_file_change_type_to_string(UnitFileChangeType s) _const_; |
154 | UnitFileChangeType unit_file_change_type_from_string(const char *s) _pure_; | |
d309c1c3 LP |
155 | |
156 | const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_; | |
157 | UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_; |