]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homework: replace homegrown "dir-is-empty" check with dir_is_empty_at()
authorLennart Poettering <lennart@poettering.net>
Thu, 21 Oct 2021 16:07:50 +0000 (18:07 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 25 Oct 2021 23:13:15 +0000 (08:13 +0900)
src/home/homework-cifs.c

index 3db18130e39a3dfd4d22bda7a20c79e748a57461..896b1bf78be18df001c4183dbe3d551851ce42ca 100644 (file)
@@ -9,6 +9,7 @@
 #include "homework-mount.h"
 #include "mount-util.h"
 #include "process-util.h"
+#include "stat-util.h"
 #include "strv.h"
 #include "tmpfile-util.h"
 
@@ -143,8 +144,6 @@ int home_activate_cifs(
 
 int home_create_cifs(UserRecord *h, HomeSetup *setup, UserRecord **ret_home) {
         _cleanup_(user_record_unrefp) UserRecord *new_home = NULL;
-        _cleanup_(closedirp) DIR *d = NULL;
-        _cleanup_close_ int copy = -1;
         int r;
 
         assert(h);
@@ -166,19 +165,11 @@ int home_create_cifs(UserRecord *h, HomeSetup *setup, UserRecord **ret_home) {
         if (r < 0)
                 return r;
 
-        copy = fcntl(setup->root_fd, F_DUPFD_CLOEXEC, 3);
-        if (copy < 0)
-                return -errno;
-
-        d = take_fdopendir(&copy);
-        if (!d)
-                return -errno;
-
-        errno = 0;
-        if (readdir_no_dot(d))
+        r = dir_is_empty_at(setup->root_fd, NULL);
+        if (r < 0)
+                return log_error_errno(r, "Failed to detect if CIFS directory is empty: %m");
+        if (r == 0)
                 return log_error_errno(SYNTHETIC_ERRNO(ENOTEMPTY), "Selected CIFS directory not empty, refusing.");
-        if (errno != 0)
-                return log_error_errno(errno, "Failed to detect if CIFS directory is empty: %m");
 
         r = home_populate(h, setup->root_fd);
         if (r < 0)