File tree 2 files changed +33
-2
lines changed
2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,16 @@ use ptr;
17
17
use sys:: cvt;
18
18
use sys:: process:: process_common:: * ;
19
19
20
+ #[ cfg( all( not( target_os = "android" ) , not( target_env = "musl" ) ) ) ]
21
+ const DEFAULT_PATH : & [ u8 ] = b"/bin:/usr/bin" ;
22
+ // Musl has a different default path.
23
+ #[ cfg( target_env = "musl" ) ]
24
+ const DEFAULT_PATH : & [ u8 ] = b"/usr/local/bin:/bin:/usr/bin" ;
25
+ // Android has a different default path.
26
+ #[ cfg( target_os = "android" ) ]
27
+ const DEFAULT_PATH : & [ u8 ] = b"/sbin:/system/sbin:/system/bin:/system/xbin:\
28
+ /odm/bin:/vendor/bin:/vendor/xbin";
29
+
20
30
////////////////////////////////////////////////////////////////////////////////
21
31
// Command
22
32
////////////////////////////////////////////////////////////////////////////////
@@ -135,14 +145,15 @@ impl Command {
135
145
Some ( envp) => {
136
146
match envp. get_items ( ) . iter ( ) . find ( |var| var. as_bytes ( ) . starts_with ( b"PATH=" ) ) {
137
147
Some ( p) => & p. as_bytes ( ) [ 5 ..] ,
138
- None => return None ,
148
+ // If there's no PATH, fall back to the default (which varies by platform).
149
+ None => DEFAULT_PATH ,
139
150
}
140
151
} ,
141
152
// maybe_envp is None if the process isn't changing the parent's env at all.
142
153
None => {
143
154
match parent_path. as_ref ( ) {
144
155
Some ( p) => p. as_bytes ( ) ,
145
- None => return None ,
156
+ None => DEFAULT_PATH ,
146
157
}
147
158
} ,
148
159
} ;
Original file line number Diff line number Diff line change @@ -55,6 +55,16 @@ fn main() {
55
55
println ! ( "passed" ) ;
56
56
}
57
57
58
+ "exec-test6" => {
59
+ let err = Command :: new ( "echo" ) . arg ( "passed" ) . env_clear ( ) . exec ( ) ;
60
+ panic ! ( "failed to spawn: {}" , err) ;
61
+ }
62
+
63
+ "exec-test7" => {
64
+ let err = Command :: new ( "echo" ) . arg ( "passed" ) . env_remove ( "PATH" ) . exec ( ) ;
65
+ panic ! ( "failed to spawn: {}" , err) ;
66
+ }
67
+
58
68
_ => panic ! ( "unknown argument: {}" , arg) ,
59
69
}
60
70
return
@@ -84,4 +94,14 @@ fn main() {
84
94
assert ! ( output. status. success( ) ) ;
85
95
assert ! ( output. stderr. is_empty( ) ) ;
86
96
assert_eq ! ( output. stdout, b"passed\n " ) ;
97
+
98
+ let output = Command :: new ( & me) . arg ( "exec-test6" ) . output ( ) . unwrap ( ) ;
99
+ assert ! ( output. status. success( ) ) ;
100
+ assert ! ( output. stderr. is_empty( ) ) ;
101
+ assert_eq ! ( output. stdout, b"passed\n " ) ;
102
+
103
+ let output = Command :: new ( & me) . arg ( "exec-test7" ) . output ( ) . unwrap ( ) ;
104
+ assert ! ( output. status. success( ) ) ;
105
+ assert ! ( output. stderr. is_empty( ) ) ;
106
+ assert_eq ! ( output. stdout, b"passed\n " ) ;
87
107
}
You can’t perform that action at this time.
0 commit comments