From: Daan De Meyer Date: Wed, 24 Jul 2024 12:54:06 +0000 (+0200) Subject: Make read_attr_path() more generic X-Git-Tag: v257-rc1~817^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5e496845212d6f1f49e6f6a749b0819301323b27;p=thirdparty%2Fsystemd.git Make read_attr_path() more generic Let's make this an openat() like function so it can be used in more scenarios. --- diff --git a/src/basic/chattr-util.c b/src/basic/chattr-util.c index d76be5c99b6..49831a26cee 100644 --- a/src/basic/chattr-util.c +++ b/src/basic/chattr-util.c @@ -148,15 +148,15 @@ int read_attr_fd(int fd, unsigned *ret) { return RET_NERRNO(ioctl(fd, FS_IOC_GETFLAGS, ret)); } -int read_attr_path(const char *p, unsigned *ret) { +int read_attr_at(int dir_fd, const char *path, unsigned *ret) { _cleanup_close_ int fd = -EBADF; - assert(p); + assert(dir_fd >= 0 || dir_fd == AT_FDCWD); assert(ret); - fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); + fd = xopenat(dir_fd, path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); if (fd < 0) - return -errno; + return fd; return read_attr_fd(fd, ret); } diff --git a/src/basic/chattr-util.h b/src/basic/chattr-util.h index c1ee63b4fae..1fe38e32b15 100644 --- a/src/basic/chattr-util.h +++ b/src/basic/chattr-util.h @@ -52,7 +52,7 @@ static inline int chattr_path(const char *path, unsigned value, unsigned mask, u } int read_attr_fd(int fd, unsigned *ret); -int read_attr_path(const char *p, unsigned *ret); +int read_attr_at(int dir_fd, const char *path, unsigned *ret); /* Combination of chattr flags, that should be appropriate for secrets stored on disk: Secure Remove + * Exclusion from Dumping + Synchronous Writing (i.e. not caching in memory) + In-Place Updating (i.e. not diff --git a/src/shared/discover-image.c b/src/shared/discover-image.c index d7a9df70b1c..dd78a013aaf 100644 --- a/src/shared/discover-image.c +++ b/src/shared/discover-image.c @@ -1070,7 +1070,7 @@ int image_rename(Image *i, const char *new_name) { case IMAGE_DIRECTORY: /* Turn of the immutable bit while we rename the image, so that we can rename it */ - (void) read_attr_path(i->path, &file_attr); + (void) read_attr_at(AT_FDCWD, i->path, &file_attr); if (file_attr & FS_IMMUTABLE_FL) (void) chattr_path(i->path, 0, FS_IMMUTABLE_FL, NULL);