]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
path-lookup: modernize runtime_directory() too
authorMike Yuan <me@yhndnzj.com>
Sat, 24 Aug 2024 13:33:53 +0000 (15:33 +0200)
committerMike Yuan <me@yhndnzj.com>
Sun, 6 Oct 2024 17:32:53 +0000 (19:32 +0200)
src/libsystemd/sd-path/path-lookup.c
src/libsystemd/sd-path/path-lookup.h
src/vmspawn/vmspawn.c

index 5d0d66914c9561d327596a047091c1b018d6339e..2b0607df0760b41e02deb0e027f0787ca546fd12 100644 (file)
 #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[] = {
index c325fa6041a2fad9cb04b3fbde55452091e0bda1..6c7c9f42da01d9800f3835819c2ef895e05b9f25 100644 (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);
index 7474b301f39979220a72c50e45ba3510485acc70..9d7f943200b79a01b42ae2ae25e986a40816c110 100644 (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");