]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: check stat() return code
authorKarel Zak <kzak@redhat.com>
Thu, 2 Feb 2012 23:01:32 +0000 (00:01 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 2 Feb 2012 23:01:32 +0000 (00:01 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsblk.c

index 5b21c5b0399b55c28a7ef960b1f402724fa5f24a..8468b3fb15a20a1b4e9d7d05dff28b4307bdfbf3 100644 (file)
@@ -469,10 +469,11 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line
 {
        char buf[1024];
        char *p = NULL;
+       int st_rc = 0;
 
        if (!cxt->st.st_rdev && (id == COL_OWNER || id == COL_GROUP ||
                                 id == COL_MODE))
-               stat(cxt->filename, &cxt->st);
+               st_rc = stat(cxt->filename, &cxt->st);
 
        switch(id) {
        case COL_NAME:
@@ -487,14 +488,14 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line
                break;
        case COL_OWNER:
        {
-               struct passwd *pw = getpwuid(cxt->st.st_uid);
+               struct passwd *pw = st_rc ? NULL : getpwuid(cxt->st.st_uid);
                if (pw)
                        tt_line_set_data(ln, col, xstrdup(pw->pw_name));
                break;
        }
        case COL_GROUP:
        {
-               struct group *gr = getgrgid(cxt->st.st_gid);
+               struct group *gr = st_rc ? NULL : getgrgid(cxt->st.st_gid);
                if (gr)
                        tt_line_set_data(ln, col, xstrdup(gr->gr_name));
                break;
@@ -502,8 +503,11 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line
        case COL_MODE:
        {
                char md[11];
-               strmode(cxt->st.st_mode, md);
-               tt_line_set_data(ln, col, xstrdup(md));
+
+               if (!st_rc) {
+                       strmode(cxt->st.st_mode, md);
+                       tt_line_set_data(ln, col, xstrdup(md));
+               }
                break;
        }
        case COL_MAJMIN: