Commit Graph

10697 Commits

Author SHA1 Message Date
Tobias Stoeckmann cb129d9cc4 lib/loopdev: Set errno in is_loopdev on error
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>
2016-08-31 09:49:01 +02:00
Karel Zak 2480b52743 mount: add note about paths verification to mount.8
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-31 09:48:43 +02:00
Rostislav Skudnov f98b563268 libblkid: [exfat] Limit maximum number of iterations in find_label
Do not hang if there is a cluster chain loop in rootdir

[kzak@redhat.com: - add return NULL]

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-30 13:50:51 +02:00
Karel Zak 4db236f7e4 libblkid: ignore empty MBR on LVM device
It's possible to use boot sector and empty MBR on LVM physical volume
to make LVM disk bootable. In this case MBR should be ignored and disk
reported as LVM.

Just for the record, this is ugly non-default LVM setup maintained for
backward compatibility (yes, LVM guys don't like it too).

Unfortunately people still use it. The proper way is to use regular
partitioned disk.

Reported-by: Xen <list@xenhideout.nl>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-30 12:07:40 +02:00
Karel Zak a1df9c9d4e libblkid: remove unused function
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-30 11:22:30 +02:00
Karel Zak 29ad8689b8 umount: cleanup umount.8 about mtab
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-30 10:41:05 +02:00
Karel Zak d00eb87ba2 umount: fix obsolete info about loop= in umount.8
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1370959
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-30 10:25:44 +02:00
Tobias Stoeckmann 8fa57ab0b5 libblkid: Avoid OOB access on illegal ZFS superblocks
64 bit systems can trigger an out of boundary access while performing
a ZFS superblock probe.

This happens due to a possible integer overflow while calculating
the remaining available bytes. The variable is of type "int" and the
string length is allowed to be larger than INT_MAX, which means that
avail calculation can overflow, circumventing the "avail < 0" check and
therefore accessing memory outside the "buff" array later on.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-08-29 13:22:24 +02:00
Tobias Stoeckmann 1037269fec libfdisk: Distinguish between first LBA sector and partition
An insufficient check leads to an invalid free space output, as seen here:

$ dd if=/dev/zero of=cfdisk.iso bs=1M count=1
$ losetup -f cfdisk.iso
$ echo w | fdisk /dev/loop0
$ echo '1,1' | sfdisk /dev/loop0 --append
$ echo '3,' | sfdisk /dev/loop0 --append
$ sfdisk --list-free /dev/loop0
Start End Sectors Size
    1   2       2   1K
$ _

In this case, libfdisk fails to notice that it tries to calculate space
between two partitions, not between start of disk and first partition.
Currently, the code tries to achieve that by checking the address of the
last "partition", which is the first_lba block.  Now if the first
partition is merely 1 block in size, the "last" address is still equal
to the first_lba block, which renders the check in libfdisk for the next
partition invalid.

I chose to use "nparts == 0" for this check, because the partitions are
properly sorted before iterating over them.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-08-29 13:22:24 +02:00
Tobias Stoeckmann 8480181838 libfdisk: Fix assert error in free space handling
An off-by-one issue exists in fdisk_get_freespaces. It can trigger an
assert, as seen here:

$ dd if=/dev/zero of=cfdisk.iso bs=1M count=1
$ losetup -f cfdisk.iso
$ echo w | fdisk /dev/loop0
$ echo '1,2' | sfdisk /dev/loop0 --append
$ echo '3,' | sfdisk /dev/loop0 --append
$ sfdisk --list-free /dev/loop0
Aborted
$ _

Problem here is an invalid "grain" processing. A grain is considered
expected free space between partitions which can be required for proper
alignment. Normally, it's 1 MB but in this case our iso is merely 1 MB
so the grain is reduced to 1 byte.

The if-condition in question checks for "last + grain <= pa->start" and
therefore even triggers if there is no space between them (due to equal
check). Eventually, the start block address is higher than the end block
address which triggers the assert().

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-08-29 13:22:24 +02:00
Karel Zak e132ae59ca lib/pager: fix test
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-26 17:47:01 +02:00
Karel Zak a9fcbf6f6a lib/pager: restore signals setting by pager_close()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-26 13:02:37 +02:00
Karel Zak 8d2f449818 fdisk: use PAGER for 'l' command.
The list of the partition types is too long. Let's try to use $PAGER.

Reported-by: Bruce Dubbs <bruce.dubbs@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-26 12:15:38 +02:00
Karel Zak e215d467ca lib/pager: cleanup and extend API
* 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>
2016-08-26 12:07:25 +02:00
Karel Zak c424fd834b su, runuser, setpriv: create links between man pages
.. and add notes about differences between the utuils.

Reported-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-18 11:12:44 +02:00
Karel Zak 0e0e167704 tests: fix losetup tests for --nooverlap
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-17 13:54:34 +02:00
Karel Zak d8ba61fcb4 losetup: allow to use --nooverlap when device specified
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-17 13:52:22 +02:00
Stanislav Brabec 912d50b3be tests: Add losetup-loop test suite
Add losetup loop test suite that tests proper behavior of conflicting and
re-used loop devices.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-17 13:02:35 +02:00
Stanislav Brabec f27d989c67 losetup: Prevent AUTOCLEAR detach race
Kernel needs some time to delete a device after losetup --detach. If
the losetup --find --nooverlay is called just after losetup --delete,
it can sometimes attempt to recycle the device that is just being
released.  To prevent this race, clear the AUTOCLEAR flag of the
device.

[kzak@redhat.com: - rebase to the new version of the code]

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-17 12:58:12 +02:00
Stanislav Brabec bfd4e1f758 loopdev: Implememt loopcxt_set_status()
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>
2016-08-17 12:49:06 +02:00
Karel Zak 9a94b634a3 losetup: add --nooverlap options
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>
2016-08-17 12:28:33 +02:00
Karel Zak f066f32aae tests: keep 'hppa' in fdisk/bsd test too
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-16 13:40:44 +02:00
Karel Zak f319e301a9 build-sys: add parisc to define ARCH_
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-16 13:39:07 +02:00
Helge Deller 569ad28288 tests: really fix fdisk/bsd for hppa
Finally fix the bsd testcase on the hppa architecture.

Commit 1b7be556e5 tried to fix it,
but missed the fact that "uname -m" returns "parisc" or "parisc64"
instead of "hppa*".

Signed-off-by: Helge Deller <deller@gmx.de>
Cc: 827225@bugs.debian.org
2016-08-16 13:36:12 +02:00
Michał Bartoszkiewicz 2b8889c44b lsns: support cgroup namespaces
Signed-off-by: Michał Bartoszkiewicz <mbartoszkiewicz@gmail.com>
2016-08-16 13:36:12 +02:00
Karel Zak 090d8c763a include/closestream: define exit codes
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-16 13:35:06 +02:00
Karel Zak 05d8868d86 include/env: minor fixes and clean ups
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-16 12:35:57 +02:00
Karel Zak 64ffc95b0f Merge branch 'misc' of https://github.com/kerolasa/lelux-utiliteetit
* 'misc' of https://github.com/kerolasa/lelux-utiliteetit:
  pg: stop building the command by default
  kill: remove pid command-name to option alias
  misc: always check setenv(3) return value
2016-08-16 12:09:00 +02:00
Rostislav Skudnov 9d89a95e88 libblkid: Check that cluster size is nonzero when probing exFAT
This should prevent division by zero in find_label()

Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com>
2016-08-16 12:08:46 +02:00
Karel Zak 3082f8518f lsns: missing ns/<name> is not error
For example user namespace is optional it does not make sense to
ignore process completely if the ns/user file is missing.

Reported-by: Michał Bartoszkiewicz <mbartoszkiewicz@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-15 11:02:18 +02:00
Sami Kerola 00971cca8a
pg: stop building the command by default
The pg command is marked deprecated in POSIX since 1997, and this project
has thought the same since Feb 2013.  Time has come to stop shipping this
binary by default.

Reference: 956e582874
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-08-14 13:30:36 +01:00
Sami Kerola 0be3ad70ad
kill: remove pid command-name to option alias
Removal was promised to happen in March 2016 and the time has come to get
rid of this unexpected feature.

Reference: c5b057b342
Reviewed-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-08-14 13:30:16 +01:00
Sami Kerola 984a60965a
misc: always check setenv(3) return value
At least glibc setenv(3) can fail when system runs out of memory.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-08-12 21:25:36 +01:00
Karel Zak 8c4ae2fd48 tests: mark build-in paths test as optional
The test makes sense only if you know what are you doing (see
 #ifdef(s) in the include/pathnames.h.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-12 10:13:22 +02:00
Karel Zak b8c65bd0b8 Merge branch 'pathnames_fbsd' of https://github.com/fichtner/util-linux 2016-08-12 10:05:00 +02:00
Karel Zak 1ef66ace16 Merge branch 'blkdev_fbsd_11' of https://github.com/fichtner/util-linux 2016-08-12 10:04:35 +02:00
Ruediger Meier 160eef814a travis: fix OSX, glibtoolize could not find sed
Since a few days travis OSX seems to have a bad libtool package:
$ glibtoolize --version
/usr/local/bin/glibtoolize: line 406: /usr/local/Library/ENV/4.3/sed: No such file or directory

Exporting SED is a simple fix. Otherwise we could have also re-installed libtool:
  brew uninstall libtool
  brew install libtool

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-08-11 18:04:00 +02:00
Franco Fichtner 0773ad14a3 pathnames: guard clashing definitions on FreeBSD 2016-08-11 15:03:50 +02:00
Franco Fichtner 6978b2c430 blkdev: guard against missing DIOCGDINFO on FreeBSD 11
DIOCGMEDIASIZE is supported and available since FreeBSD 5, it may
make sense to kill the backwards-glue completely instead.
2016-08-11 14:58:50 +02:00
Filipe Brandenburger 727c689908 libmount: Preserve empty string value in optstr parsing
Recent mount (since the switch to libmount in v2.22) drops the '=' in
mount options that are set to an empty value.  For example, the command
line below will be affected:

  # mount -o rw,myopt='' -t tmpfs tmpfs /mnt/tmp

Fix that by preserving an empty string in the options passed to the
mount(2) syscall when they are present on the command line.

Add test cases to ensure empty string handling is working as expected
and in order to prevent regressions in the future.

Also tested manually by stracing mount commands (on a kernel which
accepts a special extra option, for testing purposes.)

Before this commit:

  # strace -e mount ./mount -t tmpfs -o rw,myopt='' tmpfs /mnt/tmp
  mount("tmpfs", "/mnt/tmp", "tmpfs", MS_MGC_VAL, "myarg") = -1 EINVAL (Invalid argument)

After this commit:

  # strace -e mount ./mount -t tmpfs -o rw,myopt='' tmpfs /mnt/tmp
  mount("tmpfs", "/mnt/tmp", "tmpfs", MS_MGC_VAL, "myopt=") = 0

All test cases pass, including newly added test cases.  Also checked
them with valgrind using:

  $ tests/run.sh --memcheck libmount/optstr

Fixes #332.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
2016-08-10 13:59:52 -07:00
Filipe Brandenburger 7cd6d50aa9 tests: Allow running a single test case from tests/run.sh
Tested by running `tests/run.sh libmount/optstr` successfully.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
2016-08-10 13:59:31 -07:00
Filipe Brandenburger 88a5f90e87 tests: Use proper word splitting when executing tests
Use the shell special variable "$@" instead of the inferior $* to
execute the test command in ts_valgrind.  The expansion of "$@" respects
proper word splitting and makes it possible to pass the command empty
arguments.  It might also prevent surprises with quoting in corner
cases.

Tested that `make check` passes.

Valgrind run with `make check TS_OPTS='--nonroot --memcheck'` passes.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
2016-08-10 13:37:43 -07:00
Chris Metcalf 47bd898e91 taskset: clarify that masks are always hex in man page
The man page confusingly says that the mask is "typically"
hexadecimal, when in fact it is always hexadecimal.  Fix the
language, and provide an additional example with no leading "0x".

Also, provide an example using the --cpu-list option.

Signed-off-by: Chris Metcalf <cmetcalf@mellanox.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-09 11:31:41 +02:00
Karel Zak d4e89dea4e libmount: ignore redundant slashes
///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>
2016-08-08 17:23:54 +02:00
Sami Kerola b7a245e27a uuidd: remove unnecessary pidpile path variable
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-08 12:33:16 +02:00
Karel Zak 349ac67273 sfdisk: add show-pt-geometry to usage() and sfdisk.8
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-08 12:15:47 +02:00
Stanislav Brabec ba7f6ba53a deprecated.txt: Add sfdisk --show-pt-geometry 2016-08-08 12:03:12 +02:00
Stanislav Brabec f7c6c31f08 sfdisk: Add --show-pt-geometry compatibility code
--show-pt-geometry existed since cf3f26bf (2006), and it is used by third party
tools. To prevent failure of these tools, add a minimal compatibility code.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-08 12:03:12 +02:00
Karel Zak 041d33734e tests: fix loop-overlay test
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-04 15:15:12 +02:00
Karel Zak 05b483010e tests: fix libmount loop-overlay test
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-04 12:30:09 +02:00