summaryrefslogtreecommitdiff
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'nsenter-keep-caps' of https://github.com/dgibson/util-linuxKarel Zak2023-05-171-0/+38
|\ | | | | | | | | | | * 'nsenter-keep-caps' of https://github.com/dgibson/util-linux: Add --keep-caps option to nsenter, similar to the one in unshare unshare: Move implementation of --keep-caps option to library function
| * unshare: Move implementation of --keep-caps option to library functionDavid Gibson2023-03-291-0/+38
| | | | | | | | | | | | | | | | unshare.c open codes some logic to copy the permitted capability set to the ambient set in order to implement the --keep-caps option. Move this logic to lib/caputils.c so that we can reuse it in nsenter. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* | lib/pager: fix output truncation from buffered stdoutChris Webb2023-05-091-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 518a0ad dropped fflush(stdout) and fflush(stderr) from wait_for_pager() before STDOUT_FILENO and STDERR_FILENO are closed because it is called from a signal handler and they are async-unsafe. However, failure to flush output leads to unwanted truncation when stdout is fully buffered, which it is by default when we are linked against musl. Ensure stdout and stderr are line-buffered before redirecting them to the pager subprocess to avoid this. Addresses: https://github.com/util-linux/util-linux/issues/2218 Signed-off-by: Chris Webb <chris@arachsys.com>
* | lib/crc32c: fix assert()Karel Zak2023-04-181-1/+2
| | | | | | | | | | Addresses: https://github.com/util-linux/util-linux/pull/2165 Signed-off-by: Karel Zak <kzak@redhat.com>
* | lib: Add crc32c function that can deal with holesJeremy Linton2023-04-141-0/+18
|/ | | | | | | | | | XFS, and possibly other filesystems expect that the CRC field is excluded (or rather RAZ) during the CRC operation. Lets create a generic helper that is similar to the CRC32 version ul_crc32_exclude_offset() which computes the CRC while replacing exclude_len bytes of exclude_off with zeros. Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
* lib/env: fix memory leak [coverity scan]Karel Zak2023-03-091-4/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* nsenter: add --env for allowing environment variables inheritanceu23862023-03-021-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | This commit adds support for the -e or --env option in nsenter, allowing a new process to inherit the environment va If the option is not given, the environment variables will stay the same as in the current namespace. Example: Setup the namespace: $ docker run -d -e PROJECT='util linux' --rm alpine sleep 10000 cb0b69aa7aec $ docker inspect --format '{{ .State.Pid }}' cb0b69aa7aec 470012 Enter the namespace: $ nsenter --all -t 470012 --env env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=cb0b69aa7aec PROJECT=util linux HOME=/root Reviewed-by: Thomas Weißschuh <thomas@t-8ch.de> Reviewed-by: Karel Zak <kzak@redhat.com> Signed-off-by: u2386 <hugo.cavan2386@gmail.com>
* kill: fix buffer overflowKarel Zak2023-02-281-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: move colors canonicalization to lib/color-names.cKarel Zak2023-02-272-106/+117
| | | | | | | | | | | | | | * let's make simplified sequences (e.g. "35;4") used without lib/colors.c (without color schemes) * add function to detect already usable esc sequence * support this new feature in "test_colors --color <name|seq|...>" ./test_colors --color "red" ./test_colors --color "35;5" Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: ensure fallback to system directoryThomas Weißschuh2023-02-231-0/+2
| | | | | | | | | The return value from colors_readdir(homedir) is used to determine if the system directory should be searched. Previously the mere existence of `~/.config/terminal-colors.d/` would inhibit all lookups in `/etc/terminal-colors.d`. Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
* lib/randutils: drop unnecessary fcntl() in random_get_fd()Thomas Haller2023-02-221-6/+1
| | | | | | | | | | We already pass O_CLOEXEC flag to open(), no need to modify the file descriptor with FD_CLOEXEC afterwards. This was a left over from commit b1fa3e2234fa ('lib: use O_CLOEXEC in libcommon'). Signed-off-by: Thomas Haller <thaller@redhat.com>
* lib/colors: introduce color_get_disable_sequence()Thomas Weißschuh2023-02-151-0/+11
| | | | Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
* Merge branch 'dmesg-subsecond' of https://github.com/t-8ch/util-linuxKarel Zak2023-01-251-2/+2
|\ | | | | | | | | | | | | | | | | * 'dmesg-subsecond' of https://github.com/t-8ch/util-linux: dmesg: use subsecond granularity in iso format dmesg: add subsecond granularity for --since and --until lib/monotonic: get_suspended_time: use usec_t timeutils: add utilities for usec_t conversions dmesg: add test for --since and --until
| * lib/monotonic: get_suspended_time: use usec_tThomas Weißschuh2023-01-241-2/+2
| | | | | | | | Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
* | lib/sysfs: fix semantics of blkdev_is_hotpluggableThomas Weißschuh2023-01-241-31/+51
| | | | | | | | | | | | This is now decoubled from the kernels notion of a removable *block* device and instead uses removable kobjects. This is the correct semantic for hotpluggable devices.
* | lib/sysfs: add TODO about removable usb devicesThomas Weißschuh2023-01-241-0/+2
| | | | | | | | | | The usage of the "removable" attribute by the USB subsystem is incorrect.
* | lib/sysfs: add function blkdev_is_removableThomas Weißschuh2023-01-241-1/+13
| | | | | | | | | | | | | | This exactly represents the kernels notion of a "removable" blockdevice. That is, the device itself is persistent but can contain some sort of medium that can be changed at runtime. Specifically it is *not* hotpluggable.
* | include/c: add functions to print from signal handlersKarel Zak2023-01-241-3/+1
| | | | | | | | | | Addresses: https://github.com/util-linux/util-linux/pull/2019 Signed-off-by: Karel Zak <kzak@redhat.com>
* | Merge branch 'signal_safety' of https://github.com/crrodriguez/util-linuxKarel Zak2023-01-241-3/+3
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | * 'signal_safety' of https://github.com/crrodriguez/util-linux: sulogin: only assign to variables written by signal handlers hardlink: calling putchar is off-limits on a signal handler hardlink: last_signal should be a volatile sig_atomic_t pg: calling exit on signal handler is not allowed lib:pager: fix signal safety issues write: signal_received should be volatile qualified flock: timeout_expired must be volatile qualified last: should not use errx/warnx on signal handlers su-common: bool is a distinct type in c2x fsck: only assign to cancel_requested fsck: use sig_atomic_t type fot signal handler global vars
| * lib:pager: fix signal safety issuesCristian Rodríguez2023-01-151-3/+3
| | | | | | | | | | | | - Cannot use stdio in signal handlers, so you cannot safely call fflush. - cannot call exit() but only _exit()
* | lib/timeutils: set TZ=GMT for unit testKarel Zak2023-01-241-2/+1
| | | | | | | | | | | | | | | | It seems better to explicitly set timezone rather than assume some default libc behavior and system setting. Addresses: https://github.com/util-linux/util-linux/pull/2025 Signed-off-by: Karel Zak <kzak@redhat.com>
* | lib/timeutils: parse_timestamp: parse usecsThomas Weißschuh2023-01-231-25/+70
| | | | | | | | Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
* | lib/timeutils: parse_timestamp: fix second parsingThomas Weißschuh2023-01-231-3/+2
| | | | | | | | Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
* | lib/timeutils: parse_timestamp: add unittestsThomas Weißschuh2023-01-231-1/+50
| | | | | | | | Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
* | lib/timeutils: parse_timestamp: allow fixed reference timeThomas Weißschuh2023-01-231-3/+6
| | | | | | | | Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
* | replace open-coded instances of mempcpyCristian Rodríguez2023-01-233-6/+5
| |
* | lib/blkdev: use off_t for max valuesSamanta Navarro2023-01-161-5/+5
| | | | | | | | | | | | | | The off_t datatype is signed. Use it for high and low boundaries as well to support also very large block devices close to its limits. Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
* | lib/blkdev: set errno in more casesSamanta Navarro2023-01-161-2/+7
| | | | | | | | | | | | | | | | Applications evaluate errno in case of a -1 return value. Examples within util-linux are fsck.cramfs and mkfs.minix. Set errno more often to offer reasonable error codes to the application and user. Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
* | lib/blkdev: handle interrupted read callSamanta Navarro2023-01-161-1/+2
|/ | | | | | | | The read call may fail if it is interrupted by a signal. Do not assume that we have reached the end of the underlying block device because of this. Use read_all which retries in these cases. Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
* include: add missing license linesKarel Zak2023-01-123-2/+11
| | | | | | | | | | The header files are usually based on code from lib/. This commit copies relevant license headers from lib/ to include/ to keep things consistent. The very generic things (e.g. MBR definitions) are always public domain. Fixes: https://github.com/util-linux/util-linux/issues/2010 Signed-off-by: Karel Zak <kzak@redhat.com>
* autotools: fix build for test_loopdevThomas Weißschuh2023-01-071-2/+2
|
* Merge branch 'waitpid' of https://github.com/t-8ch/util-linuxKarel Zak2023-01-061-0/+9
|\ | | | | | | | | | | * 'waitpid' of https://github.com/t-8ch/util-linux: waitpid: add timeout support strutils: add function strtotimespec_or_err
| * strutils: add function strtotimespec_or_errThomas Weißschuh2023-01-061-0/+9
| |
* | lib/sysfs: use temporary bufferKarel Zak2023-01-062-15/+20
|/ | | | | | | It seems more readable (for humans and static analyzers) and safe to use temporary buffer than use memmove to create absolute path. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: fix compiler errorThomas Weißschuh2023-01-061-0/+3
| | | | | | | | | | | | In file included from /usr/include/stdio.h:894, from lib/strutils.c:8: In function ‘printf’, inlined from ‘test_strutils_cstrcasecmp’ at lib/strutils.c:1324:2, inlined from ‘main’ at lib/strutils.c:1348:10: /usr/include/x86_64-linux-gnu/bits/stdio2.h:112:10: error: ‘%s’ directive argument is null [-Werror=format-overflow=] 112 | return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors
* lib/strutils: include strings.hKarel Zak2023-01-051-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/signames: ignore locales when searching for signal namesKarel Zak2023-01-041-5/+6
| | | | | Fix: https://github.com/util-linux/util-linux/issues/1991 Signed-off-by: Karel Zak <kzak@redhat.com>
* include/cctype: add c_strcasecmp() and c_strncasecmp()Karel Zak2023-01-041-1/+25
| | | | | | | | Sometimes, we need to compare ASCII-only strings independently on the current locales. Let's follow our cctype.h to implement such functions. Addresses: https://github.com/util-linux/util-linux/issues/1991 Signed-off-by: Karel Zak <kzak@redhat.com>
* Merge branch 'libblkid/topology-diskseq' of https://github.com/t-8ch/util-linuxKarel Zak2023-01-021-3/+3
|\ | | | | | | | | | | | | | | | | | | * 'libblkid/topology-diskseq' of https://github.com/t-8ch/util-linux: libblkid: topology: probe diskseq libblkid: topology: allow setting of 64bit values lib/sysfs: allow parent redirect even for non-queue files blockdev: add support for ioctl BLKGETDISKSEQ libblkid: topology: add test tests: functions: allow partitions on loopdevs
| * lib/sysfs: allow parent redirect even for non-queue filesThomas Weißschuh2022-12-281-3/+3
| | | | | | | | We will also need this redirect for other sysfs files.
* | Merge branch 'cleanups' of https://github.com/t-8ch/util-linuxKarel Zak2023-01-021-1/+1
|\ \ | | | | | | | | | | | | | | | | | | | | | * 'cleanups' of https://github.com/t-8ch/util-linux: fadvise: fix parsing of option -V libblkid: zfs: remove unnecessary newline from debug messages libblkid: topology: constify some structures lib: sysfs: fix typo
| * | lib: sysfs: fix typoThomas Weißschuh2022-12-281-1/+1
| |/
* | Merge branch 'stat-parsing' of https://github.com/t-8ch/util-linuxKarel Zak2023-01-021-26/+35
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 'stat-parsing' of https://github.com/t-8ch/util-linux: procfs: get_stat_nth: handle braces in process name lib: procfs: add parsing cmd containing newline lib: procfs: add unittests lib: procfs: prefix support for tests lib: procfs: fix error message during test lib: procfs: fix typo in argument specification lib: procfs: clarify name of procfs_process_get_data_for()
| * | procfs: get_stat_nth: handle braces in process nameThomas Weißschuh2022-12-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In procfs_process_get_stat_nth() we skip to the end of the process name by looking for the ')' after it. However if the process name itself contains a ')' then find that instead of the correct one. By searching the ')' from the end of the file we can make sure to always find the correct one. Link: https://www.openwall.com/lists/oss-security/2022/12/21/6
| * | lib: procfs: prefix support for testsThomas Weißschuh2022-12-241-16/+24
| | | | | | | | | | | | This will be used in the unitttests.
| * | lib: procfs: fix error message during testThomas Weißschuh2022-12-241-3/+4
| | | | | | | | | | | | procfs_process_get_stat_nth() returns the error and does not set errno.
| * | lib: procfs: fix typo in argument specificationThomas Weißschuh2022-12-241-1/+1
| | |
| * | lib: procfs: clarify name of procfs_process_get_data_for()Thomas Weißschuh2022-12-231-5/+5
| |/ | | | | | | | | | | | | | | | | | | | | The previous name "procfs_process_get_line_for()" indicates that only a single line would be read from the file. In fact the function always returns the full file contents. This behavior is necessary are various procfs files can contain legitimate newlines. Rename the function to match its behavior.
* | Merge branch 'address_bits' of https://github.com/t-8ch/util-linuxKarel Zak2023-01-021-0/+13
|\ \ | | | | | | | | | | | | | | | * 'address_bits' of https://github.com/t-8ch/util-linux: setarch: use kernel address size if possible sysfs: add helper for /sys/kernel/address_bits
| * | sysfs: add helper for /sys/kernel/address_bitsThomas Weißschuh2022-12-211-0/+13
| |/