| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "runtime-scope.h" |
| 5 |
#include "shared-forward.h" |
| 6 |
#include "unit-file.h" |
| 7 |
|
| 8 |
typedef enum UnitFilePresetMode { |
| 9 |
UNIT_FILE_PRESET_FULL, |
| 10 |
UNIT_FILE_PRESET_ENABLE_ONLY, |
| 11 |
UNIT_FILE_PRESET_DISABLE_ONLY, |
| 12 |
_UNIT_FILE_PRESET_MODE_MAX, |
| 13 |
_UNIT_FILE_PRESET_MODE_INVALID = -EINVAL, |
| 14 |
} UnitFilePresetMode; |
| 15 |
|
| 16 |
typedef enum InstallChangeType { |
| 17 |
INSTALL_CHANGE_SYMLINK, |
| 18 |
INSTALL_CHANGE_UNLINK, |
| 19 |
INSTALL_CHANGE_IS_MASKED, |
| 20 |
INSTALL_CHANGE_IS_MASKED_GENERATOR, |
| 21 |
INSTALL_CHANGE_IS_DANGLING, |
| 22 |
INSTALL_CHANGE_DESTINATION_NOT_PRESENT, |
| 23 |
INSTALL_CHANGE_AUXILIARY_FAILED, |
| 24 |
_INSTALL_CHANGE_TYPE_MAX, |
| 25 |
_INSTALL_CHANGE_INVALID = -EINVAL, |
| 26 |
_INSTALL_CHANGE_ERRNO_MAX = -ERRNO_MAX, /* Ensure this type covers the whole negative errno range */ |
| 27 |
} InstallChangeType; |
| 28 |
|
| 29 |
static inline bool INSTALL_CHANGE_TYPE_VALID(InstallChangeType t) { |
| 30 |
return t >= _INSTALL_CHANGE_ERRNO_MAX && t < _INSTALL_CHANGE_TYPE_MAX; |
| 31 |
} |
| 32 |
|
| 33 |
typedef enum UnitFileFlags { |
| 34 |
UNIT_FILE_RUNTIME = 1 << 0, /* Public API via DBUS, do not change */ |
| 35 |
UNIT_FILE_FORCE = 1 << 1, /* Public API via DBUS, do not change */ |
| 36 |
UNIT_FILE_PORTABLE = 1 << 2, /* Public API via DBUS, do not change */ |
| 37 |
UNIT_FILE_DRY_RUN = 1 << 3, |
| 38 |
UNIT_FILE_IGNORE_AUXILIARY_FAILURE = 1 << 4, |
| 39 |
_UNIT_FILE_FLAGS_MASK_PUBLIC = UNIT_FILE_RUNTIME|UNIT_FILE_PORTABLE|UNIT_FILE_FORCE, |
| 40 |
} UnitFileFlags; |
| 41 |
|
| 42 |
typedef enum SearchFlags { |
| 43 |
SEARCH_LOAD = 1 << 0, |
| 44 |
SEARCH_FOLLOW_CONFIG_SYMLINKS = 1 << 1, |
| 45 |
SEARCH_DROPIN = 1 << 2, |
| 46 |
SEARCH_IGNORE_TEMPLATE = 1 << 3, /* Don't look up the template if the instance does not exist. */ |
| 47 |
} SearchFlags; |
| 48 |
|
| 49 |
/* type can be either one of the INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK, … listed above, or a negative |
| 50 |
* errno value. |
| 51 |
* |
| 52 |
* If source is specified, it should be the contents of the path symlink. In case of an error, source should |
| 53 |
* be the existing symlink contents or NULL. */ |
| 54 |
typedef struct InstallChange { |
| 55 |
int type; /* INSTALL_CHANGE_SYMLINK, … if positive, errno if negative */ |
| 56 |
char *path; |
| 57 |
char *source; |
| 58 |
} InstallChange; |
| 59 |
|
| 60 |
static inline bool install_changes_have_modification(const InstallChange *changes, size_t n_changes) { |
| 61 |
FOREACH_ARRAY(i, changes, n_changes) |
| 62 |
if (IN_SET(i->type, INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK)) |
| 63 |
return true; |
| 64 |
return false; |
| 65 |
} |
| 66 |
|
| 67 |
typedef struct UnitFileList { |
| 68 |
char *path; |
| 69 |
UnitFileState state; |
| 70 |
} UnitFileList; |
| 71 |
|
| 72 |
typedef enum InstallMode { |
| 73 |
INSTALL_MODE_REGULAR, |
| 74 |
INSTALL_MODE_LINKED, |
| 75 |
INSTALL_MODE_ALIAS, |
| 76 |
INSTALL_MODE_MASKED, |
| 77 |
_INSTALL_MODE_MAX, |
| 78 |
_INSTALL_MODE_INVALID = -EINVAL, |
| 79 |
} InstallMode; |
| 80 |
|
| 81 |
typedef struct InstallInfo { |
| 82 |
char *name; |
| 83 |
char *path; |
| 84 |
char *root; |
| 85 |
|
| 86 |
char **aliases; |
| 87 |
char **wanted_by; |
| 88 |
char **required_by; |
| 89 |
char **upheld_by; |
| 90 |
char **also; |
| 91 |
|
| 92 |
char *default_instance; |
| 93 |
char *symlink_target; |
| 94 |
|
| 95 |
InstallMode install_mode; |
| 96 |
bool auxiliary; |
| 97 |
} InstallInfo; |
| 98 |
|
| 99 |
int unit_file_enable( |
| 100 |
RuntimeScope scope, |
| 101 |
UnitFileFlags flags, |
| 102 |
const char *root_dir, |
| 103 |
char * const *names_or_paths, |
| 104 |
InstallChange **changes, |
| 105 |
size_t *n_changes); |
| 106 |
int unit_file_disable( |
| 107 |
RuntimeScope scope, |
| 108 |
UnitFileFlags flags, |
| 109 |
const char *root_dir, |
| 110 |
char * const *files, |
| 111 |
InstallChange **changes, |
| 112 |
size_t *n_changes); |
| 113 |
int unit_file_reenable( |
| 114 |
RuntimeScope scope, |
| 115 |
UnitFileFlags flags, |
| 116 |
const char *root_dir, |
| 117 |
char * const *names_or_paths, |
| 118 |
InstallChange **changes, |
| 119 |
size_t *n_changes); |
| 120 |
int unit_file_preset( |
| 121 |
RuntimeScope scope, |
| 122 |
UnitFileFlags file_flags, |
| 123 |
const char *root_dir, |
| 124 |
char * const *names, |
| 125 |
UnitFilePresetMode mode, |
| 126 |
InstallChange **changes, |
| 127 |
size_t *n_changes); |
| 128 |
int unit_file_preset_all( |
| 129 |
RuntimeScope scope, |
| 130 |
UnitFileFlags file_flags, |
| 131 |
const char *root_dir, |
| 132 |
UnitFilePresetMode mode, |
| 133 |
InstallChange **changes, |
| 134 |
size_t *n_changes); |
| 135 |
int unit_file_mask( |
| 136 |
RuntimeScope scope, |
| 137 |
UnitFileFlags flags, |
| 138 |
const char *root_dir, |
| 139 |
char * const *names, |
| 140 |
InstallChange **changes, |
| 141 |
size_t *n_changes); |
| 142 |
int unit_file_unmask( |
| 143 |
RuntimeScope scope, |
| 144 |
UnitFileFlags flags, |
| 145 |
const char *root_dir, |
| 146 |
char * const *names, |
| 147 |
InstallChange **changes, |
| 148 |
size_t *n_changes); |
| 149 |
int unit_file_link( |
| 150 |
RuntimeScope scope, |
| 151 |
UnitFileFlags flags, |
| 152 |
const char *root_dir, |
| 153 |
char * const *files, |
| 154 |
InstallChange **changes, |
| 155 |
size_t *n_changes); |
| 156 |
int unit_file_revert( |
| 157 |
RuntimeScope scope, |
| 158 |
const char *root_dir, |
| 159 |
char * const *names, |
| 160 |
InstallChange **changes, |
| 161 |
size_t *n_changes); |
| 162 |
int unit_file_set_default( |
| 163 |
RuntimeScope scope, |
| 164 |
UnitFileFlags flags, |
| 165 |
const char *root_dir, |
| 166 |
const char *name, |
| 167 |
InstallChange **changes, |
| 168 |
size_t *n_changes); |
| 169 |
int unit_file_get_default( |
| 170 |
RuntimeScope scope, |
| 171 |
const char *root_dir, |
| 172 |
char **ret); |
| 173 |
int unit_file_add_dependency( |
| 174 |
RuntimeScope scope, |
| 175 |
UnitFileFlags flags, |
| 176 |
const char *root_dir, |
| 177 |
char * const *names, |
| 178 |
const char *target, |
| 179 |
UnitDependency dep, |
| 180 |
InstallChange **changes, |
| 181 |
size_t *n_changes); |
| 182 |
|
| 183 |
int unit_file_lookup_state( |
| 184 |
RuntimeScope scope, |
| 185 |
const LookupPaths *lp, |
| 186 |
const char *name, |
| 187 |
UnitFileState *ret); |
| 188 |
|
| 189 |
int unit_file_get_state(RuntimeScope scope, const char *root_dir, const char *filename, UnitFileState *ret); |
| 190 |
|
| 191 |
int unit_file_exists_full( |
| 192 |
RuntimeScope scope, |
| 193 |
const LookupPaths *lp, |
| 194 |
SearchFlags flags, |
| 195 |
const char *name, |
| 196 |
char **ret_path); |
| 197 |
|
| 198 |
static inline int unit_file_exists(RuntimeScope scope, const LookupPaths *lp, const char *name) { |
| 199 |
return unit_file_exists_full(scope, lp, 0, name, NULL); |
| 200 |
} |
| 201 |
|
| 202 |
int unit_file_get_list(RuntimeScope scope, const char *root_dir, char * const *states, char * const *patterns, Hashmap **ret); |
| 203 |
|
| 204 |
InstallChangeType install_changes_add(InstallChange **changes, size_t *n_changes, InstallChangeType type, const char *path, const char *source); |
| 205 |
void install_changes_free(InstallChange *array, size_t n); |
| 206 |
|
| 207 |
int install_change_dump_error(const InstallChange *change, char **ret_errmsg, const char **ret_bus_error); |
| 208 |
int install_changes_dump( |
| 209 |
int error, |
| 210 |
const char *verb, |
| 211 |
const InstallChange *changes, |
| 212 |
size_t n_changes, |
| 213 |
bool quiet); |
| 214 |
|
| 215 |
int unit_file_verify_alias( |
| 216 |
const InstallInfo *info, |
| 217 |
const char *dst, |
| 218 |
char **ret_dst, |
| 219 |
InstallChange **changes, |
| 220 |
size_t *n_changes); |
| 221 |
|
| 222 |
typedef struct UnitFilePresetRule UnitFilePresetRule; |
| 223 |
|
| 224 |
typedef struct { |
| 225 |
UnitFilePresetRule *rules; |
| 226 |
size_t n_rules; |
| 227 |
bool initialized; |
| 228 |
} UnitFilePresets; |
| 229 |
|
| 230 |
typedef enum PresetAction { |
| 231 |
PRESET_UNKNOWN, |
| 232 |
PRESET_ENABLE, |
| 233 |
PRESET_DISABLE, |
| 234 |
PRESET_IGNORE, |
| 235 |
_PRESET_ACTION_MAX, |
| 236 |
_PRESET_ACTION_INVALID = -EINVAL, |
| 237 |
_PRESET_ACTION_ERRNO_MAX = -ERRNO_MAX, /* Ensure this type covers the whole negative errno range */ |
| 238 |
} PresetAction; |
| 239 |
|
| 240 |
DECLARE_STRING_TABLE_LOOKUP_TO_STRING(preset_action_past_tense, PresetAction); |
| 241 |
|
| 242 |
void unit_file_presets_done(UnitFilePresets *p); |
| 243 |
PresetAction unit_file_query_preset(RuntimeScope scope, const char *root_dir, const char *name, UnitFilePresets *cached); |
| 244 |
|
| 245 |
DECLARE_STRING_TABLE_LOOKUP(unit_file_state, UnitFileState); |
| 246 |
/* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */ |
| 247 |
|
| 248 |
DECLARE_STRING_TABLE_LOOKUP(install_change_type, InstallChangeType); |
| 249 |
|
| 250 |
DECLARE_STRING_TABLE_LOOKUP(unit_file_preset_mode, UnitFilePresetMode); |