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