libmount: don't use umount optimization for -l or -f

The options -l (lazy) and -f (force) means that the mountpoint may be
unreadable (for example because NFS server is unreadable). So we
should not try to be smart in this case and we should try to minimize
number of situations when stat() or readlink() is used for the
mountpoint.

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

Address: https://bugzilla.redhat.com/show_bug.cgi?id=865961
Signed-off-by: Karel Zak <kzak@redhat.com>
swapon: remove loop declaration [smatch scan]

sys-utils/swapon.c:677:2: error: 'for' loop initial declarations are
only allowed in C99 mode

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
libblkid: fix compiler warning [-Wstrict-aliasing]

libblkid/src/superblocks/befs.c: In function 'get_uuid':
libblkid/src/superblocks/befs.c:353:6: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

Signed-off-by: Karel Zak <kzak@redhat.com>
mount: add -c abbreviation for --no-canonicalize to man page

The --no-canonicalize option can also be set using -c.  The --help for
mount shows this option but the man page did not.  Add -c to the man
page.

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
mount: add long options for -L and -U to man page

The -L and -U flags both have long options too (--label and --uuid).
The usage() function will show them but the man page didn't list them.

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
lib/loopdev: improve debug messages

Signed-off-by: Karel Zak <kzak@redhat.com>
lib/loopdev: check for /sys

The current loopdev code prefers /sys to get information about
loop devices. The old methods like scan /dev are fallback solution
only. Unfortunately, the code does not check if /sys is mounted.

Addresses: http://blog.flameeyes.eu/2012/10/sophistication-can-be-bad
Signed-off-by: Karel Zak <kzak@redhat.com>
fsck.cramfs: compile with -DINCLUDE_FS_TESTS for make check

 make check
 sudo su -
 cd tests
 ./run.sh cramfs

Signed-off-by: Karel Zak <kzak@redhat.com>
login: fix compiler warning [-Wunused-result]

It's probably unnecessary paranoia, but let's check if we're able to
restore the original IDs after ~/.hushlogin file check.

Signed-off-by: Karel Zak <kzak@redhat.com>
misc: make readlink() usage more robust

Signed-off-by: Karel Zak <kzak@redhat.com>
agetty: fix autodetection for TERM

open_tty() autodetects whether to set TERM to "linux" or "vt102", but it
can apply the result only if op->term is still NULL.
script: do not try to close stderr twice

The commit cdd2a8c360c70d16804ace7cc923a6c6bb7c9ca9 broke script(1)
return value.

$ script -e -c "echo"; echo $?
1

The reason, as Daniel it reported, was that the script will close stderr
twice, once as timing file and atexit() in function close_stdout().  This
commit fixes the problem.

Reported-by: Daniel Narvaez <dwnarvaez@gmail.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
lib/loopdev: make loopcxt_get_device() more robust

Signed-off-by: Karel Zak <kzak@redhat.com>
lscpu: Fix issue found on CPU hot-remove

read_basicinfo() relies on sysfs cpu directories
"/sys/devices/system/cpu/cpu%d" with assumption that cpu
logical number %d is always sequentially assigned for all
CPUs. However, this assumption is not correct with CPU
hot-remove operation since it removes a target sysfs cpu
directory after it is ejected. As a result, lscpu may not
recognize all CPUs.

The issue can be easily reproduced on KVM or VirtualBox,
which supports CPU eject operation, as follows.

1) The system has 4 CPUs
  $ lscpu -a -e
  CPU NODE SOCKET CORE L1d:L1i:L2 ONLINE
  0   0    0      0    0:0:0      yes
  1   0    1      1    1:1:1      yes
  2   0    2      2    2:2:2      yes
  3   0    3      3    3:3:3      yes

2) Eject cpu2
  # echo 1 > /sys/bus/acpi/devices/LNXCPU:02/eject

3) lscpu no longer recognizes cpu3 after cpu2 is ejected
  $ lscpu -a -e
  CPU NODE SOCKET CORE L1d:L1i:L2 ONLINE
  0   0    0      0    0:0:0      yes
  1   0    1      1    1:1:1      yes

The following changes are made to address this issue.
 - Use maxcpus to allocate and parse bitmaps.
 - Set desc->ncpu from cpu/present, which includes both on-line
   and off-line CPUs.
 - Add is_cpu_present() to check if a CPU is present. Ejected
   CPUs are not present.

[kzak@redhat.com: - read also /sys/devices/system/cpu/possible mask to
                    determine maximal number of CPUs,
                  - err() if possible mask is not found in /sys]

Signed-off-by: Toshi Kani <toshi.kani@hp.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
tests: remove lscpu /sys dumps without 'possible' CPU mask

Signed-off-by: Karel Zak <kzak@redhat.com>
umount: allways return MOUNT_EX_*

Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid: remove obsolete tags from cache

The libblkid cache tags are not removed if a new version of the
tags is empty (e.g. label 'foo' -> '').

 # mkfs.ext4 -L test_label /dev/sda15
 # blkid /dev/sda15
 /dev/sda15: LABEL="test_label"

 # tune2fs -L '' /dev/sda15
 # blkid /dev/sda15
 /dev/sda15: LABEL="test_label"
                    ^^^^^^^^^^

Reported-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount: more robust tab filter usage

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount: don't try to play with loopdevs if umount argument is really mountpoint

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