From 1845ba368ec0ae9e9416424b829f962d92a676af Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 21 Oct 2021 18:07:50 +0200 Subject: [PATCH] homework: replace homegrown "dir-is-empty" check with dir_is_empty_at() --- src/home/homework-cifs.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/home/homework-cifs.c b/src/home/homework-cifs.c index 3db18130e3..896b1bf78b 100644 --- a/src/home/homework-cifs.c +++ b/src/home/homework-cifs.c @@ -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(©); - 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) -- 2.25.1