| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "sd-path.h" |
| 5 |
|
| 6 |
#include "sd-forward.h" |
| 7 |
#include "runtime-scope.h" |
| 8 |
|
| 9 |
typedef enum LookupPathsFlags { |
| 10 |
LOOKUP_PATHS_EXCLUDE_GENERATED = 1 << 0, |
| 11 |
LOOKUP_PATHS_TEMPORARY_GENERATED = 1 << 1, |
| 12 |
LOOKUP_PATHS_SPLIT_USR = 1 << 2, /* Legacy, use ONLY for image payloads which might be old */ |
| 13 |
} LookupPathsFlags; |
| 14 |
|
| 15 |
typedef struct LookupPaths { |
| 16 |
/* Where we look for unit files. This includes the individual special paths below, but also any vendor |
| 17 |
* supplied, static unit file paths. */ |
| 18 |
char **search_path; |
| 19 |
|
| 20 |
/* Where we shall create or remove our installation symlinks, aka "configuration", and where the user/admin |
| 21 |
* shall place their own unit files. */ |
| 22 |
char *persistent_config; |
| 23 |
char *runtime_config; |
| 24 |
|
| 25 |
/* Where units from a portable service image shall be placed. */ |
| 26 |
char *persistent_attached; |
| 27 |
char *runtime_attached; |
| 28 |
|
| 29 |
/* Where to place generated unit files (i.e. those a "generator" tool generated). Note the special semantics of |
| 30 |
* this directory: the generators are flushed each time a "systemctl daemon-reload" is issued. The user should |
| 31 |
* not alter these directories directly. */ |
| 32 |
char *generator; |
| 33 |
char *generator_early; |
| 34 |
char *generator_late; |
| 35 |
|
| 36 |
/* Where to place transient unit files (i.e. those created dynamically via the bus API). Note the special |
| 37 |
* semantics of this directory: all units created transiently have their unit files removed as the transient |
| 38 |
* unit is unloaded. The user should not alter this directory directly. */ |
| 39 |
char *transient; |
| 40 |
|
| 41 |
/* Where the snippets created by "systemctl set-property" are placed. Note that for transient units, the |
| 42 |
* snippets are placed in the transient directory though (see above). The user should not alter this directory |
| 43 |
* directly. */ |
| 44 |
char *persistent_control; |
| 45 |
char *runtime_control; |
| 46 |
|
| 47 |
/* The root directory prepended to all items above, or NULL */ |
| 48 |
char *root_dir; |
| 49 |
|
| 50 |
/* A temporary directory when running in test mode, to be nuked */ |
| 51 |
char *temporary_dir; |
| 52 |
} LookupPaths; |
| 53 |
|
| 54 |
int lookup_paths_init(LookupPaths *lp, RuntimeScope scope, LookupPathsFlags flags, const char *root_dir); |
| 55 |
int lookup_paths_init_or_warn(LookupPaths *lp, RuntimeScope scope, LookupPathsFlags flags, const char *root_dir); |
| 56 |
|
| 57 |
void lookup_paths_log(LookupPaths *p); |
| 58 |
void lookup_paths_done(LookupPaths *p); |
| 59 |
|
| 60 |
int config_directory_generic(RuntimeScope scope, const char *suffix, char **ret); |
| 61 |
int runtime_directory_generic(RuntimeScope scope, const char *suffix, char **ret); |
| 62 |
int runtime_directory(RuntimeScope scope, const char *fallback_suffix, char **ret); |
| 63 |
int runtime_directory_make(RuntimeScope scope, const char *subdir, char **ret_dir, char **ret_dir_destroy); |
| 64 |
int state_directory_generic(RuntimeScope scope, const char *suffix, char **ret); |
| 65 |
|
| 66 |
/* We don't treat /etc/xdg/systemd/ in these functions as the xdg base dir spec suggests because we assume |
| 67 |
* that is a link to /etc/systemd/ anyway. */ |
| 68 |
|
| 69 |
int user_search_dirs(const char *suffix, char ***ret_config_dirs, char ***ret_data_dirs); |
| 70 |
static inline int xdg_user_runtime_dir(const char *suffix, char **ret) { |
| 71 |
return sd_path_lookup(SD_PATH_USER_RUNTIME, suffix, ret); |
| 72 |
} |
| 73 |
static inline int xdg_user_config_dir(const char *suffix, char **ret) { |
| 74 |
return sd_path_lookup(SD_PATH_USER_CONFIGURATION, suffix, ret); |
| 75 |
} |
| 76 |
static inline int xdg_user_data_dir(const char *suffix, char **ret) { |
| 77 |
return sd_path_lookup(SD_PATH_USER_SHARED, suffix, ret); |
| 78 |
} |
| 79 |
static inline int xdg_user_state_dir(const char *suffix, char **ret) { |
| 80 |
return sd_path_lookup(SD_PATH_USER_STATE_PRIVATE, suffix, ret); |
| 81 |
} |
| 82 |
|
| 83 |
bool path_is_user_data_dir(const char *path); |
| 84 |
bool path_is_user_config_dir(const char *path); |
| 85 |
|
| 86 |
char** generator_binary_paths_internal(RuntimeScope scope, bool env_generator); |
| 87 |
static inline char** generator_binary_paths(RuntimeScope runtime_scope) { |
| 88 |
return generator_binary_paths_internal(runtime_scope, false); |
| 89 |
} |
| 90 |
static inline char** env_generator_binary_paths(RuntimeScope runtime_scope) { |
| 91 |
return generator_binary_paths_internal(runtime_scope, true); |
| 92 |
} |
| 93 |
|
| 94 |
static inline int credential_store_path(RuntimeScope runtime_scope, char ***ret) { |
| 95 |
return sd_path_lookup_strv( |
| 96 |
runtime_scope == RUNTIME_SCOPE_SYSTEM ? |
| 97 |
SD_PATH_SYSTEM_SEARCH_CREDENTIAL_STORE : SD_PATH_USER_SEARCH_CREDENTIAL_STORE, |
| 98 |
/* suffix= */ NULL, |
| 99 |
ret); |
| 100 |
} |
| 101 |
|
| 102 |
static inline int credential_store_path_encrypted(RuntimeScope runtime_scope, char ***ret) { |
| 103 |
return sd_path_lookup_strv( |
| 104 |
runtime_scope == RUNTIME_SCOPE_SYSTEM ? |
| 105 |
SD_PATH_SYSTEM_SEARCH_CREDENTIAL_STORE_ENCRYPTED : SD_PATH_USER_SEARCH_CREDENTIAL_STORE_ENCRYPTED, |
| 106 |
/* suffix= */ NULL, |
| 107 |
ret); |
| 108 |
} |