[PATCH v2 3/3] linux: Add pidfd_getpid

Florian Weimer fweimer@redhat.com
Tue May 2 17:13:44 GMT 2023


* Luca Boccassi:

> On Tue, 2 May 2023 at 17:07, Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * Adhemerval Zanella via Libc-alpha:
>> > diff --git a/sysdeps/unix/sysv/linux/pidfd_getpid.c b/sysdeps/unix/sysv/linux/pidfd_getpid.c
>> > new file mode 100644
>> > index 0000000000..d0c7987791
>> > --- /dev/null
>> > +++ b/sysdeps/unix/sysv/linux/pidfd_getpid.c
>> > @@ -0,0 +1,94 @@
>>
>> > +static bool
>> > +parse_fdinfo (const char *l, void *arg)
>> > +{
>> > +  enum { fieldlen = sizeof ("Pid:") - 1 };
>> > +  if (strncmp (l, "Pid:", fieldlen) != 0)
>> > +    return true;
>> > +
>> > +  l += fieldlen;
>> > +
>> > +  char *endp;
>> > +  long int n = strtol (l, &endp, 10);
>> > +  if (l == endp || n > INT_MAX)
>> > +    return true;
>>
>> Should this use strtoul?  Otherwise I'm not sure the overflow check will
>> work on 32-bit.
>>
>> Rest of the implementation looks okay, but the kernel should really
>> provide an ioctl or similar for this.
>
> This can be -1 when the process is gone, and it is important to get
> that distinction (with certainty) to tell the caller ESRCH. We need
> this distinction in callers.

That shouldn't be a problem, strotul processes leading signs, too.  The
entire error checking is a bit dubious because it doesn't check much,
considering strtol's general flexibility.

Thanks,
Florian



More information about the Libc-alpha mailing list