]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
namei: provide more usable error message on lstat() error
authorKarel Zak <kzak@redhat.com>
Tue, 27 Mar 2018 11:30:16 +0000 (13:30 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 27 Mar 2018 11:30:16 +0000 (13:30 +0200)
Addresses: https://github.com/karelzak/util-linux/issues/608
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/namei.c

index e2dbd0bf206e7d4ff4d673bf2cb915142ffb6e54..35cdf1964002948d152ac226ac0c61bea6e65005 100644 (file)
@@ -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;
                }