Also, a bug in pw_tmpfile was fixed: copyfile used tmp_file to report
errors, but pw_tmpfile only assigned that variable _after_ calling
copyfile.
Suggested-by: Sami Kerola <kerolasa@iki.fi>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
If a libuuid application is unable to access /dev/random or /dev/urandom
then uuid generation by uuid_generate falls back to uuid_generate_time.
This could happen in chroot or container environments.
The function ul_random_get_bytes from lib/randutils.c uses getrandom if
it is available. This could either mean that the libuuid application
skips good random bytes because the character special files do not exist
or the application trusts in good random bytes just because these files
are accessible but not necessarily usable, e.g. limit of open file
descriptors reached, lack of data, kernel without getrandom, etc.
This commit modifies ul_random_get_bytes to return an integer which
indicates if random bytes are of good quality (0) or not (1). Callers
can decide based on this information if they want to discard the random
bytes. Only libuuid checks the return value. I decided to return 1
instead of -1 because -1 feels more like an error, but weak random bytes
can be totally fine.
Another issue is that getrandom sets errno to specific values only in
case of an error, i.e. with return value -1. Set errno to 0 explicitly
if getrandom succeeds so we do not enter the fallback routine for
ENOSYS by mistake. I do not think that this is likely to happen, but it
really depends on possible wrapper function supplied by a C library.
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
When calling variadic functions, NULL must be explicitly cast to a
desired type.
This is noted in the exec(3) manpage.
The call in newgrp.c was changed for consistency.
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
The old implementation uses /proc/partitions where devices are
filtered by kernel (missing devices with ext_range=1 and removable
devices).
The problem with the old implementation is whole-disk heuristic based
on device name, order of devices, etc.
The new implementation use the same code to read also removable
devices.
Addresses: https://github.com/karelzak/util-linux/issues/1151
Signed-off-by: Karel Zak <kzak@redhat.com>
The library is not distributed and almost all code in this ar(1)
archive is Public Domain or LGPL ... but let's avoid any doubts and do
not mix non-GPL and GPL code there.
Addresses: https://github.com/karelzak/util-linux/issues/1157
Signed-off-by: Karel Zak <kzak@redhat.com>
It's was originally GPL, but all the current code in the file is from
me and I don't think it makes sense to use GPL here anymore. We need
to use lib/ files in LGPL as well as in GPL binaries, etc. Let's makes
things (build-system) less complicated.
Signed-off-by: Karel Zak <kzak@redhat.com>
The goal is to use it in libmount when generate options strings
and in libsmartcols to replace libscols_buffer.
Signed-off-by: Karel Zak <kzak@redhat.com>
The recent change in code improves main-pool on error, but we need
to kill child process if it still running to avoid hang up in next
waitpid().
Signed-off-by: Karel Zak <kzak@redhat.com>
Handle error based on return code of handle_io() and handle_signal().
Keep SIGTTIN unblocked during read() in handle_io().
Signed-off-by: Soumendra Ganguly <soumendraganguly@gmail.com>
* do not ignore all empty devices, we need more smart solution
* ignore only loop devices without backing file, for example:
# touch img
# losetup -f img
losetup: img: Warning: file is smaller than 512 bytes; the loop device may be useless or invisible for system tools.
- old version display nothing
- new version:
# lsblk /dev/loop0
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 0B 0 loop
Addresses: https://github.com/karelzak/util-linux/issues/1118
Signed-off-by: Karel Zak <kzak@redhat.com>
Permanently turn off current stdin ECHO when it is a terminal and enable setting slave ECHO instead.
Fix other minor typos, update documentation.
[kzak@redhat.com: - remove irrelevant changes
- keep --echo argument unchanged]
Signed-off-by: Karel Zak <kzak@redhat.com>
Timestamps in kernel log comes from monotonic clocksource which does not
tick when system suspended. Suspended time easily sums into hours and days
rendering human readable timestamps in dmesg useless.
Adjusting timestamps accouring to current delta between boottime and
monotonic clocksources produces accurate timestamps for messages printed
since last resume. Which are supposed to be most interesting.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
All simple function to parse --lock <mode> and $LOCK_BLOCK_DEVICE,
and to flock the fd.
The supported <mode> is:
"1" or "yes" - LOCK_EX
"0" or "no" - do nothing
"nonblock" - LOCK_EX | LOCK_NB
The function tries LOCK_NB before the solo LOCK_EX and prints
inform user that it will wait, for example:
session A:
# sfdisk --lock /dev/sdc
session B:
# sfdisk --lock /dev/sdc
sfdisk: /dev/sdc: device already locked, waiting to get lock ...
^C
# sfdisk --lock=nonblock /dev/sdc
sfdisk: /dev/sdc: device already locked
Addresses: https://github.com/karelzak/util-linux/issues/921
Signed-off-by: Karel Zak <kzak@redhat.com>
There is value in ensuring that manual page sections use consistently
named sections, as far as possible, and also that sections have a
consistent order within manual pages. This is one of a series of patches
to place manual page sections in a consistent order.
In this patch, we ensure that the ENVIRONMENT, FILES, and CONFORMING TO
sections are always placed toward the end of the page, just above NOTES.
One page is not fixed by this patch: term-utils/agetty.8. This page
is a mess of unusual section names, and probably requires an individual
edit.
Testing that no gross editing mistake (causing accidental loss or addition
of text) was performed as follows:
$ cat $(grep '\.SH' -l $(find . -name '*.[1-9]') |sort) | sort > a
[Apply patch]
$ cat $(grep '\.SH' -l $(find . -name '*.[1-9]') |sort) | sort > b
$ diff a b
$ echo $?
0
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
There is value in ensuring that manual page sections use consistently
named sections, as far as possible, and also that sections have a
consistent order within manual pages. This is one of a series of patches
to place manual page sections in a consistent order.
In this patch, we ensure that the NOTES, HISTORY, BUGS, and EXAMPLE
sections are always placed near the end of the page, just above
AUTHORS, COPYRIGHT, SEE ALSO, and AVAILABILITY.
One page is not fixed by this patch: term-utils/agetty.8. This page
is a mess of unusual section names, and probably requires an individual
edit.
Testing that no gross editing mistake (causing accidental loss or addition
of text) was performed as follows:
$ cat $(grep '\.SH' -l $(find . -name '*.[1-9]') |sort) | sort > a
[Apply patch]
$ cat $(grep '\.SH' -l $(find . -name '*.[1-9]') |sort) | sort > b
$ diff a b
$ echo $?
0
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
There is quite some value (in terms of readability and user
expectations) if consistent names are used for the sections
within manual pages. This patch is one of a series to bring
about this consistency.
Currently we have EXAMPLE (10) or EXAMPLES (23).
Let's standardize on the EXAMPLE (which is also what is
suggested in man-pages(7)) and used consistently across
a large number of pages in the Linux man-pages project.
(I realize the choice to go EXAMPLE, rather than EXAMPLES,
may be debatable. If necessary, I'd write a patch that instead
goes the other way, but I'd prefer to follow man-pages(7).)
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Using double quotes in .SH lines containing multiple words is unneeded,
and in any case is not consistently done in the util-linux manual pages,
where double quotes are used in only around half of the cases.
(This usage was long ago elminated in the man-pages project, with
no ill effects reported to date.)
Remove these quotes, so that .SH lines are more uniform, in preparation
for some (more easily) scripted doiscovery of consistency problems in
(and possibly global fixes to) the manual pages.
Other than stripping the double quotes, this patch makes no changes to
the content of the manual pages.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
For example
./test_strutils --size '1.0000000000000000000000000000018000000000000000010M'
./test_strutils --size '1.18446744073709551615M'
ends with infinite loop due to frac_div variable overflow.
Addresses: https://github.com/karelzak/util-linux/issues/1023
Signed-off-by: Karel Zak <kzak@redhat.com>
Lsblk throws the following error for nvmeNcXnY devices.
lsblk: nvme1c1n1: unknown device name
This is because nvmeNcXnY devices are hidden and do not have
the file /sys/block/<nvmeNcXnY>/dev.
Following patch was added
https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=d51f05bfecb299a830897106460bf395be440c0a
Which made lsblk read from /sys/block/<nvmeNcXnY>/device/dev
which do exist for nvmeNcXnY devices.
After the above patch, the unknown error goes away.
However, another error is encountered in the very next step.
nvme1c1n1: failed to initialize sysfs handler
This is because lsblk looks for /sys/dev/block/242:1
(nvmeNcXnY major:minor) pathname which usually exists for other
block devices but not for the nvmeNcXnY devices as they are hidden.
Below patch does not even print this error for hidden devices
and exits silently.
[kzak@redhat.com: - add prefix to make sysfs_devname_is_hidden()
usable for /sys dumps
- use the function in initialize_device() more early]
Signed-off-by: Ritika Srivastava <ritika.srivastava@oracle.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
We already have mbs_safe_nwidth() but it assumes that all "bad" chars
will be encoded by \x<hex>. Now we need also function that do not care
about encoding.
Signed-off-by: Karel Zak <kzak@redhat.com>
* 'map-user' of https://github.com/mat8913/util-linux:
unshare: Support names for map-user/group options
lib/pwdutils: add xgetgrnam
unshare: allow custom uid/gid mappings in userns
Let's consolidate the code, we need to use it in libfdisk too. It
seems better to keep it generic and libblkid independent.
This patch also removes blkid_encode_alloc(), this function is overkill.
Signed-off-by: Karel Zak <kzak@redhat.com>
The logger and rtwake time function changes continue the same fixes as
previous commit - use thread safe functions. The libsmartcols condition
removal is possible because width must be greater than tb->termwidth that is
size_t and cannot be smaller than zero. And remove couple FIXME's that are
old and unlikely ever to get fixed.
Reference: 3160589d86
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
ASAN is pretty unhappy with getpid() << 16, it seems better to save
into unsigned int and than do the bit-op.
Addresses: https://github.com/karelzak/util-linux/issues/942
Signed-off-by: Karel Zak <kzak@redhat.com>
It's mostly wrappers for compatibility and another trivial stuff etc.
Let's keep it as public domain to make it more portable to LGPL, GPL
and BSD code.
Signed-off-by: Karel Zak <kzak@redhat.com>
CC: Sami Kerola <kerolasa@iki.fi>
CC: Ruediger Meier <ruediger.meier@ga-group.nl>
Add a comma (,) after "e.g." and "i.e.", or use English words
(man-pages(7) [package "manpages"]).
Abbreviation points should be protected (usually with the
non-printing, zero width character '\&') from being interpreted as an
end of sentence, if they are not, and that independent of their current
place on the line.
This is important when typing, as one does not usually know in
advance when the editor jumps to a new line.
Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
The file is originally from libuuid, this library is under BSD
licence. Unfortunately, I have added LGPL header by accident to the
file (commit 0f23ee0c85).
The file under LGPL was modified (in relevant way) by Sami,
Christopher and me. We all agree with re-licensing back to BSD.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Christopher James Halse Rogers <chris@cooperteam.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
It some cases it makes sense to disable ECHO flag also when script
used in pipe. This new option allows to keep full control in user's
hands.
Signed-off-by: Karel Zak <kzak@redhat.com>
We need a proper way how to inform child (shell) that the game is
over. It seems the best is to send EOF to child rather than
immediately break PTY mainloop where we have poll(), because shell can
still produce data etc.
Signed-off-by: Karel Zak <kzak@redhat.com>
For tools like su(1) is ECHO flag unexpected for use-case like
echo 'date' | su - user
but script(1) need the echo to keep input recorded.
The patch also return execlp() use to script(1) code.
Signed-off-by: Karel Zak <kzak@redhat.com>
The parse-date.y is used only for hwclock, let's keep it together.
Note that the file (originally from gnulib) has GPLv3 license, so it's
better to make it obvious that we use it really only for hwclock (also
GPL).
Signed-off-by: Karel Zak <kzak@redhat.com>
The classic way which is based on file-descriptors table size is
pretty expensive (due to table size) and forces code to do many
unnecessary close() calls. It seems better to use /proc/self/fds and
close used descriptors only.
Addresses: https://github.com/karelzak/util-linux/issues/883
Signed-off-by: Karel Zak <kzak@redhat.com>
* add ul_path_stat()
* make sure all paths for ul_path_..() functions are always
interpreted relatively to the context directory and prefix. This is
difference between ul_path_ API and standard libc "at" functions. We
do not use any exception for absolute paths. The reason is that we
need to read from prefixed paths although application assume absolute
path (/dev/sda1 means /prefix/dev/sda1 if a /prefix is defined).
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/test_pty-monotonic.o: In function `get_boot_time':
/home/travis/build/karelzak/util-linux/lib/monotonic.c:29: undefined reference to `clock_gettime'
lib/test_pty-monotonic.o: In function `gettime_monotonic':
/home/travis/build/karelzak/util-linux/lib/monotonic.c:56: undefined reference to `clock_gettime'
Signed-off-by: Karel Zak <kzak@redhat.com>
It's necessary to create signal-fd before fork() to get SIGCHLD,
because child could be faster than our code.
Signed-off-by: Karel Zak <kzak@redhat.com>
Now the code is duplicate on many places, but all we usually need is to
remember child status. It seems good enough to have very simple
callback child_die() to inform application about a change.
The patch also add PID to all signal related callbacks.
Signed-off-by: Karel Zak <kzak@redhat.com>
This allows to control mainloop behavior from PTY applications. For
example you can write to child (shell) process independently on the
current stdin.
Signed-off-by: Karel Zak <kzak@redhat.com>
The idea is to consolidate script(1), scriptlive(1) and su(1) --pty
and use the same code everywhere.
TODO: add callbacks for stdin/out logging (necessary for script(1)).
Signed-off-by: Karel Zak <kzak@redhat.com>
Add the --keep-caps option to unshare to preserve capabilities that
are granted when creating a new user namespace. This allows the child
process to retain privilege within the new user namespace without also
being UID 0.