@@ -85,11 +85,11 @@ impl PosixSpawnAttr {
85
85
/// Get spawn flags. See
86
86
/// [posix_spawnattr_getflags](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawnattr_getflags.html).
87
87
#[ doc( alias( "posix_spawnattr_getflags" ) ) ]
88
- pub fn flags ( & mut self ) -> Result < PosixSpawnFlags > {
88
+ pub fn flags ( & self ) -> Result < PosixSpawnFlags > {
89
89
let mut flags: libc:: c_short = 0 ;
90
90
let res = unsafe {
91
91
libc:: posix_spawnattr_getflags (
92
- & mut self . attr as * mut libc:: posix_spawnattr_t ,
92
+ & self . attr as * const libc:: posix_spawnattr_t ,
93
93
& mut flags,
94
94
)
95
95
} ;
@@ -120,12 +120,12 @@ impl PosixSpawnAttr {
120
120
/// Get spawn pgroup. See
121
121
/// [posix_spawnattr_getpgroup](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawnattr_getpgroup.html).
122
122
#[ doc( alias( "posix_spawnattr_getpgroup" ) ) ]
123
- pub fn pgroup ( & mut self ) -> Result < Pid > {
123
+ pub fn pgroup ( & self ) -> Result < Pid > {
124
124
let mut pid: libc:: pid_t = 0 ;
125
125
126
126
let res = unsafe {
127
127
libc:: posix_spawnattr_getpgroup (
128
- & mut self . attr as * mut libc:: posix_spawnattr_t ,
128
+ & self . attr as * const libc:: posix_spawnattr_t ,
129
129
& mut pid,
130
130
)
131
131
} ;
@@ -158,12 +158,12 @@ impl PosixSpawnAttr {
158
158
/// Get spawn sigdefault. See
159
159
/// [posix_spawnattr_getsigdefault](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawnattr_getsigdefault.html).
160
160
#[ doc( alias( "posix_spawnattr_getsigdefault" ) ) ]
161
- pub fn sigdefault( & mut self ) -> Result <SigSet > {
161
+ pub fn sigdefault( & self ) -> Result <SigSet > {
162
162
let mut sigset = mem:: MaybeUninit :: uninit( ) ;
163
163
164
164
let res = unsafe {
165
165
libc:: posix_spawnattr_getsigdefault(
166
- & mut self . attr as * mut libc:: posix_spawnattr_t,
166
+ & self . attr as * const libc:: posix_spawnattr_t,
167
167
sigset. as_mut_ptr( ) ,
168
168
)
169
169
} ;
@@ -196,12 +196,12 @@ impl PosixSpawnAttr {
196
196
/// Get spawn sigmask. See
197
197
/// [posix_spawnattr_getsigmask](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawnattr_getsigmask.html).
198
198
#[ doc( alias( "posix_spawnattr_getsigmask" ) ) ]
199
- pub fn sigmask( & mut self ) -> Result <SigSet > {
199
+ pub fn sigmask( & self ) -> Result <SigSet > {
200
200
let mut sigset = mem:: MaybeUninit :: uninit( ) ;
201
201
202
202
let res = unsafe {
203
203
libc:: posix_spawnattr_getsigmask(
204
- & mut self . attr as * mut libc:: posix_spawnattr_t,
204
+ & self . attr as * const libc:: posix_spawnattr_t,
205
205
sigset. as_mut_ptr( ) ,
206
206
)
207
207
} ;
@@ -387,14 +387,19 @@ impl Drop for PosixSpawnFileActions {
387
387
}
388
388
}
389
389
390
- // Specifically for use with posix_spawn and posix_spawnp.
391
- // https://github.com/rust-lang/libc/issues/1272
390
+ // The POSIX standard requires those `args` and `envp` to be of type `*const *mut [c_char]`,
391
+ // but implementations won't modify them, making the `mut` type redundant. Considering this,
392
+ // Nix does not expose this mutability, but we have to change the interface when calling the
393
+ // underlying libc interfaces , this helper function does the conversion job.
394
+ //
395
+ // SAFETY:
396
+ // It is safe to add the mutability in types as implementations won't mutable them.
392
397
unsafe fn to_exec_array < S : AsRef < CStr > > ( args : & [ S ] ) -> Vec < * mut libc:: c_char > {
393
398
let mut v: Vec < * mut libc:: c_char > = args
394
399
. iter ( )
395
- . map ( |s| s. as_ref ( ) . as_ptr ( ) as * mut libc :: c_char )
400
+ . map ( |s| s. as_ref ( ) . as_ptr ( ) . cast_mut ( ) )
396
401
. collect ( ) ;
397
- v. push ( std:: ptr:: null :: < libc :: c_char > ( ) as * mut libc :: c_char ) ;
402
+ v. push ( std:: ptr:: null_mut ( ) ) ;
398
403
v
399
404
}
400
405
0 commit comments