summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* lib/ttyutils: avoid checking same thing twiceSami Kerola2019-07-011-8/+8
| | | | | | Check cols and lines are not NULL only once. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* Revert "lib/loopdev.c: Inline loopcxt_has_device"Karel Zak2019-06-181-1/+1
| | | | | | ... no caller in that file, this change has no effect. This reverts commit 3bb960c7b5f1428f1bff885b2667787e8af5001b.
* lib/path: make sure ul_path_read_buffer() derminate resultKarel Zak2019-06-171-2/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: fix reference counting for parentKarel Zak2019-06-111-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize: fix compiler warning [-Wsign-compare]Karel Zak2019-06-101-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/ttyutils: introduce get_terminal_stdfd()Karel Zak2019-05-271-9/+18
| | | | | | Let's use separate function to detect what is the current terminal. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/ismounted: use xstrncpy()Karel Zak2019-05-201-4/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: use xstrncpy()Karel Zak2019-05-201-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: use xstrncpy()Karel Zak2019-05-201-8/+5Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: use xstrncpy()Karel Zak2019-05-201-6/+4Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: remove unnecessary gotoKarel Zak2019-05-201-5/+4Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: remove redundant if statementSami Kerola2019-05-181-3/+1Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/mangle: fix possible null pointer dereference [cppcheck]Sami Kerola2019-05-181-2/+2
| | | | | | Fix effects code that is used when testing util-linux, so quite low impact. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/strutils: keep static analyzer happy [coverity scan]Karel Zak2019-05-151-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: fix resource leak [coverity scan]Karel Zak2019-05-151-2/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: fix possible NULL dereferencing [coverity scan]Karel Zak2019-05-151-2/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: fix ul_path_get_dirfd() usage [coverity scan]Karel Zak2019-05-151-1/+5
| | | | | | ul_path_get_dirfd() returns negative number on error... Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: consolidate ul_path_mkpath() usageKarel Zak2019-05-151-74/+28Star
| | | | | | | * always use errno from ul_path_mkpath() * keep code simple and short as possible Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: fix possible NULL pointer dereferencing [coverity scan]Karel Zak2019-05-151-0/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: fix "maybe be" duplicationAustin English2019-05-151-1/+1
| | | | Signed-off-by: Austin English <austinenglish@gmail.com>
* losetup: keep static analyzer happy [coverity scan]Karel Zak2019-05-141-4/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: keep static analyzer happy [coverity scan]Karel Zak2019-05-141-2/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize: verify DM paths [coverity scan]Karel Zak2019-05-141-1/+1
| | | | | | | | | | | | | Now the code only checks that /sys/.../dm/name exists, but never verify the device node in /dev (because path prefix is never NULL). The prefix is used to redirect hardcoded paths to /sys dumps (e.g. lsblk regression tests, etc.) This bug has been introduced in v2.33. Fortunately, it's probably no big issue as /dev is always in sync with /sys (thanks to udevd). Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: parse_size() fix frac digit calculationKarel Zak2019-05-131-10/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Old code: ./test_strutils --size 0.5MiB 0.5MiB : 512000 : 500K : 500 KiB ./test_strutils --size 0.50MiB 0.50MiB : 5120000 : 4.9M : 4.9 MiB New code: ./test_strutils --size 0.5MiB 0.5MiB : 524288 : 512K : 512 KiB ./test_strutils --size 0.50MiB 0.50MiB : 524288 : 512K : 512 KiB Note that the new implementation also does not use float points, because we need to support PiB and so on... it seems good enough for things like: ./test_strutils --size 7.13G 7.13G : 7656104581 : 7.1G : 7.1 GiB ./test_strutils --size 7.16G 7.16G : 7690675814 : 7.2G : 7.2 GiB to avoid situation where cfdisk creates partition with completely crazy numbers. Addresses: https://github.com/karelzak/util-linux/issues/782 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: parse_size() fix frac with zerosKarel Zak2019-05-131-7/+12
| | | | | | Fix 0.001G as well as accept 0.000G as valid number. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev.c: Retry LOOP_SET_STATUS64 on EAGAINRomain Izard2019-05-071-4/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | A recent bugfix in the Linux kernel made it possible for the LOOP_SET_STATUS64 ioctl to fail when called with a non-zero offset, with an EAGAIN errno: 5db470e229e2 loop: drop caches if offset or block_size are changed This fix changes a silent failure (where mount could sometimes access the backing loop image through the cache without the specified offset) to an explicit failure, and it has also been backported on stable branches. On a 5.0 kernel, other changes to the loop driver make it hard to get generate the EAGAIN error, but this bugfix has also been backported to stables branches, without these changes. At least with the 4.14 stable branch, the EAGAIN error can be quickly generated with the following loop: while mount -o loop,offset=239 disk point && umount point; do :; done Retry the ioctl when it fails with EAGAIN, which means that mount or losetup will eventually succeed when encountering this case. [kzak@redhat.com: - use our local portable xusleep()] Signed-off-by: Romain Izard <romain.izard.pro@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/fileutils: add xreaddir()Karel Zak2019-04-112-30/+0Star
| | | | | | | Remove duplicate code and keep only one implementation in include/fileutils.h. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't use sscanf() for fstab parsingKarel Zak2019-04-081-1/+1
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/780 Signed-off-by: Karel Zak <kzak@redhat.com>
* taskset: fix cpuset list parserKarel Zak2019-03-201-8/+24
| | | | | | | | | | | | | | | taskset hangs when executed with badly formatted cpuset list, for example: $ taskset -c 0--1 true The current cpuset list parser is pretty weak as based on scanf() without strings verification ("-1" as input for "%u" returns unexpected number). It seems faster and better to use strtoul() and isdigit(). Addresses: https://github.com/karelzak/util-linux/issues/77 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: remove extra semi-colonsKarel Zak2019-03-191-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev.c: Inline loopcxt_has_deviceMarcos Paulo de Souza2019-03-031-1/+1
| | | | | | | loopcxt_has_device is a one liner, so adding inline statement does not hurt. Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
* docs: fix typos [codespell]Sami Kerola2019-02-182-5/+5
| | | | | Reference: https://github.com/codespell-project/codespell Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/strutils: support two decimal places in size_to_human_string() outputKarel Zak2019-02-121-4/+11
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: force to "never" mode on non-terminal outputKarel Zak2019-02-041-5/+15
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: set blocksize when create a new deviceKarel Zak2019-01-221-0/+23
| | | | | | | | | | | The partition scanner in kernel depends on blocksize. We need to set the blocksize before we call LOOP_SET_STATUS64 (this ioctl triggers the scanner). This patch extends the internal API to save blocksize into loopdev context to be usable later for loopcxt_setup_device(). Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: differentiate between setter()s and ioctl callsKarel Zak2019-01-221-5/+5
| | | | | | | | Now the internal API uses loopcxt_set_...() to set context variables as well as to call ioctls. This patch introduces loopcxt_ioctl_...() to makes things more obvious to readers. Signed-off-by: Karel Zak <kzak@redhat.com>
* include: add indirect monotonic clock id specifierSami Kerola2019-01-121-5/+1Star
| | | | | | | Avoid repeated ifdef checks in code by adding a project specific preprocessor definition. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* timeutils: match today day and this year correctlySami Kerola2019-01-121-12/+15
| | | | | | | | | Assumption all years since 1970 have been exactly 365 days long has it's problems when leap years happen. Lets use struct tm fields that are provided by localtime_r(), making year and day to be correctly compared even when it's late new years eve somewhere else than UTC-0. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* choom: fix negative adjust score usageKarel Zak2018-12-101-0/+22
| | | | | | | | It's really bad idea to use uint64_t (ul_path_write_u64(()) when write signed number. Addresses: https://github.com/karelzak/util-linux/issues/723 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: allow to close dirfdKarel Zak2018-12-071-3/+19
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add function to detect partitioned devicesKarel Zak2018-12-071-0/+14
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: do not require dirfd()Karel Zak2018-12-031-2/+6
| | | | | | | The dirfd() is required on many places, but it should not be required for all utils by ./configure.ac. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/timer: add fallback if timer_create() not availableKarel Zak2018-12-031-5/+35
| | | | | | | | | | | | | * add struct ul_timer as API abstraction to hide differences between timer_create() and setitimer() * add setitimer() detection to ./configure.ac * add fallback code to use setitimer() if timer_create() not available (for example on OSX) Addresses: https://github.com/karelzak/util-linux/issues/584 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize: fix typoKarel Zak2018-11-301-1/+1
| | | | | Addresses: https://github.com/karelzak/util-linux/commit/8b8277b7a812c04f2288460f3a8d23cdd53ff66d#commitcomment-31491031 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize: do restricted canonicalize in a subprocessRian Hunter2018-11-301-22/+77
| | | | | | | | | | | | | | | | | | | Accessing FUSE mounts require suid/sgid (saved uid) to be equal to the owner of the mount. If mount is running as a setuid process, swapping creds by only setting the euid/egid isn't enough to change the suid/sgid as well. We must do a full setuid()/setgid(), but that removes our ability to re-assume the identity of the original euid. The solution is swap creds in a child process, preserving the creds of the parent. [kzak@redhat.com: - use switch() rather than if() for fork - use all-io.h - close unused pipe[] ends - be more strict about used types] Addresses: https://github.com/karelzak/util-linux/pull/705 Co-Author: Karel Zak <kzak@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: return from xstrmode()Karel Zak2018-09-141-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors:: fix compiler warnings [-Wcast-qual]Karel Zak2018-07-231-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: fix compiler warning [-Wcast-qual]Karel Zak2018-07-231-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/mangle: const quialifier cleanupKarel Zak2018-07-201-4/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/color-names: const cleanupKarel Zak2018-07-201-3/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>