URI: 
       Fix df hanging when statvfs() fails. - ubase - suckless linux base utils
  HTML git clone git://git.suckless.org/ubase
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit ab4f93cf47f423da2399cbe35cbc6c109e5e1825
   DIR parent f701698297ec1d1230caaa9403362c3a2b95f5ed
  HTML Author: Risto Salminen <ripejcp@gmail.com>
       Date:   Mon, 26 Jan 2015 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:
         M df.c                                |      17 ++++++++++++-----
       
       1 file changed, 12 insertions(+), 5 deletions(-)
       ---
   DIR 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;
        }