Skip to content

Commit b89b056

Browse files
committed
Add set_inheritable for Windows Handles
1 parent 7417110 commit b89b056

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

library/std/src/os/windows/io/handle.rs

+12
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ impl OwnedHandle {
198198
})?;
199199
unsafe { Ok(Self::from_raw_handle(ret)) }
200200
}
201+
202+
/// Allow child processes to inherit the handle.
203+
pub(crate) fn set_inheritable(&self) -> io::Result<()> {
204+
cvt(unsafe {
205+
c::SetHandleInformation(
206+
self.as_raw_handle(),
207+
c::HANDLE_FLAG_INHERIT,
208+
c::HANDLE_FLAG_INHERIT,
209+
)
210+
})?;
211+
Ok(())
212+
}
201213
}
202214

203215
impl TryFrom<HandleOrInvalid> for OwnedHandle {

library/std/src/sys/windows/handle.rs

+4
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ impl Handle {
221221
Ok(Self(self.0.duplicate(access, inherit, options)?))
222222
}
223223

224+
pub(crate) fn set_inheritable(&self) -> io::Result<()> {
225+
self.0.set_inheritable()
226+
}
227+
224228
/// Performs a synchronous read.
225229
///
226230
/// If the handle is opened for asynchronous I/O then this abort the process.

0 commit comments

Comments
 (0)