summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* lib/parse-date: don't use xalloc in lib-like codeKarel Zak2017-05-121-3/+12
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: remove duplicate includesKarel Zak2017-05-121-1/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/mbsedit: fix typo in commentSami Kerola2017-05-101-1/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/timer: add commentKarel Zak2017-04-281-0/+17
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/timer.c: prevent pathological race conditionRasmus Villemoes2017-04-261-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | flock(1) uses the timer facility to interrupt a blocking flock(2) call. However, in a pathological case (or with a sufficiently short timeout), the timer may fire and the signal be delivered after the timer is set up, but before we get around to doing the flock(2) call. In that case, we'd block forever. Checking timeout_expired right before calling flock(2) does not eliminate that race, so the only option is to make the timer fire repeatedly. Having the timer fire after we've returned from flock(2) is not a problem, since we only check timeout_expired in case of EINTR (also, this firing after return could also happen with the current code). There is currently one other user of setup_timer (misc-utils/uuidd.c), but in that case the signal handler simply exits. Future users of setup_timer obviously need to ensure that they can tolerate multiple signal deliveries. Choosing 1% of the initial timeout as the repeating interval is somewhat arbitrary. However, I put a lower bound of 0.01s, since setting the interval much smaller than this may end up effectively live-locking the process, handling a never-ending stream of signals. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
* lib/timer.c: remove bogus SA_SIGINFO from timer_settime callRasmus Villemoes2017-04-261-1/+1
| | | | | | | | | The only valid flag for timer_settime is TIMER_ABSTIME, which we certainly don't want here. This seems to be harmless since timer_settime doesn't validate the flags parameter, TIMER_ABSTIME is universally 0x1, and no architecture has SA_SIGINFO == 1. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
* parse-date: remove extraneous form feedJ William Piggott2017-04-101-2/+0Star
| | | | | | * lib/parse-date.y: Remove extraneous form feed (FF, 0x0C, ^L). Signed-off-by: J William Piggott <elseifthen@gmx.com>
* Merge branch '2017wk13' of https://github.com/kerolasa/lelux-utiliteetitKarel Zak2017-04-041-1/+0Star
|\ | | | | | | | | | | | | | | * '2017wk13' of https://github.com/kerolasa/lelux-utiliteetit: docs: improve agetty.8 manual page agetty: make --remote to forward --nohostname as -H to login lib/cpuset: stop changing variable that is not read agetty: remove variable that is set but not read
| * lib/cpuset: stop changing variable that is not readSami Kerola2017-04-011-1/+0Star
| | | | | | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* | lib/strutils: fix typos in huge size suffixesKarel Zak2017-04-031-3/+3
|/ | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: fix characters reorder in login promptKarel Zak2017-03-271-4/+0Star
| | | | | | | | | | | | | | The current agetty uses TIOCSTI ioctl to return already read chars from login name back to the terminal (without read() before tcsetattr() we will lost data already written by user). The ioctl based solution is fragile due to race -- we can return chars when terminal already contains another new chars. The result is reordered chars in login name. The solution is to use extra buffer for already read data. Reported-by: Michael Tretter <m.tretter@pengutronix.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* Merge branch '2017wk11' of git://github.com/kerolasa/lelux-utiliteetitKarel Zak2017-03-242-9/+9
|\ | | | | | | | | | | | | | | | | * '2017wk11' of git://github.com/kerolasa/lelux-utiliteetit: blkid: add control struct blkid: simplify version option handling tests: add static keyword where needed [smatch scan] tests: do not use plain 0 as NULL [smatch scan] libsmartcols: fix test variable shadowing
| * tests: do not use plain 0 as NULL [smatch scan]Sami Kerola2017-03-172-9/+9
| | | | | | | | | | | | Likewise commit 87918040658f2fa9b1bf78f1f8f4f5c065a2e3a3. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* | Merge remote-tracking branch 'jwpi/hwclock-date7'Karel Zak2017-03-233-0/+1647
|\ \ | |/ |/| | | | | | | | | | | * jwpi/hwclock-date7: lib: add parse-date documentation hwclock: use parse_date function build-sys: add parse-date.y lib: add parse-date.y
| * build-sys: add parse-date.yKarel Zak2017-03-042-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | * add lib/parse-date.y to build system * add necessary autotools stuff to generate .c on the fly (autotools are smart enough to add generated file to tarball) * check for bison version by ./autogen.sh * add non-wanted junk to .gitignore With some modification by J William Piggott with regard to moving the parse-date API into timeutils.h Signed-off-by: J William Piggott <elseifthen@gmx.com>
| * lib: add parse-date.yJ William Piggott2017-03-041-0/+1645
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * include/timeutils.h Add parse-date API * lib/parse-date.y - new file Lib function that parses a date string into a timespec struct. Derived from gnulib-dd7a871 parse-datetime.y with these changes: * reduced to a single function API renamed to parse_date() * removed gnulib dependencies * removed debugging * converted to util-linux coding style * include/cctype.h - new file Like ctype.h only hard coded to the 'C' locale. Used by lib/parse-date.y. Derived from gnulib-dd7a871 c-ctype.h with these changes: * removed gnulib dependencies * converted to util-linux coding style * add requisite util-linux constants Signed-off-by: J William Piggott <elseifthen@gmx.com>
* | lib/colors: assert rathen than overflow [-Wnull-dereference]Karel Zak2017-03-131-1/+4
|/ | | | | | | | lib/colors.c: In function 'colors_read_schemes': lib/colors.c:412:7: warning: potential null pointer dereference [-Wnull-dereference] Reported-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/idcache: add void to function declaration [smatch scan]Sami Kerola2017-02-201-1/+1
| | | | | | | lib/idcache.c:29:29: warning: non-ANSI function declaration of function 'new_idcache' Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: add static keyword to where needed [smatch scan]Sami Kerola2017-02-202-2/+2
| | | | | | | text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be static? Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: do not use plain 0 as NULL [smatch scan]Sami Kerola2017-02-202-3/+3
| | | | | | | | | | text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer Since many 'struct option' has used zero as NULL make them more readable in same go by reindenting, and using named argument requirements. Reference: https://lwn.net/Articles/93577/ Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/mbsedit: add simple buffer editorKarel Zak2017-02-162-0/+223
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/randutils: glibc 2.25 has getrandom(2) declarationSami Kerola2017-02-131-1/+1
| | | | | | | Use correct header file to include the function. Reference: http://git.kernel.org/cgit/docs/man-pages/man-pages.git/commit/?id=2cbb6fb4e926e56dc3985b19ac02389321a0af5d Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* docs: Fix word repetitionsYuri Chornoivan2017-02-131-1/+1
|
* lib: add timegm() portability function to lib/timeutils.cSami Kerola2017-02-031-0/+19
| | | | | | | | | Local timegm() is a replacement function in cases it is missing from libc implementation. Hopefully the replacement is never, or very rarely, used. CC: Ruediger Meier <ruediger.meier@ga-group.nl> Reviewed-by: J William Piggott <elseifthen@gmx.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/strutils: return end pointer by isdigit_string()Karel Zak2017-01-281-2/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: test_linux_version is Linux onlyKarel Zak2017-01-041-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/linux_version: fix code indentionKarel Zak2017-01-041-35/+35
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: use unique ifdefs for testsKarel Zak2017-01-0415-32/+32
| | | | | | | Let's use unique TEST_PROGRAM_<NAME> ifdefs to make build system more robust. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/linux_version: add test for manual testingKarel Zak2017-01-022-0/+51
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/linux_version: fix stupid typoKarel Zak2017-01-021-1/+1
| | | | | | ... introduced by commit d404065a. Sorry. Signed-off-by: Karel Zak <kzak@redhat.com>
* Merge branch 'getrandom' of git://github.com/kerolasa/lelux-utiliteetitKarel Zak2016-12-221-16/+53
|\ | | | | | | | | * 'getrandom' of git://github.com/kerolasa/lelux-utiliteetit: lib/randutils: use getrandom(2) when it is available
| * lib/randutils: use getrandom(2) when it is availableSami Kerola2016-12-111-16/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | System call getrandom(2) is relatively new, available since kernel 3.17 but not supported by glibc 2.24. That in mind autotools is made to check availability of this function and keep old code as fallback. It is reasonable assume it will take years before the syscall(2) and fallback are unproblematic to remove. One might ask why bother using getrandom(2). Main reason is to avoid unnecessary system calls to achieve exactly same end result. That demonstrated with 'strace -c ./mcookie' showing 36 calls before, and 32 after this change. Secondly the getrandom(2) function got to kernel with promise it can be used to avoid file descriptor run down, and since uuidd uses random_get_bytes() it should fulfill it's promise here. Reference: http://man7.org/linux/man-pages/man2/getrandom.2.html Reference: https://lwn.net/Articles/606141/ Reviewed-by: Karel Zak <kzak@redhat.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* | docs: replace FTP by HTTPS in kernel.org URLsSébastien Helleu2016-12-191-1/+1
|/ | | | | | | The links to ftp://ftp.kernel.org/ are replaced by https://www.kernel.org/. Signed-off-by: Karel Zak <kzak@redhat.com>
* docs: various pages: Format pathnames as italic (.I)Michael Kerrisk2016-12-091-3/+3
| | | | | | | | | In the majority of pages, pathnames are formatted as Italic, which is the norm. However, there are several cases where they are formatted as bold. This patch fixes a number of those exceptions. Signed-off-by: Michael Kerrisk <mtk.man-pages@gmail.com>
* misc: spelling, always use "cannot" instead of "can not"Ruediger Meier2016-11-301-3/+3
| | | | | | Just to be consistent ... Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib,strutils: add strtoux[16|32|64]_or_err functionsHeiko Carstens2016-11-091-6/+38
| | | | | | | Add helper functions which allow to parse hexadecimal numbers. Based on a patch from Clemens von Mann. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
* lib/crc32: prefix public functionsGustavo Zacarias2016-10-191-2/+2
| | | | | | | | | | | Make the publicly-visible crc32 library functions prefixed by ul_, such as crc32() -> ul_crc32(). This is because it clashes with the crc32() function from zlib. For newer versions of glib (2.50+) zlib and libblkid are required dependencies and otherwise results in build failure when building statically. Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
* lib/randutils: remove unnecessary functionKarel Zak2016-10-041-9/+3Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/mbsalign: free buffer after error [coverity scan]Karel Zak2016-10-041-5/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libsmartcols: support multi-line cells based on line breaksKarel Zak2016-09-061-3/+9
| | | | | | | | | | Now libsmartcols completely control when and how wrap long lines/cells. This is sometimes user unfriendly and it would be nice to support multi-line cells where wrap is based on \n (new line char). This patch add new column flag SCOLS_FL_WRAPNL. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/randutils: add xsrand() and rand_get_number()Karel Zak2016-09-061-3/+15
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: Set errno in is_loopdev on errorTobias Stoeckmann2016-08-311-5/+6
| | | | | | | | | | | | | | The function is_loopdev does not set errno if the supplied string does not reference a valid loop device. Fix this to avoid an error message like this one: losetup: /: failed to use device: Success I prefer this one: losetup: /: failed to use device: No such device Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
* lib/pager: fix testKarel Zak2016-08-261-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/pager: restore signals setting by pager_close()Karel Zak2016-08-261-5/+23
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/pager: cleanup and extend APIKarel Zak2016-08-261-4/+51
| | | | | | | | | * clean up function names * add functions to temporary redirect to the pager and then restore original terminal output Signed-off-by: Karel Zak <kzak@redhat.com>
* loopdev: Implememt loopcxt_set_status()Stanislav Brabec2016-08-171-1/+35
| | | | | | | | | | | | Implement stand-alone loopcxt_set_status(). It allows manipulation with some loop device parameters even if it is initialized. Its function is limited by the kernel implementation, and only a small subset of changes is allowed. For more see linux/drivers/block/loop.c:loop_set_status() Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* losetup: add --nooverlap optionsKarel Zak2016-08-171-5/+9
| | | | | | | | | | | | | | | | | | | | | This patch introduces overlap detections and loop devices re-use for losetup(8). We already support this feature for mount(8) where it's enabled by default (because we mount filesystems and it's always mistake to share the same filesystem between more loop devices). Stanislav has suggested to enable this feature also for losetup by default. I'm not sure about it, IMHO it's better to keep losetup(8) simple and stupid by default, and inform users about possible problems and solutions in the man page. The feature forces losetup to scan all loop devices always when new one is requested. This maybe disadvantage (especially when we use control-loop to avoid /sys or /dev scans) on system with huge number of loop devices. Co-Author: Stanislav Brabec <sbrabec@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: always check setenv(3) return valueSami Kerola2016-08-121-1/+2
| | | | | | At least glibc setenv(3) can fail when system runs out of memory. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* blkdev: guard against missing DIOCGDINFO on FreeBSD 11Franco Fichtner2016-08-111-2/+2
| | | | | DIOCGMEDIASIZE is supported and available since FreeBSD 5, it may make sense to kill the backwards-glue completely instead.
* libmount: ignore redundant slashesKarel Zak2016-08-081-28/+72
| | | | | | | | | | | | | | | ///aaa/bbb and /aaa/bbb/ are the same paths. This is important especially with NFS where number of slashes are not the same in the /proc/self/mountinfo and fstab or utab. The regular URI is euler://tmp but /proc contains euler:/tmp Reported-by: Ales Novak <alnovak@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>