summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* lib/canonicalize: fix truncation warningSami Kerola2018-05-101-2/+3
| | | | | | | | | | | | | | | | | | lib/canonicalize.c: In function ‘canonicalize_dm_name’: lib/canonicalize.c:42:45: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 244 [-Wformat-truncation=] snprintf(path, sizeof(path), "/dev/mapper/%s", name); Notice that this warnign fix does not improve code enormously. The earlier snprintf() truncation will not happen a bit earlier when fgets() is called. In that sense this change merely makes one easy to silence warning to disappear, and therefore improve change of noticing useful messaging as such crops up. [kzak@redhat.com: - use macro rather than hardcoded string for mapper path] Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/randutils: don't break on EAGAIN, use usleep()Karel Zak2018-03-201-5/+12
| | | | | | | | | | | | | | | | | The current code uses lose_counter to make more attempts to read random numbers. It seems better to wait a moment between attempts to avoid busy loop (we do the same in all-io.h). The worst case is 1 second delay for all random_get_bytes() on systems with uninitialized entropy pool -- for example you call sfdisk (MBR Id or GPT UUIDs) on very first boot, etc. In this case it will use libc rand() as a fallback solution. Note that we do not use random numbers for security sensitive things like keys or so. It's used for random based UUIDs etc. Addresses: https://github.com/karelzak/util-linux/pull/603 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/randutils: Do not block on getrandom()Carlo Caione2018-03-191-1/+5
| | | | | | | | | | | | In Endless we have hit a problem when using 'sfdisk' on the really first boot to automatically expand the rootfs partition. On this platform 'sfdisk' is blocking on getrandom() because not enough random bytes are available. This is an ARM platform without a hwrng. We fix this passing GRND_NONBLOCK to getrandom(). 'sfdisk' will use the best entropy it has available and fallback only as necessary. Signed-off-by: Carlo Caione <carlo@endlessm.com>
* libblkid: ignore private Stratis devicesTony Asleson2018-03-091-9/+15
| | | | | | | | [kzak@redhat.com: - tiny coding style changes] References: 20e1c3dc03399d6988ef35dedc1364cfc12e9263 Signed-off-by: Tony Asleson <tasleson@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: fix typos using codespellRuediger Meier2018-02-161-1/+1
| | | | | | Some more funny typos, please review carefully. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lsblk: try device/dev to read devnoKarel Zak2018-02-091-43/+54
| | | | | | | | | Now sysfs_devname_to_devno() reads devno from /dev or /sys/block/<name>/dev, but it seems that NVME uses /sys/block/<name>/device/dev. Reported-by: Potnuri Bharat Teja <bharat@chelsio.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/exec_shell: (and pager) use errexec()Karel Zak2018-02-012-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/exec_shell: cleanup function attributesKarel Zak2018-02-011-1/+1
| | | | | Reported-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()Karel Zak2018-01-172-2/+2
| | | | | | | Let's make it possible to use debug.h without environment variables. Suggested-by: J William Piggott <elseifthen@gmx.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* Merge branch 'mbsencode' of https://github.com/yontalcar/util-linuxKarel Zak2018-01-121-5/+4Star
|\ | | | | | | | | | | | | | | | | | | * 'mbsencode' of https://github.com/yontalcar/util-linux: tests: mark mbsencode as KNOWN_FAIL tests: mbsencode - test for HAVE_WIDECHAR lib/mbsalign: Fix escaping nonprintable multibyte characters tests: mbsencode - removed emoji, added control unicode character tests: add tests for encode functions from lib/mbsalign.c lib/mbsalign: escape "\x" when HAVE_WIDECHAR not defined
| * lib/mbsalign: Fix escaping nonprintable multibyte charactersVaclav Dolezal2018-01-111-1/+1
| | | | | | | | Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
| * lib/mbsalign: escape "\x" when HAVE_WIDECHAR not definedVaclav Dolezal2017-12-221-4/+3Star
| | | | | | | | Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>