]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
exec-util: tighten variable scope a bit
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 17 Mar 2023 03:46:51 +0000 (12:46 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 17 Mar 2023 11:38:15 +0000 (20:38 +0900)
src/shared/exec-util.c

index 40e9342cd5211c24a9e065defc97bf06b4e44ac7..d38bfc9e4af082106e7ca5c8418c211a02e88985 100644 (file)
@@ -203,23 +203,24 @@ int execute_directories(
                 ExecDirFlags flags) {
 
         char **dirs = (char**) directories;
-        _cleanup_free_ char *name = NULL;
         _cleanup_close_ int fd = -EBADF;
         int r;
         pid_t executor_pid;
 
         assert(!strv_isempty(dirs));
 
-        r = path_extract_filename(dirs[0], &name);
-        if (r < 0)
-                return log_error_errno(r, "Failed to extract file name from '%s': %m", dirs[0]);
-
         if (callbacks) {
                 assert(callback_args);
                 assert(callbacks[STDOUT_GENERATE]);
                 assert(callbacks[STDOUT_COLLECT]);
                 assert(callbacks[STDOUT_CONSUME]);
 
+                _cleanup_free_ char *name = NULL;
+
+                r = path_extract_filename(dirs[0], &name);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to extract file name from '%s': %m", dirs[0]);
+
                 fd = open_serialization_fd(name);
                 if (fd < 0)
                         return log_error_errno(fd, "Failed to open serialization file: %m");