* 'vipw-shortwrite' of https://github.com/DankRank/util-linux:
ul_copy_file: make defines for return values
read_all: return 0 when EOF occurs after 0 bytes
ul_copy_file: add test program
ul_copy_file: handle EAGAIN and EINTR
ul_copy_file: use all_read/all_write
ul_copy_file: use BUFSSIZ for buffer size
nologin: use ul_copy_file
login: use ul_copy_file
configure.ac: check for sendfile
ul_copy_file: use sendfile
vipw: move copyfile to the lib
vipw: fix short write handling in copyfile
Originally it would return -1 (without setting errno) if the fd was
already at EOF when you called read_all.
This is already fixed in sendfile_all.
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
I did this by implementing a function called sendfile_all() similar to
read_all()/write_all().
The manpage for sendfile doesn't mention EINTR, but I decided to check
it anyway, just in case.
Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
Do note that according to man sendfile, "Other UNIX systems implement
sendfile() with different semantics and prototypes."
If this is something we care about, a better check is needed.
Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
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>
* fix final message where number of moved sectors overflow number of
all moved sectors
* align last step size before we use it for backward mode source and
destination offsets calculation
Addresses: https://github.com/karelzak/util-linux/issues/1176
Signed-off-by: Karel Zak <kzak@redhat.com>
* 'whereis' of https://github.com/ferivoz/util-linux:
whereis: extend test case
whereis: filter bin, man and src differently
whereis: do not strip suffixes
whereis: do not ignore trailing numbers
whereis: add --disable-whereis to configure
whereis: add lib32 directories
whereis: support zst compressed man pages
whereis: fix out of boundary read
`--json` implies `--dump`, thus `--json --dump` must be
allowed. `--list-free` is incompatible with `--dump`, and thus also
with `--json`. Currently `--json --dump` is prohibited, even though
`--list-free` is not specified at all.
Regression introduced in 03154d2cf2.
Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com>
Consider "s." prefixes for source code files only (even though I do not
know which VCS does that), compression suffixes for manual pages and
strict matching for executables.
Calling "whereis python3" is kind of okay to return python3.8 next to
python3, but python3.8-config is not the same tool as python3.
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
The whereis implementations of FreeBSD, macOS, NetBSD, and OpenBSD do
not strip suffixes. Although whereis is not a POSIX tool and has no
shared standard, even its manual page indicates that the supplied names
are command names.
Commands do not have a suffix on Linux systems.
Stripping suffixes actually leads to issues with tools like fsck.ext4,
since fsck.ext4 is not the same tool as fsck and definitely not the same
tool as fsck.minix.
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
The commands diff and diff3 are so distinct that their manual pages
should not be mixed in whereis output.
Theoretically this works for commands and binaries with links to each
other, e.g. gpg and gpg2, but if gpg is version 1 and gpg2 is version 2
then manual pages do not match either.
Also the while loop does not decrement "i" while incrementing "dp". The
effect of this is that the output of whereis depends on manual pages
being compressed or not.
The easiest solution is to not ignore trailing numbers.
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
Add zst as extension for manual pages. Current version of man-db
supports zst extension out of the box.
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>
Since `off` and `nr` approach each other, the for-loop ends prematurely
when at least half of the buffer was written. I think under certain
conditions this could cause the copy to be incomplete.
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
* 'ul-refactor' of https://github.com/kerolasa/util-linux:
ul: flip comparisons to lesser to greater order
ul: use size_t to measure memory allocation size
ul: improve function and variable names
ul: rename enumerated mode symbols
ul: remove function like putwp preprocessor define
ul: free most allocations ncurses did during setupterm()
ul: replace global runtime variables with a control structure
ul: add a term capabilities tracking structure
ul: remove function prototypes
ul: tidy up coding style
ul: add basic tests
It seems our putp() based output is not portable as some ncurses
implementations strictly follow POSIX where putp() accepts only
terminfo capability strings and nothing else.
We already use standard stdio.h functions to output terminfo strings
(e.g. for colors). It seems we can do the same for cal(1) to
highlight the current day.
Note that mix putp() and fputs() is bad idea due to different
buffering ways in some cases (see cal.c git log for more details).
This patch also reduces complexity of the code as we can directly
output to stdout without snprintf to string.
Addresses: https://github.com/karelzak/util-linux/pull/1167
Signed-off-by: Karel Zak <kzak@redhat.com>
The size_t is the type libc memory allocation functions use. The size_t
also provides allocation range that is enough not to a simple tool like this
to perform paranoia size checks. Just let the realloc(3) fail if there is
not enough memory available to handle the requested line size. That is a
lot more straightforward.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
First two are are ISO/IEC 2022 graphic character sets G0 (normal) and G1
(alternative), that one has to Switch In (SI) and Switch Out (SO). The rest
are about how ul(1) is interacting with various text emphasis.
Reference: https://tldp.org/HOWTO/Keyboard-and-Console-HOWTO-6.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The #ifdef HAVE_WIDECHAR can be removed, because the command already is
using wide character functions elsewhere without fallbacks.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>