summaryrefslogtreecommitdiffstats
path: root/misc-utils/lsblk.c
diff options
context:
space:
mode:
authorKarel Zak2012-02-03 00:01:32 +0100
committerKarel Zak2012-02-03 00:01:32 +0100
commit1dc42eb620b0739213ba3341619def3654810874 (patch)
treed80e2bfc95a9e5f13034c2049cf0538e6b59b3b2 /misc-utils/lsblk.c
parentlogin: allocate buffer with shell name (diff)
downloadkernel-qcow2-util-linux-1dc42eb620b0739213ba3341619def3654810874.tar.gz
kernel-qcow2-util-linux-1dc42eb620b0739213ba3341619def3654810874.tar.xz
kernel-qcow2-util-linux-1dc42eb620b0739213ba3341619def3654810874.zip
lsblk: check stat() return code
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/lsblk.c')
-rw-r--r--misc-utils/lsblk.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index 5b21c5b03..8468b3fb1 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -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: