Skip to content

Commit aeda51c

Browse files
authored
Rollup merge of rust-lang#93530 - anonion0:pthread_sigmask_fix, r=JohnTitor
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()`.
2 parents af68f71 + e6aafbc commit aeda51c

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
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-1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ impl Command {
328328
#[cfg(not(target_os = "emscripten"))]
329329
{
330330
use crate::mem::MaybeUninit;
331+
use crate::sys::cvt_nz;
331332
// Reset signal handling so the child process starts in a
332333
// standardized state. libstd ignores SIGPIPE, and signal-handling
333334
// libraries often set a mask. Child processes inherit ignored
@@ -337,7 +338,7 @@ impl Command {
337338
// we're about to run.
338339
let mut set = MaybeUninit::<libc::sigset_t>::uninit();
339340
cvt(sigemptyset(set.as_mut_ptr()))?;
340-
cvt(libc::pthread_sigmask(libc::SIG_SETMASK, set.as_ptr(), ptr::null_mut()))?;
341+
cvt_nz(libc::pthread_sigmask(libc::SIG_SETMASK, set.as_ptr(), ptr::null_mut()))?;
341342

342343
#[cfg(target_os = "android")] // see issue #88585
343344
{

0 commit comments

Comments
 (0)