Commit Graph

13574 Commits

Author SHA1 Message Date
Sami Kerola 273ebba11d include/xalloc: reindent function bodies to unify indentation
The file used unusual 7 spaces indent step in some of the functions.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-21 15:00:16 +02:00
Sami Kerola aba9e76e25 include/xalloc: use multiline function declarations
There are two things happening in this commit.  1) Move each function
attribute to it's own line 2) move function return value after attributes so
that function inputs and outputs are on same line.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-21 15:00:16 +02:00
Sami Kerola ff9da8efca setpwnam: use more appropriate allocation size types
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-21 15:00:16 +02:00
Sami Kerola 073abd4ca8 column: pass control struct to local_wcstok()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-21 15:00:16 +02:00
Karel Zak 23b98f775f Merge branch 'container' of https://github.com/slashdd/util-linux
* 'container' of https://github.com/slashdd/util-linux:
  fstrim shouldn't run inside a container
2019-08-21 14:37:26 +02:00
Karel Zak 5200aa99d2 partx: document -d vs. --nr and fix test
The commit ab025087f9 has disabled error
message, but unfortunately it keeps wrong return code. This has been fixed
by commit 53ae7d60cf.

This commit add hit about it to docs and fix regression test too.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-21 13:42:22 +02:00
Karel Zak 53ae7d60cf partx: don't report ENXIO as error on -d
The errno ENXIO should be ignored, unfortunately the current code uses
variable 'rc' for ioctl return code as well as for final del_parts()
return value. So, failed ioctl (which should be ignored) affects all
del_parts() status.

  # modprobe scsi_debug dev_size_mb=100
  # partx  -d --nr 1-1024 /dev/sdc; echo $?
  1

The device dos not contains any partitions, so 0 return code is
expected in this case.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1739179
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-21 10:51:18 +02:00
Patrick Steinhardt ad167a9023 libmount: fix comment referring to passno field
There's an obvious copy-paste error in `mnt_parse_table_line` when
referring to the 6th field of the fstab format, where it says "freq"
instead of "passno". This has probably been copied from the 5th field,
which is in fact correctly labelled as "freq".

Fix the mistake by changing the comment to say "passno" instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2019-08-20 14:04:33 +02:00
Patrick Steinhardt cdd2d60e56 wdctl: remove duplicate include of <unistd.h>
The <unistd.h> header is included twice in "wdctl.c". Remove one
of these includes to keep "make checkincludes" happy.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2019-08-19 15:00:35 +02:00
Kevin Hao 042057d802 libmount: Keep the mnt_tab info for the existent dest in mnt_copy_fs()
The "umount -f -a -r" get stuck in a endless loop when run with a
mountinfo like below:
  15 0 179:2 / / ro,relatime - ext4 /dev/root ro
  16 15 0:6 / /dev rw,relatime - devtmpfs devtmpfs rw,size=242896k,nr_inodes=60724,mode=755
  17 15 0:4 / /proc rw,relatime - proc proc rw
  18 15 0:15 / /mnt/.psplash rw,relatime - tmpfs tmpfs rw,size=40k
  19 15 0:16 / /sys rw,relatime - sysfs sysfs rw
  20 19 0:7 / /sys/kernel/debug rw,relatime - debugfs debugfs rw
  21 15 0:17 / /run rw,nosuid,nodev - tmpfs tmpfs rw,mode=755
  22 15 0:18 / /var/volatile rw,relatime - tmpfs tmpfs rw
  23 15 179:1 / /boot rw,relatime - vfat /dev/mmcblk0p1 rw,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro
  24 16 0:19 / /dev/pts rw,relatime - devpts devpts rw,gid=5,mode=620,ptmxmode=000
  25 18 0:20 / /mnt/.psplash rw,relatime - tmpfs tmpfs rw,size=40k

The reason is that the two same mnt entry "/mnt/.psplash" will cause
the dst->tab set to NULL when umount this mnt entry the second time.
This will trigger an endless loop in mnt_reset_table() because that
mnt entry is linked on the libmnt_table but its .tab is set to NULL.

Signed-off-by: Kevin Hao <kexin.hao@windriver.com>
2019-08-19 14:36:55 +02:00
Karel Zak 424b66c514 tests: Skip fdisk/mbr-nondos-mode on Sparc as unsupported
The test has been originally designed as usable on sparc, but now we
use it for many features which are MBR specific.

Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Co-Author: Anatoly Pugachev <matorola@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-19 14:30:35 +02:00
Karel Zak 9210c0d225 chfn: don't append extra tailing commas
# grep kzak /etc/passwd
 kzak1000:1000::/home/kzak:/bin/bash

 # chfn kzak
 ...
 grep kzak /etc/passwd

old version:
 kzak1000:1000:Karel Zak,,,,:/home/kzak:/bin/bash

fixed version:
 kzak1000:1000:Karel Zak:/home/kzak:/bin/bash

Reported-by: Filip Dvorak <fdvorak@redhat.com>
References: f723cbf544
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-19 14:03:07 +02:00
Eric Desrochers 0280d31a2b fstrim shouldn't run inside a container
Container type implies the following products:
openvz	OpenVZ/Virtuozzo
lxc	Linux container implementation by LXC
lxc-libvirt	Linux container implementation by libvirt
systemd-nspawn	systemd's minimal container implementation, see systemd-nspawn(1)
docker	Docker container manager
podman	Podman container manager
rkt	rkt app container runtime
wsl	Windows Subsystem for Linux

References:
https://www.freedesktop.org/software/systemd/man/systemd.unit.html
https://www.freedesktop.org/software/systemd/man/systemd-detect-virt.html#

Fix: #840

Signed-off-by: Eric Desrochers <eric.desrochers@canonical.com>
2019-08-14 13:31:25 -04:00
Rosen Penev 050def0f35
Remove unused utime.h header
It is sometimes unavailable and errors on inclusion. For example, when
disabled in uClibc-ng.
2019-08-08 12:14:39 -07:00
Rosen Penev 76b680b1a9
Remove isascii usage
There is a c_isascii function that can be used.

isascii is deprecated and not available with some libcs like uClibc-ng
where it can be compile time disabled.
2019-08-08 12:12:55 -07:00
Karel Zak c60231a744 tests: update fdisk output
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-08 14:20:05 +02:00
Karel Zak 08474fde66 libfdisk: (script) support shortcuts in the type= field
The unnamed-field format supports partition type shortcuts:

	",1MiB,L'

but for named-field format it requires full type:

 (mbr)	"size=1MiB,type=83"
 (gpt)  "size=1MiB,type=0FC63DAF-8483-4772-8E79-3D69D8477DE4"

This patch implements type shortcuts also for named-field format:

	"size=1MiB,type=L"

to make it more user-friendly and unified.

Addresses: https://github.com/karelzak/util-linux/issues/837
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-08 10:34:27 +02:00
Karel Zak 11aaedf574 tests: use subtests for mountpoint(1)
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-07 11:45:57 +02:00
Karel Zak cd38987bf4 Merge branch 'issue832' of https://github.com/kerolasa/util-linux
* 'issue832' of https://github.com/kerolasa/util-linux:
  mountpoint: add --nofollow option
2019-08-07 11:20:21 +02:00
Karel Zak 2adf30dceb Merge branch 'master' of https://github.com/chstarkd/util-linux
* 'master' of https://github.com/chstarkd/util-linux:
  removed double space
  fixed mount man page typo, "bythe" -> "by the"
2019-08-07 11:16:14 +02:00
Karel Zak cb74ebad25 libfdisk: refer to partx(8) rather than to kpartx(8)
Reported-by: Petr Pisar <petr.pisar@atlas.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-06 12:24:33 +02:00
Chistyj Arkadij 0797511930 removed double space 2019-08-04 21:21:55 +03:00
Chistyj Arkadij e9d2e0c819 fixed mount man page typo, "bythe" -> "by the" 2019-08-04 17:06:38 +03:00
Sami Kerola 6d56251220
mountpoint: add --nofollow option
The no follow option will allow user to distinct mount points from symbolic
links pointing to them.  Arguably this is pretty pedantic option, mounting a
device or bind mount to a directory via symlink does not have or cause any
issues.

Addresses: https://github.com/karelzak/util-linux/issues/832
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-02 19:39:05 +01:00
Karel Zak 3661aab4cf dmesg: fix output hex encoding
The current code ignores single-byte non-printable characters.

Reported-by: Marc Deslauriers <marc.deslauriers@canonical.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-01 11:43:58 +02:00
Karel Zak 0c493067dd choom: improve docs
It's not obvious from the current docs that you have to explicitly
split command line options and wanted commands.

Addresses: https://github.com/karelzak/util-linux/issues/833
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-01 11:06:06 +02:00
Karel Zak c4d6d1c54d libblkid: fix file descriptor leak in blkid_verify()
The function blkid_verify() uses private device file descriptor and
uses blkid_probe_set_device() to assign the descriptor to low-level
probing code. Unfortunately, close() in this case is not enough as the
prober can internally open whole-disk device too.

The library API has been extended so blkid_probe_set_device()
deallocates and close previously used prober for whole-disk. This new
functionality is used in blkid_verify() now.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1734545
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-31 16:31:10 +02:00
Karel Zak efee3e01bf Merge branch '2019wk29' of https://github.com/kerolasa/util-linux
* '2019wk29' of https://github.com/kerolasa/util-linux:
  lscpu: prefer memcpy() to manual pointer arithmetic
2019-07-29 11:13:51 +02:00
Yousong Zhou 325bfd53e8 column: fix outputing empty column at the end of line
The following commands manifests the problem.  In old versions before
commit 4762ae9d60 ("column: use libsmartcols for --table"), both of them
should output with 2 "|"

	echo '||'  | column -o '|' -s '|' -t
	echo '|| ' | column -o '|' -s '|' -t

Fixes: 4762ae9d60 ("column: use libsmartcols for --table")
Signed-off-by: Yousong Zhou <zhouyousong@yunionyun.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
2019-07-29 10:33:58 +02:00
Sami Kerola b5f376d11d
lscpu: prefer memcpy() to manual pointer arithmetic
With pointer arithmetic clang address sanitizer gives following error this
change addresses.  Notice the following happens only when running as root.

sys-utils/lscpu-dmi.c:83:14: runtime error: load of misaligned address
0x55a1d62f3d1d for type 'const uint16_t' (aka 'const unsigned short'), which
requires 2 byte alignment

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-07-27 19:00:34 +01:00
Karel Zak 8bad603ae0 lscpu: (man) add note about cache sizes
Addresses: https://github.com/karelzak/util-linux/issues/827
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-25 12:23:59 +02:00
Sami Kerola 2a952555d2 agetty: simplify code in dolog() preprocessor blocks
Aim is to make dolog() a lot more readable and understandable, with downside
of when (rarely?) USE_SYSLOG it not defined the function will use a bit more
space from stack.  I think that is price well worth paying.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-07-24 11:11:46 +02:00
Sami Kerola 1aaee548e3 login: simplify string handling
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-07-24 11:11:29 +02:00
Sami Kerola 0675f52ab5 last: replace strncat() with more robust mem2strcpy()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-07-24 11:11:10 +02:00
Karel Zak 7ea0907364 tests: (fdisk) update padding in output
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-23 16:35:20 +02:00
Karel Zak fc970a0947 tests: (libsmartcols) add padding tests
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-23 16:26:48 +02:00
Karel Zak 94dbb32273 libsmartcols: cleanup and extend padding functionality
LIBSMARTCOLS_DEBUG_PADDING=on in the next examples forces libsmartcols
print '.' as a padding char. See line "ffff" in the exmaples.

* default output is to fill all except last cell

	$ LIBSMARTCOLS_DEBUG_PADDING=on ./sample-scols-fromfile --nlines 10  --width 80 --column tests/ts/libsmartcols/files/col-name --column tests/ts/libsmartcols/files/col-number --column tests/ts/libsmartcols/files/col-string --column tests/ts/libsmartcols/files/col-string tests/ts/libsmartcols/files/data-string tests/ts/libsmartcols/files/data-number tests/ts/libsmartcols/files/data-string-empty tests/ts/libsmartcols/files/data-string-empty 2> /dev/null
	NAME.. ......NUM STRINGS STRINGS
	aaaa.. ........0 aaaa... aaaa
	bbb... ......100 bbb.... bbb
	ccccc. .......21 ccccc.. ccccc
	dddddd ........3 dddddd. dddddd
	ee.... ......411 ee..... ee
	ffff.. .....5111 .......
	gggggg 678993321 gggggg. gggggg
	hhh... ..7666666 hhh.... hhh

* scols_table_enable_minout() minimizes output for tailing empty cells, example:

	$ LIBSMARTCOLS_DEBUG_PADDING=on ./sample-scols-fromfile --nlines 10 --minout  --width 80 --column tests/ts/libsmartcols/files/col-name --column tests/ts/libsmartcols/files/col-number --column tests/ts/libsmartcols/files/col-string --column tests/ts/libsmartcols/files/col-string tests/ts/libsmartcols/files/data-string tests/ts/libsmartcols/files/data-number tests/ts/libsmartcols/files/data-string-empty tests/ts/libsmartcols/files/data-string-empty 2> /dev/null
	NAME.. ......NUM STRINGS STRINGS
	aaaa.. ........0 aaaa... aaaa
	bbb... ......100 bbb.... bbb
	ccccc. .......21 ccccc.. ccccc
	dddddd ........3 dddddd. dddddd
	ee.... ......411 ee..... ee
	ffff.. .....5111
	gggggg 678993321 gggggg. gggggg
	hhh... ..7666666 hhh.... hhh

* cleanup up scols_table_enable_maxout() use, example:

	$ LIBSMARTCOLS_DEBUG_PADDING=on ./sample-scols-fromfile --nlines 10 --maxout  --width 80 --column tests/ts/libsmartcols/files/col-name --column tests/ts/libsmartcols/files/col-number --column tests/ts/libsmartcols/files/col-string --column tests/ts/libsmartcols/files/col-string tests/ts/libsmartcols/files/data-string tests/ts/libsmartcols/files/data-number tests/ts/libsmartcols/files/data-string-empty tests/ts/libsmartcols/files/data-string-empty 2> /dev/null
	NAME.............. ..................NUM STRINGS............ STRINGS............
	aaaa.............. ....................0 aaaa............... aaaa...............
	bbb............... ..................100 bbb................ bbb................
	ccccc............. ...................21 ccccc.............. ccccc..............
	dddddd............ ....................3 dddddd............. dddddd.............
	ee................ ..................411 ee................. ee.................
	ffff.............. .................5111 ................... ...................
	gggggg............ ............678993321 gggggg............. gggggg.............
	hhh............... ..............7666666 hhh................ hhh................

Note that we cannot make scols_table_enable_minout() default because
for example "column --table" is pretty commonly used with non-blank
columns separator and in this case all cells has to be filled.

	$ echo -e "aa,b,ccc\na,,\naaa,bbb,ccc" |  column --table --separator ',' --output-separator '|'
	aa |b  |ccc
	a  |   |
	aaa|bbb|ccc

Addresses: https://github.com/karelzak/util-linux/issues/826
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-23 16:24:42 +02:00
Karel Zak 10c39f03a1 libfdisk: improve partition copy on resize
It seems pretty fragile to copy also reference counting and reference
to table list.

Addresses: https://github.com/karelzak/util-linux/pull/822
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-22 12:09:38 +02:00
Karel Zak 1768d77c18 libblkid: (drbd) fix comment formatting
... to avoid misinterpretation by gtk-docs.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-22 11:49:45 +02:00
Karel Zak 68cf159b07 Merge branch 'master_fix-partition-copy' of https://github.com/vojtechtrefny/util-linux 2019-07-22 11:35:12 +02:00
Karel Zak c64d452b3e fstrim: fix systemd service protection
ProtectHome=yes makes /home inaccessible, but we need to open the
directories (mountpoints) read-only.

Addresses: https://github.com/karelzak/util-linux/issues/824
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-22 11:10:30 +02:00
Vojtech Trefny 79f37ec4e1 libfdisk: Fix double free of *_chs strings in fdisk_partition
__copy_partition doesn't duplicate these strings which leads to
occasional double free.

Signed-off-by: Vojtech Trefny <vtrefny@redhat.com>
2019-07-19 13:42:49 +02:00
Karel Zak 1ace839781 libfdisk: don't use NTFS as MBR
Same as 7c643ed285.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-17 12:42:39 +02:00
Karel Zak cdb9140967 libblkid: do not interpret NTFS as MBR
# mkntfs -Q -F /dev/sdc

old version:
 # ./blkid -p /dev/sdc
 /dev/sdc: UUID="0E9E8C5F2F718479" TYPE="ntfs" USAGE="filesystem" PTTYPE="dos"

new version:
 # ./blkid -p /dev/sdc
 /dev/sdc: UUID="0E9E8C5F2F718479" TYPE="ntfs" USAGE="filesystem"

Reported-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-17 12:35:45 +02:00
Karel Zak 7c643ed285 libfdisk: don't use FAT as MBR
The current libfdisk MBR detection is too weak, the result is that it
reuses MBR from FAT. The correct behavior is to create a new MBR, wipe
first sector (on write) and warn about obsolete FAT superblock.

Reported-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-17 12:11:38 +02:00
Karel Zak b106229206 build-sys: improve hwclock CMOS dependences
Let's use standard UL_* macros to check for dependencies
(architectures and hwclock).

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-15 15:32:49 +02:00
Karel Zak c7eca69d6d build-sys: add UL_REQUIRES_ARCH()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-15 15:31:40 +02:00
Carlos Santos 88bc304ba8 hwclock: use CMOS clock only if available
- Add --disable-hwclock-cmos configuration argument
- Add USE_HWCLOCK_CMOS (enabled by default for i386/x86_64)
- Add define(USE_HWCLOCK_CMOS)
- Compile hwclock-cmos.c only if USE_HWCLOCK_CMOS is true
- Remove all unnecessary #ifdefs from hwclock-cmos.c
- Add #ifdef USE_HWCLOCK_CMOS around the determine_clock_access_method()
  call in hwclock.c

Signed-off-by: Carlos Santos <unixmania@gmail.com>
2019-07-15 13:56:13 +02:00
Karel Zak 8ebecc18e8 tests: (libmount) make X-* and x-* more robust
Addresses: https://github.com/karelzak/util-linux/issues/818
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-15 12:46:11 +02:00
Karel Zak 9e677de1ec lsblk: fix -E segfault
We need to check if referenced wholedisk defines the de-duplication
key...

Addresses: https://github.com/karelzak/util-linux/issues/819
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-15 12:28:26 +02:00