summaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)AuthorFilesLines
2012-08-13Fix non-Linux buildSamuel Thibault2-4/+7
loopdev.c, test_pager, and get_max_number_of_cpus() are linux-specific. get_linux_version will only work on Linux, let's introduce system_supports_ext4_ext2() which assumes that mounting ext2 with ext4 is not supported on non-Linux systems. [kzak@redhat.com: - use #ifdef SYS_sched_getaffinity rather than __linux__] Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-13lib/tt: always escape '\' to simplify parsing in scriptsKarel Zak1-14/+3
The commands echo(1) and printf(1) are usable for escape sequences decoding, for example for x in $(findmnt --noheading --raw --output TARGET); do printf "%b" $x done but it's necessary to escape all '\' chars, otherwise for example \b in foo\bar will be interpreted as backspace. It means that for example findmnt(8) has to use \x5c for the backslash. # findmnt --noheading --raw --output TARGET /dev/sda1 /mnt/ugly/foo\x5cbar Reported-by: Pádraig Brady <P@draigBrady.com> Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-08lib/tt: fix \x%02x usageKarel Zak1-4/+4
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-07include/tt: improve work with non-utf8 charsKarel Zak1-9/+23
Reported-by: Pádraig Brady <P@draigBrady.com> Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-06lib/tt: count read cells, improve \x?? hex encodingKarel Zak1-14/+161
* use wcwidth() to count real number of columns required for multibyte strings * encode control characters with \x?? in raw and export (NAME=data) outputs * use \x?? for controls and non-printable characters in the default outputs * use \x?? to encode already existing hex sequences, for example /mnt/ugly\x20space ---> /mnt/ugly\x5cx20space this is not used in the default output, but in raw/export outputs only (which is designed for scripts). Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-30build-sys: move tests to check_PROGRAMSKarel Zak1-3/+3
Thanks to Mike Frysinger. Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-26lib/strutils: add string_add_to_idarray() - parse and add to id listMilan Broz1-0/+27
Signed-off-by: Milan Broz <mbroz@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-16lib/match: fix compiler warning [-Wmissing-prototypes]Karel Zak1-0/+2
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-16translation: unify file open error messagesSami Kerola2-3/+3
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16lib/loopdev: minor bug fix: add missing semicolonSami Kerola1-1/+1
Missing semicolon made test_loop_info() to return function loopcxt_enable_debug() return value, which happen to be void. I suspect the loopcxt_enable_debug() was usually not executed, while it should be. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16lib/pager: minor compiler warning fixesSami Kerola1-1/+3
Add missing function prototype, and declare structure before use of it. lib/pager.c:162:6: warning: no previous prototype for function 'setup_pager' [-Wmissing-prototypes] lib/pager.c:20:29: warning: tentative definition of variable with internal linkage has incomplete non-array type 'struct child_process' [-Wtentative-definition-incomplete-type] Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-09fix buffer overrun in some calls to sscanfKarel Zak2-2/+2
Reported-by: Sergei Antonov <saproj@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-26build-sys: cleanup .gitignore filesKarel Zak1-1/+0
- move all binaries to top-level .gitignore - remove unnecessary */.gitignore files Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-26build-sys: convert lib/ to libcommon.laKarel Zak1-13/+42
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-26build-sys: define per-test -DTEST_PROGRAM in lib/Karel Zak1-4/+21
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-26build-sys: convert lib/ to moduleKarel Zak2-61/+64
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-21lib/loopdev: use warn_unused_result forimportant functionsKarel Zak1-24/+41
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-21lib/sysfs: use warn_unused_result for sysfs_init()Karel Zak1-1/+2
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-21lib/mangle: fix a memory leak in the test caseCong Wang1-2/+6
Marek reported there is a memory leak in lib/mangle.c CC mangle.o mangle.c:160:9: warning: Memory is never released; potential leak of memory pointed to by 'ss' This patch fixes it. Reported-by: Marek Otahal <markotahal@gmail.com> Cc: Karel Zak <kzak@redhat.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
2012-06-21lib/sysfs: check if cxt->dir_path is NULL in sysfs_readlink()Cong Wang1-0/+3
cxt->dir_path could be NULL, for example, when sysfs_init() fails, check this before calling readlink()/readlink_at(). Cc: Karel Zak <kzak@redhat.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
2012-06-17lib/mbsalign: abort() when non-expected case is encounteredSami Kerola1-0/+2
Fixes the following compiler warning (9 occurrences), and makes program to crash if mbsaligh() is called with unexpected align value (which would be programming error). ../lib/mbsalign.c:260:7: warning: switch missing default case [-Wswitch-default] Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-15lib/blkdev: return static strings by blkdev_scsi_type_to_name()Karel Zak1-22/+19
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-15Merge branch '2012wk23' of git://github.com/kerolasa/lelux-utiliteetitKarel Zak5-4/+54
* '2012wk23' of git://github.com/kerolasa/lelux-utiliteetit: lsblk: use blkdev_scsi_type_to_name() blkdev: add blkdev_scsi_type_to_name() wipefs: use symbolic value for markup mode eject: inform if CD-ROM drive is not ready docs: clean up partx.8 manual include: fix void pointer arithmetics warnings sysfs: fix printf format warnings build: fix unused parameter warnings build: fix redundant redeclaration warnings include: fix spurious list.h warnings uuidd: use output redirection which works [checkbashisms] blkid: fix realloc memory leak [cppcheck] setarch: do not use -1 as array index [cppcheck]
2012-06-12losetup: improve -a to report loopdevs < 512 bytesKarel Zak1-17/+95
# ll ~/xxx2 -rw-r--r-- 1 root root 500 Jun 12 14:30 /root/xxx2 old version: # losetup -a new version: # losetup -a /dev/loop0: [2052]:535312 (/root/xxx2) The new version scans /sys/block/loopN, kernel >= 2.6.37 is required otherwise fallback to the original not-so-smart /proc/partitions scan. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=730266 Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-11blkdev: add blkdev_scsi_type_to_name()Sami Kerola1-1/+47
Add a function, and necessary symbols, to convert scsi type id's to name strings. Reference: http://permalink.gmane.org/gmane.linux.utilities.util-linux-ng/5994 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-11sysfs: fix printf format warningsSami Kerola1-1/+1
sysfs.c:93:3: warning: format '%u' expects argument of type 'unsigned int *', but argument 3 has type 'int *' [-Wformat] sysfs.c:93:3: warning: format '%u' expects argument of type 'unsigned int *', but argument 4 has type 'int *' [-Wformat] Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-11build: fix unused parameter warningsSami Kerola2-2/+4
pager.c:203:14: warning: unused parameter 'argc' [-Wunused-parameter] pager.c:203:26: warning: unused parameter 'argv' [-Wunused-parameter] randutils.c:108:14: warning: unused parameter 'argc' [-Wunused-parameter] randutils.c:108:26: warning: unused parameter 'argv' [-Wunused-parameter] optstr.c:774:37: warning: unused parameter 'optstr' [-Wunused-parameter] optstr.c:774:51: warning: unused parameter 'value' [-Wunused-parameter] optstr.c:774:65: warning: unused parameter 'valsz' [-Wunused-parameter] optstr.c:774:79: warning: unused parameter 'next' [-Wunused-parameter] Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-11build: fix redundant redeclaration warningsSami Kerola1-0/+2
env.c:24:15: warning: redundant redeclaration of 'environ' [-Wredundant-decls] su.c:81:15: warning: redundant redeclaration of 'environ' [-Wredundant-decls] fstab.c:581:14: warning: redundant redeclaration of 'strsignal' [-Wredundant-decls] kill.h:1:13: note: previous declaration of 'get_pids' was here kill.c:152:13: warning: redundant redeclaration of 'get_pids' [-Wredundant-decls] kill.c:142:5: warning: redundant redeclaration of 'main' [-Wredundant-decls] getopt.c:89:5: warning: redundant redeclaration of 'main' [-Wredundant-decls] agetty.c:536:15: warning: redundant redeclaration of 'optarg' [-Wredundant-decls] agetty.c:537:13: warning: redundant redeclaration of 'optind' [-Wredundant-decls] script.c:161:13: warning: redundant redeclaration of 'optind' [-Wredundant-decls] wall.c:96:13: warning: redundant redeclaration of 'optind' [-Wredundant-decls] libmount.h:362:26: note: previous declaration of 'mnt_update_get_fs' was here libmount.h:454:26: note: previous declaration of 'mnt_context_get_fs' was here mountP.h:383:26: warning: redundant redeclaration of 'mnt_context_get_fs' [-Wredundant-decls] mountP.h:398:26: warning: redundant redeclaration of 'mnt_update_get_fs' [-Wredundant-decls] Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-05Merge branch '2012wk22' of git://github.com/kerolasa/lelux-utiliteetitKarel Zak1-3/+9
* '2012wk22' of git://github.com/kerolasa/lelux-utiliteetit: docs: clean up getopt.1 manual docs: clean up dmesg.1 manual docs: clean up chcpu.8 manual fileutils: xmkstemp() interface change docs: fix all man page groff warnings tools: add checkmans.sh docs: clean up wdctl.8 manual docs: clean up login.1 manual login: allow TTYGROUP name begin by number build-sys: add su executable to .gitignore logindefs: change getlogindefs_num() to return unsigned long Conflicts: login-utils/su.c sys-utils/dmesg.1
2012-06-05lib/strutils: circumvent missing localeconv()maximilian attems1-1/+1
Add stub too nls.h, include it instead of locale.h. Code in strutils handles already returned NULL. Signed-off-by: maximilian attems <max@stro.at>
2012-06-02fileutils: xmkstemp() interface changeDave Reisner1-3/+9
We can not let the user control where TMPDIR is for this tempfile. This will be where we write the updated passwd file, and must be capable of being moved atomically with rename(2). Therefore, it cannot be on a different device, or setpwnam() and vipw/vigr programs will invariably fail with EXDEV. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-05-29lib/pager: repair build for non-Linux.Thomas Schwinge1-1/+1
Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
2012-05-28libmount: add MNT_ERR_LOOPDEVKarel Zak1-0/+4
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-22lib/tt: export tt_fputs_{quoted,nonblank} functionKarel Zak1-4/+4
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-15lib/strutils: create type specific strtoxx_or_err()Karel Zak1-21/+74
We need [un]signed int ([u]int32_t) on many places. It's also more readable and robust to use uintXX_t types than for example "long long". Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-15include: move get_terminal_width() to ttyutils.hPetr Uzel1-27/+1
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-15include: rename writeall.h to all-io.hPetr Uzel1-1/+1
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-15lib/mangle: check for end of string on every iterationDave Reisner1-4/+5
Checking for the null byte at the end of the string only conditionally leads to segfaults, evidenced by mount helpers crashing on writes to /run/mount/utab. Simply check for the null on each iteration, and append a null byte to the mangled string before breaking. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-10libuuid: avoid double open and leaking fd (reworked)Petr Uzel1-5/+3
This reverts commit 6126f7a53c57485a9a29ddd772765695f23c92e6 and fixes the double open and leaking descriptor in a different way, that is by using newly introduced function 'have_random_source()' to check whether good random source is available while deciding which uuid type to generate (random/time). This is better than calling random_get_fd() twice, passing the file descriptor down the stack and reusing it in next call to random_get_fd(). Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-04libuuid: avoid double open and leaking descriptorPetr Uzel1-3/+5
We are opening /dev/urandom twice in uuid_generate(): first to check if the file is available and then later __uuid_generate_random() again to actually get the random data. Moreover, descriptor from the first open is leaking. Fix by passign the descriptor down the stack and reusing it there. References: http://marc.info/?l=util-linux-ng&m=133406051131131&w=2 Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-03lib/strutils: add string_to_bitmask()Karel Zak1-0/+43
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-03include/tt: remove obsolete stuffKarel Zak1-1/+1
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-26lib/tt: check for non-printable chars for raw/export formatKarel Zak1-3/+3
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-26lib/tt: encode data for RAW and EXPORT formatKarel Zak1-2/+30
* all tt based utils will properly encode blank chars for raw output format and quotes for export output format Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-26lib/mangle: cleanup, add unhexmangleKarel Zak1-18/+39
* use strchr() rather than for() * small refactoring in mangle code * add un-hex-mangle Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-23lib/fileutils: add get_fd_tabsize()Karel Zak1-0/+24
as a fallback for the function getdtablesize() Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-23Fix typos found by misspellingsBernhard Voelker1-1/+1
The tool misspellings (https://github.com/lyda/misspell-check) detected several typos. Command used: $ git ls-files | grep -v ^po/ | misspellings -f - * isosize: Fix typo in usage string. * configure.ac: Fix typo in help string of --enable-most-builds option. * fdisk: Fix typo in man page. * libblkid, blkid, mount: Likewise. * Fix various typos in docs and in source code comments. Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-04-23lib/pager: fix compiler warningsKarel Zak1-4/+2
pager.c: In function ‘start_command’: pager.c:82:7: warning: unused variable ‘err’ [-Wunused-variable] pager.c:49:25: warning: unused variable ‘fderr’ [-Wunused-variable] pager.c:49:15: warning: unused variable ‘fdout’ [-Wunused-variable] pager.c:48:25: warning: unused variable ‘need_err’ [-Wunused-variable] pager.c:48:15: warning: unused variable ‘need_out’ [-Wunused-variable] Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-23lib: add pager functionalityDavidlohr Bueso2-0/+216
When some program' output exceeds the terminal's dimensions, it is a nice feature to call a pager that acts as calling 'less' to allow better user navigation. This patch adds this functionality, based on what perf and git have (ie: git log). Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-04-10lib: random utilitiesDavidlohr Bueso2-0/+122
Add a random number(s) generator specific file. The intial functions are based on what libuuid provide. I did some modifications like avoid WIN32 checks - this is util-LINUX. [kzak@redhat.com: - move jrand_seed to lib/randutils.c - use TLS for jrand_seed (like original code from libuuid) - use size_t for buffer sizes - add close() to random_get_bytes] Signed-off-by: Davidlohr Bueso <dave@gnu.org> Signed-off-by: Karel Zak <kzak@redhat.com>