summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* lib/strutils: follow const in parse_size()Karel Zak2018-07-201-13/+15
| | | | | | | | | * don't cast from char to const char * don't share endptr from strtoxxx() with rest of the code as the end pointer is char, but code works with const chars Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: remove redundant conditionKarel Zak2018-07-181-1/+1
| | | | | | | [util-linux-2.32.1/lib/strutils.c:122]: (style) Redundant condition: If 'EXPR == '0'', the comparison 'EXPR' is always true. Reported-by: David Binderman <dcb314@hotmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/pager: fix compiler warning [-Wrestrict]Karel Zak2018-07-181-2/+4
| | | | | | | lib/pager.c: In function ‘pager_preexec’: lib/pager.c:148:12: warning: passing argument 2 to restrict-qualified parameter aliases with argument 4 [-Wrestrict] Signed-off-by: Karel Zak <kzak@redhat.com>
* Merge branch 'quick-fix-20180625' of https://github.com/sjitech/util-linuxKarel Zak2018-07-041-1/+2
|\ | | | | | | | | * 'quick-fix-20180625' of https://github.com/sjitech/util-linux: exec_shell: prevent ".: applet not found" error when SHELL env is not set.
| * exec_shell: prevent ".: applet not found" error when SHELL env is not set.osexp20002018-06-251-1/+2
| | | | | | | | When SHELL env is not set, it cause xstrdup(NULL) be executed, and result in weird error message ".: applet not found" instead of /bin/sh being used.
* | lib/path: remove unused expressionRuediger Meier2018-06-251-1/+1
|/ | | | | | | error: expression result unused [-Werror,-Wunused-value] prefix = optarg, "failed to parse range start"; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/path: allow dir-path formattingKarel Zak2018-06-211-3/+9
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsblk: fix ul_path_read_string() usageKarel Zak2018-06-211-4/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsblk: use prefix for DM nameKarel Zak2018-06-211-3/+11
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: cleanup function namesKarel Zak2018-06-211-4/+3Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: improve debug message on redirectKarel Zak2018-06-211-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: fix sysfs_blkdev_get_wholedisk()Karel Zak2018-06-211-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: simplify debug messageKarel Zak2018-06-211-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: add ul_prefix_fopen(), improve cpuset funcsKarel Zak2018-06-211-2/+27
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: don't use extra '/'Karel Zak2018-06-211-4/+16
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: add more debug messagesKarel Zak2018-06-211-2/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: make ul_path_read_ usable with NULL handlerKarel Zak2018-06-211-11/+22
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: add ul_path_read_buffer()Karel Zak2018-06-211-0/+29
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: add ul_path_get_abspath()Karel Zak2018-06-211-1/+33
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: fix ul_path_read_string() usageKarel Zak2018-06-211-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add sysfs_blkdev_get_parent()Karel Zak2018-06-211-0/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: make possible to call sysfs_blkdev_deinit_path() in loopKarel Zak2018-06-212-9/+17
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: fix read string to be backwardly compatibleKarel Zak2018-06-211-0/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path lib/sysfs: add debugKarel Zak2018-06-212-2/+74
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: remove obsolete macroKarel Zak2018-06-211-1/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: use new ul_path_* APIKarel Zak2018-06-211-24/+25
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add ul_new_sysfs_path() shortcutKarel Zak2018-06-211-20/+33
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: new implementationKarel Zak2018-06-212-531/+448Star
| | | | | | | | | * reuse ul_path_* API * allow to use prefix for sysfs paths, so we can use snapshots from sysfs for regression tests Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: new implementationKarel Zak2018-06-212-140/+918
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The goal is to avoid duplicate code in path.c and sysfs.c and make it possible to define prefix for paths for all sysfs and procfs based utils. Now we have /proc snapshots (for tests) for lscpu only. It would be nice to have the same (for sysfs) for lsblk and another tools. * very simple API to read numbers, strings and symlinks * based on openat() pc = ul_new_path("/sys/block/sda"); ul_path_read_u64(pc, &size, "size"); ul_path_read_u64(pc, &lsz, "queue/logical_block_size"); * printf-like API to generate paths, for example: ul_path_readf_u64(pc, &num, "sda%d/size", partno) * allow to define prefix to redirect hardcoded paths to another location, for example: pc = ul_new_path("/sys/block/sda"); ul_path_set_prefix(pc, "/my/regression/dump"); ul_path_read_u64(pc, &num, "size"); to read /my/regression/dump/sys/block/sda/size * allow to extend the API by "dialects", for example for sysfs: pc = ul_new_path(NULL); sysfs_blkdev_init_path(pc, devno, NULL); and use ul_path_* functions to read from @pc initialized by sysfs_blkdev_init_path() * add test_path binary Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: fix strnlen() fallbackKarel Zak2018-05-281-2/+2
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/643 Signed-off-by: Karel Zak <kzak@redhat.com>
* script: add more info to script headerKarel Zak2018-05-141-0/+7
| | | | | | | | | | | | | | | | This patch introduces [...] to store extra information about terminal to the typescript header. For example: Script started on 2018-05-14 12:52:32+02:00 [TERM="xterm-256color" TTY="/dev/pts/3" COLS="190" LINES="53"] or Script started on 2018-05-14 12:54:01+02:00 [<not executed on terminal>] if stdout is not terminal. Addresses: https://github.com/karelzak/util-linux/issues/583 Signed-off-by: Karel Zak <kzak@redhat.com>