tools: add fd_change_cloexec helper
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
1c042cdc6c
commit
ff7049d481
|
@ -533,3 +533,12 @@ pub fn join(data: &Vec<String>, sep: char) -> String {
|
||||||
|
|
||||||
list
|
list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn fd_change_cloexec(fd: RawFd, on: bool) -> Result<(), Error> {
|
||||||
|
use nix::fcntl::{fcntl, F_GETFD, F_SETFD, FdFlag};
|
||||||
|
let mut flags = FdFlag::from_bits(fcntl(fd, F_GETFD)?)
|
||||||
|
.ok_or_else(|| format_err!("unhandled file flags"))?; // nix crate is stupid this way...
|
||||||
|
flags.set(FdFlag::FD_CLOEXEC, on);
|
||||||
|
fcntl(fd, F_SETFD(flags))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue