ubase

suckless linux base utils
git clone git://git.2f30.org/ubase.git
Log | Files | Refs | README | LICENSE

commit 34fe428b88d6165acca8164893b5d86e5ddc7d2c
parent 6f1462a49340e2537c4d6b18d7603f03d49a179e
Author: Risto Salminen <ripejcp@gmail.com>
Date:   Mon Jan 26 20:53:14 +0200

Fix df hanging when statvfs() fails.

Now df prints out an appropriate error message when statvfs() fails
instead of just hanging. Also make df return 1 when statvfs() fails.

Diffstat:
df.c | 17++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/df.c b/df.c @@ -13,7 +13,7 @@ static int aflag = 0; static int hflag = 0; static int kflag = 0; -static void mnt_show(const char *fsname, const char *dir); +static int mnt_show(const char *fsname, const char *dir); static void usage(void) @@ -26,6 +26,7 @@ main(int argc, char *argv[]) { struct mntent *me = NULL; FILE *fp; + int ret = 0; ARGBEGIN { case 'a': @@ -61,11 +62,12 @@ main(int argc, char *argv[]) if (aflag == 0) if (strcmp(me->mnt_type, "rootfs") == 0) continue; - mnt_show(me->mnt_fsname, me->mnt_dir); + if (mnt_show(me->mnt_fsname, me->mnt_dir) < 0) + ret = 1; } endmntent(fp); - return 0; + return ret; } #define CALC_POWER(n, power, base, i) do { \ @@ -107,7 +109,7 @@ print_human( avail, postfixes[k], capacity, dir); } -static void +static int mnt_show(const char *fsname, const char *dir) { struct statvfs s; @@ -115,7 +117,10 @@ mnt_show(const char *fsname, const char *dir) int capacity = 0; int bs; - statvfs(dir, &s); + if (statvfs(dir, &s) < 0) { + weprintf("statvfs %s:", dir); + return -1; + } bs = s.f_frsize / blksize; total = s.f_blocks * bs; @@ -133,4 +138,6 @@ mnt_show(const char *fsname, const char *dir) else printf("%-12s %9llu %9llu %9llu %7d%% %s\n", fsname, total, used, avail, capacity, dir); + + return 0; }