summaryrefslogtreecommitdiffstats
path: root/include
Commit message (Collapse)AuthorAgeFilesLines
...
* 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>
* closestream: remove dummy function __fpending()Sami Kerola2018-03-271-9/+7Star
| | | | | | | | Exclude __fpending() from build when function is not available. This is more obvious than adding a dummy function and expecting compiler to eliminate it as dead code. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libblkid: ignore private Stratis devicesTony Asleson2018-03-091-1/+1
| | | | | | | | [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>
* include/c: add errexec()Karel Zak2018-02-011-0/+6
| | | | | | | | | | | | | | | | The new errexec() macro consolidate and unify the way how util-linux tools react to failed exec()-like functions: * exit code 126 when program located, but not usable * exit code 127 when could not find program to exec The exit codes are compatible with coreutils. Note that all the change is located in c.h; the file exitcodes.h contains API specific (mkfs, fsck, ...) codes only. Addresses: https://github.com/karelzak/util-linux/pull/311 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/exec_shell: cleanup function attributesKarel Zak2018-02-011-1/+6
| | | | | Reported-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* cal: Use ALTMON_* correctlyRafal Luzynski2018-01-221-0/+30
| | | | | | | | | | | cal: use ALTMON_* and _NL_ABALTMON_* constants to display months in a standalone form correctly. These constants have just been newly added to glibc. ALTMON_x has been used in BSD family since 1990s and has been accepted as the future POSIX extension. _NL_ABALTMON_* is exclusively a GNU extension but it is expected to be added to POSIX in future. More info: https://sourceware.org/bugzilla/show_bug.cgi?id=10871
* include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()Karel Zak2018-01-171-7/+12
| | | | | | | 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>
* include/debug: improve debug messageKarel Zak2018-01-121-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include/debug: print info when addresses suppressedKarel Zak2018-01-121-1/+3
| | | | | Suggested-by: Peter Cordes <peter@cordes.ca> Signed-off-by: Karel Zak <kzak@redhat.com>
* include/debug: don't print pointer address for SUID programsKarel Zak2018-01-123-16/+34
| | | | | | | | | | | | | | | | * introduce new flag __UL_DEBUG_FL_NOADDR to suppress pointer address printing * use __UL_DEBUG_FL_NOADDR when SUID * move ul_debugobj() to debugobj.h, and require UL_DEBUG_CURRENT_MASK to provide access to the current mask from ul_debugobj(). It's better than modify all ul_debugobj() calls and use the global mask as argument. * remove never used UL_DEBUG_DEFINE_FLAG Reported-by: halfdog <me@halfdog.net> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/md5: use ul_/UL_ prefixKarel Zak2017-12-121-15/+10Star
| | | | | | | The symbols names are too generic. Addresses: https://github.com/karelzak/util-linux/issues/548 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sha1: use ul_/UL_prefix for symbolsKarel Zak2017-12-121-34/+15Star
| | | | | | | | Unfortunately, the symbols are visible in statically compiled libuuid and the names are too generic. Addresses: https://github.com/karelzak/util-linux/issues/548 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/signames: remove unused functionSami Kerola2017-11-281-1/+0Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/mbsalign: add mbs_invalid_encode()Karel Zak2017-11-221-0/+3
| | | | | | Like mbs_safe_encode(), but it does not care about control chars. Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: add missing includeKarel Zak2017-11-161-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: Add simple crc32c() functionJohn Groves2017-11-161-0/+9
| | | | | | | | Source: freebsd/sys/libkern/crc32.c This code is an unmodified fragment from the source. Will fixup comments / naming in next commit Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/timeutils: add common ISO timestamp masksJ William Piggott2017-11-101-9/+17
| | | | | | | | | | | | | | | | | | | | | | * Start the ISO format flags at bit 0 instead of bit 1. * Remove unnecessary _8601 from ISO format flag names to avoid line wrapping and to ease readability. * ISO timestamps have date-time-timzone in common, so move the TIMEZONE flag to bit 2 causing all timestamp masks to have the first three bits set and the last four bits as timestamp 'options'. * Change the 'SPACE' flag to a 'T' flag, because it makes the code and comments more concise. * Add common ISO timestamp masks. * Implement the ISO timestamp masks in all applicable code using the strxxx_iso() functions. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* lib/timeutils: add get_gmtoff()J William Piggott2017-11-101-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This new function returns the GMT offset relative to its argument. It is used in this patch to fix two bugs: 1) On platforms that the tm struct excludes tm_gmtoff, hwclock assumes a one hour DST offset. This can cause an incorrect kernel timezone setting. For example: Master branch tested with tm_gmtoff illustrates the correct offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494204.192398, -660) Master branch tested without tm_gmtoff has an incorrect offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494249.193852, -690) Patched tested without tm_gmtoff has the correct offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494260.194208, -660) 2) ISO 8601 'extended' format requires all time elements to use a colon (:). Current invalid ISO 8601: $ hwclock 2017-10-08 16:25:17.895462-0400 Patched: $ hwclock 2017-10-08 16:25:34.141895-04:00 Also required by this change: login-utils/last.c: increase ISO out_len and in_len by one to accommodate the addition of the timezone colon. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* lib/timeutils: ISO_8601_BUFSIZ too smallJ William Piggott2017-11-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Although iso-8601 specifies years as 4 digits, it allows them to be wider. The current POSIX year width is limited by 'int tm_year' at 10 digits plus a negative sign. That, and the possibility of nanosecond time makes the widest POSIX iso-8601 time 41 characters. Plus the \0 string terminator yields a buffer size of 42. Before truncated output: /sbin/hwclock --utc --noadjfile --predict --date '-2147483765 years' -2147481748-09-25 20:29:45.0000 Patched: ./hwclock --utc --noadjfile --predict --date '-2147483765 years' -2147481748-09-25 20:17:21.000000-0456 ./hwclock --utc --noadjfile --predict --date '-2147483766 years' hwclock: invalid date '-2147483766 years' Comparable to coreutils 'date' command: date -Ins --date '-2147483765 years' -2147481748-09-25T19:49:31,578899297-0456 date -Ins --date '-2147483766 years' date: invalid date '-2147483766 years' The 'date' output illustrates the full 41 character POSIX iso-8601 Signed-off-by: J William Piggott <elseifthen@gmx.com>
* agetty: add support for /etc/issue.dKarel Zak2017-11-071-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | The /etc/issue file has been originally designed to inform users about the system (version, name, etc.). In last years is growing number of additional tools (containers, maintenance tools and interfaces, ...) and many admins and downstream maintainer want to add some tool specific hints to the issue file, but it mess to share one file between more packages and/or scripts. The solution is /etc/issue.d directory. The directory is extension to the standard system /etc/issue. The /etc/issue file has to exist, otherwise the directory will be ignored. It means "rm /etc/issue" (or --onissue) is still the way how keep our system silent independently on 3rd-party installed files in the /etc/issue.d directory. The content of the files in the directory are printed after content of the /etc/issue. The files are printed in version-sort order and .issue file extension is required (00-foo.issue 01-bar.issue ...). The change is backwardly compatible. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/mangle: return size of the decoded bufferKarel Zak2017-11-011-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Fix typo in carefulputc.hNik Nyby2017-10-251-3/+3
| | | | Signed-off-by: Nik Nyby <nikolas@gnu.org>
* lib/path: make path_set_prefix() independent on cpu_set_tKarel Zak2017-10-231-5/+4Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/signames: remove signame array from header fileKarel Zak2017-10-231-126/+3Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* signames: Make input char buffers constNiklas Hambüchen2017-10-141-1/+1
|
* kill: Extract signal names into signames.h/signames.cNiklas Hambüchen2017-10-142-0/+133
|
* losetup: Add support for logical block sizeStanislav Brabec2017-09-271-0/+3
| | | | | | | | | | | | | | | | | | | | Kernel since 4.14 supports setting of logical block size[1]. It allows to create loop devices that report logical block size different from 512. Add support for this feature to losetup. References: [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/block/loop.c?id=89e4fdecb51cf5535867026274bc97de9480ade5 [kzak@redhat.com: - fix loopcxt_get_blocksize() - remove lo_blocksize from loop_info64] Signed-off-by: Stanislav Brabec <sbrabec@suse.cz> Cc: Ming Lei <ming.lei@redhat.com> Cc: Hannes Reinecke <hare@suse.com> Cc: Omar Sandoval <osandov@fb.com> Cc: Jens Axboe <axboe@kernel.dk> Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: fix non-blkid compilationKarel Zak2017-09-191-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/pwdutils: add xgetlogin()Karel Zak2017-09-181-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* login: add xgetpwnam()Karel Zak2017-09-182-0/+11
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* hwclock: update usage()J William Piggott2017-09-051-1/+1
| | | | | | Improve usage strings for debug and version. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* libuuid: add support for hash-based UUIDsPhilip Prindeville2017-09-052-0/+47
| | | | | | | | | Adding V3 and V5 UUIDs per RFC-4122. [kzak@redhat.com: - fix symbols file] Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* rfkill: make programming style to match util-linux projectSami Kerola2017-08-301-0/+4
| | | | | | | | Use the usual facilities, add translation strings, move global variables at the beginning of the file, make usage() look as expected, add standard command-line option parsing. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* fdisk: use strutils to trim whitespace from inputVaclav Dolezal2017-08-291-1/+1
| | | | Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
* include: move pamfail.h to auth.cSami Kerola2017-08-052-27/+0Star
| | | | | | | This removes one small header file, and makes inline function to static to only file it is used in. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* build: use --runstatedir instead of --localstatedirAndreas Henriksson2017-07-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The util-linux code was previously aligned to use @localstatedir@ and the util-linux build system was set to override the default to use /run. Current GNU Coding Standards introduced the @runstatedir@ variable for this purpose. Lets use that instead. The GNU default for @runstatedir@ is ${localstatedir}/run so util-linux still override the default to be /run to preserve the status quo from before. The only difference is that you'll now pass --runstatedir to override the location on the command line instead of --localstatedir. (FWIW, Debhelper in compat 11 will automatically start passing --runstatedir=/run to all autotools configured builds. It already passes --localstatedir=/var (to avoid it ending up with the GNU default /usr/local/var) which breaks the util-linux build system code that tries to default it to /run. This change will thus allow util-linux and debhelper to work better together and avoid the need for a package-specific override.) Relevant historic commits: * commit 07a16b9d1e5a48550a0d19abb9a900853433ffa2 "build-sys: change --localstatedir to /run" * commit 80c51185d50f00a2701f9379f10fc48a0f885dfc "uuidd: use run configured state directory" * commit 01c5b787947aeaffc7e56000827e3edefa357c59 "agetty: use configured run state directory" [kzak@redhat.com: - add $runstatedir fallback for autoconf < 2.70 - check for unmodified $localstatedir] CC: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Andreas Henriksson <andreas@fatal.se> Signed-off-by: Karel Zak <kzak@redhat.com>
* partx: move partx.h to include/Karel Zak2017-07-142-0/+63
| | | | | | Let's make the ioctls usable also for libfdisk. Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: don't use CDROM_GET_CAPABILITY ioctl for DM devicesKarel Zak2017-07-121-1/+1
| | | | | | | | | For some reason kernel commit e980f62353c697cbf0c4325e43df6e44399aeb64 add extra warning when the ioctl is used for DM devices. It seems we can avoid this ioctl when the device has dm/uuid. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1469532 Signed-off-by: Karel Zak <kzak@redhat.com>