fd-util: introduce fd_reopen() helper for reopening an fd
We have the same code for this in place at various locations, let's unify that. Also, let's repurpose test-fs-util.c as a test for this new helper cal..
This commit is contained in:
@@ -1186,7 +1186,6 @@ static int parse_attribute_from_arg(Item *item) {
|
||||
}
|
||||
|
||||
static int fd_set_attribute(Item *item, int fd, const struct stat *st) {
|
||||
char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
|
||||
_cleanup_close_ int procfs_fd = -1;
|
||||
_cleanup_free_ char *path = NULL;
|
||||
unsigned f;
|
||||
@@ -1213,9 +1212,7 @@ static int fd_set_attribute(Item *item, int fd, const struct stat *st) {
|
||||
if (!S_ISDIR(st->st_mode))
|
||||
f &= ~FS_DIRSYNC_FL;
|
||||
|
||||
xsprintf(procfs_path, "/proc/self/fd/%i", fd);
|
||||
|
||||
procfs_fd = open(procfs_path, O_RDONLY|O_CLOEXEC|O_NOATIME);
|
||||
procfs_fd = fd_reopen(fd, O_RDONLY|O_CLOEXEC|O_NOATIME);
|
||||
if (procfs_fd < 0)
|
||||
return -errno;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user