Karel Zak [Wed, 21 Mar 2018 11:23:22 +0000 (12:23 +0100)]
tests: use libtool to execute with valgrind
The libtool based build system uses scripts rather than real binaries
in $top_builddir. It's necessary to use libtool --mode=execute to call
valgrind for the real binary (from .libs/).
Gerald Schaefer [Tue, 20 Mar 2018 16:17:38 +0000 (17:17 +0100)]
lsmem: fix total online/offline memory calculation
lsmem currently calculates the total online/offline memory by iterating
over all lsmem->blocks. Depending on the lsmem options, there may be
only one lsmem->block, because all sysfs memory blocks could be merged
into one. In this case, the calculation is wrong, because the individual
online/offline state of the sysfs memory blocks is not preserved, but
rather lsmem->blocks[0].state is set to the state of the first sysfs
memory block, typically MEMORY_STATE_ONLINE (at least on s390).
This means that "Total offline memory" will always be calculated as 0
in such cases, e.g. when using "lsmem --summary", or any options that
would merge the table output to one line, like "lsmem -o RANGE":
~# lsmem --summary
Memory block size: 1G
Total online memory: 20G
Total offline memory: 0B
Adding the "-a" option shows the real summary, since there is no block
merging going on, and the calculation is therefore correct:
~# lsmem -a --summary
Memory block size: 1G
Total online memory: 16G
Total offline memory: 4G
Fix this by moving the online/offline calculation into the loop that
is iterating over all sysfs memory blocks, instead of iterating over
potentially merged lsmem->blocks.
Reported-by: Alexander Klein <alkl@linux.vnet.ibm.com> Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Karel Zak [Tue, 20 Mar 2018 13:17:24 +0000 (14:17 +0100)]
lib/randutils: don't break on EAGAIN, use usleep()
The current code uses lose_counter to make more attempts to read
random numbers. It seems better to wait a moment between attempts to
avoid busy loop (we do the same in all-io.h).
The worst case is 1 second delay for all random_get_bytes() on systems
with uninitialized entropy pool -- for example you call sfdisk (MBR Id
or GPT UUIDs) on very first boot, etc. In this case it will use libc
rand() as a fallback solution.
Note that we do not use random numbers for security sensitive things
like keys or so. It's used for random based UUIDs etc.
Addresses: https://github.com/karelzak/util-linux/pull/603 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 20 Mar 2018 09:54:22 +0000 (10:54 +0100)]
libmount: make libmount.h more robust
Let's include sys/mount.h to be sure that our local libmount fallbacks
are not used by default to avoid possible conflicts with later included
sys/mount.h.
Addresses: https://github.com/systemd/systemd/pull/8452 Reported-by: Lennart Poettering <lennart@poettering.net> Signed-off-by: Karel Zak <kzak@redhat.com>
Carlo Caione [Mon, 19 Mar 2018 10:31:07 +0000 (10:31 +0000)]
lib/randutils: Do not block on getrandom()
In Endless we have hit a problem when using 'sfdisk' on the really first
boot to automatically expand the rootfs partition. On this platform
'sfdisk' is blocking on getrandom() because not enough random bytes are
available. This is an ARM platform without a hwrng.
We fix this passing GRND_NONBLOCK to getrandom(). 'sfdisk' will use the
best entropy it has available and fallback only as necessary.
Ruediger Meier [Sat, 10 Mar 2018 18:44:32 +0000 (19:44 +0100)]
tests: consolidate ts_device_has UUID or LABEL
Regarding parallel root checks ...
- fix: add a few missing "udevadm settle" where we are using LABELs or UUIDs
- introduce ts_udevadm_settle():
* Still trivial implementation. The idea is to use it in future for all
tests instead of directly calling "udevadm settle". So we could add debug
messages, wait for specific events, add code for non-udev systems or even
use "udevadm --{start,stop}-exec-queue" to be really sure what we are
doing and why using udevadm at all.
* The currently unused args may be used in future and show the code reader
already now why we are calling "udevadm settle" at all.
* So far this patch only affects swapon/, mount/, libmount/ tests, and is
only about UUIDs and LABELs, but may be continued later for "partitions",
"md devices", whatever.
* We are calling ts_udevadm_settle() right *before* we need a LABEL or
UUID, not just *after* we created one. This may be a bit better for
speed and shows the code reader which command would fail without settle.
- function ts_device_has_uuid() is unused now, we trust blkid(1). Renamed to
ts_is_uuid() in case we would need it again.
Ruediger Meier [Fri, 9 Mar 2018 17:27:44 +0000 (18:27 +0100)]
tests: fix grep expressions for devices
ts_is_mounted "/dev/loop1" returned true if /dev/loop17 was
mounted. A very annoying source of sporadic failures since
many years. This issue became more visible since running the
checks in parallel, which increases the probability to get
bigger loop device numbers.
Dirk Mueller [Sat, 17 Mar 2018 12:18:38 +0000 (13:18 +0100)]
Avoid crash in min/max caculation when cpu#0 being offline
When cpu#0 is offline, atof(NULL) is called which causes
a segfault or endless loop depending on implementation
circumstances. So instead of implicitely assumping that the
first cpu is always available, do the presence checks for
all including the first one.
Karel Zak [Fri, 9 Mar 2018 09:30:53 +0000 (10:30 +0100)]
Merge branch 'setpriv-example' of https://github.com/yrro/util-linux
* 'setpriv-example' of https://github.com/yrro/util-linux:
setpriv: add example section
setpriv: include --init-groups in the list of options that can be specified with --[re]gid
setpriv: improve description in man page
Ruediger Meier [Thu, 8 Mar 2018 10:45:30 +0000 (11:45 +0100)]
tests: re-introduce bash 3 compatibility (OSX)
Bash 4 is now almost 10 years old and it seemed to be fine in 613a337e
to use associative arrays. Unfortunately OSX will probably never update
to 4 because of GPLv3. We don't want to lose our travis OSX build and
use plain arrays again.
BTW remove that "informative warnings" about unlocked resources. They
were only silent so far because of a bug. Any system where scsi_debug
is broken would print a lot of these warnings. This also tells us that
we could even stop calling ts_unlock() explicitly. Just exiting the
tests would be good enough.
Note that currently flock(1) is not available on our OSX build anyways.
Ruediger Meier [Wed, 7 Mar 2018 16:58:23 +0000 (17:58 +0100)]
tests: dont't timeout flock
The only situation where we would block endless is if another parallel test
has the lock and hangs for another reason. This means that the other test
would still keep hanging even if we timeout here. The user would have to
interrupt the other test or the whole test-suite anyways.
Note that we would certainly run into any timeout when using --parallel=200,
so that all scsi tests start the same time.
Ruediger Meier [Wed, 7 Mar 2018 16:51:35 +0000 (17:51 +0100)]
tests: don't use unlocked resources
The test-suite did not survive when flock timeouts after 30s because
then ts_cleanup_on_exit() may use resources (e.g. rmmod scsi_debug)
while not having the lock.
Ruediger Meier [Tue, 6 Mar 2018 23:29:59 +0000 (00:29 +0100)]
tests: don't lock fd 1 (stdout), don't use /proc/$$/fd
On debian-kfreebsd we've locked stdout which messed up our test logs. Using
/proc/*/fd/ is not portable. Even ts_init's test for "/proc/self/fd"
does not help because /proc/*/fd behaves strange here:
$ ls -l /proc/$$/fd
lr--r--r-- 1 rudi user 0 Mar 6 23:11 /proc/2194/fd -> unknown
$ file /proc/$$/fd
/proc/2194/fd: broken symbolic link to `unknown'
## wtf?
$ test -d /proc/$$/fd; echo $?
0
$ ls -l /proc/$$/fd/
ls: cannot access /proc/2194/fd/: No such file or directory
## but
$ ls -l /proc/self/fd/
total 0
cr-xr-xr-x 1 root root 0, 3 Mar 6 19:39 0
cr-xr-xr-x 1 root root 0, 4 Mar 6 19:39 1
cr-xr-xr-x 1 root root 0, 5 Mar 6 19:39 2
cr-xr-xr-x 1 root root 0, 6 Mar 6 19:39 3
This is how this patch changes the test output:
[...]
blkid: partitions probing: [06] sgi ... OK
blkid: partitions probing: [07] sun ... OK
blkid: partitions probing ... OK (all 7 sub-tests PASSED)
-ls: cannot access /proc/66215/fd/: No such file or directory
+ blkid: mbr-wholedisk ... SKIPPED (missing scsi_debug module (dry-run))
blkid: MD raid0 (whole-disks) ... SKIPPED (losetup not found)
blkid: MD raid1 (last partition) ... SKIPPED (missing in PATH: mdadm)
blkid: MD raid1 (whole-disks) ... SKIPPED (losetup not found)
@@ -343,11 +343,11 @@
dmesg: facilities ... SKIPPED (test_dmesg not found)
dmesg: indentation ... SKIPPED (test_dmesg not found)
eject: umount ... SKIPPED (eject not found)
-ls: cannot access /proc/69561/fd/: No such file or directory
-ls: cannot access /proc/69609/fd/: No such file or directory
+ fdisk: align 512/4K ... SKIPPED (missing scsi_debug module (dry-run))
+ fdisk: align 512/4K +alignment_offset ... SKIPPED (missing scsi_debug module (dry-run))
fdisk: align 512/4K +MD ... SKIPPED (missing in PATH: mdadm)
fdisk: align 512/512 ... SKIPPED (losetup not found)
[...]
Ruediger Meier [Tue, 23 Jan 2018 23:20:15 +0000 (00:20 +0100)]
tests: add wierd sleep for libmount/context
I still don't understand why this helps to fix these tests on my system.
udevadm settle had no positive effect. Adding the sleeps before
"is_mounted" also didn't fixed that, that's amazing!?
Below the test log, very often seen on my system since a long time:
Ruediger Meier [Wed, 7 Mar 2018 09:40:23 +0000 (10:40 +0100)]
uuidd: don't truncate long socket paths
This was the error
uuidd: couldn't bind unix socket /var/tmp/portage/sys-apps/util-linux-2.31.1/work/util-linux-2.31.1-abi_x86_64.amd64/tests/output/uuid/uuiddkOcTUuoZ7kaP3: Address already in use
because the socket path was truncated to 108 chars which was luckily
an existing directory.
Now we abort early with "uuidd: socket name too long: ... "
Reported-by: Thomas Deutschmann <whissi@gentoo.org> Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Sam Morris [Tue, 6 Mar 2018 17:05:38 +0000 (17:05 +0000)]
setpriv: fix manpage typo
The example given in the man page didn't work. Judging by commit db663995bd93e170a43b1a7050c7a738782dabfb, --inh-caps= used to be called
--caps= but the man page was not updated after the change was made.
Karel Zak [Tue, 6 Mar 2018 13:44:23 +0000 (14:44 +0100)]
libmount: fix fs pattern usage in mount --all
The command "mount -a -t <pattern>" uses the -t as pattern to filter
fstab entries. And "mount -t <type>" is used to specify FS type.
Unfortunately libmount does not care about this difference when it
calls standard mount functionality. The original pattern is still in
the library control struct and mnt_do_mount() tries to use it as FS
type.
This patch is just bugfix. Maybe the long term solution would be to
differentiate between the pattern and type in the library API. Now the
library follows mount(8) command line and it's little bit messy.
Reported-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Even though iterating with "len" seems counter-intuitive, it fixes
this issue. The variable len is only in the last iteration not a
multiplication of pagesize -- which is the requirement for mmap.
If a file is larger than 4 GB on a 32 bit system with large file
support (default), it can happen that not all pages are properly
processed. This happens due to an int truncation (off_t vs size_t).
You can reproduce this on 32 bit with these commands:
$ dd if=/dev/zero of=4gb-file seek=4294967295 count=1 bs=1
$ fincore 4gb-file
fincore: failed to do mmap: 4gb-file: Invalid argument
If a file is larger than 4 GB, the first few pages of a file won't
be properly processed. "len" will be smaller than window_size,
but the for-loop iterates "window_size" bytes, skipping some pages.
Karel Zak [Fri, 16 Feb 2018 10:25:22 +0000 (11:25 +0100)]
Merge branch 'maybe-for-v2.32' of https://github.com/rudimeier/util-linux
* 'maybe-for-v2.32' of https://github.com/rudimeier/util-linux:
tests: use pgrep instead of ps --ppid ...
misc: fix typos using codespell
lsns: fix clang compiler warning
tests: add udevadm settle to sfdisk/resize
build-sys: disable bz2 tarball and fix some am warnings
Ruediger Meier [Sun, 21 Jan 2018 23:04:38 +0000 (00:04 +0100)]
lsns: fix clang compiler warning
../sys-utils/lsns.c:360:8: warning: comparison of integers of different signs: '__u32' (aka 'unsigned int') and 'int' [-Wsign-compare]
if (!(NLMSG_OK(nlh, reslen)
^~~~~~~~~~~~~~~~~~~~~
/usr/include/linux/netlink.h:90:24: note: expanded from macro 'NLMSG_OK'
(nlh)->nlmsg_len <= (len))
~~~~~~~~~~~~~~~~ ^ ~~~
Ruediger Meier [Thu, 15 Feb 2018 20:18:27 +0000 (21:18 +0100)]
build-sys: disable bz2 tarball and fix some am warnings
Nobody needs the .bz2 tarball. We dont't even upload it to
kernel.org.
BTW we fix dozens of these automake warnings:
automake-1.13/am/ltlibrary.am: warning: 'libblkid.la': linking libtool libraries using a non-POSIX
automake-1.13/am/ltlibrary.am: archiver requires 'AM_PROG_AR' in 'configure.ac'
So we can remove -Wno-portability. The only warning left is this
last GNU-make'ism which somebody may fix when reading it:
sys-utils/Makemodule.am:191: warning: addprefix sys-utils/,$(SETARCH_LINKS: non-POSIX variable name
sys-utils/Makemodule.am:191: (probably a GNU make extension)
Makefile.am:90: 'sys-utils/Makemodule.am' included from here
taiyu [Thu, 15 Feb 2018 06:50:36 +0000 (22:50 -0800)]
libsmartcols: fixes issue with 0 width columns
[kzak@redhat.com: - it's possible that column has zero width when
minimal width is reduced due to very small terminal. In this case
make sure that we do not use such column at all.]