@@ -2,9 +2,30 @@ use std::collections::HashMap;
2
2
use std:: ffi:: OsStr ;
3
3
use std:: fmt:: Debug ;
4
4
use std:: fs;
5
+ #[ cfg( unix) ]
6
+ use std:: os:: unix:: process:: ExitStatusExt ;
5
7
use std:: path:: { Path , PathBuf } ;
6
8
use std:: process:: { Command , ExitStatus , Output } ;
7
9
10
+ fn exec_command (
11
+ input : & [ & dyn AsRef < OsStr > ] ,
12
+ cwd : Option < & Path > ,
13
+ env : Option < & HashMap < String , String > > ,
14
+ ) -> Result < ExitStatus , String > {
15
+ let status = get_command_inner ( input, cwd, env)
16
+ . spawn ( )
17
+ . map_err ( |e| command_error ( input, & cwd, e) ) ?
18
+ . wait ( )
19
+ . map_err ( |e| command_error ( input, & cwd, e) ) ?;
20
+ #[ cfg( unix) ]
21
+ {
22
+ if let Some ( signal) = status. signal ( ) {
23
+ return Err ( command_error ( input, & cwd, format ! ( "Process received signal {}" , signal) ) ) ;
24
+ }
25
+ }
26
+ Ok ( status)
27
+ }
28
+
8
29
fn get_command_inner (
9
30
input : & [ & dyn AsRef < OsStr > ] ,
10
31
cwd : Option < & Path > ,
@@ -89,11 +110,7 @@ pub fn run_command_with_output(
89
110
input : & [ & dyn AsRef < OsStr > ] ,
90
111
cwd : Option < & Path > ,
91
112
) -> Result < ( ) , String > {
92
- let exit_status = get_command_inner ( input, cwd, None )
93
- . spawn ( )
94
- . map_err ( |e| command_error ( input, & cwd, e) ) ?
95
- . wait ( )
96
- . map_err ( |e| command_error ( input, & cwd, e) ) ?;
113
+ let exit_status = exec_command ( input, cwd, None ) ?;
97
114
check_exit_status ( input, cwd, exit_status, None , true ) ?;
98
115
Ok ( ( ) )
99
116
}
@@ -103,11 +120,7 @@ pub fn run_command_with_output_and_env(
103
120
cwd : Option < & Path > ,
104
121
env : Option < & HashMap < String , String > > ,
105
122
) -> Result < ( ) , String > {
106
- let exit_status = get_command_inner ( input, cwd, env)
107
- . spawn ( )
108
- . map_err ( |e| command_error ( input, & cwd, e) ) ?
109
- . wait ( )
110
- . map_err ( |e| command_error ( input, & cwd, e) ) ?;
123
+ let exit_status = exec_command ( input, cwd, env) ?;
111
124
check_exit_status ( input, cwd, exit_status, None , true ) ?;
112
125
Ok ( ( ) )
113
126
}
@@ -117,11 +130,7 @@ pub fn run_command_with_output_and_env_no_err(
117
130
cwd : Option < & Path > ,
118
131
env : Option < & HashMap < String , String > > ,
119
132
) -> Result < ( ) , String > {
120
- let exit_status = get_command_inner ( input, cwd, env)
121
- . spawn ( )
122
- . map_err ( |e| command_error ( input, & cwd, e) ) ?
123
- . wait ( )
124
- . map_err ( |e| command_error ( input, & cwd, e) ) ?;
133
+ let exit_status = exec_command ( input, cwd, env) ?;
125
134
check_exit_status ( input, cwd, exit_status, None , false ) ?;
126
135
Ok ( ( ) )
127
136
}
0 commit comments