File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,12 @@ enum Inheritable {
145
145
Writer ,
146
146
}
147
147
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`.
148
154
fn create_pipe ( kind : Inheritable ) -> std:: io:: Result < ( c_int , c_int ) > {
149
155
let mut fds = [ -1 as c_int , -1 as c_int ] ;
150
156
@@ -162,6 +168,8 @@ fn create_pipe(kind: Inheritable) -> std::io::Result<(c_int, c_int)> {
162
168
value => value,
163
169
} ;
164
170
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.
165
173
if unsafe { libc:: fcntl ( fds[ no_inherit_idx] , libc:: F_SETFD , flags | libc:: FD_CLOEXEC ) } == -1 {
166
174
return Err ( std:: io:: Error :: last_os_error ( ) ) ;
167
175
}
You can’t perform that action at this time.
0 commit comments