-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I propose exposing the pidfd instance for Tokio-spawned child processes on Linux #6980
Conversation
I'm concerned about the forwards-compatibility impact of this change. If we expose this method, then we can never change the implementation to use something different than pidfd internally. And it's not been very long since we last changed the internals to use pidfd; we used to use a signal handler instead. |
Thanks for the PR @ChrysoliteAzalea! I share @Darksonn 's concerns here and I'm generally opposed to this direction. To say it in my own words:
|
@Darksonn @ipetkov Thank you for your replies! If holding the pidfd instance is seen as an implementation detail, then I'm not sure whether exposing it would be appropriate. I've just seen that
As far as I understand, users should abstain from closing the pidfd, re-seating it with
I understand, given Tokio already has |
For now I will close this PR. If the standard library stabilizes |
Hello, everyone! I propose giving the
tokio::process::Child
client code access to the underlying pidfd instance on Linux.Motivation
Pidfd instances on Linux are file descriptors referring to a process (either running or terminated). Tokio uses these file descriptors internally to receive notifications when Tokio-spawned child process has terminated. If pidfd is not supported, Tokio falls back to checking all watched child processes on receiving the
SIGCHLD
signal. However, watching and waiting for child processes is not the only use-case for pidfd, it can be used to send arbitrary signals to a child (pidfd_send_signal()
) if you have signalling rights, intervene with its operation (process_madvise()
,pidfd_getfd()
) if you have ptrace rights, entering child's namespace (setns()
). Future versions of Linux may add other use-cases for the pidfd instances.Solution
I propose adding a new
unsafe
method ontokio::process::Child
structure -- theget_pidfd()
that returns a pidfd instance as long as it's supported by the operating system (this is obviously a Linux-only feature). It'sunsafe
because closing it may break thetokio::process::Child
operation, therefore, the client code should probably use something likestd::os::fd::BorrowedFd
to wrap it.