]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
rm-rf: fix errno handling
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 18 Mar 2023 14:35:04 +0000 (23:35 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 24 Mar 2023 19:50:27 +0000 (04:50 +0900)
src/shared/rm-rf.c

index 6cc4265737b3c4b13b9b0f7839a8cbe07ccd3242..1695e1555a299d91994bbb10ac5bc04f1a5abe9a 100644 (file)
@@ -287,8 +287,8 @@ int rm_rf_children(
                                  if (!newdirname)
                                          return log_oom();
 
-                                 int newfd = openat(fd, de->d_name,
-                                                    O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME);
+                                 int newfd = RET_NERRNO(openat(fd, de->d_name,
+                                                               O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME));
                                  if (newfd >= 0) {
                                          todos[n_todo++] = (TodoEntry) { TAKE_PTR(d), TAKE_PTR(dirname) };
                                          fd = newfd;
@@ -296,8 +296,8 @@ int rm_rf_children(
 
                                          goto next_fd;
 
-                                 } else if (errno != -ENOENT && ret == 0)
-                                         ret = -errno;
+                                 } else if (newfd != -ENOENT && ret == 0)
+                                         ret = newfd;
 
                         } else if (r < 0 && r != -ENOENT && ret == 0)
                                 ret = r;