# include <sys/syscall.h>
# include <unistd.h>
-# if defined(SYS_pidfd_send_signal) && defined(SYS_pidfd_open)
-# ifndef HAVE_PIDFD_SEND_SIGNAL
+# if !defined(HAVE_PIDFD_SEND_SIGNAL) && defined(SYS_pidfd_send_signal)
static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
unsigned int flags)
{
return syscall(SYS_pidfd_send_signal, pidfd, sig, info, flags);
}
-# endif
+# endif
-# ifndef HAVE_PIDFD_OPEN
+# if !defined(HAVE_PIDFD_OPEN) && defined(SYS_pidfd_open)
static inline int pidfd_open(pid_t pid, unsigned int flags)
{
return syscall(SYS_pidfd_open, pid, flags);
}
-# endif
+# endif
-# ifndef HAVE_PIDFD_GETFD
+# if !defined(HAVE_PIDFD_GETFD) && defined(SYS_pidfd_getfd)
static inline int pidfd_getfd(int pidfd, int targetfd, unsigned int flags)
{
return syscall(SYS_pidfd_getfd, pidfd, targetfd, flags);
}
-# endif
+# endif
+#endif /* HAVE_SYS_SYSCALL_H */
-# define UL_HAVE_PIDFD 1
-# endif /* SYS_pidfd_send_signal */
-#endif /* HAVE_SYS_SYSCALL_H */
+/*
+ * Dummy fallbacks for cases when #ifdef HAVE_PIDFD_* makes the code too complex.
+ */
-#ifndef UL_HAVE_PIDFD
+#if !defined(HAVE_PIDFD_SEND_SIGNAL) && !defined(SYS_pidfd_send_signal)
static inline int pidfd_send_signal(int pidfd __attribute__((unused)),
int sig __attribute__((unused)),
siginfo_t *info __attribute__((unused)),
errno = ENOSYS;
return -1;
}
+#endif
+#if !defined(HAVE_PIDFD_OPEN) && !defined(SYS_pidfd_open)
static inline int pidfd_open(pid_t pid __attribute__((unused)),
unsigned int flags __attribute__((unused)))
{
errno = ENOSYS;
return -1;
}
+#endif
+# if !defined(HAVE_PIDFD_GETFD) && !defined(SYS_pidfd_getfd)
static inline int pidfd_getfd(int pidfd __attribute__((unused)),
int targetfd __attribute__((unused)),
unsigned int flags __attribute__((unused)))
/* 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 {
#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,
do_pid,
require_handler,
use_sigval,
-#ifdef UL_HAVE_PIDFD
+#ifdef USE_KILL_WITH_TIMEOUT
timeout,
#endif
verbose;
#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
#ifdef HAVE_SIGQUEUE
"sigqueue",
#endif
-#ifdef UL_HAVE_PIDFD
+#ifdef USE_KILL_WITH_TIMEOUT
"pidfd",
#endif
};
continue;
}
#endif
-#ifdef UL_HAVE_PIDFD
+#ifdef USE_KILL_WITH_TIMEOUT
if (!strcmp(arg, "--timeout")) {
struct timeouts *next;
return argv;
}
-#ifdef UL_HAVE_PIDFD
+#ifdef USE_KILL_WITH_TIMEOUT
static int kill_with_timeout(const struct kill_control *ctl)
{
int pfd, n;
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
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);
}
}
-#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);
pid_t pid_bind = 0, pid_idmap = 0;
const char *newinterp = NULL;
pid_t pid = 0;
-#ifdef UL_HAVE_PIDFD
+#ifdef HAVE_PIDFD_OPEN
int fd_parent_pid = -1;
#endif
int fd_idmap, fd_bind = -1;
sigaddset(&sigset, SIGTERM) != 0 ||
sigprocmask(SIG_BLOCK, &sigset, &oldsigset) != 0)
err(EXIT_FAILURE, _("sigprocmask block failed"));
-#ifdef UL_HAVE_PIDFD
+#ifdef HAVE_PIDFD_OPEN
if (kill_child_signo != 0) {
/* make a connection to the original process (parent) */
fd_parent_pid = pidfd_open(getpid(), 0);
if (kill_child_signo != 0) {
if (prctl(PR_SET_PDEATHSIG, kill_child_signo) < 0)
err(EXIT_FAILURE, "prctl failed");
-#ifdef UL_HAVE_PIDFD
+#ifdef HAVE_PIDFD_OPEN
/* Use poll() to check that there is still the original parent. */
if (fd_parent_pid != -1) {
struct pollfd pollfds[1] = {