1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-10-26 17:25:34 +03:00

Merge pull request #24008 from poettering/tmpfiles-is-dir-fix

tmpfiles: fix wrong is_dir_fd() call
This commit is contained in:
Lennart Poettering 2022-07-14 18:16:07 +02:00 committed by GitHub
commit 6ecc6c4536
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 26 deletions

View File

@ -35,31 +35,23 @@ int is_symlink(const char *path) {
return !!S_ISLNK(info.st_mode);
}
int is_dir(const char* path, bool follow) {
int is_dir_full(int atfd, const char* path, bool follow) {
struct stat st;
int r;
assert(path);
assert(atfd >= 0 || atfd == AT_FDCWD);
assert(atfd >= 0 || path);
if (follow)
r = stat(path, &st);
if (path)
r = fstatat(atfd, path, &st, follow ? 0 : AT_SYMLINK_NOFOLLOW);
else
r = lstat(path, &st);
r = fstat(atfd, &st);
if (r < 0)
return -errno;
return !!S_ISDIR(st.st_mode);
}
int is_dir_fd(int fd) {
struct stat st;
if (fstat(fd, &st) < 0)
return -errno;
return !!S_ISDIR(st.st_mode);
}
int is_device_node(const char *path) {
struct stat info;

View File

@ -13,8 +13,13 @@
#include "missing_stat.h"
int is_symlink(const char *path);
int is_dir(const char *path, bool follow);
int is_dir_fd(int fd);
int is_dir_full(int atfd, const char *fname, bool follow);
static inline int is_dir(const char *path, bool follow) {
return is_dir_full(AT_FDCWD, path, follow);
}
static inline int is_dir_fd(int fd) {
return is_dir_full(fd, NULL, false);
}
int is_device_node(const char *path);
int dir_is_empty_at(int dir_fd, const char *path, bool ignore_hidden_or_backup);

View File

@ -1629,15 +1629,12 @@ static int create_directory_or_subvolume(const char *path, mode_t mode, bool sub
r = btrfs_is_subvol(empty_to_root(arg_root)) > 0;
}
if (!r)
/* Don't create a subvolume unless the root directory is
* one, too. We do this under the assumption that if the
* root directory is just a plain directory (i.e. very
* light-weight), we shouldn't try to split it up into
* subvolumes (i.e. more heavy-weight). Thus, chroot()
* environments and suchlike will get a full brtfs
* subvolume set up below their tree only if they
* specifically set up a btrfs subvolume for the root
* dir too. */
/* Don't create a subvolume unless the root directory is one, too. We do this under
* the assumption that if the root directory is just a plain directory (i.e. very
* light-weight), we shouldn't try to split it up into subvolumes (i.e. more
* heavy-weight). Thus, chroot() environments and suchlike will get a full brtfs
* subvolume set up below their tree only if they specifically set up a btrfs
* subvolume for the root dir too. */
subvol = false;
else {
@ -1657,7 +1654,7 @@ static int create_directory_or_subvolume(const char *path, mode_t mode, bool sub
if (!IN_SET(r, -EEXIST, -EROFS))
return log_error_errno(r, "Failed to create directory or subvolume \"%s\": %m", path);
k = is_dir_fd(pfd);
k = is_dir_full(pfd, bn, /* follow= */ false);
if (k == -ENOENT && r == -EROFS)
return log_error_errno(r, "%s does not exist and cannot be created as the file system is read-only.", path);
if (k < 0)