Commit Graph

14722 Commits

Author SHA1 Message Date
Egor Chelak 212bde6cf7 ul_copy_file: handle EAGAIN and EINTR
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>
2020-11-09 07:19:39 +02:00
Egor Chelak f19a16550a ul_copy_file: use all_read/all_write
Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:36 +02:00
Egor Chelak e453099640 ul_copy_file: use BUFSSIZ for buffer size
Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:30 +02:00
Egor Chelak 9203b41a4f nologin: use ul_copy_file
Suggested-by: Sami Kerola <kerolasa@iki.fi>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:24 +02:00
Egor Chelak 8fcdbefb7b login: use ul_copy_file
Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:15 +02:00
Egor Chelak 360cdaa6c7 configure.ac: check for sendfile
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>
2020-11-09 07:19:00 +02:00
Egor Chelak a8b4e7cad1 ul_copy_file: use sendfile
Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:18:49 +02:00
Egor Chelak b9dcd38462 vipw: move copyfile to the lib
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>
2020-11-09 07:18:42 +02:00
Egor Chelak 12235ef107 vipw: fix short write handling in copyfile
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>
2020-10-29 19:06:13 +02:00
Karel Zak 9210db64a6 ul: fix use of unsigned number
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-21 12:45:02 +02:00
Karel Zak 732d75945e dmesg: add --since and --until
$ date
Wed 21 Oct 2020 12:05:07 PM CEST

$ dmesg --ctime --since '1 hour ago'
[Wed Oct 21 11:47:13 2020] AAA
[Wed Oct 21 11:55:48 2020] BBB

$ dmesg --ctime --since '1 hour ago' --until '10 minutes ago'
[Wed Oct 21 11:47:13 2020] AAA

Addresses: https://github.com/karelzak/util-linux/issues/1166
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-21 12:09:18 +02:00
Karel Zak 5064635395 ul: small coding changes
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-21 11:16:34 +02:00
Karel Zak 9c4762cb6b Merge branch 'ul-refactor' of https://github.com/kerolasa/util-linux
* '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
2020-10-21 11:08:11 +02:00
Karel Zak 07c8462fb7 cal: do not use putp(), directly use stdio functions
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>
2020-10-21 10:19:26 +02:00
Sami Kerola 1a3f71b292
ul: flip comparisons to lesser to greater order
1 < 2 < x < 4 is the order is the natural of values.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 21:13:25 +01:00
Sami Kerola 0186ff364d
ul: use size_t to measure memory allocation size
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>
2020-10-20 21:13:24 +01:00
Sami Kerola 9a59ee6525
ul: improve function and variable names
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 21:13:24 +01:00
Sami Kerola 580c63259b
ul: rename enumerated mode symbols
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>
2020-10-20 21:12:49 +01:00
Sami Kerola 52e3ce0097
ul: remove function like putwp preprocessor define
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>
2020-10-20 20:29:27 +01:00
Sami Kerola 1962d5cfca
ul: free most allocations ncurses did during setupterm()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola eaf68e3083
ul: replace global runtime variables with a control structure
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola 4942193926
ul: add a term capabilities tracking structure
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola a2811907e9
ul: remove function prototypes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola 5b627d8496
ul: tidy up coding style
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola aa439c6035
ul: add basic tests
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:20 +01:00
Dr. David Alan Gilbert 97c9ec9ce3 libmount: Fix 0x%u usage
There's a couple of places which use varients on "0x%u" in format strings;
that's almost always wrong - you either want 0x%x or just %u.  In libmount's
case it's flags, so I'm assuming the intention really is hex.  In the ja.po
case it's %u in the original msgid.

Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
2020-10-19 12:15:15 +02:00
Sami Kerola 43ce3e7311 sfdisk: do not free device name too soon [coverity scan]
Fixes use after free error.

CID: 360798
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 12:00:53 +02:00
Sami Kerola c60c65c37e login: close() only a file descriptor that is open [coverity scan]
CID: 360819
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 11:59:16 +02:00
Karel Zak d3e58a8ec9 switch_root: fix double close [coverity scan]
Up on successful fdopendir(3) file descriptior that will be closed, that
happens in recursiveRemove() switch_root(8) function.

CID: 360697
Reference: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdopendir.html
Co-Author: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 11:56:35 +02:00
Sami Kerola 7f9e76b4df fsck, libblkid: fix printf format string issue [coverity scan]
According to coverirty a printf format string contains an unrecognized
format specifier (CWE-628).  Lets avoid glibc extension "%m" that is same
as "%s", strerror(errno).

CID: 360699
CID: 360718
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 11:35:16 +02:00
Sami Kerola 12558a4c47 nsenter / switch_root: fix insecure chroot [coverity scan]
If a call to chroot is not followed by a call to chdir("/") the chroot jail
confinement can be violated.  See also CWE-243.

CID: 360718
CID: 360800
Reference: http://cwe.mitre.org/data/definitions/243.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 11:32:38 +02:00
Sami Kerola d2ab69ff61 login: ensure getutxid() does not use uninitialized variable [coverity scan]
Field ut.ut_pid is uninitialized when calling getutxline().  The safest
option is to ensure all struct data is initialized in the function.

CID: 360793
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 11:30:45 +02:00
Sami Kerola 8df3f8ef84 lib/pager: fix improper use of negative value [coverity scan]
The close(2) cannot accept a negative number.

CID: 360777
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 11:30:08 +02:00
Sami Kerola 232fcae81c unshare: fix bad bit shift operation [coverity scan]
Variable cap was 32 bits and shifting it by 64 bits resulted to the shift
going over a variable boundary.

CID: 360799
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-16 11:27:42 +02:00
Sami Kerola dab057ebd2 hardlink: fix hardlink pcre leak
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 11:25:11 +02:00
Sami Kerola afbf8fe223 col: fix --help short option in usage() output
The col(1) is using unusual -H as --help short option.  The -h is used for
--tabs (horizontal tab?) in this implementation.

Fixes: 62dee0176a
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 11:13:04 +02:00
Karel Zak 2ceccca901 tests: update sfdisk wipe tests
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-16 10:59:17 +02:00
Karel Zak 29decc7b37 sfdisk: disable bootbits protection on '--wipe always'
Addresses: https://github.com/karelzak/util-linux/issues/1156
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-15 12:04:15 +02:00
Karel Zak e57cbfe0aa mkfs.minix: add --lock and LOCK_BLOCK_DEVICE
Addresses: https://github.com/karelzak/util-linux/issues/921
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-14 11:33:13 +02:00
Karel Zak 91f80d9a2a Merge branch 'master' of https://github.com/eric-simpson/util-linux
* 'master' of https://github.com/eric-simpson/util-linux:
  do not require sys/syscall.h on non-linux platforms
2020-10-14 10:24:25 +02:00
Karel Zak f51c63af47 Merge branch 'dusty-remove-fstab-condition' of https://github.com/dustymabe/util-linux
* 'dusty-remove-fstab-condition' of https://github.com/dustymabe/util-linux:
  fstrim: remove fstab condition from fstrim.timer
2020-10-14 10:23:20 +02:00
Eric Simpson 811351ac98 do not require sys/syscall.h on non-linux platforms
In order to build util-linux on other platforms (such as IBM i), do not require the linux-specific sys/syscall.h.
2020-10-13 12:55:05 -04:00
Karel Zak 017c0308c7 tests: update atari partx tests
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-13 18:34:39 +02:00
Dusty Mabe 9651b677f1
fstrim: remove fstab condition from fstrim.timer
In 9995da0 we added support to fstrim to be able to fall back to
`/proc/self/mountinfo` if `/etc/fstab` didn't exist, but we forgot
to remove the `/etc/fstab` condition from the timer. Let's remove
that condition from the timer so we can go back to periodically
running `fstrim.service`.
2020-10-13 11:28:07 -04:00
Karel Zak 0d061b6e68 tests: update atari blkid tests
The old images of the atari label are truncated and in-table stored
sizes do not match with real images sizes -- libblkid checks it now.

I have no idea how to generate ICD format, let's ignore it in tests
for now.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-13 16:29:19 +02:00
Karel Zak 282ceadc3a libblkid: make Atari more robust
* ignore large disks
* check in-table stored device size
* check bad sectors list
* check partition dimensions against in-table device size

Addresses: https://github.com/karelzak/util-linux/issues/1159
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-13 16:19:20 +02:00
Karel Zak 75cd5e2f28 losetup: increase limit of setup attempts
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-13 12:55:44 +02:00
Karel Zak 3ff6fb802d losetup: avoid infinite busy loop
issue report:
 if i run the heavy duty test from #16859 a couple of times I can get
 the loopback layer in the kernel into a state where there's a loopback
 block device allocated, that you can open, but where both LOOP_CLR_FD
 and _SET_FD fail with EBUSY. and /dev/loop-control still returns it as
 the next free one...  weird state util-linux losetup when called to
 allocate a new device then freezes

This commit:
* restrict number of attempts to 16
* use 200000ms sleep between attempts
* add note about non-atomic loop device setup to the man page

Reported-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-13 10:58:04 +02:00
Karel Zak a83bea2d3d bash-completion: (lsblk) update columns
and fix lsblk --help output

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-12 13:19:35 +02:00
Karel Zak 7636d906ef lsblk: add --width option
Addresses: https://github.com/karelzak/util-linux/issues/1160
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-12 12:19:48 +02:00