Karel Zak [Wed, 31 Aug 2016 13:51:11 +0000 (15:51 +0200)]
sfdisk: make non-interactive output more readable
# echo -e ',1M\n,2M' | sfdisk /dev/sdc
Old version:
>>> Created a new DOS disklabel with disk identifier 0x8fc7d065.
Created a new partition 1 of type 'Linux' and of size 1 MiB.
/dev/sdc2: Created a new partition 2 of type 'Linux' and of size 2 MiB.
/dev/sdc3:
New version:
>>> Created a new DOS disklabel with disk identifier 0x9afe17c0.
/dev/sdc1: Created a new partition 1 of type 'Linux' and of size 1 MiB.
/dev/sdc2: Created a new partition 2 of type 'Linux' and of size 2 MiB.
/dev/sdc3: Done.
Addresses: https://github.com/karelzak/util-linux/issues/337 Signed-off-by: Karel Zak <kzak@redhat.com>
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:
Karel Zak [Tue, 30 Aug 2016 10:07:40 +0000 (12:07 +0200)]
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>
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.
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.
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().
Stanislav Brabec [Wed, 17 Aug 2016 10:54:40 +0000 (12:54 +0200)]
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>
Karel Zak [Wed, 17 Aug 2016 10:28:33 +0000 (12:28 +0200)]
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>
Karel Zak [Tue, 16 Aug 2016 10:09:00 +0000 (12:09 +0200)]
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
Sami Kerola [Mon, 8 Aug 2016 21:08:16 +0000 (22:08 +0100)]
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.
Ruediger Meier [Thu, 11 Aug 2016 15:30:20 +0000 (17:30 +0200)]
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
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.)
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>
Chris Metcalf [Tue, 9 Aug 2016 09:31:41 +0000 (11:31 +0200)]
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>
Karel Zak [Mon, 8 Aug 2016 15:23:54 +0000 (17:23 +0200)]
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>
--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.
lscpu: print correct number of threads per core if possible
lscpu calculates the number of threads per core by dividing the number
of online cpus with the number of cores. This may or may not give the
correct number of threads per core depending on the number of online
CPUs (and which CPUs are online).
At least on s390 there is a new "max thread id" field within
/proc/cpuinfo present which reliably allows us to tell the number of
threads per core. Let's use this instead, like we already have also
special treatment to figure out the number core per socket etc. on
s390.
lscpu: only try to read sysfs attributes of present CPUs
lscpu can skip all CPUs which are possible but not present. For
configurations where a lot of CPUs are possible but only few CPUs are
present this saves a lot of pointless glibc/system calls.
With the --physical option lscpu will use the IDs that are reported by
the kernel (e.g. core id for the CORE column) instead of calculating
them on it's own.
This has the advantage that it is possible to tell on which physical
hardware CPUs a Linux instance runs. The logical IDs that lscpu
generates on it own are based on comparing of CPU masks and may or may
not be identical with the physical IDs.
If the kernel was unable to retrieve an ID for a topology element then
the corresponding sysfs file will normally contain "-1". In the
extended and parsable output a dash "-" will be displayed for such
cases.
Stanislav Brabec [Thu, 14 Jul 2016 13:29:44 +0000 (15:29 +0200)]
libmout: Reuse loop device safely
Add a safety check to mnt_context_setup_loopdev(). Only a loop device with equal
offset and sizelimit will be reused. If any overlapping loop device exists,
MNT_ERR_LOOPOVERLAP is returned.
Stanislav Brabec [Thu, 14 Jul 2016 13:29:09 +0000 (15:29 +0200)]
Add sizelimit to internal API
Fully safe checks of loop device need to check sizelimit. To prevent need of two
nearly equal functions, introduce sizelimit parameter to several internal
functions:
loopdev_is_used()
loopdev_find_by_backing_file()
loopcxt_is_used()
loopcxt_find_by_backing_file()
If sizelimit is zero, fall back to the old behavior (ignoring of sizelimit).
Karel Zak [Tue, 2 Aug 2016 13:26:49 +0000 (15:26 +0200)]
Merge branch 'oclint' of git://github.com/kerolasa/lelux-utiliteetit
* 'oclint' of git://github.com/kerolasa/lelux-utiliteetit:
libblkid: fix debugging macro [oclint]
agetty: move unreachable code to pre-processor #else segment [oclint]
setterm: fix declarations shadowing variables in the global scope [oclint]
misc: fix declarations shadowing variables in the global scope [oclint]
dmesg: drop core at impossible case in read_buffer() [oclint]
libmount, look: remove dead code [oclint]
syspriv: flip inverted logic [oclint]
logger: simplify if clause [oclint]
libblkid: simplify if clause [oclint]
lslogins: simplify if clause and move definition and comments [oclint]
switch_root: simplify code and reduce indentation [oclint]
misc: simplify if clauses [oclint]
Sami Kerola [Wed, 27 Jul 2016 10:17:47 +0000 (11:17 +0100)]
getops: improve getopt-parse.bash example
Use correct names of example scripts in the script. Remove use of
backticks, they require quoting that makes the example harder to follow.
Split one-liners to one-command-at-a-time expressions. Add continue keyword
to avoid additional case statement matching. Be strict with quoting.
Reported-by: Benno Schulenberg <bensberg@justemail.net> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Sami Kerola [Sun, 3 Jul 2016 19:57:23 +0000 (20:57 +0100)]
libblkid: fix debugging macro [oclint]
The oclint was complaining 'empty do/while statement' that turned out to be
true and I started to think it is best to use the same DBG() macro as in
other source files for this library.
Sami Kerola [Mon, 4 Jul 2016 21:12:55 +0000 (22:12 +0100)]
libblkid: simplify if clause [oclint]
Move negative and positive testing of 'has' variable to top level, and test
flag bit mask on second level. This way the 'has' needs to be checked only
once.
Sami Kerola [Mon, 4 Jul 2016 21:16:54 +0000 (22:16 +0100)]
lslogins: simplify if clause and move definition and comments [oclint]
The if clause change is pretty trivial. Moving the macro near to where it
is used makes sense to people who want to read the code. And finally the
comment about user list was at wrong spot.
all old versions to v2.20 -- returns 0
from v2.20 to v2.26 -- returns 1
since v2.26 -- returns 0
I think re-read errors should not be interpreted as fatal errors,
because it's pretty common that you want to modify only one partition
(e.g. resize) and then another partitions are probably still in use
and re-read all PT does not make sense.
What we need is to improve granularity for re-read and calls it only
when really necessary (all PT modified) and otherwise call BLKPG
(add/delete/resize) ioctls.
Reported-by: Nikhil Valluru <vvnikhil@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Sami Kerola [Mon, 18 Jul 2016 20:49:27 +0000 (21:49 +0100)]
logger: remove trailing spaces when outputing to journal
Issues:
1. Whitespace-ish \r is not stripped, while it should be.
2. In journal \r is considered unprintable.
Lennart: "it is the duty of the client side to drop the trailing whitespace,
which "logger" doesn't do".
Reported-by: Ivan Babrou <ibobrik@gmail.com> Explained-by: Lennart Poettering <lennart@poettering.net>
Reference: https://github.com/systemd/systemd/issues/3416 Signed-off-by: Sami Kerola <kerolasa@iki.fi>