include/tt: improve work with non-utf8 chars

Reported-by: Pádraig Brady <P@draigBrady.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/tt: fix \x%02x usage

Signed-off-by: Karel Zak <kzak@redhat.com>
lib/tt: always escape '\' to simplify parsing in scripts

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>
lscpu: limit options --all, --online, --offline to parsable and extended output

Passing the --all, --online or --offline options for the output summary
doesn't make much sense. It should be limited to the two list output options.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
fdisk: aix: fix warning

Fixes:
 warning: no previous prototype for ‘aix_nolabel’

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Fix non-Linux build

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>
eject: return proper 0/1 from eject_cdrom()

main() expects this method to return 0 for failure and 1 for success, as
the other eject_*() methods do. Add the missing comparison of ioctl() >= 0

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
dmesg: fix kmsg read if read returns EPIPE

The /dev/kmsg can return EPIPE if current record has beed modified
while reading.

For init_kmsg, it cause switch to DMESG_METHOD_SYSLOG
(which is not expected) and later it can truncate output.

Signed-off-by: Milan Broz <mbroz@redhat.com>
libmount: fix unmangle code

old version:
  /mnt/ugly/te\134st\134 -> /mnt/ugly/te\st\134

fixed version:
  /mnt/ugly/te\134st\134 -> /mnt/ugly/te\st\

Reported-by: Naja Melan <najamelan@autistici.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/sysfs: expect p<N> suffix for partitions

 ... so for example lsblk(8) will see partitioned loop devices

loop0       7:0    0    80G  0 loop
├─loop0p1 259:0    0   100M  0 loop
└─loop0p2 259:1    0  79.9G  0 loop

Signed-off-by: Karel Zak <kzak@redhat.com>
lib/mangle: remove unused variable

Signed-off-by: Karel Zak <kzak@redhat.com>
lib/sysfs; add sysfs_partno_to_devno()

Signed-off-by: Karel Zak <kzak@redhat.com>
resizepart: add new command

This is a simple wrapper for BLKPG_RESIZE_PARTITION (since kernel 3.6).

Co-Author: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
resizepart: remove debug message

Signed-off-by: Karel Zak <kzak@redhat.com>
lsblk: add WWN, improve udev support

 * read WWN from udev DB

 * use *_ENC properties from udev DB to get original unmodified
   strings (otherwise for example blank space is replaced with '_' in
   ID_FS_LABEL)

 * always read from udev, libblkid is fallback solution only

Signed-off-by: Karel Zak <kzak@redhat.com>
lib/sysfs: make sysfs_partno_to_devno better readable

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
column: --separator segfaults

The --separator and --columns long options in util-linux-2.21.2 and in
a git clone from 5 minutes ago, don't work:

$ echo foobar | column -s x
foobar

$ echo foobar | column -c 10
foobar

$ echo foobar | column --separator=x
column: option '--separator' doesn't allow an argument

$ echo foobar | column --separator x
Segmentation fault

$ echo foobar | column --columns 10
column: bad columns width value: '(null)': Invalid argument

$ echo foobar | column --columns=10
column: option '--columns' doesn't allow an argument

Looks like a simple case of missing has_arg flag in the "struct
option" initialization for these two options. The patch just adds the
flag. I haven't done thorough testing of the patched code, but it
seems to work OK and it no longer segfaults or tries to dereference a
null pointer.

Signed-off-by: Karel Zak <kzak@redhat.com>
build-sys: expand paths at make time

autoconf docs about *dir variables (e.g bindir):

 ... A corollary is that you should not use these variables except in
 makefiles...

 ...you should not rely on AC_CONFIG_FILES to replace bindir and friends
 in your shell scripts and other files; instead, let make manage their
 replacement.

Signed-off-by: Karel Zak <kzak@redhat.com>
uuidd: improve systemd unit files

 - use $usrsbin_execdir
 - add [Install] section
 - use long options

Signed-off-by: Karel Zak <kzak@redhat.com>
tests: update build-sys tests

 - remove tests programs (no more compiled by default)
 - add resizepart

Signed-off-by: Karel Zak <kzak@redhat.com>