components/coreutils/patches/df.c.patch
changeset 5169 c5d3147d411a
parent 5168 6c7bce5c3955
child 5170 970e0f411b42
equal deleted inserted replaced
5168:6c7bce5c3955 5169:c5d3147d411a
     1 From: Pádraig Brady <[email protected]>
       
     2 Date: Mon, 18 Aug 2014 16:59:26 +0000 (+0100)
       
     3 Subject: df: improve mount point selection with inaccurate mount list
       
     4 X-Git-Url: http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commitdiff_plain;h=ed1a495b
       
     5 
       
     6 df: improve mount point selection with inaccurate mount list
       
     7 
       
     8 v8.23 has a test failure on Fedora rawhide build servers
       
     9 in tests/df/skip-duplicate.sh.  This was due to no '/'
       
    10 entry being output by df.  That was due to an inaccurate
       
    11 /proc/mounts on the build environment as stat(/mnt/point)
       
    12 identified all these /proc/mounts entries as having the
       
    13 same device id:
       
    14 
       
    15   /                    rootfs
       
    16   /                    /dev/md1
       
    17   /dev                 devtmpfs
       
    18   /run                 tmpfs
       
    19   /boot                /dev/md0
       
    20   /proc/filesystems    /dev/md1
       
    21 
       
    22 Since the device name on the right changes for a given id,
       
    23 that causes the entries to be continually replaced, thus
       
    24 resulting in no '/' entry.  I'm guessing this is due to
       
    25 the mock environment bind mounting unneeded or sensitive
       
    26 items to a dummy file on the host / (/dev/md1) though
       
    27 have not looked into those details.
       
    28 
       
    29 So rather than relying on an accurate /proc/mounts,
       
    30 the attached patch takes a more conservative replacement
       
    31 approach and only swaps a new device entry when the
       
    32 mount point matches.  That should handle all practical
       
    33 cases while also avoiding this situation.
       
    34 
       
    35 * src/df.c (filter_mount_list): Only replace entries with
       
    36 different device names when the mount point also matches.
       
    37 ---
       
    38 
       
    39 diff --git a/src/df.c b/src/df.c
       
    40 index 3ef5d33..e907b94 100644
       
    41 --- src/df.c
       
    42 +++ src/df.c
       
    43 @@ -640,13 +640,18 @@ filter_mount_list (bool devices_only)
       
    44  
       
    45            if (devlist)
       
    46              {
       
    47 -              /* ...let the shorter mountdir win.  */
       
    48 +                  /* let "real" devices with '/' in the name win.  */
       
    49                if ((strchr (me->me_devname, '/')
       
    50                     && ! strchr (devlist->me->me_devname, '/'))
       
    51 +                  /* let a shorter mountdir win.  */
       
    52                    || (strlen (devlist->me->me_mountdir)
       
    53                        > strlen (me->me_mountdir))
       
    54 -                  /* or one overmounted on a different device.  */
       
    55 -                  || ! STREQ (devlist->me->me_devname, me->me_devname))
       
    56 +                  /* let an entry overmounted on a different device win...  */
       
    57 +                  || (! STREQ (devlist->me->me_devname, me->me_devname)
       
    58 +                      /* ... but only when matching an exsiting mount point, to
       
    59 +                      avoid problematic replacement when given inaccurate mount
       
    60 +                      lists, seen with some chroot environments for example.  */
       
    61 +                      && STREQ (me->me_mountdir, devlist->me->me_mountdir)))
       
    62                  {
       
    63                    /* Discard mount entry for existing device.  */
       
    64                    discard_me = devlist->me;