summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* misc: fix redundant assignment and reassignments before use [cppcheck]Sami Kerola2015-08-081-1/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/blkdev: use 64-bit to count size in bytesKarel Zak2015-08-051-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/timeutils: fix indention [smatch scan]Karel Zak2015-08-051-6/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: fix test_colors buildKarel Zak2015-07-241-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libsmartcols: don't link with tinfoKarel Zak2015-07-243-36/+54
| | | | | | | Let's move color names to sequence translation to separate file to make it usable without all the stuff in lib/colors.c. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/procutils: add proc_get_cmdline()Karel Zak2015-07-201-0/+31
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lslogins: merge read_utmp() codeKarel Zak2015-07-162-80/+1Star
| | | | | | | The code is used only in lslogins, so it does not make sense to maintain it in libcommon. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: make strmode() more genericKarel Zak2015-06-301-17/+19
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* rtcwake: improve read_clock_mode()Sami Kerola2015-06-291-0/+12
| | | | | | | | Make skipping two lines more robust, and add message about unexpected adjfile contents when running with --verbose. Reviewed-by: Karel Zak <kzak@redhat.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* sys-utils/disk-utils/lib: fix printf format types [cppcheck]Boris Egorov2015-06-251-3/+3
| | | | | | Fix 'invalidPrintfArgType' cppcheck warnings Signed-off-by: Boris Egorov <egorov@linux.com>
* procutils: reset errno before readdirRuediger Meier2015-06-161-0/+1
| | | | | | | readdir(3p): "When the end of the directory is encountered, a null pointer shall be returned and errno is not changed" Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* losetup: be careful with errnoKarel Zak2015-06-151-0/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: Use dup_fd_cloexec instead of direct call to fcntlGuillem Jover2015-06-081-1/+1
| | | | Signed-off-by: Guillem Jover <guillem@hadrons.org>
* lib/fileutils: Add new dup_fd_cloexec functionGuillem Jover2015-06-081-0/+30
| | | | | | | | This function duplicates and marks a file descriptor as close-on-exec. Takes care of build and run-time support for the fcntl F_DUPFD_CLOEXEC command, and other errors. Signed-off-by: Guillem Jover <guillem@hadrons.org>
* lsblk: use internally sysfs devnamesKarel Zak2015-05-291-2/+4
| | | | | | | It seems better to keep the strange sysfs devnames internally and translate to real devnames only on output or when we read from /dev. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: rename devname functions, cleanupKarel Zak2015-05-281-9/+25
| | | | | | | | | | | | | | | | | | Well, I don't have mental power to use function names like sysfs_devname_to_dev_name() so this patch renames to sysfs_devname_sys_to_dev() sysfs_devname_dev_to_sys() It also cleanups usage of the functions. We have to be sure that sysfs.c code returns regular devnames. The existence of the sysfs devnames (with '!') should be completely hidden in sysfs specific code. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: Fix /dev to /sys node name translationStanislav Brabec2015-05-281-2/+6
| | | | | | | | | | | | | | | d0dc6c1 introduced translation of /sys names to /dev names, as required by the kernel linux/drivers/base/core.c: device_get_devnode(). But there are other places of code that use /dev names in /sys. They need reverse translation from '/' to '!'. For example, fdisk -l returns empty list since a22c6eb for device nodes in subdirectories (used e. g. by cciss driver). Introduce yet another helper sysfs_dev_name_to_devname() and use it where appropriate. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* Fix /sys to /dev node name translationStanislav Brabec2015-05-261-0/+2
| | | | | | | | | | | | | | linux/drivers/base/core.c: device_get_devnode() defines a translation of '!' in sysfs nodes to '/' in /dev nodes. The same translation has to be done to properly support device nodes with slash (e. g. device nodes of cciss driver and several other drivers). Introduce new helper sysfs_devname_to_devno() and use it where appropriate. Fixes for example lsblk -f on devices using cciss driver. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* lib/strv: add new functions (from systemd)Karel Zak2015-05-154-1/+495
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: fix string_add_to_idarray() int vs. size_tKarel Zak2015-04-221-3/+2Star
| | | | | | | | | | | | | | | | | | | | The function uses "int" as argument, but for array size (and index) is better to use unsigned type (size_t). If we mix "size_t" in util (e.g. fdisk) and "int" in lib/strutils.c then result is unexpected behavior on ppc64. # sfdisk --list -o DEVICE,START,SIZE /dev/sdb Disk /dev/sdb: 50 MiB, 52428800 bytes, 102400 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 32768 bytes Disklabel type: gpt Disk identifier: 3B8559DB-33AF-43E9-BEFC-C331D829B539 lt-sfdisk: libfdisk/src/label.c:178: fdisk_label_get_field: Assertion `id > 0' failed. The patch cleanup all code to use size_t everywhere. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs.c: use fcntl(..F_DUPFD_CLOEXEC) instead of dup(2)Cristian Rodríguez2015-04-141-1/+1
| | | | | "The two descriptors do not share file descriptor flags (the close-on-exec flag). The close-on-exec flag for the duplicate descriptor is off"
* lib/timer: use separate file for timersKarel Zak2015-03-062-38/+49
| | | | | | | | It seems that static builds require -lpthread for timer_* functions. It's better to keep it out of our libs (e.g. libmount) to avoid unnecessary dependence. Signed-off-by: Karel Zak <kzak@redhat.com>
* flock: fix timeout handler pointer usageKarel Zak2015-03-051-2/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* flock: improve timeout handlingSami Kerola2015-03-051-0/+34
| | | | | | | | | | | | Signal ALRM raised by the timer, and the timer only, will be considered as a timeout criteria. Secondly time interval is made to use monotonic clock. Documentation of ITIMER_REAL is unclear whether that time is affected various sources of clock skew, or does it even tick when system is suspended. Reviewed-by: Karel Zak <kzak@redhat.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/colors: use libtinfo to check terminal capabilityKarel Zak2015-02-272-5/+44
| | | | | | | | | | | | | | | The current implementation assumes that all terminals supports colors and users are forcet to use terminal-colors.d/ to disable colors for some terminals. This patch checks for maximal supported colors for the current terminal and colors are automatically disabled for terminals like vt100. The patch moves lib/colors.c from libcommon.la to libtcolors.la to avoid collisions with another utils. Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: add --disable-colors-defaultKarel Zak2015-02-251-2/+11
| | | | | | | | The current util-linux is to have enabled colorized outputs by default, this default behavior is possible to change by new configure option --disable-colors-default. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: extend parse_switch() to accept more optionsKarel Zak2015-02-241-6/+24
| | | | | | | * allow to specify more 0|1 pairs * allow to specify error message Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: move parse_switch() from setterm(1) to librarySami Kerola2015-02-241-0/+8
| | | | | | | To allow sharing the code with other utilities. Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: accept not just 'B' but also lowercase 'b' in a size suffixBenno Schulenberg2015-02-021-2/+2
| | | | | | | Just line 'M' and 'm' are accepted for mega, 'G' and 'g' for giga, 'S' and 's' for sectors, and so on. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* lib/sysfs: use ssize_t for sysfs_readlink() [coverity scan]Karel Zak2015-01-281-4/+3Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* docs: fix two "maybe be" duplications in program commentsBenno Schulenberg2015-01-261-5/+2Star
| | | | | | Also improve the grammar of the comments and some neighbours. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* build-sys: fix make checkincludes warningsSami Kerola2015-01-071-8/+4Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib: fix crc32 and crc64 interger overflows [AddressSanitizer]Sami Kerola2014-12-192-2/+5
| | | | | | | | | | lib/crc32.c:111:11: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'size_t' (aka 'unsigned long') lib/crc64.c:101:12: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'size_t' (aka 'unsigned long') Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/mbalign: fix unsigned integer overflow [AddressSanitizer]Sami Kerola2014-12-191-1/+1
| | | | | | | | | This error was reported 155 times. lib/mbsalign.c:322:18: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'size_t' (aka 'unsigned long') Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* docs: fix the grammar of the recent comment about commentsBenno Schulenberg2014-12-191-2/+3
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* terminal-colors.d: add note about comments to man pageKarel Zak2014-12-121-0/+4
| | | | | Reported-by: Jan Pokorný <jpokorny@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add subsystem and hotplug detectionKarel Zak2014-12-021-1/+152
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: use static buffers when parse schemeKarel Zak2014-11-211-19/+29
| | | | | | | * use static buffers when parse scheme colors * cleanup deallocation on error in sequence parser Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: fix double free on error pathAndreas Henriksson2014-11-191-3/+5
| | | | | | | | | | | | The error path was a bit unclear on the semantics. The seq argument would get freed but not the name argument. Then the caller frees them both when the function returns an error. This fixes the problem my making the function not touch the arguments unless we're going to return success. Also improve the description for this function to make it more obvious what the callers should expect. Addresses: CID#77487 (on scan.coverity.com for JIghtuse/util-linux) Signed-off-by: Andreas Henriksson <andreas@fatal.se>
* build-sys: move all around clock_gettime() to monotonic.cKarel Zak2014-11-192-25/+27
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: use monotonic time rater than gettimeofdayKarel Zak2014-11-181-0/+23
| | | | | | Based on patch Alexander Samilovskih <alexsamilovskih@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* tests: fix memory leak [AddressSanitizer]Sami Kerola2014-11-181-0/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/loopdev: remove test programKarel Zak2014-11-042-154/+0Star
| | | | | | | All is already covered by losetup and mount. The test program has never been used in our regression tests. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: replace custom DBG() with include/debug.hKarel Zak2014-11-041-102/+88Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* docs: update info about env debug variablesKarel Zak2014-11-031-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include/debug: fix typoKarel Zak2014-10-241-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* terminal-colors.d: add debug stuffKarel Zak2014-10-222-12/+63
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* terminal-colors.d: fix filter by nameKarel Zak2014-10-221-3/+2Star
| | | | | Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=766077 Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: "ambivalent" applies to intentions, "ambiguous" to resultsBenno Schulenberg2014-10-011-1/+1
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* lslogins: free after error [coverity scan]Karel Zak2014-09-261-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>