diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-05-07 14:13:55 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-05-07 18:18:27 +0200 |
commit | 158681f0f97d1efe9c7edf06aa86230964b8d0e6 (patch) | |
tree | d36cc281abae62e7bad9de70a4ebc4f53b824b38 /src/basic | |
parent | core/service: use switch for service_enter_start (diff) | |
download | systemd-158681f0f97d1efe9c7edf06aa86230964b8d0e6.tar.xz systemd-158681f0f97d1efe9c7edf06aa86230964b8d0e6.zip |
basic/mkdir: use timespec_store instead of _nsec for mkdir_p_root_full
Follow-up for 34c3d574742e867ef97e79509e4051a82f1b7d9b
O_RDONLY is dropped when O_DIRECTORY is specified, since
it's unnecessary and even arguably confusing here, as
the dir is modified.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/mkdir.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/basic/mkdir.c b/src/basic/mkdir.c index c378f89604..20329e04c2 100644 --- a/src/basic/mkdir.c +++ b/src/basic/mkdir.c @@ -209,6 +209,8 @@ int mkdir_p_root_full(const char *root, const char *p, uid_t uid, gid_t gid, mod _cleanup_close_ int dfd = -EBADF; int r; + assert(p); + r = path_extract_directory(p, &pp); if (r == -EDESTADDRREQ) { /* only fname is passed, no prefix to operate on */ @@ -226,7 +228,7 @@ int mkdir_p_root_full(const char *root, const char *p, uid_t uid, gid_t gid, mod if (r < 0) return r; - dfd = chase_and_open(pp, root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_DIRECTORY, NULL); + dfd = chase_and_open(pp, root, CHASE_PREFIX_ROOT, O_CLOEXEC|O_DIRECTORY, NULL); if (dfd < 0) return dfd; } @@ -241,25 +243,22 @@ int mkdir_p_root_full(const char *root, const char *p, uid_t uid, gid_t gid, mod r = btrfs_subvol_make_fallback(dfd, bn, m); else r = RET_NERRNO(mkdirat(dfd, bn, m)); - if (r < 0) { - if (r == -EEXIST) - return 0; - + if (r == -EEXIST) + return 0; + if (r < 0) return r; - } if (ts == USEC_INFINITY && !uid_is_valid(uid) && !gid_is_valid(gid)) return 1; - _cleanup_close_ int nfd = -EBADF; - nfd = openat(dfd, bn, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW); + _cleanup_close_ int nfd = openat(dfd, bn, O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW); if (nfd < 0) return -errno; if (ts != USEC_INFINITY) { struct timespec tspec; + timespec_store(&tspec, ts); - timespec_store_nsec(&tspec, ts); if (futimens(dfd, (const struct timespec[2]) { { .tv_nsec = UTIME_OMIT }, tspec }) < 0) return -errno; |