pgrep: provide definition for __NR_pidfd_open if needed

Markus Mayer <[email protected]> Wed, 11 Dec 2024 15:58:25 -0800
Newsgroups gmane.linux.procps.devel
Message-ID <CAGt4E5syqWvu=TAzdKHO0vXT-92nqj+7VqMn9p=W4v0ro0dH-Q@mail.gmail.com>
Hi all,

I provided a pull request that defines __NR_pidfd_open if the kernel
headers do not.

This patch came about due to a situation we are running into when
building procps-ng for our target platforms. We generally use older
kernel headers during cross compilation than the actual kernel version
on the system at run time. This means kernel headers can be from a 4.x
kernel at build time, but the binaries will run on 5.x or 6.x kernels.

With the existing procps-ng process, one has to disable certain
features when __NR_pidfd_open is not defined at compile time. This
means functionality is lacking at runtime when support for it would
actually be present.

Since procps-ng is already providing its own pidfd_open() function
call to work around libc limitations, providing the syscall number
seems like really low-hanging fruit. This way kernel limitations can
also be bypassed. I believe that in the era of cross-compilation for
embedded devices, the scenario of build-time kernel headers being
older than runtime kernels isn't all that unusual. So I think others
will benefit as well. And if the binary does run on a kernel that
doesn't support __NR_pidfd_open, it'll simply fail at runtime with an
error message.

Regards,
-Markus