Commit Graph

777 Commits

Author SHA1 Message Date
Sami Kerola 5119ef0a83
lib/ttyutils: avoid checking same thing twice
Check cols and lines are not NULL only once.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-07-01 22:02:06 +01:00
Karel Zak dab1303287 Revert "lib/loopdev.c: Inline loopcxt_has_device"
... no caller in that file, this change has no effect.

This reverts commit 3bb960c7b5.
2019-06-18 22:05:16 +02:00
Karel Zak e3188dd90a lib/path: make sure ul_path_read_buffer() derminate result
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-17 15:47:39 +02:00
Karel Zak 4a0e70663c lib/sysfs: fix reference counting for parent
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-11 12:11:32 +02:00
Karel Zak 348f57d669 lib/canonicalize: fix compiler warning [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-10 11:00:38 +02:00
Karel Zak a6d9d23b5f lib/ttyutils: introduce get_terminal_stdfd()
Let's use separate function to detect what is the current terminal.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-27 12:49:12 +02:00
Karel Zak 8ecc6ba807 lib/ismounted: use xstrncpy()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-20 13:03:58 +02:00
Karel Zak e2569bcf26 lib/path: use xstrncpy()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-20 12:57:16 +02:00
Karel Zak 94d9fd9f6a lib/sysfs: use xstrncpy()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-20 12:57:07 +02:00
Karel Zak 91072cd480 losetup: use xstrncpy()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-20 12:46:39 +02:00
Karel Zak 9d6852d3a2 lib/colors: remove unnecessary goto
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-20 12:41:12 +02:00
Sami Kerola cc7ffe129d
lib/colors: remove redundant if statement
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-18 22:56:15 +01:00
Sami Kerola 4f807791ee
lib/mangle: fix possible null pointer dereference [cppcheck]
Fix effects code that is used when testing util-linux, so quite low impact.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-18 22:09:25 +01:00
Karel Zak 6d92f7d7bf lib/strutils: keep static analyzer happy [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:09:16 +02:00
Karel Zak 91bf581742 lib/path: fix resource leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:01:32 +02:00
Karel Zak 8083862536 lib/path: fix possible NULL dereferencing [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 15:57:09 +02:00
Karel Zak 8e28151329 lib/path: fix ul_path_get_dirfd() usage [coverity scan]
ul_path_get_dirfd() returns negative number on error...

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 15:52:54 +02:00
Karel Zak 2c417af196 lib/path: consolidate ul_path_mkpath() usage
* always use errno from ul_path_mkpath()
* keep code simple and short as possible

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 15:47:29 +02:00
Karel Zak b24650294d lib/path: fix possible NULL pointer dereferencing [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 15:36:49 +02:00
Austin English 5cee62edc4 lib/colors: fix "maybe be" duplication
Signed-off-by: Austin English <austinenglish@gmail.com>
2019-05-15 13:48:34 +02:00
Karel Zak 3011b381e3 losetup: keep static analyzer happy [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-14 16:43:40 +02:00
Karel Zak dcf6f5b3d9 lib/colors: keep static analyzer happy [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-14 16:37:35 +02:00
Karel Zak 0ed52c662e lib/canonicalize: verify DM paths [coverity scan]
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>
2019-05-14 15:47:02 +02:00
Karel Zak 8c368dc6d3 lib/strutils: parse_size() fix frac digit calculation
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>
2019-05-13 17:07:14 +02:00
Karel Zak 482e0a0754 lib/strutils: parse_size() fix frac with zeros
Fix 0.001G as well as accept 0.000G as valid number.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-13 16:15:58 +02:00
Romain Izard eab90ef8d4 lib/loopdev.c: Retry LOOP_SET_STATUS64 on EAGAIN
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>
2019-05-07 12:36:00 +02:00
Karel Zak 7761bd3bb6 lib/fileutils: add xreaddir()
Remove duplicate code and keep only one implementation in
include/fileutils.h.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-11 13:11:53 +02:00
Karel Zak 36fcefa651 libmount: don't use sscanf() for fstab parsing
Addresses: https://github.com/karelzak/util-linux/issues/780
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-08 13:34:47 +02:00
Karel Zak 65bcbf105b taskset: fix cpuset list parser
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>
2019-03-20 13:12:25 +01:00
Karel Zak 357dd756d1 lib/path: remove extra semi-colons
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-19 13:57:05 +01:00
Marcos Paulo de Souza 3bb960c7b5 lib/loopdev.c: Inline loopcxt_has_device
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>
2019-03-03 09:15:13 -03:00
Sami Kerola 110260830d docs: fix typos [codespell]
Reference: https://github.com/codespell-project/codespell
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-02-18 13:22:43 +01:00
Karel Zak 07b94c9f32 lib/strutils: support two decimal places in size_to_human_string() output
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-12 14:20:55 +01:00
Karel Zak 5db5962339 lib/colors: force to "never" mode on non-terminal output
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-04 14:14:37 +01:00
Karel Zak 75d239ffd8 lib/loopdev: set blocksize when create a new device
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>
2019-01-22 11:37:35 +01:00
Karel Zak 9fcc893624 lib/loopdev: differentiate between setter()s and ioctl calls
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>
2019-01-22 11:12:42 +01:00
Sami Kerola ee6e39305c
include: add indirect monotonic clock id specifier
Avoid repeated ifdef checks in code by adding a project specific
preprocessor definition.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-01-12 08:46:53 +00:00
Sami Kerola d393c00c6c
timeutils: match today day and this year correctly
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>
2019-01-12 08:46:29 +00:00
Karel Zak c455cdb30d choom: fix negative adjust score usage
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>
2018-12-10 14:26:04 +01:00
Karel Zak c9ea91d41e lib/path: allow to close dirfd
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak 93c687d895 lib/sysfs: add function to detect partitioned devices
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak a68ed87ffe build-sys: do not require dirfd()
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>
2018-12-03 11:23:33 +01:00
Karel Zak 6df5acf970 lib/timer: add fallback if timer_create() not available
* 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>
2018-12-03 11:23:33 +01:00
Karel Zak e11d0b8c88 lib/canonicalize: fix typo
Addresses: 8b8277b7a8 (commitcomment-31491031)
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-11-30 10:25:04 +01:00
Rian Hunter e101a9eb0f lib/canonicalize: do restricted canonicalize in a subprocess
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>
2018-11-30 10:25:04 +01:00
Karel Zak 5b82289b60 lib/strutils: return from xstrmode()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-09-14 16:26:38 +02:00
Karel Zak 892fc7d9de lib/colors:: fix compiler warnings [-Wcast-qual]
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-23 11:55:25 +02:00
Karel Zak 0145c00a12 lib/loopdev: fix compiler warning [-Wcast-qual]
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-23 11:17:28 +02:00
Karel Zak 78c66fc61d lib/mangle: const quialifier cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 15:31:42 +02:00
Karel Zak c8b237a0ed lib/color-names: const cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 13:58:10 +02:00