@@ -249,14 +249,14 @@ fn xargo_check() -> Command {
249
249
Command :: new ( env:: var_os ( "XARGO_CHECK" ) . unwrap_or_else ( || OsString :: from ( "xargo-check" ) ) )
250
250
}
251
251
252
- /// Execute the command. If it fails, fail this process with the same exit code.
253
- /// Otherwise, continue .
252
+ /// Execute the `Command`, where possible by replacing the current process with a new process
253
+ /// described by the `Command`. Then exit this process with the exit code of the new process .
254
254
fn exec ( mut cmd : Command ) -> ! {
255
255
// On non-Unix imitate POSIX exec as closely as we can
256
256
#[ cfg( not( unix) ) ]
257
257
{
258
258
let exit_status = cmd. status ( ) . expect ( "failed to run command" ) ;
259
- std:: process:: exit ( exit_status. code ( ) . unwrap_or ( -1 ) ) ;
259
+ std:: process:: exit ( exit_status. code ( ) . unwrap_or ( -1 ) )
260
260
}
261
261
// On Unix targets, actually exec
262
262
// If exec returns, process setup has failed. This is the same error condition as the expect in
@@ -269,10 +269,10 @@ fn exec(mut cmd: Command) -> ! {
269
269
}
270
270
}
271
271
272
- /// Execute the command and pipe `input` into its stdin.
273
- /// If it fails, fail this process with the same exit code.
274
- /// Otherwise, continue .
275
- fn exec_with_pipe ( mut cmd : Command , input : & [ u8 ] ) {
272
+ /// Execute the `Command`, where possible by replacing the current process with a new process
273
+ /// described by the `Command`. Then exit this process with the exit code of the new process .
274
+ /// `input` is also piped to the new process's stdin .
275
+ fn exec_with_pipe ( mut cmd : Command , input : & [ u8 ] ) -> ! {
276
276
#[ cfg( unix) ]
277
277
{
278
278
use std:: os:: unix:: io:: FromRawFd ;
@@ -283,25 +283,15 @@ fn exec_with_pipe(mut cmd: Command, input: &[u8]) {
283
283
let res = unsafe { libc:: pipe ( fds. as_mut_ptr ( ) ) } ;
284
284
assert_eq ! ( res, 0 , "failed to create pipe" ) ;
285
285
286
- // We need to set close-on-exec, otherwise our pipe isn't readable after exec
287
- // SAFETY: fcntl has no preconditions
288
- unsafe {
289
- for fd in & fds {
290
- let res = libc:: fcntl (
291
- * fd,
292
- libc:: F_SETFD ,
293
- libc:: fcntl ( * fd, libc:: F_GETFD ) | libc:: FD_CLOEXEC ,
294
- ) ;
295
- assert_eq ! ( res, 0 , "failed to set close-on-exec for pipe" ) ;
296
- }
297
- }
298
-
299
- // SAFETY: Both elements of fds are open file descriptors, because pipe2 returned 0
286
+ // SAFETY: Both elements of fds are open file descriptors, because pipe returned 0
300
287
let dst = unsafe { Stdio :: from_raw_fd ( fds[ 0 ] ) } ;
301
288
let mut src = unsafe { File :: from_raw_fd ( fds[ 1 ] ) } ;
302
289
303
290
src. write_all ( input) . expect ( "failed to write out test source" ) ;
304
291
292
+ // Close the writing part of the pipe in the parent process
293
+ drop ( src) ;
294
+
305
295
cmd. stdin ( dst) ;
306
296
exec ( cmd)
307
297
}
@@ -936,10 +926,11 @@ fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
936
926
cmd. arg ( "--emit=metadata" ) ;
937
927
}
938
928
929
+ // Alter the `-o` parameter so that it does not overwrite the JSON file we stored above.
939
930
let mut args = env. args . clone ( ) ;
940
931
for i in 0 ..args. len ( ) {
941
932
if args[ i] == "-o" {
942
- args[ i + 1 ] = format ! ( "{} _miri", args [ i + 1 ] ) ;
933
+ args[ i + 1 ] . push_str ( " _miri") ;
943
934
}
944
935
}
945
936
0 commit comments