to extract a pidfd we must consume the child · rust-lang/rust@8abf149 (original) (raw)
`@@ -19,7 +19,7 @@ struct InnerPidFd;
`
19
19
`///
`
20
20
`` /// A PidFd
can be obtained by setting the corresponding option on [Command
]
``
21
21
`` /// with [create_pidfd
]. Subsequently, the created pidfd can be retrieved
``
22
``
`` -
/// from the [Child
] by calling [pidfd
] or [take_pidfd
].
``
``
22
`` +
/// from the [Child
] by calling [pidfd
] or [into_pidfd
].
``
23
23
`///
`
24
24
`/// Example:
`
25
25
```` /// ```no_run
````
`@@ -33,7 +33,7 @@ struct InnerPidFd;
`
33
33
`/// .expect("Failed to spawn child");
`
34
34
`///
`
35
35
`/// let pidfd = child
`
36
``
`-
/// .take_pidfd()
`
``
36
`+
/// .into_pidfd()
`
37
37
`/// .expect("Failed to retrieve pidfd");
`
38
38
`///
`
39
39
`` /// // The file descriptor will be closed when pidfd
is dropped.
``
`@@ -44,7 +44,7 @@ struct InnerPidFd;
`
44
44
`` /// [create_pidfd
]: CommandExt::create_pidfd
``
45
45
`` /// [Child
]: process::Child
``
46
46
`` /// [pidfd
]: fn@ChildExt::pidfd
``
47
``
`` -
/// [take_pidfd
]: ChildExt::take_pidfd
``
``
47
`` +
/// [into_pidfd
]: ChildExt::into_pidfd
``
48
48
`` /// [pidfd_open(2)
]: https://man7.org/linux/man-pages/man2/pidfd_open.2.html
``
49
49
`#[derive(Debug)]
`
50
50
`#[repr(transparent)]
`
`@@ -159,18 +159,26 @@ pub trait ChildExt: Sealed {
`
159
159
`` /// [Child
]: process::Child
``
160
160
`fn pidfd(&self) -> Result<&PidFd>;
`
161
161
``
162
``
`` -
/// Takes ownership of the [PidFd
] created for this [Child
], if available.
``
``
162
`` +
/// Returns the [PidFd
] created for this [Child
], if available.
``
``
163
`+
/// Otherwise self is returned.
`
163
164
`///
`
164
165
`/// A pidfd will only be available if its creation was requested with
`
165
166
`` /// [create_pidfd
] when the corresponding [Command
] was created.
``
166
167
`///
`
``
168
`+
/// Taking ownership of the PidFd consumes the Child to avoid pid reuse
`
``
169
`` +
/// races. Use [pidfd
] and [BorrowedFd::try_clone_to_owned
] if
``
``
170
`+
/// you don't want to disassemble the Child yet.
`
``
171
`+
///
`
167
172
`/// Even if requested, a pidfd may not be available due to an older
`
168
173
`/// version of Linux being in use, or if some other error occurred.
`
169
174
`///
`
170
175
`` /// [Command
]: process::Command
``
171
176
`` /// [create_pidfd
]: CommandExt::create_pidfd
``
``
177
`` +
/// [pidfd
]: ChildExt::pidfd
``
172
178
`` /// [Child
]: process::Child
``
173
``
`-
fn take_pidfd(&mut self) -> Result;
`
``
179
`+
fn into_pidfd(self) -> crate::result::Result<PidFd, Self>
`
``
180
`+
where
`
``
181
`+
Self: Sized;
`
174
182
`}
`
175
183
``
176
184
`` /// Os-specific extensions for [Command
]
``
`@@ -181,7 +189,7 @@ pub trait CommandExt: Sealed {
`
181
189
`` /// spawned by this [Command
].
``
182
190
`/// By default, no pidfd will be created.
`
183
191
`///
`
184
``
`` -
/// The pidfd can be retrieved from the child with [pidfd
] or [take_pidfd
].
``
``
192
`` +
/// The pidfd can be retrieved from the child with [pidfd
] or [into_pidfd
].
``
185
193
`///
`
186
194
`/// A pidfd will only be created if it is possible to do so
`
187
195
`` /// in a guaranteed race-free manner. Otherwise, [pidfd
] will return an error.
``
`@@ -195,7 +203,7 @@ pub trait CommandExt: Sealed {
`
195
203
`` /// [Command
]: process::Command
``
196
204
`` /// [Child
]: process::Child
``
197
205
`` /// [pidfd
]: fn@ChildExt::pidfd
``
198
``
`` -
/// [take_pidfd
]: ChildExt::take_pidfd
``
``
206
`` +
/// [into_pidfd
]: ChildExt::into_pidfd
``
199
207
`fn create_pidfd(&mut self, val: bool) -> &mut process::Command;
`
200
208
`}
`
201
209
``