summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-10-21 18:07:50 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-10-26 08:13:15 +0900
commit1845ba368ec0ae9e9416424b829f962d92a676af (patch)
tree6d5ddfd35a9784c857190b61f47af1f40150e72b
parentb1ccd7d7377c0895338d72f54ea34ec4eeebc455 (diff)
downloadsystemd-1845ba368ec0ae9e9416424b829f962d92a676af.tar.gz
homework: replace homegrown "dir-is-empty" check with dir_is_empty_at()
-rw-r--r--src/home/homework-cifs.c19
1 files 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(&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)