From: Mike Yuan Date: Sat, 24 Aug 2024 13:33:53 +0000 (+0200) Subject: path-lookup: modernize runtime_directory() too X-Git-Tag: v257-rc1~317^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8cff087d27f8b0a1eca5c63261f5918e10b0b70f;p=thirdparty%2Fsystemd.git path-lookup: modernize runtime_directory() too --- diff --git a/src/libsystemd/sd-path/path-lookup.c b/src/libsystemd/sd-path/path-lookup.c index 5d0d66914c9..2b0607df076 100644 --- a/src/libsystemd/sd-path/path-lookup.c +++ b/src/libsystemd/sd-path/path-lookup.c @@ -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[] = { diff --git a/src/libsystemd/sd-path/path-lookup.h b/src/libsystemd/sd-path/path-lookup.h index c325fa6041a..6c7c9f42da0 100644 --- a/src/libsystemd/sd-path/path-lookup.h +++ b/src/libsystemd/sd-path/path-lookup.h @@ -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); diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index 7474b301f39..9d7f943200b 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -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");