File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,39 @@ impl Client {
55
55
56
56
unsafe fn mk ( ) -> io:: Result < ( Client , String ) > {
57
57
let mut pipes = [ 0 ; 2 ] ;
58
+
59
+ // Attempt atomically-create-with-cloexec if we can on Linux,
60
+ // detected by using the `syscall` function in `libc` to try to work
61
+ // with as many kernels/glibc implementations as possible.
62
+ #[ cfg( target_os = "linux" ) ]
63
+ {
64
+ use std:: sync:: atomic:: { AtomicBool , Ordering } ;
65
+
66
+ static PIPE_AVAILABLE : AtomicBool = AtomicBool :: new ( true ) ;
67
+ if PIPE_AVAILABLE . load ( Ordering :: SeqCst ) {
68
+ match libc:: syscall ( libc:: SYS_pipe , pipes. as_mut_ptr ( ) ) {
69
+ -1 => {
70
+ let err = io:: Error :: last_os_error ( ) ;
71
+ if err. raw_os_error ( ) == Some ( libc:: ENOSYS ) {
72
+ PIPE_AVAILABLE . store ( false , Ordering :: SeqCst ) ;
73
+ } else {
74
+ return Err ( err) ;
75
+ }
76
+ }
77
+ _ => {
78
+ let string_arg = format ! (
79
+ "--jobserver-fds={},{}" ,
80
+ pipes[ 0 ] . as_raw_fd( ) ,
81
+ pipes[ 1 ] . as_raw_fd( )
82
+ ) ;
83
+ return Ok ( ( Client :: from_fds ( pipes[ 0 ] , pipes[ 1 ] ) , string_arg) ) ;
84
+ }
85
+ }
86
+ }
87
+ }
88
+
58
89
cvt ( libc:: pipe ( pipes. as_mut_ptr ( ) ) ) ?;
90
+
59
91
let string_arg = format ! (
60
92
"--jobserver-fds={},{}" ,
61
93
pipes[ 0 ] . as_raw_fd( ) ,
You can’t perform that action at this time.
0 commit comments