summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2018-03-27 13:30:16 +0200
committerKarel Zak2018-03-27 13:30:16 +0200
commite19cc7b65b31c57f0fe9cb73c9afad5197796f82 (patch)
treeaaa1337d6cbaca62b76452e8a66ec1df04121e89
parentMerge branch 'master' of https://github.com/pali/util-linux (diff)
downloadkernel-qcow2-util-linux-e19cc7b65b31c57f0fe9cb73c9afad5197796f82.tar.gz
kernel-qcow2-util-linux-e19cc7b65b31c57f0fe9cb73c9afad5197796f82.tar.xz
kernel-qcow2-util-linux-e19cc7b65b31c57f0fe9cb73c9afad5197796f82.zip
namei: provide more usable error message on lstat() error
Addresses: https://github.com/karelzak/util-linux/issues/608 Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--misc-utils/namei.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/misc-utils/namei.c b/misc-utils/namei.c
index e2dbd0bf2..35cdf1964 100644
--- a/misc-utils/namei.c
+++ b/misc-utils/namei.c
@@ -59,7 +59,7 @@ struct namei {
struct namei *next; /* next item */
int level;
int mountpoint; /* is mount point */
- int noent; /* is this item not existing */
+ int noent; /* this item not existing (stores errno from stat()) */
};
static int flags;
@@ -151,9 +151,10 @@ new_namei(struct namei *parent, const char *path, const char *fname, int lev)
nm->level = lev;
nm->name = xstrdup(fname);
- nm->noent = (lstat(path, &nm->st) == -1);
- if (nm->noent)
+ if (lstat(path, &nm->st) != 0) {
+ nm->noent = errno;
return nm;
+ }
if (S_ISLNK(nm->st.st_mode))
readlink_to_namei(nm, path);
@@ -280,7 +281,7 @@ print_namei(struct namei *nm, char *path)
blanks += 1;
blanks += nm->level * 2;
printf("%*s ", blanks, "");
- printf(_("%s - No such file or directory\n"), nm->name);
+ printf(_("%s - %s\n"), nm->name, strerror(nm->noent));
return -1;
}