mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-20 14:03:39 +03:00
tree-wide: port various places over to open_mkdir_at()
This commit is contained in:
parent
c73094f3ac
commit
96603ea076
@ -2499,6 +2499,7 @@ int temporary_filesystem_add(
|
||||
|
||||
static int make_tmp_prefix(const char *prefix) {
|
||||
_cleanup_free_ char *t = NULL;
|
||||
_cleanup_close_ int fd = -1;
|
||||
int r;
|
||||
|
||||
/* Don't do anything unless we know the dir is actually missing */
|
||||
@ -2517,18 +2518,20 @@ static int make_tmp_prefix(const char *prefix) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (mkdir(t, 0777) < 0) /* umask will corrupt this access mode, but that doesn't matter, we need to
|
||||
* call chmod() anyway for the suid bit, below. */
|
||||
return -errno;
|
||||
/* umask will corrupt this access mode, but that doesn't matter, we need to call chmod() anyway for
|
||||
* the suid bit, below. */
|
||||
fd = open_mkdir_at(AT_FDCWD, t, O_EXCL|O_CLOEXEC, 0777);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
if (chmod(t, 01777) < 0) {
|
||||
r = -errno;
|
||||
r = RET_NERRNO(fchmod(fd, 01777));
|
||||
if (r < 0) {
|
||||
(void) rmdir(t);
|
||||
return r;
|
||||
}
|
||||
|
||||
if (rename(t, prefix) < 0) {
|
||||
r = -errno;
|
||||
r = RET_NERRNO(rename(t, prefix));
|
||||
if (r < 0) {
|
||||
(void) rmdir(t);
|
||||
return r == -EEXIST ? 0 : r; /* it's fine if someone else created the dir by now */
|
||||
}
|
||||
|
@ -127,15 +127,17 @@ int home_setup_cifs(
|
||||
return log_oom();
|
||||
|
||||
if (FLAGS_SET(flags, HOME_SETUP_CIFS_MKDIR)) {
|
||||
r = mkdir_p(j, 0700);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create CIFS subdirectory: %m");
|
||||
setup->root_fd = open_mkdir_at(AT_FDCWD, j, O_CLOEXEC, 0700);
|
||||
if (setup->root_fd < 0)
|
||||
return log_error_errno(setup->root_fd, "Failed to create CIFS subdirectory: %m");
|
||||
}
|
||||
}
|
||||
|
||||
setup->root_fd = open(j ?: HOME_RUNTIME_WORK_DIR, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
|
||||
if (setup->root_fd < 0)
|
||||
return log_error_errno(errno, "Failed to open home directory: %m");
|
||||
if (setup->root_fd < 0) {
|
||||
setup->root_fd = open(j ?: HOME_RUNTIME_WORK_DIR, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
|
||||
if (setup->root_fd < 0)
|
||||
return log_error_errno(errno, "Failed to open home directory: %m");
|
||||
}
|
||||
|
||||
setup->mount_suffix = TAKE_PTR(cdir);
|
||||
return 0;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user