From: Karel Zak Date: Wed, 8 Sep 2021 11:16:29 +0000 (+0200) Subject: lib/path: use flags for fstatat() X-Git-Tag: v2.38-rc1~144^2~97 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=db9ad223d6f136d95254d73808c39786d80abf2e;p=thirdparty%2Futil-linux.git lib/path: use flags for fstatat() Signed-off-by: Karel Zak --- diff --git a/include/path.h b/include/path.h index e720893399..3ce70c40b2 100644 --- a/include/path.h +++ b/include/path.h @@ -48,7 +48,7 @@ int ul_path_is_accessible(struct path_cxt *pc); char *ul_path_get_abspath(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...) __attribute__ ((__format__ (__printf__, 4, 5))); -int ul_path_stat(struct path_cxt *pc, struct stat *sb, const char *path); +int ul_path_stat(struct path_cxt *pc, struct stat *sb, int flags, const char *path); int ul_path_access(struct path_cxt *pc, int mode, const char *path); int ul_path_accessf(struct path_cxt *pc, int mode, const char *path, ...) __attribute__ ((__format__ (__printf__, 3, 4))); diff --git a/lib/path.c b/lib/path.c index f0b010e67e..cf3a33e046 100644 --- a/lib/path.c +++ b/lib/path.c @@ -339,7 +339,7 @@ int ul_path_accessf(struct path_cxt *pc, int mode, const char *path, ...) return !p ? -errno : ul_path_access(pc, mode, p); } -int ul_path_stat(struct path_cxt *pc, struct stat *sb, const char *path) +int ul_path_stat(struct path_cxt *pc, struct stat *sb, int flags, const char *path) { int rc; @@ -353,7 +353,8 @@ int ul_path_stat(struct path_cxt *pc, struct stat *sb, const char *path) if (path) { if (*path == '/') path++; - rc = fstatat(dir, path, sb, 0); + rc = fstatat(dir, path, sb, flags); + } else rc = fstat(dir, sb); /* dir itself */ diff --git a/lib/procfs.c b/lib/procfs.c index ec55fb4803..8173d6274c 100644 --- a/lib/procfs.c +++ b/lib/procfs.c @@ -167,7 +167,7 @@ int procfs_process_get_uid(struct path_cxt *pc, uid_t *uid) struct stat sb; int rc; - if ((rc = ul_path_stat(pc, &sb, NULL)) == 0) + if ((rc = ul_path_stat(pc, &sb, 0, NULL)) == 0) *uid = sb.st_uid; return rc; } diff --git a/libmount/src/context_veritydev.c b/libmount/src/context_veritydev.c index 298a029988..a8cb1f6938 100644 --- a/libmount/src/context_veritydev.c +++ b/libmount/src/context_veritydev.c @@ -223,7 +223,7 @@ int mnt_context_setup_veritydev(struct libmnt_context *cxt) root_hash_sig_file = strndup(val, len); rc = root_hash_sig_file ? 0 : -ENOMEM; if (rc == 0) - rc = ul_path_stat(NULL, &hash_sig_st, root_hash_sig_file); + rc = ul_path_stat(NULL, &hash_sig_st, 0, root_hash_sig_file); if (rc == 0) rc = !S_ISREG(hash_sig_st.st_mode) || !hash_sig_st.st_size ? -EINVAL : 0; if (rc == 0) { diff --git a/misc-utils/lsblk-properties.c b/misc-utils/lsblk-properties.c index bc6079371b..ada9b03b70 100644 --- a/misc-utils/lsblk-properties.c +++ b/misc-utils/lsblk-properties.c @@ -191,7 +191,7 @@ static struct lsblk_devprop *get_properties_by_file(struct lsblk_device *ld) return NULL; if (ul_path_set_prefix(pc, lsblk->sysroot) != 0) goto done; - if (ul_path_stat(pc, &sb, ld->filename) != 0 || !S_ISREG(sb.st_mode)) + if (ul_path_stat(pc, &sb, 0, ld->filename) != 0 || !S_ISREG(sb.st_mode)) goto done; fp = ul_path_fopen(pc, "r", ld->filename); diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index 4f65e38c49..0665f05c5d 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -561,7 +561,7 @@ static struct file *collect_outofbox_file(struct path_cxt *pc, struct stat sb; struct file *f; - if (ul_path_stat(pc, &sb, name) < 0) + if (ul_path_stat(pc, &sb, 0, name) < 0) return NULL; if (ul_path_readlink(pc, sym, sizeof(sym), name) < 0) return NULL;