summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-11-16 15:24:07 +0100
committerLennart Poettering <lennart@poettering.net>2021-11-17 21:48:29 +0100
commit96603ea076ff9b24810aacbaa703bdb126e8e531 (patch)
treec4d74147ba3176843be9d59954328d4e967d11fc /src/shared
parentfs-util: add new helper open_mkdir_at() (diff)
downloadsystemd-96603ea076ff9b24810aacbaa703bdb126e8e531.tar.xz
systemd-96603ea076ff9b24810aacbaa703bdb126e8e531.zip
tree-wide: port various places over to open_mkdir_at()
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/copy.c14
-rw-r--r--src/shared/creds-util.c6
2 files changed, 6 insertions, 14 deletions
diff --git a/src/shared/copy.c b/src/shared/copy.c
index fd83d74265..bb3ac8a3f8 100644
--- a/src/shared/copy.c
+++ b/src/shared/copy.c
@@ -485,8 +485,6 @@ static int hardlink_context_setup(
}
static int hardlink_context_realize(HardlinkContext *c) {
- int r;
-
if (!c)
return 0;
@@ -498,15 +496,9 @@ static int hardlink_context_realize(HardlinkContext *c) {
assert(c->subdir);
- if (mkdirat(c->parent_fd, c->subdir, 0700) < 0)
- return -errno;
-
- c->dir_fd = openat(c->parent_fd, c->subdir, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
- if (c->dir_fd < 0) {
- r = -errno;
- (void) unlinkat(c->parent_fd, c->subdir, AT_REMOVEDIR);
- return r;
- }
+ c->dir_fd = open_mkdir_at(c->parent_fd, c->subdir, O_EXCL|O_CLOEXEC, 0700);
+ if (c->dir_fd < 0)
+ return c->dir_fd;
return 1;
}
diff --git a/src/shared/creds-util.c b/src/shared/creds-util.c
index b764198b76..0c8181bce2 100644
--- a/src/shared/creds-util.c
+++ b/src/shared/creds-util.c
@@ -215,10 +215,10 @@ int get_credential_host_secret(CredentialSecretFlags flags, void **ret, size_t *
fn = "credential.secret";
}
- (void) mkdir_p(p, 0755);
- dfd = open(p, O_CLOEXEC|O_DIRECTORY|O_RDONLY);
+ mkdir_parents(p, 0755);
+ dfd = open_mkdir_at(AT_FDCWD, p, O_CLOEXEC, 0755);
if (dfd < 0)
- return -errno;
+ return dfd;
if (FLAGS_SET(flags, CREDENTIAL_SECRET_FAIL_ON_TEMPORARY_FS)) {
r = fd_is_temporary_fs(dfd);