diff options
| author | Karel Zak <kzak@redhat.com> | 2025-03-04 09:47:11 +0100 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2025-03-04 11:39:26 +0100 |
| commit | 4a1053812f396619070b6849f4d8830c1ee272ee (patch) | |
| tree | a58bca3d65d0b4bd0019627d865e120151254e48 /misc-utils/kill.c | |
| parent | 455e609f06810d01336b61a273673e4fddeb33c2 (diff) | |
| download | util-linux-4a1053812f396619070b6849f4d8830c1ee272ee.tar.gz | |
include/pidfd-utils: improve robustness
* remove global UL_HAVE_PIDFD, in many cases we need only subset of pidfd
kernel API, rrather than all the functios
* improve #ifdefs for pidfd_*() direct syscalls
* improve dummy fallback to not redefine system header files
Fixes: https://github.com/util-linux/util-linux/issues/3437
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/kill.c')
| -rw-r--r-- | misc-utils/kill.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/misc-utils/kill.c b/misc-utils/kill.c index a911df6b72..fefe0d8917 100644 --- a/misc-utils/kill.c +++ b/misc-utils/kill.c @@ -67,12 +67,16 @@ /* partial success, otherwise we return regular EXIT_{SUCCESS,FAILURE} */ #define KILL_EXIT_SOMEOK 64 +#if defined(HAVE_PIDFD_OPEN) && defined(HAVE_PIDFD_SEND_SIGNAL) +# define USE_KILL_WITH_TIMEOUT 1 +#endif + enum { KILL_FIELD_WIDTH = 11, KILL_OUTPUT_WIDTH = 72 }; -#ifdef UL_HAVE_PIDFD +#ifdef USE_KILL_WITH_TIMEOUT # include <poll.h> # include "list.h" struct timeouts { @@ -89,7 +93,7 @@ struct kill_control { #ifdef HAVE_SIGQUEUE union sigval sigdata; #endif -#ifdef UL_HAVE_PIDFD +#ifdef USE_KILL_WITH_TIMEOUT struct list_head follow_ups; #endif bool check_all, @@ -97,7 +101,7 @@ struct kill_control { do_pid, require_handler, use_sigval, -#ifdef UL_HAVE_PIDFD +#ifdef USE_KILL_WITH_TIMEOUT timeout, #endif verbose; @@ -269,7 +273,7 @@ static void __attribute__((__noreturn__)) usage(void) #ifdef HAVE_SIGQUEUE fputs(_(" -q, --queue <value> use sigqueue(2), not kill(2), and pass <value> as data\n"), out); #endif -#ifdef UL_HAVE_PIDFD +#ifdef USE_KILL_WITH_TIMEOUT fputs(_(" --timeout <milliseconds> <follow-up signal>\n" " wait up to timeout and send follow-up signal\n"), out); #endif @@ -296,7 +300,7 @@ static void __attribute__((__noreturn__)) print_kill_version(void) #ifdef HAVE_SIGQUEUE "sigqueue", #endif -#ifdef UL_HAVE_PIDFD +#ifdef USE_KILL_WITH_TIMEOUT "pidfd", #endif }; @@ -443,7 +447,7 @@ static char **parse_arguments(int argc, char **argv, struct kill_control *ctl) continue; } #endif -#ifdef UL_HAVE_PIDFD +#ifdef USE_KILL_WITH_TIMEOUT if (!strcmp(arg, "--timeout")) { struct timeouts *next; @@ -485,7 +489,7 @@ static char **parse_arguments(int argc, char **argv, struct kill_control *ctl) return argv; } -#ifdef UL_HAVE_PIDFD +#ifdef USE_KILL_WITH_TIMEOUT static int kill_with_timeout(const struct kill_control *ctl) { int pfd, n; @@ -537,7 +541,7 @@ static int kill_verbose(const struct kill_control *ctl) printf("%ld\n", (long) ctl->pid); return 0; } -#ifdef UL_HAVE_PIDFD +#ifdef USE_KILL_WITH_TIMEOUT if (ctl->timeout) { rc = kill_with_timeout(ctl); } else @@ -590,7 +594,7 @@ int main(int argc, char **argv) textdomain(PACKAGE); close_stdout_atexit(); -#ifdef UL_HAVE_PIDFD +#ifdef USE_KILL_WITH_TIMEOUT INIT_LIST_HEAD(&ctl.follow_ups); #endif argv = parse_arguments(argc, argv, &ctl); @@ -642,7 +646,7 @@ int main(int argc, char **argv) } } -#ifdef UL_HAVE_PIDFD +#ifdef USE_KILL_WITH_TIMEOUT while (!list_empty(&ctl.follow_ups)) { struct timeouts *x = list_entry(ctl.follow_ups.next, struct timeouts, follow_ups); |
