Re: For review: pidfd_open(2) manual page

Started by Florian Weimer on Sep 23, 2019 · 6 messages from 4 authors · Last reply Sep 23, 2019

open the first message on its own page

Message details and related content
* Michael Kerrisk:
SYNOPSIS
       int pidfd_open(pid_t pid, unsigned int flags);
Should this mention <sys/types.h> for pid_t?
ERRORS
       EINVAL flags is not 0.

       EINVAL pid is not valid.

       ESRCH  The process specified by pid does not exist.
Presumably, EMFILE and ENFILE are also possible errors, and so is
ENOMEM.
       A  PID  file descriptor can be monitored using poll(2), select(2),
       and epoll(7).  When the process that it refers to terminates,  the
       file descriptor indicates as readable.  Note, however, that in the
       current implementation, nothing can be read from the file descrip‐
       tor.
“is indicated as readable” or “becomes readable”?  Will reading block?
       The  pidfd_open()  system call is the preferred way of obtaining a
       PID file descriptor.  The alternative is to obtain a file descrip‐
       tor by opening a /proc/[pid] directory.  However, the latter tech‐
       nique is possible only if the proc(5) file system is mounted; fur‐
       thermore,  the  file  descriptor  obtained in this way is not pol‐
       lable.
One question is whether the glibc wrapper should fall back back to the
/proc subdirectory if it is not available.  Probably not.
       static
       int pidfd_open(pid_t pid, unsigned int flags)
       {
           return syscall(__NR_pidfd_open, pid, flags);
       }
Please call this function something else (not pidfd_open), so that the
example continues to work if glibc provides the system call wrapper.
Message details and related content
On Mon, Sep 23, 2019 at 3:53 AM Florian Weimer [off-list ref] wrote:
* Michael Kerrisk:
quoted
SYNOPSIS
       int pidfd_open(pid_t pid, unsigned int flags);
Should this mention <sys/types.h> for pid_t?
quoted
ERRORS
       EINVAL flags is not 0.

       EINVAL pid is not valid.

       ESRCH  The process specified by pid does not exist.
Presumably, EMFILE and ENFILE are also possible errors, and so is
ENOMEM.
quoted
       A  PID  file descriptor can be monitored using poll(2), select(2),
       and epoll(7).  When the process that it refers to terminates,  the
       file descriptor indicates as readable.
The phrase "becomes readable" is simpler than "indicates as readable"
and conveys the same meaning. I agree with Florian's comment on this
point below.
quoted
Note, however, that in the
       current implementation, nothing can be read from the file descrip‐
       tor.
“is indicated as readable” or “becomes readable”?  Will reading block?
quoted
       The  pidfd_open()  system call is the preferred way of obtaining a
       PID file descriptor.  The alternative is to obtain a file descrip‐
       tor by opening a /proc/[pid] directory.  However, the latter tech‐
       nique is possible only if the proc(5) file system is mounted; fur‐
       thermore,  the  file  descriptor  obtained in this way is not pol‐
       lable.
Referring to procfs directory FDs as pidfds will probably confuse
people. I'd just omit this paragraph.
One question is whether the glibc wrapper should fall back back to the
/proc subdirectory if it is not available.  Probably not.
I'd prefer that glibc not provide this kind of fallback.
posix_fallocate-style emulation is, IMHO, too surprising.
Message details and related content
On Mon, Sep 23, 2019 at 12:53:09PM +0200, Florian Weimer wrote:
* Michael Kerrisk:
quoted
SYNOPSIS
       int pidfd_open(pid_t pid, unsigned int flags);
Should this mention <sys/types.h> for pid_t?
quoted
ERRORS
       EINVAL flags is not 0.

       EINVAL pid is not valid.

       ESRCH  The process specified by pid does not exist.
Presumably, EMFILE and ENFILE are also possible errors, and so is
ENOMEM.
So, error codes that could surface are:
EMFILE: too many open files
ENODEV: the anon inode filesystem is not available in this kernel (unlikely)
ENOMEM: not enough memory (to allocate the backing struct file)
ENFILE: you're over the max_files limit which can be set through proc

I think that should be it.
quoted
       A  PID  file descriptor can be monitored using poll(2), select(2),
       and epoll(7).  When the process that it refers to terminates,  the
       file descriptor indicates as readable.  Note, however, that in the
       current implementation, nothing can be read from the file descrip‐
       tor.
“is indicated as readable” or “becomes readable”?  Will reading block?
quoted
       The  pidfd_open()  system call is the preferred way of obtaining a
       PID file descriptor.  The alternative is to obtain a file descrip‐
       tor by opening a /proc/[pid] directory.  However, the latter tech‐
       nique is possible only if the proc(5) file system is mounted; fur‐
       thermore,  the  file  descriptor  obtained in this way is not pol‐
       lable.
One question is whether the glibc wrapper should fall back back to the
/proc subdirectory if it is not available.  Probably not.
No, that would not be transparent to userspace. Especially because both
fds differ in what can be done with them.
quoted
       static
       int pidfd_open(pid_t pid, unsigned int flags)
       {
           return syscall(__NR_pidfd_open, pid, flags);
       }
Please call this function something else (not pidfd_open), so that the
example continues to work if glibc provides the system call wrapper.
Agreed!
Message details and related content
Hello Florian,

Thanks for taking a look at this page.

On 9/23/19 12:53 PM, Florian Weimer wrote:
* Michael Kerrisk:
quoted
SYNOPSIS
       int pidfd_open(pid_t pid, unsigned int flags);
Should this mention <sys/types.h> for pid_t?
Seems reasonable. I added this.
quoted
ERRORS
       EINVAL flags is not 0.

       EINVAL pid is not valid.

       ESRCH  The process specified by pid does not exist.
Presumably, EMFILE and ENFILE are also possible errors, and so is
ENOMEM.
Thanks. I've added those.
quoted
       A  PID  file descriptor can be monitored using poll(2), select(2),
       and epoll(7).  When the process that it refers to terminates,  the
       file descriptor indicates as readable.  Note, however, that in the
       current implementation, nothing can be read from the file descrip‐
       tor.
“is indicated as readable” or “becomes readable”?  Will reading block?
It won't block. Reads from a pidfd always fail with the error EINVAL
(regardless of whether the target process has terminated).

I specifically wanted to avoid "becomes readable" to avoid any
suggestion that read() does something for a pidfd. I thought 
"indicates as readable" was fine, but you, Christian and Joel 
all called this wording out, so I changed this to:

"When the process that it refers to terminates,
these interfaces indicate the file descriptor as readable."
quoted
       The  pidfd_open()  system call is the preferred way of obtaining a
       PID file descriptor.  The alternative is to obtain a file descrip‐
       tor by opening a /proc/[pid] directory.  However, the latter tech‐
       nique is possible only if the proc(5) file system is mounted; fur‐
       thermore,  the  file  descriptor  obtained in this way is not pol‐
       lable.
One question is whether the glibc wrapper should fall back back to the
/proc subdirectory if it is not available.  Probably not.
No, since the FD returned by opening /proc/PID is less functional
(it is not pollable) than the one returned by pidfd_open().
quoted
       static
       int pidfd_open(pid_t pid, unsigned int flags)
       {
           return syscall(__NR_pidfd_open, pid, flags);
       }
Please call this function something else (not pidfd_open), so that the
example continues to work if glibc provides the system call wrapper.
I figured that if the syscall does get added to glibc, then I would
modify the example. In the meantime, this does seem the most natural
way of doing things, since the example then uses the real syscall
name as it would be used if there were a wrapper function.
 
But, this leads to the question: what do you think the likelihood
is that this system call will land in glibc?

Thanks for your feedback, Florian. I've pushed various changes
to the Git branch at 
https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/log/?h=draft_pidfd

Cheers,

Michael


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
Message details and related content
Hello Christian,

On 9/23/19 4:47 PM, Christian Brauner wrote:
On Mon, Sep 23, 2019 at 12:53:09PM +0200, Florian Weimer wrote:
quoted
* Michael Kerrisk:
quoted
SYNOPSIS
       int pidfd_open(pid_t pid, unsigned int flags);
Should this mention <sys/types.h> for pid_t?
quoted
ERRORS
       EINVAL flags is not 0.

       EINVAL pid is not valid.

       ESRCH  The process specified by pid does not exist.
Presumably, EMFILE and ENFILE are also possible errors, and so is
ENOMEM.
So, error codes that could surface are:
EMFILE: too many open files
ENODEV: the anon inode filesystem is not available in this kernel (unlikely)
ENOMEM: not enough memory (to allocate the backing struct file)
ENFILE: you're over the max_files limit which can be set through proc

I think that should be it.
Thanks. I've added those.
quoted
quoted
       A  PID  file descriptor can be monitored using poll(2), select(2),
       and epoll(7).  When the process that it refers to terminates,  the
       file descriptor indicates as readable.  Note, however, that in the
       current implementation, nothing can be read from the file descrip‐
       tor.
“is indicated as readable” or “becomes readable”?  Will reading block?
quoted
       The  pidfd_open()  system call is the preferred way of obtaining a
       PID file descriptor.  The alternative is to obtain a file descrip‐
       tor by opening a /proc/[pid] directory.  However, the latter tech‐
       nique is possible only if the proc(5) file system is mounted; fur‐
       thermore,  the  file  descriptor  obtained in this way is not pol‐
       lable.
One question is whether the glibc wrapper should fall back back to the
/proc subdirectory if it is not available.  Probably not.
No, that would not be transparent to userspace. Especially because both
fds differ in what can be done with them.
quoted
quoted
       static
       int pidfd_open(pid_t pid, unsigned int flags)
       {
           return syscall(__NR_pidfd_open, pid, flags);
       }
Please call this function something else (not pidfd_open), so that the
example continues to work if glibc provides the system call wrapper.
Agreed!
See my reply to Florian. (So far, I didn't change anything here.)

Thanks,

Michael



-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
Message details and related content
Hello Daniel,

Than you for reviewing the page!

On 9/23/19 1:26 PM, Daniel Colascione wrote:
On Mon, Sep 23, 2019 at 3:53 AM Florian Weimer [off-list ref] wrote:
quoted
* Michael Kerrisk:
quoted
SYNOPSIS
       int pidfd_open(pid_t pid, unsigned int flags);
Should this mention <sys/types.h> for pid_t?
quoted
ERRORS
       EINVAL flags is not 0.

       EINVAL pid is not valid.

       ESRCH  The process specified by pid does not exist.
Presumably, EMFILE and ENFILE are also possible errors, and so is
ENOMEM.
quoted
       A  PID  file descriptor can be monitored using poll(2), select(2),
       and epoll(7).  When the process that it refers to terminates,  the
       file descriptor indicates as readable.
The phrase "becomes readable" is simpler than "indicates as readable"
and conveys the same meaning. I agree with Florian's comment on this
point below.
See my reply to Florian. (I did change the text here.)
quoted
quoted
Note, however, that in the
       current implementation, nothing can be read from the file descrip‐
       tor.
“is indicated as readable” or “becomes readable”?  Will reading block?
quoted
       The  pidfd_open()  system call is the preferred way of obtaining a
       PID file descriptor.  The alternative is to obtain a file descrip‐
       tor by opening a /proc/[pid] directory.  However, the latter tech‐
       nique is possible only if the proc(5) file system is mounted; fur‐
       thermore,  the  file  descriptor  obtained in this way is not pol‐
       lable.
Referring to procfs directory FDs as pidfds will probably confuse
people. I'd just omit this paragraph.
See my reply to Christian (and feel free to argue the point, please).
So far, I have made no change here.
quoted
One question is whether the glibc wrapper should fall back back to the
/proc subdirectory if it is not available.  Probably not.
I'd prefer that glibc not provide this kind of fallback.
posix_fallocate-style emulation is, IMHO, too surprising.
Agreed.

Cheers,

Michael


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help