Skip to content

Commit c492355

Browse files
committed
fix error handling for pthread_sigmask(3)
Errors from pthread_sigmask(3) were handled using cvt(), which expects a return value of -1 on error and uses errno. However, pthread_sigmask(3) returns 0 on success and an error number otherwise. Fix it by replacing cvt() with cvt_nz().
1 parent bbad745 commit c492355

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

library/std/src/sys/unix/process/process_common/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::*;
33
use crate::ffi::OsStr;
44
use crate::mem;
55
use crate::ptr;
6-
use crate::sys::cvt;
6+
use crate::sys::{cvt, cvt_nz};
77

88
macro_rules! t {
99
($e:expr) => {
@@ -39,7 +39,7 @@ fn test_process_mask() {
3939
let mut old_set = mem::MaybeUninit::<libc::sigset_t>::uninit();
4040
t!(cvt(sigemptyset(set.as_mut_ptr())));
4141
t!(cvt(sigaddset(set.as_mut_ptr(), libc::SIGINT)));
42-
t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, set.as_ptr(), old_set.as_mut_ptr())));
42+
t!(cvt_nz(libc::pthread_sigmask(libc::SIG_SETMASK, set.as_ptr(), old_set.as_mut_ptr())));
4343

4444
cmd.stdin(Stdio::MakePipe);
4545
cmd.stdout(Stdio::MakePipe);
@@ -48,7 +48,7 @@ fn test_process_mask() {
4848
let stdin_write = pipes.stdin.take().unwrap();
4949
let stdout_read = pipes.stdout.take().unwrap();
5050

51-
t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, old_set.as_ptr(), ptr::null_mut())));
51+
t!(cvt_nz(libc::pthread_sigmask(libc::SIG_SETMASK, old_set.as_ptr(), ptr::null_mut())));
5252

5353
t!(cvt(libc::kill(cat.id() as libc::pid_t, libc::SIGINT)));
5454
// We need to wait until SIGINT is definitely delivered. The

library/std/src/sys/unix/process/process_unix.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl Command {
279279
stdio: ChildPipes,
280280
maybe_envp: Option<&CStringArray>,
281281
) -> Result<!, io::Error> {
282-
use crate::sys::{self, cvt_r};
282+
use crate::sys::{self, cvt_nz, cvt_r};
283283

284284
if let Some(fd) = stdio.stdin.fd() {
285285
cvt_r(|| libc::dup2(fd, libc::STDIN_FILENO))?;
@@ -333,7 +333,7 @@ impl Command {
333333
// we're about to run.
334334
let mut set = MaybeUninit::<libc::sigset_t>::uninit();
335335
cvt(sigemptyset(set.as_mut_ptr()))?;
336-
cvt(libc::pthread_sigmask(libc::SIG_SETMASK, set.as_ptr(), ptr::null_mut()))?;
336+
cvt_nz(libc::pthread_sigmask(libc::SIG_SETMASK, set.as_ptr(), ptr::null_mut()))?;
337337

338338
#[cfg(target_os = "android")] // see issue #88585
339339
{

0 commit comments

Comments
 (0)