From: Karel Zak Date: Tue, 27 Mar 2018 11:30:16 +0000 (+0200) Subject: namei: provide more usable error message on lstat() error X-Git-Tag: v2.33-rc1~344 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e19cc7b65b31c57f0fe9cb73c9afad5197796f82;p=thirdparty%2Futil-linux.git namei: provide more usable error message on lstat() error Addresses: https://github.com/karelzak/util-linux/issues/608 Signed-off-by: Karel Zak --- diff --git a/misc-utils/namei.c b/misc-utils/namei.c index e2dbd0bf20..35cdf19640 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; }