Skip to content

Commit

Permalink
Add set_inheritable for Windows Handles
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Apr 26, 2022
1 parent 7417110 commit b89b056
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions library/std/src/os/windows/io/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ impl OwnedHandle {
})?;
unsafe { Ok(Self::from_raw_handle(ret)) }
}

/// Allow child processes to inherit the handle.
pub(crate) fn set_inheritable(&self) -> io::Result<()> {
cvt(unsafe {
c::SetHandleInformation(
self.as_raw_handle(),
c::HANDLE_FLAG_INHERIT,
c::HANDLE_FLAG_INHERIT,
)
})?;
Ok(())
}
}

impl TryFrom<HandleOrInvalid> for OwnedHandle {
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/windows/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ impl Handle {
Ok(Self(self.0.duplicate(access, inherit, options)?))
}

pub(crate) fn set_inheritable(&self) -> io::Result<()> {
self.0.set_inheritable()
}

/// Performs a synchronous read.
///
/// If the handle is opened for asynchronous I/O then this abort the process.
Expand Down

0 comments on commit b89b056

Please sign in to comment.