1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-26 14:04:03 +03:00

path-lookup: modernize runtime_directory() too

This commit is contained in:
Mike Yuan 2024-08-24 15:33:53 +02:00
parent 60cd6deb06
commit 8cff087d27
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3
3 changed files with 10 additions and 10 deletions

View File

@ -17,16 +17,15 @@
#include "tmpfile-util.h"
#include "user-util.h"
int runtime_directory(char **ret, RuntimeScope scope, const char *suffix) {
int runtime_directory(RuntimeScope scope, const char *suffix, char **ret) {
int r;
assert(ret);
assert(IN_SET(scope, RUNTIME_SCOPE_SYSTEM, RUNTIME_SCOPE_USER));
assert(suffix);
assert(IN_SET(scope, RUNTIME_SCOPE_SYSTEM, RUNTIME_SCOPE_USER, RUNTIME_SCOPE_GLOBAL));
assert(ret);
/* Accept $RUNTIME_DIRECTORY as authoritative
* If its missing apply the suffix to /run or $XDG_RUNTIME_DIR
* if we are in a user runtime scope.
* If it's missing, apply the suffix to /run/, or $XDG_RUNTIME_DIR if we are in a user runtime scope.
*
* Return value indicates whether the suffix was applied or not */
@ -45,7 +44,7 @@ int runtime_directory(char **ret, RuntimeScope scope, const char *suffix) {
*ret = d;
}
return true;
return 1;
}
static const char* const user_data_unit_paths[] = {

View File

@ -58,6 +58,8 @@ int lookup_paths_init_or_warn(LookupPaths *lp, RuntimeScope scope, LookupPathsFl
void lookup_paths_log(LookupPaths *p);
void lookup_paths_done(LookupPaths *p);
int runtime_directory(RuntimeScope scope, const char *suffix, char **ret);
int xdg_user_dirs(char ***ret_config_dirs, char ***ret_data_dirs);
/* We don't treat /etc/xdg/systemd/ in these functions as the xdg base dir spec suggests because we assume
@ -72,7 +74,6 @@ static inline int xdg_user_config_dir(const char *suffix, char **ret) {
static inline int xdg_user_data_dir(const char *suffix, char **ret) {
return sd_path_lookup(SD_PATH_USER_SHARED, suffix, ret);
}
int runtime_directory(char **ret, RuntimeScope scope, const char *suffix);
bool path_is_user_data_dir(const char *path);
bool path_is_user_config_dir(const char *path);

View File

@ -1488,11 +1488,11 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
/* if we are going to be starting any units with state then create our runtime dir */
if (arg_tpm != 0 || arg_directory || arg_runtime_mounts.n_mounts != 0) {
r = runtime_directory(&arg_runtime_directory, arg_privileged ? RUNTIME_SCOPE_SYSTEM : RUNTIME_SCOPE_USER, "systemd/vmspawn");
r = runtime_directory(arg_privileged ? RUNTIME_SCOPE_SYSTEM : RUNTIME_SCOPE_USER, "systemd/vmspawn",
&arg_runtime_directory);
if (r < 0)
return log_error_errno(r, "Failed to lookup runtime directory: %m");
if (r) {
/* r > 0 means we need to create our own runtime dir */
if (r > 0) { /* We need to create our own runtime dir */
r = mkdir_p(arg_runtime_directory, 0755);
if (r < 0)
return log_error_errno(r, "Failed to create runtime directory: %m");