Skip to content

Commit 445555d

Browse files
committed
Document private create_pipe() function
1 parent d1eaa88 commit 445555d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/pipe.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ enum Inheritable {
145145
Writer,
146146
}
147147

148+
// Invokes `pipe(2)` and sets either the reader or writer as inheritable by child processes, and
149+
// returns the reader/writer file descriptor pair.
150+
//
151+
// This function is necessary over existing libraries like `os_pipe` because they all use the
152+
// `FD_CLOEXEC` flag by default, meaning they can't be inherited by child processes, like we need
153+
// for using `conmon`.
148154
fn create_pipe(kind: Inheritable) -> std::io::Result<(c_int, c_int)> {
149155
let mut fds = [-1 as c_int, -1 as c_int];
150156

@@ -162,6 +168,8 @@ fn create_pipe(kind: Inheritable) -> std::io::Result<(c_int, c_int)> {
162168
value => value,
163169
};
164170

171+
// Set `FD_CLOEXEC` for the end of the pipe intended for the parent process, leaving the other
172+
// end inheritable by the child process.
165173
if unsafe { libc::fcntl(fds[no_inherit_idx], libc::F_SETFD, flags | libc::FD_CLOEXEC) } == -1 {
166174
return Err(std::io::Error::last_os_error());
167175
}

0 commit comments

Comments
 (0)