summaryrefslogtreecommitdiffstats
path: root/include
Commit message (Collapse)AuthorAgeFilesLines
* Remove isascii usageRosen Penev2019-08-081-1/+3
| | | | | | | There is a c_isascii function that can be used. isascii is deprecated and not available with some libcs like uClibc-ng where it can be compile time disabled.
* include/xalloc: ensure xstrdup() and xstrndup() returns nonnull attributeSami Kerola2019-07-141-4/+2Star
| | | | | | | Turned out lsblk is passing null as argument to xstrdup(), so fix that and add assert() to make sure promise of not returning null is kept in future. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* Merge branch 'topic/wdctl'Karel Zak2019-06-171-3/+1Star
|\
| * wdctl; read from /sys if necessaryKarel Zak2019-06-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | The device can be inaccessible for non-root user or busy (already used by another process). In this case it seems better to read information from /sys. Note that /sys does not provide struct watchdog_info.options, so we cannot print list of supported watchdog features. Addresses: https://github.com/karelzak/util-linux/issues/804 Signed-off-by: Karel Zak <kzak@redhat.com>
| * wdctl: default to /dev/watchdog0Karel Zak2019-06-171-3/+0Star
| | | | | | | | | | | | | | Let's use miscdev /dev/watchdog as fallback only. We need (if possible) cdev /dev/watchdog0 as this device has entry in /sys/class/watchdog. Signed-off-by: Karel Zak <kzak@redhat.com>
* | include/closestream: avoid close more than onceKarel Zak2019-06-171-2/+5
|/ | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/ttyutils: introduce get_terminal_stdfd()Karel Zak2019-05-272-0/+3
| | | | | | Let's use separate function to detect what is the current terminal. Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: (sgi) improve checksum calculation [-Waddress-of-packed-member]Karel Zak2019-05-221-6/+11
| | | | | | | | Let's keep compilers and static analyzers happy. The idea is to use memcpy() to copy from buffer to variable and use all label as unsigned char rather than vectorize by uint32_t. Signed-off-by: Karel Zak <kzak@redhat.com>
* include/c: use __has_attributeKarel Zak2019-05-211-12/+19
| | | | | | | | | | | | | | The __has macros are more portable (supported by gcc as well as clang). The old __GNUC_PREREQ is deprecated and it should be removed in future. (Well, the __has macros are supported since gcc 5, so we should be patient as some old stable distros (e.g. RHEL 7) use gcc 4.x). This patch helps clang to correctly analyze our xalloc.h stuff. Signed-off-by: Karel Zak <kzak@redhat.com>
* include/strutils: fix potential null pointer dereferenceSami Kerola2019-05-161-1/+3
| | | | | | | | Recent lscpu fix caused gcc -Wnull-dereference to go off that this change addresses. Reference: b94acada9ed0e11a7e82f8f60280c5b6058e4250 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lscpu: move trailing null after removing characters from a stringSami Kerola2019-05-161-0/+1
| | | | | | | | | From the test input string ':' characters are removed: cat x86_64-epyc_7451/sys/devices/system/cpu/vulnerabilities/spectre_v2 Mitigation: Full AMD retpoline, IBPB: conditional, STIBP: disabled, RSB filling Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* build-sys: use __SANITIZE_ADDRESS__ rather than custom USE_CLOSE_ATEXITKarel Zak2019-05-071-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* 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>