summaryrefslogtreecommitdiffstats
path: root/include
Commit message (Collapse)AuthorAgeFilesLines
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-0/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include/closestream: add close_stdout_atexit()Karel Zak2019-04-161-0/+11
| | | | | | | | It seems better to have a way to control when atexit(close_stdout()) is used, because close stdout means that for example ASAN (or another into binary integrated tool) is not able to print the final summary. Signed-off-by: Karel Zak <kzak@redhat.com>
* include/strutils: add functions to replace and remove chars from stringKarel Zak2019-04-111-0/+16
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/fileutils: add xreaddir()Karel Zak2019-04-111-0/+15
| | | | | | | 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 swaps parsingKarel Zak2019-04-081-1/+0Star
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/780 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't use sscanf() for mountinfo parsingKarel Zak2019-04-081-1/+1
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/780 Signed-off-by: Karel Zak <kzak@redhat.com>
* include/path.h: remove duplicate header inclusionSami Kerola2019-02-181-1/+0Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* include: add no return function attributeSami Kerola2019-02-181-1/+2
| | | | | | | | | This warning is repeated 112 times when compiling with all warnings. xalloc.h:23:1: warning: function '__err_oom' could be declared with attribute 'noreturn' [-Wmissing-noreturn] Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/strutils: support two decimal places in size_to_human_string() outputKarel Zak2019-02-121-3/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: force to "never" mode on non-terminal outputKarel Zak2019-02-041-0/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: set blocksize when create a new deviceKarel Zak2019-01-221-0/+2
| | | | | | | | | | | 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-4/+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-0/+6
| | | | | | | 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-3/+0Star
| | | | | | | | | 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/+1
| | | | | | | | 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>
* Merge branch '2018wk48' of https://github.com/kerolasa/util-linuxKarel Zak2018-12-101-1/+1
|\ | | | | | | | | * '2018wk48' of https://github.com/kerolasa/util-linux: include/c: check returns_nonnull function attribute with __GNUC_PREREQ
| * include/c: check returns_nonnull function attribute with __GNUC_PREREQSami Kerola2018-12-021-1/+1
| | | | | | | | | | | | | | | | | | Karel pointed out previous commit could have been better in github feedback, so lets use the version check macro instead of compare versions directly. Previous-commit: f1b327f8d5c8de7bf7fae99e85765d0954a25bac Reference: https://github.com/karelzak/util-linux/pull/704#issuecomment-432605211 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* | include/list: add list_entry_is_first() and list_count_entries()Karel Zak2018-12-071-0/+21
| | | | | | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* | lib/path: allow to close dirfdKarel Zak2018-12-071-0/+2
| | | | | | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* | lib/sysfs: add function to detect partitioned devicesKarel Zak2018-12-071-0/+1
| | | | | | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* | lib/timer: add fallback if timer_create() not availableKarel Zak2018-12-031-2/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* | include/c: re-add type checking in container_of()Ruediger Meier2018-12-031-2/+2
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts parts of commit eb06d5d4, which seems to be based on Linux kernel commit c7acec71. Unlike the original kernel patch we did not add that even stronger type checking by using macro BUILD_BUG_ON_MSG. So basically we removed a useful warning when compiling such broken code: struct st { int a; char b; }; struct st t = { .a = 1, .b = 2 }; struct st *x = container_of(&t.a, struct st, b); printf("%p %p\n", (void *)&t, (void *)x); Moreover we also introduced a new compiler warning for intel/icc: "arithmetic on pointer to void or function type" Let's just revert the update of container_of() because adding a kernel-like BUILD_BUG_ON_MSG would be too much noise and also problematic (see kernel commit c03567a8). Also note that the original problem addressed by the kernel commit seems to be only reproducible with gcc 4.9, not with any later gcc nor clang,icc. Moreover, currently we have no such use-case in the UL sources anyways. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* include/c: use returns_nonnull function attribute in xalloc.hSami Kerola2018-11-212-5/+13
| | | | | | | | Let the compiler optimize based on the knowledge that the return value will never be null. Reference: https://patchwork.ozlabs.org/patch/281112/#631159 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* rtcwake: use poweroff if shutdown is not foundJustin Chen2018-11-061-0/+1
| | | | | | | Some systems do not have the shutdown command. Use poweroff as an alternative. Signed-off-by: Justin Chen <justinpopo6@gmail.com>
* include/c: add str2memcpy() and mem2strcpy()Karel Zak2018-10-031-0/+28
| | | | | | | | str2memcpy() - copy zero terminated string to optionally terminated buffer mem2strcpy() - copy from buffer to zero terminated string Signed-off-by: Karel Zak <kzak@redhat.com>
* include/ttyutils: define values if missing.Sevan Janiyan2018-10-031-0/+34
| | | | | | | Upstreamed from pkgsrc. Addresses: https://github.com/karelzak/util-linux/pull/695 Signed-off-by: Karel Zak <kzak@redhat.com>
* include/c: add NAME_MAX compatSevan Janiyan2018-10-031-0/+4
| | | | | | | Upstreamed from pkgsrc. Addresses: https://github.com/karelzak/util-linux/pull/695 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: return from xstrmode()Karel Zak2018-09-141-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Add built in fallbacks for motd fileLudwig Nussel2018-09-071-1/+1
| | | | | | | | | | | | | | | Use several locations for built in default for motd to allow for e.g. run time generated motd without having to modify config files. login.c already splits by colon. /usr/share/misc/motd - chould be shipped by distributions /run/motd - potentially run time created file with dynamic information /etc/motd - for the admin fill with local information Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
* lib/mangle: const quialifier cleanupKarel Zak2018-07-201-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include/list, include/c: update and container_of()Karel Zak2018-07-202-7/+12
| | | | | | | | * update container_of() to version without "const" qualifier * use container_of() in list_entry() Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: const qualifier cleanupKarel Zak2018-07-201-2/+2
| | | | | | | | * use "const" in functions where we don't modify arguments * use "const" when cast from const buffer to any struct (superblock etc.) Signed-off-by: Karel Zak <kzak@redhat.com>
* include/all-io: const cleanupKarel Zak2018-07-201-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include/strutils: remove unnecessary castKarel Zak2018-07-201-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include/path: make sure PATH_MAX is definedKarel Zak2018-06-211-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: allow dir-path formattingKarel Zak2018-06-211-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsblk: use prefix for DM nameKarel Zak2018-06-211-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: cleanup function namesKarel Zak2018-06-211-2/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: add ul_prefix_fopen(), improve cpuset funcsKarel Zak2018-06-211-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: add ul_path_read_buffer()Karel Zak2018-06-211-0/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: add ul_path_get_abspath()Karel Zak2018-06-211-0/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add sysfs_blkdev_get_parent()Karel Zak2018-06-211-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path lib/sysfs: add debugKarel Zak2018-06-212-0/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: use new ul_path_* APIKarel Zak2018-06-211-3/+2Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add ul_new_sysfs_path() shortcutKarel Zak2018-06-211-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: new implementationKarel Zak2018-06-211-75/+50Star
| | | | | | | | | * 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-211-27/+106
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* include/pt-mbr.h: fix integer overflowSami Kerola2018-05-281-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | gcc -fsanitize=undefined gives following warning. include/pt-mbr.h:27:51: runtime error: left shift of 248 by 24 places cannot be represented in type 'int' It looks like char is converted internally to int before bit-shift, and that type overflows when char value is greater than 127. Following code snippet will show the effect what is stored when undefined behaviour happens. #include <stdio.h> #include <inttypes.h> int main(int argc, unsigned char **argv) { char p[] = { 170, 170, 170, 170 }; unsigned int uint = p[3]; uint64_t res = 0; /* overflow */ res = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); printf("%" PRIu64 "\n", res); /* this is fine */ res = 0; res = p[0] | (p[1] << 8) | (p[2] << 16) | (uint << 24); printf("%" PRIu64 "\n", res); return 0; } I tested gcc 8.1.0, clang 6.0.0, and tcc 0.9.27 and they all printed the same values. $ ./a.out 18446744073709551530 4294967210 Because output is result of undefined behavior what is stored may change in future, and other compilers / version might do something different. In the case of what pt-mbr.h the destination data type size was commonly 32 bits in size, that truncated excess rubbish from bitshift. Needless to say that was not very robust code. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* script: add more info to script headerKarel Zak2018-05-141-0/+1
| | | | | | | | | | | | | | | | 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-0/+2
| | | | | | | | | | | | | | | | | | 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>