@@ -202,26 +202,24 @@ impl Command {
202
202
// emscripten has no signal support.
203
203
#[ cfg( not( any( target_os = "emscripten" ) ) ) ]
204
204
{
205
- use crate :: mem;
205
+ use crate :: mem:: MaybeUninit ;
206
206
// Reset signal handling so the child process starts in a
207
207
// standardized state. libstd ignores SIGPIPE, and signal-handling
208
208
// libraries often set a mask. Child processes inherit ignored
209
209
// signals and the signal mask from their parent, but most
210
210
// UNIX programs do not reset these things on their own, so we
211
211
// need to clean things up now to avoid confusing the program
212
212
// we're about to run.
213
- let mut set: libc:: sigset_t = mem :: uninitialized ( ) ;
213
+ let mut set = MaybeUninit :: < libc:: sigset_t > :: uninit ( ) ;
214
214
if cfg ! ( target_os = "android" ) {
215
215
// Implementing sigemptyset allow us to support older Android
216
216
// versions. See the comment about Android and sig* functions in
217
217
// process_common.rs
218
- libc:: memset ( & mut set as * mut _ as * mut _ ,
219
- 0 ,
220
- mem:: size_of :: < libc:: sigset_t > ( ) ) ;
218
+ set. as_mut_ptr ( ) . write_bytes ( 0u8 , 1 ) ;
221
219
} else {
222
- cvt ( libc:: sigemptyset ( & mut set) ) ?;
220
+ cvt ( libc:: sigemptyset ( set. as_mut_ptr ( ) ) ) ?;
223
221
}
224
- cvt ( libc:: pthread_sigmask ( libc:: SIG_SETMASK , & set,
222
+ cvt ( libc:: pthread_sigmask ( libc:: SIG_SETMASK , set. as_ptr ( ) ,
225
223
ptr:: null_mut ( ) ) ) ?;
226
224
let ret = sys:: signal ( libc:: SIGPIPE , libc:: SIG_DFL ) ;
227
225
if ret == libc:: SIG_ERR {
@@ -273,7 +271,7 @@ impl Command {
273
271
fn posix_spawn ( & mut self , stdio : & ChildPipes , envp : Option < & CStringArray > )
274
272
-> io:: Result < Option < Process > >
275
273
{
276
- use crate :: mem;
274
+ use crate :: mem:: MaybeUninit ;
277
275
use crate :: sys;
278
276
279
277
if self . get_gid ( ) . is_some ( ) ||
@@ -315,63 +313,63 @@ impl Command {
315
313
316
314
let mut p = Process { pid : 0 , status : None } ;
317
315
318
- struct PosixSpawnFileActions ( libc:: posix_spawn_file_actions_t ) ;
316
+ struct PosixSpawnFileActions ( MaybeUninit < libc:: posix_spawn_file_actions_t > ) ;
319
317
320
318
impl Drop for PosixSpawnFileActions {
321
319
fn drop ( & mut self ) {
322
320
unsafe {
323
- libc:: posix_spawn_file_actions_destroy ( & mut self . 0 ) ;
321
+ libc:: posix_spawn_file_actions_destroy ( self . 0 . as_mut_ptr ( ) ) ;
324
322
}
325
323
}
326
324
}
327
325
328
- struct PosixSpawnattr ( libc:: posix_spawnattr_t ) ;
326
+ struct PosixSpawnattr ( MaybeUninit < libc:: posix_spawnattr_t > ) ;
329
327
330
328
impl Drop for PosixSpawnattr {
331
329
fn drop ( & mut self ) {
332
330
unsafe {
333
- libc:: posix_spawnattr_destroy ( & mut self . 0 ) ;
331
+ libc:: posix_spawnattr_destroy ( self . 0 . as_mut_ptr ( ) ) ;
334
332
}
335
333
}
336
334
}
337
335
338
336
unsafe {
339
- let mut file_actions = PosixSpawnFileActions ( mem :: uninitialized ( ) ) ;
340
- let mut attrs = PosixSpawnattr ( mem :: uninitialized ( ) ) ;
337
+ let mut file_actions = PosixSpawnFileActions ( MaybeUninit :: uninit ( ) ) ;
338
+ let mut attrs = PosixSpawnattr ( MaybeUninit :: uninit ( ) ) ;
341
339
342
- libc:: posix_spawnattr_init ( & mut attrs. 0 ) ;
343
- libc:: posix_spawn_file_actions_init ( & mut file_actions. 0 ) ;
340
+ libc:: posix_spawnattr_init ( attrs. 0 . as_mut_ptr ( ) ) ;
341
+ libc:: posix_spawn_file_actions_init ( file_actions. 0 . as_mut_ptr ( ) ) ;
344
342
345
343
if let Some ( fd) = stdio. stdin . fd ( ) {
346
- cvt ( libc:: posix_spawn_file_actions_adddup2 ( & mut file_actions. 0 ,
344
+ cvt ( libc:: posix_spawn_file_actions_adddup2 ( file_actions. 0 . as_mut_ptr ( ) ,
347
345
fd,
348
346
libc:: STDIN_FILENO ) ) ?;
349
347
}
350
348
if let Some ( fd) = stdio. stdout . fd ( ) {
351
- cvt ( libc:: posix_spawn_file_actions_adddup2 ( & mut file_actions. 0 ,
349
+ cvt ( libc:: posix_spawn_file_actions_adddup2 ( file_actions. 0 . as_mut_ptr ( ) ,
352
350
fd,
353
351
libc:: STDOUT_FILENO ) ) ?;
354
352
}
355
353
if let Some ( fd) = stdio. stderr . fd ( ) {
356
- cvt ( libc:: posix_spawn_file_actions_adddup2 ( & mut file_actions. 0 ,
354
+ cvt ( libc:: posix_spawn_file_actions_adddup2 ( file_actions. 0 . as_mut_ptr ( ) ,
357
355
fd,
358
356
libc:: STDERR_FILENO ) ) ?;
359
357
}
360
358
if let Some ( ( f, cwd) ) = addchdir {
361
- cvt ( f ( & mut file_actions. 0 , cwd. as_ptr ( ) ) ) ?;
359
+ cvt ( f ( file_actions. 0 . as_mut_ptr ( ) , cwd. as_ptr ( ) ) ) ?;
362
360
}
363
361
364
- let mut set: libc:: sigset_t = mem :: uninitialized ( ) ;
365
- cvt ( libc:: sigemptyset ( & mut set) ) ?;
366
- cvt ( libc:: posix_spawnattr_setsigmask ( & mut attrs. 0 ,
367
- & set) ) ?;
368
- cvt ( libc:: sigaddset ( & mut set, libc:: SIGPIPE ) ) ?;
369
- cvt ( libc:: posix_spawnattr_setsigdefault ( & mut attrs. 0 ,
370
- & set) ) ?;
362
+ let mut set = MaybeUninit :: < libc:: sigset_t > :: uninit ( ) ;
363
+ cvt ( libc:: sigemptyset ( set. as_mut_ptr ( ) ) ) ?;
364
+ cvt ( libc:: posix_spawnattr_setsigmask ( attrs. 0 . as_mut_ptr ( ) ,
365
+ set. as_ptr ( ) ) ) ?;
366
+ cvt ( libc:: sigaddset ( set. as_mut_ptr ( ) , libc:: SIGPIPE ) ) ?;
367
+ cvt ( libc:: posix_spawnattr_setsigdefault ( attrs. 0 . as_mut_ptr ( ) ,
368
+ set. as_ptr ( ) ) ) ?;
371
369
372
370
let flags = libc:: POSIX_SPAWN_SETSIGDEF |
373
371
libc:: POSIX_SPAWN_SETSIGMASK ;
374
- cvt ( libc:: posix_spawnattr_setflags ( & mut attrs. 0 , flags as _ ) ) ?;
372
+ cvt ( libc:: posix_spawnattr_setflags ( attrs. 0 . as_mut_ptr ( ) , flags as _ ) ) ?;
375
373
376
374
// Make sure we synchronize access to the global `environ` resource
377
375
let _env_lock = sys:: os:: env_lock ( ) ;
@@ -380,8 +378,8 @@ impl Command {
380
378
let ret = libc:: posix_spawnp (
381
379
& mut p. pid ,
382
380
self . get_argv ( ) [ 0 ] ,
383
- & file_actions. 0 ,
384
- & attrs. 0 ,
381
+ file_actions. 0 . as_ptr ( ) ,
382
+ attrs. 0 . as_ptr ( ) ,
385
383
self . get_argv ( ) . as_ptr ( ) as * const _ ,
386
384
envp as * const _ ,
387
385
) ;
0 commit comments