summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* losetup: use loop-control to explicitly ask for deviceKarel Zak2013-08-061-0/+30
| | | | | | | | | | | | | | | | Now we use LOOP_CTL_GET_FREE ioctl to ask for free device, for example losetup -f foo.img Unfortunately, losetup(8) allows to ask for specified device losetup /dev/loop100 foo.img and in this case we assume that the device already exists in the system. This is incorrect, we should be able to use loop-control LOOP_CTL_ADD ioctl to ask for the specified device. Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: set errno for misaligned offsetsKarel Zak2013-07-191-7/+19
| | | | | References: https://bugs.archlinux.org/task/36189 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/mbsalign: initializations values are never read [clang-analyzer]Sami Kerola2013-07-091-2/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/loopdev: assigned value is never read [clang-analyzer]Sami Kerola2013-07-091-1/+0Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/canonical: use realpath() from libcKarel Zak2013-07-011-151/+29Star
| | | | | | | .. after many many years it seems that we can follow libc code rather than duplicate realpath(3) implementation. Signed-off-by: Karel Zak <kzak@redhat.com>
* exec_shell: add a license and touch up func defMike Frysinger2013-07-011-1/+20
| | | | | | | | | | When this file was created, the standard license header was missed. Add it using the same one from unshare.c. The noreturn attribute is not needed since we include the header which has it on the prototype. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libmount: be robust for empty target/source stringsKarel Zak2013-06-171-2/+5
| | | | | | | | | | * lib/canonicalize.c: don't interpret empty strings as relative paths * libmount: more robust libmnt_table find function and debug messages References: https://bugzilla.novell.com/show_bug.cgi?id=825150 Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: remove unused codeSami Kerola2013-06-071-10/+0Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/tty: fix get_terminal_name() usage, cleanup codeKarel Zak2013-05-281-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/tty: don't hardcode terminal fd in get_terminal_name()Karel Zak2013-05-131-2/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: fix loopcxt_check_size() to work with blkdevsKarel Zak2013-05-131-1/+15
| | | | | | | | | | | | | | The loopcxt_check_size() is workaround for kernels < v3.9, kernel has been fixed by commit 541c742a7559eb65f0e36d3e2338c2ca532a3e61. The function sets loopdev size according to backing file size. The problem is that the backing file could be a block device where stat.st_size is zero, so we have to use blkdev_get_size() for block devices. Addresses: https://bugs.archlinux.org/task/35193 Reported-by: Dave Reisner <d@falconindy.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: add colormode_or_err()Karel Zak2013-05-071-9/+15
| | | | | | ... to make the code easy to use in utils. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/colors: add support for auto, always and never modesKarel Zak2013-05-062-2/+76
| | | | | | ... to implement --color[=<when>] Signed-off-by: Karel Zak <kzak@redhat.com>
* loopdev: sync capacity after setting itJeff Mahoney2013-04-093-6/+85
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I recently tried to mount an hfsplus file system from an image file with a partition table by using the loop offset and sizelimit options to specify the location of the file system. hfsplus stores some metadata at a set offset from the end of the partition, so it's sensitive to the device size reported by the kernel. It worked with this: But failed with this: /dev/loop0: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000 /dev/loop1: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000 /proc/partitions shows the correct number of blocks to match the sizelimit. But if I set a breakpoint in mount before the mount syscall, I could see: 102400000 102432768 The kernel loop driver will set the gendisk capacity of the device at LOOP_SET_STATUS64 but won't sync it to the block device until one of two conditions are met: All open file descriptors referring to the device are closed (and it will sync when re-opened) or if the LOOP_SET_CAPACITY ioctl is called to sync it. Since mount opens the device and passes it directly to the mount syscall after LOOP_SET_STATUS64 without closing and reopening it, the sizelimit argument is effectively ignroed. The capacity needs to be synced immediately for it to work as expected. This patch adds the LOOP_SET_CAPACITY call to loopctx_setup_device since the device isn't yet released to the user, so it's safe to sync the capacity immediately. [kzak@redhat.com: - port to the current git HEAD, - use uint64_t] Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* various: fix variable and function declarations [smatch scan]Sami Kerola2013-04-091-2/+2
| | | | | | | | | | | | | | | | | disk-utils/fsck.minix.c:511:9: warning: mixing declarations and code fdisks/sfdisk.c:982:5: warning: mixing declarations and code fdisks/sfdisk.c:1254:5: warning: mixing declarations and code fdisks/sfdisk.c:1564:5: warning: mixing declarations and code lib/mbsalign.c:279:7: warning: mixing declarations and code libblkid/src/devname.c:378:17: warning: mixing declarations and code libfdisk/src/alignment.c:219:9: warning: mixing declarations and code term-utils/wall.c:111:9: warning: mixing declarations and code text-utils/col.c:418:19: warning: non-ANSI function declaration of function 'flush_blanks' text-utils/col.c:553:12: warning: non-ANSI function declaration of function 'alloc_line' text-utils/rev.c:105:9: warning: mixing declarations and code text-utils/tailf.c:245:9: warning: mixing declarations and code Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib: use O_CLOEXEC in libcommonKarel Zak2013-04-039-24/+25
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize: don't use /dev/mapper/<name> if the node does not existKarel Zak2013-04-031-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsblk: fix hctl buffer usage [coverity scan]Karel Zak2013-03-271-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/mbsalign: correct license header from GPLv[23] to LGPLv2+Pádraig Brady2013-03-201-2/+2
| | | | | | * lib/mbsalign.c: s/GPLv3/LGPLv2+/ * include/mbsalign.h: s/GPLv2/LGPLv2+/ * README.licensing: Remove mention GPLv3 as it's not actually used.
* dmesg: more colors, more funKarel Zak2013-03-181-1/+1
| | | | | | | | * colorize subsystem prefix * colorize time * colorize by keywords (now "segfault" only) Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: add strtotimeval_or_err()Karel Zak2013-03-131-0/+10
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/procutils: add simple API to scan /proc/PID/*Karel Zak2013-03-122-4/+128
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/procutils: test refactoringKarel Zak2013-03-121-4/+16
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: simplify strtosize(), return info about suffixKarel Zak2013-03-111-37/+28Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fdisk: add callback for ask-numbers APIKarel Zak2013-03-111-0/+10
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Merge branch 'patch-1' of https://github.com/dtrebbien/util-linuxKarel Zak2013-02-201-0/+7
|\ | | | | | | | | * 'patch-1' of https://github.com/dtrebbien/util-linux: Implement mempcpy() in terms of memcpy() if mempcpy() is unavailable
| * Implement mempcpy() in terms of memcpy() if mempcpy() is unavailableDaniel Trebbien2013-01-311-0/+7
| |
* | lib/tty: don't truncate output on non-terminalsKarel Zak2013-02-191-2/+8
| | | | | | | | | | | | | | | | | | | | | | for example: $ findmnt | cat $ lslocks > foo the output should not be truncated. Signed-off-by: Karel Zak <kzak@redhat.com>
* | unshare,nsenter: spawn shell by defaultZbigniew Jędrzejewski-Szmek2013-02-142-1/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | The behaviour mimics chroot. Possibly it would have been nicer to to query the password database in the new namepace and run the shell of the user there, but it's hard to do correctly. getpwuid() might need to load nss plugins, and the arch in the new namespace might be different (in case of NEWNS mounts), or the hostname might be different, etc. So in general it's not possible to do it reliably. Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
* | build-sys: test for secure_getenv() too.Cristian Rodríguez2013-02-061-2/+3
| | | | | | | | | | | | | | In current glibc versions, internal __secure_getenv no longer exists and was replaced by secure_getenv() Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org>
* | a pointer should not be compared to zero [coccinelle]Sami Kerola2013-02-061-1/+1
| | | | | | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* | textual: spell and encode the name of Arkadiusz Miśkiewicz correctlyBenno Schulenberg2013-02-061-1/+1
|/ | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* include: cleanup copyright headersKarel Zak2013-01-088-8/+38
| | | | | | | We use the code from include/ and lib/ on many places, so use public domain if possible or LGPL for code copied from libs. Signed-off-by: Karel Zak <kzak@redhat.com>
* sulogin: remove consoles.c from libcommonKarel Zak2012-12-232-787/+0Star
| | | | | | | | - move struct chardata to include/ttyutils.h - move console.{h,c} to login-utils/sulogin-* (it's sulogin specific) - fix sulogin and agetty includes Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/ismounted: improve loopdev supportKarel Zak2012-12-191-18/+9Star
| | | | | | | ... to make it usable for situations when the same backing file is mapped to more loop devices. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/ismounted: basic support for loop devicesKarel Zak2012-12-192-10/+35
| | | | | | | | | | | | | | | | | | | | | | # losetup -a /dev/loop0 /dev/loop0: [2053]:1048578 (/home/fs-images/filesystems/ext2.img) # findmnt /dev/loop0 TARGET SOURCE FSTYPE OPTIONS /mnt/test /dev/loop0 ext3 rw,relatime,data=ordered old version: ./test_ismounted /home/fs-images/filesystems/ext2.img not mounted new version: ./test_ismounted /home/fs-images/filesystems/ext2.img mounted on /mnt/test Reported-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: fix loopdev_find_by_backing_file()Karel Zak2012-12-191-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* sulogin: mount temporary /dev and /proc if not foundWerner Fink2012-12-181-0/+73
| | | | | | | | | This is very usefull if initrd can not loaded that is no /dev and no /proc is found. Also if the /etc/shadow and /etc/passwd is copied into the initrd the sulogin can be used in initrd even before /dev and/or /proc are mounted. Signed-off-by: Werner Fink <werner@suse.de>
* sulogin: use the linked lists from list.h for consoles listWerner Fink2012-12-181-30/+48
| | | | | | | | | | with this the double linked list feature from util-linux is used instead of the single linked list. [kzak@redhat.com: use list_last_entry() and list INIT macros] Signed-off-by: Werner Fink <werner@suse.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* include/list: add list_last_entry()Karel Zak2012-12-181-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/canonicalize: add canonicalize_path_restricted() to canonicalize without ↵Karel Zak2012-11-261-0/+42
| | | | | | suid permisssions Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: add path_read_u64()Karel Zak2012-11-231-0/+22
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path: rename functions to be more explicitKarel Zak2012-11-231-8/+10
| | | | | | ... and to have names compatible with lib/sysfs.c Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/ttyutils: add get_terminal_name()Karel Zak2012-11-221-2/+43
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/ttyutils: add test programKarel Zak2012-11-222-0/+14
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/ttyutils: create .c fileKarel Zak2012-11-222-0/+40
| | | | | | | | Well, now all tty stuff are incline functions in include/ttyutils.h. It's seems more elegant to create regular lib/ttyutils.c for libcommon and write test program. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: make loopcxt_get_device() more robustKarel Zak2012-11-121-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/console: fix possible fd leakKarel Zak2012-11-091-1/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/consoles: try another methods before go to fallbackKarel Zak2012-11-091-10/+4Star
| | | | | | | | The current code goes immediately to the fallback section if any detection method fails. It seems better to try another methods before the fallback solution. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/consoles: add debug messagesKarel Zak2012-11-091-8/+59
| | | | | | - may be enabled by CONSOLES_DEBUG env. variable Signed-off-by: Karel Zak <kzak@redhat.com>