Skip to content

Clean up pidwait and pidfd_open logic

Ross Burton requested to merge rossburton/procps:pidfd into master

The existing logic is a little confused and the attempted fix in !166 (merged) ended up being reverted because it wasn't quite right.

The existing code tries to determine if pidof_open() exists, and if not if the syscall number for pidfd_open is known. This code is broken in several ways:

  • AC_CHECK_FUNC doesn't define HAVE_PIDFD_OPEN at all, but that symbol is used in pgrep.c.
  • The syscall number is fixed (434), so the define is just for tidier code.

This becomes a problem in situations where the toolchain is built with an old kernel (before the syscall was added) but a recent glibc (which has pidfd_open):

  • pidfd_open() is found, so enable_pidwait=yes is assigned. As the check uses AC_CHECK_FUNC, HAVE_PIDFD_OPEN is not defined automatically.

  • pgrep.c then does #if defined(ENABLE_PIDWAIT) && !defined(HAVE_PIDFD_OPEN). ENABLE_PIDWAIT is true and HAVE_PIDFD_OPEN is not defined (despite being present) so the code tries to implement pidfd_open() using the undefined __NR_pidfd_open:

    pgrep.c:841:24: error: ‘__NR_pidfd_open’ undeclared

Also then the use of pidfd_open() without a prototype causes errors in some compilers (clang, notably) because sys/pidfd.h isn't included.

Apart from the bugs, this logic overcomplicates the problem. At build time you can't know what syscalls the kernel will support, so the logic should be just:

  • The caller of configure can decide if pidwait is enabled or not
  • pidwait's implementation should call pidfd_open() if present, otherwise use syscall() and have a fallback of the hard-coded syscall number.

This patch enables pidwait and adds --disable-pidwait if desired, does the right include for the pidfd_open prototype, and implements the fallback logic of pidfd_open() then syscall() correctly.

Signed-off-by: Ross Burton ross.burton@arm.com

Merge request reports

Loading