Commit graph

2236 commits

Author SHA1 Message Date
Karel Zak
60c3686b81 lsblk: use sysfs_blkdev_is_removable()
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-01-24 17:38:49 +01:00
Karel Zak
46768d677f Merge branch 'signal_safety' of https://github.com/crrodriguez/util-linux
* 'signal_safety' of https://github.com/crrodriguez/util-linux:
  sulogin: only assign to variables written by signal handlers
  hardlink: calling putchar is off-limits on a signal handler
  hardlink: last_signal should be a volatile sig_atomic_t
  pg: calling exit on signal handler is not allowed
  lib📟 fix signal safety issues
  write: signal_received should be volatile qualified
  flock: timeout_expired must be volatile qualified
  last: should not use errx/warnx on signal handlers
  su-common: bool is a distinct type in c2x
  fsck: only assign to cancel_requested
  fsck: use sig_atomic_t type fot signal handler global vars
2023-01-24 16:45:42 +01:00
Thomas Weißschuh
54a0643829 lsfd: make a few structs const 2023-01-23 13:52:00 +01:00
Thomas Weißschuh
c4a66fa9c6 uuidd: use sizeof_member 2023-01-23 13:52:00 +01:00
Cristian Rodríguez
7165c9bb1e remove no longer needed braces 2023-01-23 13:52:00 +01:00
Cristian Rodríguez
cba3345215 replace open-coded instances of mempcpy 2023-01-23 13:52:00 +01:00
Karel Zak
91a484feba lsfd: remove strcpy(), keep things based on sizeof()
* use safe xstrncpy() rather than strcpy()
* use sizeof() for static buffers rather than macro with real size
  (this solution is more robust for future code changes)
* use xcalloc() to zeroize allocated memory

Signed-off-by: Karel Zak <kzak@redhat.com>
2023-01-20 15:20:55 +01:00
Cristian Rodríguez
ab35a4fb0e hardlink: calling putchar is off-limits on a signal handler
Using putchar or any stdio function in signal handlers will
lead to funny results as they cannot be async signal safe.
One can write to stdout instead.
2023-01-15 01:33:14 +00:00
Cristian Rodríguez
86d9efee19 hardlink: last_signal should be a volatile sig_atomic_t 2023-01-15 01:33:14 +00:00
Karel Zak
a8e071fa20 logger: (man) fix examples
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-01-13 12:18:27 +01:00
Thomas Weißschuh
0d3bc6fdbd waitpid: add support for already exited PIDs 2023-01-09 13:16:30 +00:00
Thomas Weißschuh
8528bd29aa waitpid: add timeout support 2023-01-06 14:37:55 +00:00
Karel Zak
0e39aa22ba Merge branch 'misc-utils-rename-symlink-paths' of https://github.com/ChickenProp/util-linux
* 'misc-utils-rename-symlink-paths' of https://github.com/ChickenProp/util-linux:
  `rename -s` treats paths the same as without `-s`.
2023-01-05 13:03:46 +01:00
Thomas Weißschuh
550d32c49e waitpid: add new command
This command implements waiting for the exit of multiple processes.
Especially it allows to wait for process that are not children of the
current process.

In contrast to wait(1P) it does not allow to retrieve the processes exit
codes.
2023-01-04 01:18:33 +00:00
Philip Hazelden
fa7abf332f rename -s treats paths the same as without -s.
That is, it only updates the final path component, unless either the
expression or the replacement contains a '/'.

As discussed in #1962.
2023-01-03 19:43:28 +00:00
Karel Zak
e6c3efa3fd Merge branch 'cleanups' of https://github.com/t-8ch/util-linux
* 'cleanups' of https://github.com/t-8ch/util-linux:
  fadvise: fix parsing of option -V
  libblkid: zfs: remove unnecessary newline from debug messages
  libblkid: topology: constify some structures
  lib: sysfs: fix typo
2023-01-02 13:24:23 +01:00
Karel Zak
71a5654183 Merge branch 'lsblk-nvme' of https://github.com/mbroz/util-linux
* 'lsblk-nvme' of https://github.com/mbroz/util-linux:
  Update email.
  lsblk: add revision output to --nvme list
  lsblk: read firmware revision from udev
2023-01-02 13:04:38 +01:00
Karel Zak
9141e620cb Merge branch 'mmc' of https://github.com/t-8ch/util-linux
* 'mmc' of https://github.com/t-8ch/util-linux:
  lsblk: add mmc transport
2023-01-02 12:44:57 +01:00
Karel Zak
6a81d75b83 Merge branch 'meson-debian' of https://github.com/zeha/util-linux
* 'meson-debian' of https://github.com/zeha/util-linux:
  meson: install uuidd.rc with -Dsysvinit=enabled
  meson: fix pkg-config name of libaudit
  meson: fix build with -Dselinux=enabled
2023-01-02 12:23:11 +01:00
Karel Zak
45e0307a4a Merge branch 'misc-utils-rename-documentation' of https://github.com/ChickenProp/util-linux
* 'misc-utils-rename-documentation' of https://github.com/ChickenProp/util-linux:
  rename.1: document edge cases.
2023-01-02 12:22:11 +01:00
Thomas Weißschuh
bb78a177cd fadvise: fix parsing of option -V 2022-12-28 04:52:15 +00:00
Milan Broz
67b8731fa6 Update email.
This email no longer works.

Signed-off-by: Milan Broz <gmazyland@gmail.com>
2022-12-23 11:48:17 +01:00
Milan Broz
39a9b2c9a9 lsblk: add revision output to --nvme list
This is similar to --scsi output now.

Signed-off-by: Milan Broz <gmazyland@gmail.com>
2022-12-23 11:48:04 +01:00
Milan Broz
8e89dd8bac lsblk: read firmware revision from udev
This supports more device types like NVMEs.

Signed-off-by: Milan Broz <gmazyland@gmail.com>
2022-12-23 11:47:40 +01:00
Thomas Weißschuh
62491dc126 lsblk: add mmc transport 2022-12-21 18:46:46 +00:00
Karel Zak
97be86cf2d Merge branch 'proc/byteorder' of https://github.com/t-8ch/util-linux
* 'proc/byteorder' of https://github.com/t-8ch/util-linux:
  lscpu: add testcase for Linux 6.2 x86_64
  tests: make mk-input.sh scripts executable
  tests: add ts_check_native_byteorder
  lscpu: test endianess
  sysfs: sysfs_get_byteorder: add context parameter
  lsfd: use runtime byteorder
  lscpu: use runtime byteorder
  sysfs: read runtime byteorder
2022-12-21 10:06:46 +01:00
Chris Hofstaedtler
5e67b421a6 meson: install uuidd.rc with -Dsysvinit=enabled
Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
2022-12-18 23:40:48 +01:00
Philip Hazelden
eb09fc2eb1 rename.1: document edge cases.
Document the behaviour of an empty `expression` argument, and of `/` in
the `expression` and `replacement` arguments.

I also tried to make it slightly clearer that `-s` changes where a
symlink points, but doesn't change the thing that it points at.
2022-12-18 16:41:46 +00:00
Thomas Weißschuh
ef5d0cfe92 lsblk: align function prototype 2022-12-12 20:02:58 +00:00
Karel Zak
85a956a709 hardlink: cleanup options
* add missing stuff to bash-completion
* reorder --help output
* reorder man page

Signed-off-by: Karel Zak <kzak@redhat.com>
2022-12-08 11:12:47 +01:00
Karel Zak
a9b1dfd945 hardlink: add --respect-dir
Fixes: https://github.com/util-linux/util-linux/issues/1942
Signed-off-by: Karel Zak <kzak@redhat.com>
2022-12-08 10:49:45 +01:00
Masatake YAMATO
115c02fe88 lsfd: consider 64bit addresses when scanning /proc/pid/map_files dir
Close #1930.

The original code assumed 48bit addresses. This assumption came
from linux running on x86_64. As reported in #1930, Linux on
sparc64 uses 64bit addresses.

Tested-by: Anatoly Pugachev <matorola@gmail.com>
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2022-11-30 14:55:32 +09:00
Thomas Weißschuh
7578e03f12 sysfs: sysfs_get_byteorder: add context parameter
This can be used to read the file /sys/kernel/cpu_byteorder from an
alternative root-directory.
2022-11-25 19:21:45 +01:00
Thomas Weißschuh
db79a10027 lsfd: use runtime byteorder 2022-11-25 19:20:32 +01:00
Masatake YAMATO
c5eb81b39d lsfd: show extra information returned from ioctl(..., NS_GET_NSTYPE)
lsfd uses the information to fill the newly added NS.TYPE and NS.NAME
columns:

  # ./lsfd -oCOMMAND,PID,USER,ASSOC,SOURCE,MNTID,NS.TYPE,NS.NAME,NAME
           -Q '(FD >= 0) and (SOURCE == "nsfs")'
  COMMAND            PID USER ASSOC SOURCE MNTID NS.TYPE          NS.NAME NAME
  NetworkManager    1114 root     8   nsfs     3     net net:[4026531840] net:[4026531840]
  NetworkManager    1114 root     9   nsfs     3     mnt mnt:[4026532758] mnt:[4026532758]
  lsfd             14379 root     3   nsfs     3     net net:[4026531840] net:[4026531840]
  podman         1532759 root     7   nsfs  1546     net net:[4026533029] /run/netns/netns-4f5ecc46-d6a0-175c-46a8-2e4ba180b94a

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2022-11-23 20:05:05 +09:00
Masatake YAMATO
fba9898fd5 lsfd: collect namespace files after collecting information about "nodev" fs
In my plan, lsfd will need the information of the backing device for
"nsfs" file system before collecing the information about th namespaces
associated with fds.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2022-11-23 19:50:31 +09:00
Masatake YAMATO
eb3130759c lsfd: introduce is_mapped_file macro
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2022-11-23 16:42:11 +09:00
Masatake YAMATO
c0f84bd12d lsfd: introduce is_opened_file macro
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2022-11-23 16:42:11 +09:00
Thomas Weißschuh
006612cdf4 fileeq/lsfd: use correct format specifier 2022-11-22 14:57:17 +01:00
Karel Zak
96ccdc00e1 logger: always update header when read from stdin
The current code updates the header only when the priority has been
changed. It's incorrect because wanted is a valid header or each entry
(don't forget that logger for stdin use-case is used in pipe to log
long-time running processes).

This patch also fixes the initial timestamp; it was originally generated
on logger startup, it now generates the header on the first message.

$ (sleep 2; date; sleep 2; date; sleep 2; date) | logger --stderr --no-act

old:
<13>Nov  1 10:42:14 kzak: Tue Nov  1 10:42:16 AM CET 2022
<13>Nov  1 10:42:14 kzak: Tue Nov  1 10:42:18 AM CET 2022
<13>Nov  1 10:42:14 kzak: Tue Nov  1 10:42:20 AM CET 2022

new:
<13>Nov  1 10:19:02 kzak: Tue Nov  1 10:19:02 AM CET 2022
<13>Nov  1 10:19:04 kzak: Tue Nov  1 10:19:04 AM CET 2022
<13>Nov  1 10:19:06 kzak: Tue Nov  1 10:19:06 AM CET 2022

Fixes: https://github.com/util-linux/util-linux/issues/1866
Signed-off-by: Karel Zak <kzak@redhat.com>
2022-11-01 10:30:06 +01:00
Karel Zak
0f0b854e82 Merge branch 'cdown/2022-10-26/check_handler' of https://github.com/cdown/util-linux
* 'cdown/2022-10-26/check_handler' of https://github.com/cdown/util-linux:
  kill: Support mandating the presence of a userspace signal handler
2022-10-31 14:03:41 +01:00
Karel Zak
22e16fbf8d Merge branch 'lsfd-s390-proc-net-L3' of https://github.com/masatake/util-linux
* 'lsfd-s390-proc-net-L3' of https://github.com/masatake/util-linux:
  lsfd: unify the code for reading /proc/net/tcp and udp
  lsfd: make the logic for verifying the initial line of /proc/net/{tcp,udp} more flexible
2022-10-31 13:54:45 +01:00
Chris Down
30463e36ae kill: Support mandating the presence of a userspace signal handler
In production we've had several incidents over the years where a process
has a signal handler registered for SIGHUP or one of the SIGUSR signals
which can be used to signal a request to reload configs, rotate log
files, and the like. While this may seem harmless enough, what we've
seen happen repeatedly is something like the following:

1. A process is using SIGHUP/SIGUSR[12] to request some
   application-handled state change -- reloading configs, rotating a log
   file, etc;
2. This kind of request is deprecated and removed, so the signal handler
   is removed. However, a site where the signal might be sent from is
   missed (often logrotate or a service manager);
3. Because the default disposition of these signals is terminal, sooner
   or later these applications are going to be sent SIGHUP or similar
   and end up unexpectedly killed.

I know for a fact that we're not the only organistion experiencing this:
in general, signal use is pretty tricky to reason about and safely
remove because of the fairly aggressive SIG_DFL behaviour for some
common signals, especially for SIGHUP which has a particularly ambiguous
meaning. Especially in a large, highly interconnected codebase,
reasoning about signal interactions between system configuration and
applications can be highly complex, and it's inevitable that on occasion
a callsite will be missed.

In some cases the right call to avoid this will be to migrate services
towards other forms of IPC for this purpose, but inevitably there will
be some services which must continue using signals, so we need a safe
way to support them.

This patch adds support for the -r/--require-handler flag, which checks
if a userspace handler is present for the signal being sent. If it is
not, the process will be skipped.

With this flag we can enforce that all SIGHUP reload cases and SIGUSR
equivalents use --require-handler. This effectively mitigates the case
we've seen time and time again where SIGHUP is used to rotate log files
or reload configs, but the sending site is mistakenly left present after
the removal of signal handler, resulting in unintended termination of
the process.

Signed-off-by: Chris Down <chris@chrisdown.name>
2022-10-26 17:10:55 +01:00
Masatake YAMATO
58d2f31eb0 lsfd: unify the code for reading /proc/net/tcp and udp
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2022-10-26 12:01:37 +09:00
Masatake YAMATO
b49529f06f lsfd: make the logic for verifying the initial line of /proc/net/{tcp,udp} more flexible
The format of /proc/net/udp was changed in
6c25449e1a32 ("net: udp: fix alignment problem in udp4_seq_show()").
This kind of change can be applied to /proc/net/tcp, too.

Co-Authored-by: Thomas Weißschuh <thomas@t-8ch.de>
Co-Authored-by: Masatake YAMATO <yamato@redhat.com>
2022-10-26 11:56:00 +09:00
Karel Zak
3471bc1d08 lsblk: improve mountpoint columns formatting
Let's mark the columns by no-extreme libsmartcols flag. It makes
output more compact if there are too long mount paths.

Signed-off-by: Karel Zak <kzak@redhat.com>
2022-10-25 11:11:06 +02:00
Karel Zak
15ce5b753b lsfd: fix compiler warning [-Werror,-Wextra-semi]
isc-utils/lsfd-sock-xinfo.c:588:34: error: extra ';' outside of a function [-Werror,-Wextra-semi]
define_fill_column_func(tcp, TCP);
                                 ^
misc-utils/lsfd-sock-xinfo.c:703:34: error: extra ';' outside of a function [-Werror,-Wextra-semi]
define_fill_column_func(udp, UDP);
                                 ^
Addresses: 92a0dbce7c
Signed-off-by: Karel Zak <kzak@redhat.com>
2022-10-21 14:23:50 +02:00
Masatake YAMATO
92a0dbce7c lsfd: use extra information loaded from /proc/net/udp
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2022-10-20 05:15:09 +09:00
Masatake YAMATO
b569eb96eb lsfd: (man) write more about TCP scokets
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2022-10-20 05:15:09 +09:00
Masatake YAMATO
36697f4dd8 fadvice: delete a unused struct definition
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2022-10-18 05:12:23 +09:00