Update debug messages for a combined --systz and --hctosys in
the set_system_clock function.
New debug messages:
hwclock --test -D --systz --localtime
Calling settimeofday(NULL, 240) to warp System time.
Test mode: clock was not changed
hwclock --test -D --systz --utc
Calling settimeofday(NULL, 0) to lock the warp function.
Calling settimeofday(NULL, 240) to set the kernel timezone.
Test mode: clock was not changed
hwclock --test -D --hctosys --utc
Calling settimeofday(1502239269.733639, 240)
Test mode: clock was not changed
hwclock --test -D --hctosys --localtime
Calling settimeofday(NULL, 240) to set persistent_clock_is_local.
Calling settimeofday(1502253708.200200, 240)
Test mode: clock was not changed
Signed-off-by: J William Piggott <elseifthen@gmx.com>
The set_system_clock_timezone() function is nearly identical to
set_system_clock(). Three additional statements are required
to include systz in hctosys.
This patch is intentionally incomplete to make reviewing the
actual required changes easier. Other patches in this set will:
* remove set_system_clock_timezone()
* fix messages and debugging
* fix comments
* and finally refactor set_system_clock()
Signed-off-by: J William Piggott <elseifthen@gmx.com>
Karel Zak [Thu, 24 Aug 2017 13:37:16 +0000 (15:37 +0200)]
fdisk: fix readline interaction with signals
The high-level readline API is crazy to use with signals. Fortunately
the library provides low-level rl_callback_* API. In this case we can
use poll() to wait for input and control all signals, etc.
This patch also a little changes fdisk behavior on CTRL+C and CTRL+D.
The signals does not kill fdisk, but forces fdisk to return to the
main menu, if already in the main menu then exit. If the disk layout
has been modified than ask "Do you really want to exit...".
Karel Zak [Tue, 22 Aug 2017 12:55:51 +0000 (14:55 +0200)]
libfdisk: add fdisk_save_user_grain()
Let's provide API for applications that don't want to use the default
1MiB grain. The new function allow to use "as minimal as possible" if
grain is set by fdisk_save_user_grain() to 512.
If the phy sector size (or minimal I/O size) is greater than specified
grain size than smallest possible setting is used.
Karel Zak [Tue, 22 Aug 2017 12:48:14 +0000 (14:48 +0200)]
libfdisk: (gpt) fix size-1 error
If partition does not require alignment, then don't call LBA align
function and don't use size-=1 (fdisk_align_lba_in_range() returns
unmodified size and we call size=-1 more than once for the same size).
Karel Zak [Mon, 21 Aug 2017 09:11:11 +0000 (11:11 +0200)]
isosize: iterate over all arguments even when something fails
Earlier the command exit too early if one of the arguments failed. After
this change all arguments are examined, and command return value will have
information what happen during processing.
Sami Kerola [Sat, 12 Aug 2017 08:31:11 +0000 (09:31 +0100)]
look: use WORDLIST environment variable to find word list
The WORDLIST is the same hunspell(1) and ispell(1) uses to achieve the same.
Apparently aspell(1) does not work with files like traditional dict lists.
Reference: https://github.com/hunspell/hunspell/blob/master/man/hunspell.1#L388
Reference: http://www.skrenta.com/rt/man/ispell.1.html
Reference: http://aspell.net/man-html/Creating-an-Individual-Word-List.html#Creating-an-Individual-Word-List Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The MBR partition pseudo-UUID is generated from table ID and partition
partno. The final UUID size limit is 37 bytes. The table ID has to be
restricted to keep compiler happy (for MBR the table ID is 8 bytes
as string).
Karel Zak [Mon, 14 Aug 2017 08:33:06 +0000 (10:33 +0200)]
lib/randutils: improve getrandom() usage
The getrandom() does not have to return all requested bytes (missing
entropy or when interrupted by signal). The current implementation in
util-linux stupidly asks for all random data again, rather than only
for missing bytes.
The current code also does not care if we repeat our requests for
ever; that's bad.
This patch uses the same way as we already use for reading from
/dev/urandom. It means:
* repeat getrandom() for only missing bytes
* limit number of unsuccessful request (16 times)
* fallback to /dev/urandom on ENOSYS (old kernel or so...)
Addresses: https://github.com/karelzak/util-linux/issues/496 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Thu, 10 Aug 2017 08:26:21 +0000 (10:26 +0200)]
Merge branch 'master' of https://github.com/RAOF/util-linux
* 'master' of https://github.com/RAOF/util-linux:
lib/randutils.c: More paranoia in getrandom() call.
lib/randutils.c: Fall back gracefully when kernel doesn't support getrandom(2).
lib/randutils.c: Fall back gracefully when kernel doesn't support getrandom(2).
The 3.16 kernel is supported until 2020, and various distros have kernels of the same
vintage. It's entirely possible for code built against newer headers to be run against
these kernels, so fall-back to the old “read /dev/{u,}random” method if the kernel doesn'
support getrandom()
Sami Kerola [Sat, 29 Jul 2017 21:27:46 +0000 (22:27 +0100)]
bash-completion: look for look completions
The look(1) uses positional arguments, where first one is a word from
dictionary. It is reasonable to assume most of the time people search from
system word lists so propose completions from there. The second argument is
a dictionary file, that might invalidate the first input but that only
happens to users who have an idea what the want without bash-completion.
Sami Kerola [Sat, 29 Jul 2017 16:19:47 +0000 (17:19 +0100)]
vipw: use explicit_bzero() to clear buffer after copy
This should make leaking end of /etc/shadow file more unlikely.
Notice that there is now way to tell to editors they should ensure none it
does not leak any buffers, drop cores, and so on, when editing sensitive
data. In short this change is addressing the issue only partially.
Every hwclock operation that requires reading the RTC, tests
hclock_valid and prints a different warning. This redundancy
is unnecessary.
Move the warning to the RTC read block (the test was moved in
a previous patch in this set). This reduces function arguments
and is a significant code clean up. It will also benefit the
translators.
Signed-off-by: J William Piggott <elseifthen@gmx.com>
The select() synchronization branch only returns success or
fail. There is no reason for the busywait branch to do more.
If synchronization fails for any reason then it must exit,
otherwise all drift correction operation will be invalid.
Signed-off-by: J William Piggott <elseifthen@gmx.com>
hwclock: correlate hclocktime instead of set_time.
Correlate hclocktime with set_time instead of the other way around,
because set_time is used for timestamps in the adjtime file so it needs
to be unadulterated.
Also create var startup_hclocktime for correlated time.
Signed-off-by: J William Piggott <elseifthen@gmx.com>
Over the past decade a few commits for a corner case problem
have left the RTC read branch in a bad place.
The problem was: when a corrupted RTC could not be read, then
it also could not be reset, because hwclock would error out
due to the RTC read failure.
2.15-rc1 commit 3b96a7a Aug 9 2008
2.19-rc1 commit 5606df5 Dec 29 2010
2.23-rc1 commit ab8f402 Mar 21 2013
The first fix was to ignore a synchronization timeout only for
the busywait branch.
Two and a half years later a commit describing the same problem
took a little more heavy-handed approach by ignoring all
synchronization failures and the RTC read after it, for both of
the RTC set functions.
Because the previous fix also ignored the select() branch timeout
it caused a bogus warning. The chosen workaround for that was to
only print the select() timeout message in debug mode (this is
reverted by another patch).
The problem with these fixes is that we cannot just ignore the
synchronization timeout like that, because then the drift
correction operations will be invalid. The original logic was
correct; we must exit when synchronization fails.
Another problem is that now there are statements between the
timing-critical synchronize-read-timestamp trio (which were
also in the wrong order, but that part of the problem goes
back further in history).
The solution is to skip the RTC read block completely for the
RTC set functions when not also using the --update-drift
option. If we are updating the drift correction factor during
a set function then we must synchronize and read the RTC.
Otherwise reading the RTC is not needed. Anyone trying to set
a corrupt RTC should not be using --update-drift, because the
resulting drift correction factor would be invalid.
Using this approach has the added benefit of significantly
reducing system shutdown time when not using --update-drift:
time ./hwclock --test --systohc; time ./hwclock-master --test --systohc
Test mode: clock was not changed
real 0m0.072s
user 0m0.066s
sys 0m0.003s
Test mode: clock was not changed
real 0m1.000s
user 0m0.169s
sys 0m0.005s
I've see differences as high as 1.518 seconds.
Signed-off-by: J William Piggott <elseifthen@gmx.com>
Move the predict branch above the RTC read branch.
Move drift correction into the RTC read branch, because it
requires an accurate RTC read, and it needs to be skipped for
operations that do not require an RTC read.
Simplify the RTC read branch test.
Signed-off-by: J William Piggott <elseifthen@gmx.com>
Karel Zak [Thu, 3 Aug 2017 13:09:06 +0000 (15:09 +0200)]
libblkid: mark UBI as RAID
UBI is volume manager rather than filesystem. Note that libblkid has
optimized RAIDs probing (don't search for another filesystems is RAID
detected). We also don't search for RAIDs on very small devices, but
this optimization is ignored for UBI char devices (size=1byte).
Rafał Miłecki [Wed, 2 Aug 2017 12:14:18 +0000 (14:14 +0200)]
libblkid: add support for UBI superblock
UBI is a volume management system that can be used on a raw flash
partition for providing multiple logical volumes. Detecting UBI
superblock may be useful for tools wanting to simplify or automate
attaching UBI.
Please note it's not directly related to the ubifs support which is just
a filesystem working on top of UBI volume.
In other words: UBI can be used on MTD partition (e.g. /dev/mtdblock0)
while ubifs can be used on UBI volume (e.g. /dev/ubi0_0).
This patch adds simple code reading UBI version and unique number and
setting it in the blkid_probe.
setpriv: document accepted formats for naming caps
Since commit fbd15c4d4 (setpriv: support setting unnamed capabilities,
2017-07-17), it is possible to name capabilities not only by name, but
also by their index. While using the human-readable name is usually
recommended, using the index may be required in case new capabilities
have been introduced to the kernel for which we have no name yet. The
newly introduce format format is not documented inside of setpriv(1),
though, which is being fixed in this commit.
The rtc driver has not returned EINVAL for unimplemented ioctls since
v2.5.8 in 2002. However, it does return it for other errors; making the
current test potentially problematic. Since 9f3d0fc util-linux assumes
kernel >= 2.6.0 so remove EINVAL as an ioctl test.
Signed-off-by: J William Piggott <elseifthen@gmx.com>
hwclock previously used printf for custom errno messages.
Later they were converted to use warn(), but were not
squashed. One of the reasons for warn and errno is to avoid
making translators deal with a multitude custom strings.
Also the custom strings are incorrect:
hwclock --hctosys
hwclock: Must be superuser to set system clock.
Unable to set system clock.
We do not know what the system permissions are set to. The
correct response is to simply say permission was denied; as
the default errno string does. The second line is redundant
and just adds noise the code and to logs.
Patched:
hwclock --hctosys
hwclock: settimeofday() failed: Operation not permitted
Signed-off-by: J William Piggott <elseifthen@gmx.com>
build: use --runstatedir instead of --localstatedir
The util-linux code was previously aligned to use @localstatedir@ and
the util-linux build system was set to override the default to use /run.
Current GNU Coding Standards introduced the @runstatedir@ variable
for this purpose. Lets use that instead.
The GNU default for @runstatedir@ is ${localstatedir}/run so util-linux
still override the default to be /run to preserve the status quo from
before. The only difference is that you'll now pass --runstatedir to
override the location on the command line instead of --localstatedir.
(FWIW, Debhelper in compat 11 will automatically start passing
--runstatedir=/run to all autotools configured builds. It already
passes --localstatedir=/var (to avoid it ending up with the GNU default
/usr/local/var) which breaks the util-linux build system code that
tries to default it to /run. This change will thus allow util-linux
and debhelper to work better together and avoid the need for a
package-specific override.)
whereis: include native multiarch path in lib search paths
This includes atleast the native multiarch path in the paths to search.
(Maybe also other multiarch paths should also be searched? But atleast
this is a first step.)
Before this change (on Debian):
$ whereis libc
libc: /usr/share/man/man7/libc.7.gz
After this change:
$ whereis libc
libc: /usr/lib/x86_64-linux-gnu/libc.so /usr/lib/x86_64-linux-gnu/libc.a /usr/share/man/man7/libc.7.gz
Addresses: https://bugs.debian.org/856968 Signed-off-by: Andreas Henriksson <andreas@fatal.se>
Karel Zak [Mon, 31 Jul 2017 09:45:23 +0000 (11:45 +0200)]
libsmartcols: add scols_table_enable_noencoding()
Now the library encode all output. It seems too strict and difficult
to use the library for some use-cases -- for example if you want to
use the library for already colorized output (by esc.sequences).
Karel Zak [Wed, 19 Jul 2017 09:30:57 +0000 (11:30 +0200)]
libfdisk: add fdisk_disable_dialogs()
The default (for historical reasons) is to use dialog driven partitioning.
It's possible to avoid dialogs by fdisk_partition template for
fdisk_add_partition().
Unfortunately in some case (mostly DOS driver) it's not enough, because
we need to distinguish between logical and primary partitions. If we know
that dialogs are unwanted then we can default to primary partition, etc.
This function simplify semantic of the library for non-interactive
programs.
When setting capabilities, we accept human readable names like for
example `sys_rawio` or `net_admin`. To do so the translation between the
capability name and its in-kernel index, we rely on the function
`capng_name_to_capability`. When the function does not know the named
capability, it will return an error value and we abort setting the
capability.
This relies upon the ability of libcap to know all capabilities inside
of the kernel. But actually, it is possible that new capabilities are
introduced inside of the Linux kernel which are not recognized yet by
the library. When dumping these unknown capabilities, libcap will simply
return a string like "cap_38", that is it will append the capability's
in-kernel index to the prefix "cap_". This may lead a user to also think
that "cap_38" may be passed to the switches "--inh-caps" or
"--ambient-caps", which is unfortunately not the case.
We can do better here by instead accepting strings in the form of
"cap_N". To do so, we can simply rely on the fact that capability
indices are steadily increasing and that the highest index known to the
kernel is stored inside of the kernel's procfs, made readily available
by our function `real_cap_last_cap()`. So in case libcap does not know a
capability name, we can simply parse the string and, if it is in the
correct format, check whether the detected index is between 0 and the
highest capability index. If so, we can treat it as a valid capability
string and apply it.
warning on 32bit systems:
../lib/parse-date.y: In function 'parse_date':
../lib/parse-date.y:1509:7: warning: format '%ld' expects argument of type 'long int', but argument 4 has type 'intmax_t' [-Wformat=]
abs_time_zone_min);
^