]>
Commit | Line | Data |
---|---|---|
663996b3 MS |
1 | #pragma once |
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 | |
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. | |
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 | |
16 | Lesser General Public License for more details. | |
17 | ||
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/>. | |
20 | ***/ | |
21 | ||
e3bff60a MP |
22 | typedef enum UnitFileScope UnitFileScope; |
23 | typedef enum UnitFileState UnitFileState; | |
24 | typedef enum UnitFilePresetMode UnitFilePresetMode; | |
25 | typedef enum UnitFileChangeType UnitFileChangeType; | |
db2df898 | 26 | typedef enum UnitFileType UnitFileType; |
e3bff60a MP |
27 | typedef struct UnitFileChange UnitFileChange; |
28 | typedef struct UnitFileList UnitFileList; | |
29 | typedef struct UnitFileInstallInfo UnitFileInstallInfo; | |
30 | ||
4c89c718 MP |
31 | #include <stdbool.h> |
32 | ||
663996b3 | 33 | #include "hashmap.h" |
4c89c718 | 34 | #include "macro.h" |
e3bff60a | 35 | #include "path-lookup.h" |
db2df898 MP |
36 | #include "strv.h" |
37 | #include "unit-name.h" | |
663996b3 | 38 | |
e3bff60a | 39 | enum UnitFileScope { |
663996b3 MS |
40 | UNIT_FILE_SYSTEM, |
41 | UNIT_FILE_GLOBAL, | |
42 | UNIT_FILE_USER, | |
43 | _UNIT_FILE_SCOPE_MAX, | |
44 | _UNIT_FILE_SCOPE_INVALID = -1 | |
e3bff60a | 45 | }; |
663996b3 | 46 | |
e3bff60a | 47 | enum UnitFileState { |
663996b3 MS |
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, | |
f47781d8 | 56 | UNIT_FILE_INDIRECT, |
db2df898 | 57 | UNIT_FILE_BAD, |
663996b3 MS |
58 | _UNIT_FILE_STATE_MAX, |
59 | _UNIT_FILE_STATE_INVALID = -1 | |
e3bff60a | 60 | }; |
663996b3 | 61 | |
e3bff60a | 62 | enum UnitFilePresetMode { |
e842803a MB |
63 | UNIT_FILE_PRESET_FULL, |
64 | UNIT_FILE_PRESET_ENABLE_ONLY, | |
65 | UNIT_FILE_PRESET_DISABLE_ONLY, | |
5eef597e | 66 | _UNIT_FILE_PRESET_MAX, |
e842803a | 67 | _UNIT_FILE_PRESET_INVALID = -1 |
e3bff60a | 68 | }; |
e842803a | 69 | |
e3bff60a | 70 | enum UnitFileChangeType { |
663996b3 MS |
71 | UNIT_FILE_SYMLINK, |
72 | UNIT_FILE_UNLINK, | |
73 | _UNIT_FILE_CHANGE_TYPE_MAX, | |
74 | _UNIT_FILE_CHANGE_TYPE_INVALID = -1 | |
e3bff60a | 75 | }; |
663996b3 | 76 | |
e3bff60a | 77 | struct UnitFileChange { |
663996b3 MS |
78 | UnitFileChangeType type; |
79 | char *path; | |
80 | char *source; | |
e3bff60a | 81 | }; |
663996b3 | 82 | |
e3bff60a | 83 | struct UnitFileList { |
663996b3 MS |
84 | char *path; |
85 | UnitFileState state; | |
e3bff60a | 86 | }; |
663996b3 | 87 | |
db2df898 MP |
88 | enum UnitFileType { |
89 | UNIT_FILE_TYPE_REGULAR, | |
90 | UNIT_FILE_TYPE_SYMLINK, | |
91 | UNIT_FILE_TYPE_MASKED, | |
92 | _UNIT_FILE_TYPE_MAX, | |
93 | _UNIT_FILE_TYPE_INVALID = -1, | |
94 | }; | |
95 | ||
e3bff60a | 96 | struct UnitFileInstallInfo { |
663996b3 MS |
97 | char *name; |
98 | char *path; | |
663996b3 MS |
99 | |
100 | char **aliases; | |
101 | char **wanted_by; | |
102 | char **required_by; | |
f47781d8 | 103 | char **also; |
e842803a MB |
104 | |
105 | char *default_instance; | |
db2df898 MP |
106 | |
107 | UnitFileType type; | |
108 | ||
109 | char *symlink_target; | |
e3bff60a | 110 | }; |
663996b3 | 111 | |
db2df898 MP |
112 | static inline bool UNIT_FILE_INSTALL_INFO_HAS_RULES(UnitFileInstallInfo *i) { |
113 | assert(i); | |
114 | ||
115 | return !strv_isempty(i->aliases) || | |
116 | !strv_isempty(i->wanted_by) || | |
117 | !strv_isempty(i->required_by); | |
118 | } | |
119 | ||
120 | static inline bool UNIT_FILE_INSTALL_INFO_HAS_ALSO(UnitFileInstallInfo *i) { | |
121 | assert(i); | |
122 | ||
123 | return !strv_isempty(i->also); | |
124 | } | |
125 | ||
60f067b4 JS |
126 | int unit_file_enable(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes); |
127 | int unit_file_disable(UnitFileScope scope, bool runtime, const char *root_dir, char **files, UnitFileChange **changes, unsigned *n_changes); | |
128 | int unit_file_reenable(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes); | |
129 | int unit_file_link(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes); | |
e842803a MB |
130 | int unit_file_preset(UnitFileScope scope, bool runtime, const char *root_dir, char **files, UnitFilePresetMode mode, bool force, UnitFileChange **changes, unsigned *n_changes); |
131 | int unit_file_preset_all(UnitFileScope scope, bool runtime, const char *root_dir, UnitFilePresetMode mode, bool force, UnitFileChange **changes, unsigned *n_changes); | |
60f067b4 JS |
132 | int unit_file_mask(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes); |
133 | int unit_file_unmask(UnitFileScope scope, bool runtime, const char *root_dir, char **files, UnitFileChange **changes, unsigned *n_changes); | |
134 | int unit_file_set_default(UnitFileScope scope, const char *root_dir, const char *file, bool force, UnitFileChange **changes, unsigned *n_changes); | |
14228c0d | 135 | int unit_file_get_default(UnitFileScope scope, const char *root_dir, char **name); |
db2df898 MP |
136 | 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); |
137 | ||
138 | int unit_file_lookup_state(UnitFileScope scope, const char *root_dir,const LookupPaths *paths, const char *name, UnitFileState *ret); | |
139 | int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret); | |
663996b3 MS |
140 | |
141 | int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h); | |
db2df898 | 142 | Hashmap* unit_file_list_free(Hashmap *h); |
663996b3 | 143 | |
e3bff60a | 144 | int unit_file_changes_add(UnitFileChange **changes, unsigned *n_changes, UnitFileChangeType type, const char *path, const char *source); |
663996b3 MS |
145 | void unit_file_changes_free(UnitFileChange *changes, unsigned n_changes); |
146 | ||
e842803a | 147 | int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name); |
663996b3 MS |
148 | |
149 | const char *unit_file_state_to_string(UnitFileState s) _const_; | |
150 | UnitFileState unit_file_state_from_string(const char *s) _pure_; | |
151 | ||
152 | const char *unit_file_change_type_to_string(UnitFileChangeType s) _const_; | |
153 | UnitFileChangeType unit_file_change_type_from_string(const char *s) _pure_; | |
e842803a MB |
154 | |
155 | const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_; | |
156 | UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_; |