~nabijaczleweli/voreutils

104fd7f51ee109614c3b92cff9e13eccf3ca1a5d — наб 2 months ago 26cc8e7
Don't error if there isn't a mtab at all in df

This matches coreutils, and fixes dfing in bare chroots:
    root@tarta:~# df -h /
    df: Warning: cannot read table of mounted file systems: No such file or directory
    Filesystem      Size  Used Avail Use% Mounted on
    -               118G  3.6G  109G   4% /
    root@tarta:~# ~nab/df -h /
    /home/nab/df: /etc/mtab, /proc/mounts: No such file or directory
    Filesystem   Size Used  Avail Use% Mounted on
    -          126.6G 3.8G 116.3G   4% /

    root@tarta:~# df; echo $?
    df: cannot read table of mounted file systems: No such file or directory
    1
    root@tarta:~# ~nab/df; echo $?
    /home/nab/df: /etc/mtab, /proc/mounts: No such file or directory
    /home/nab/df: no filesystems
    1
1 files changed, 7 insertions(+), 5 deletions(-)

M cmd/df.cpp
M cmd/df.cpp => cmd/df.cpp +7 -5
@@ 193,14 193,16 @@ int main(int argc, char * const * argv) {
		if(!mtab && MTAB2)
			mtab = {MTAB2, "re"};
		if(!mtab)
			return std::fprintf(stderr, "%s: %s%s%s: %s\n", argv[0], MTAB, MTAB2 ? ", " : "", MTAB2 ?: "", std::strerror(errno)), 1;
			std::fprintf(stderr, "%s: %s%s%s: %s\n", argv[0], MTAB, MTAB2 ? ", " : "", MTAB2 ?: "", std::strerror(errno));
		else {
#if __sun
		for(mnttab mt; !getmntent(mtab, &me);)
			mtab_entries.emplace_back(entry{me.mnt_special, me.mnt_mountp, me.mnt_fstype});
			for(mnttab mt; !getmntent(mtab, &me);)
				mtab_entries.emplace_back(entry{me.mnt_special, me.mnt_mountp, me.mnt_fstype});
#else
		while(auto me = getmntent(mtab))
			mtab_entries.emplace_back(entry{me->mnt_fsname, me->mnt_dir, me->mnt_type});
			while(auto me = getmntent(mtab))
				mtab_entries.emplace_back(entry{me->mnt_fsname, me->mnt_dir, me->mnt_type});
#endif
		}
	}
#else
	{