28namespace scoped_ignore_sig {
33static volatile sig_atomic_t got_sigpipe = 0;
48 auto *
osig = signal (SIGPIPE, handle_sigpipe);
49 SCOPE_EXIT { signal (SIGPIPE,
osig); };
51#ifdef HAVE_SIGPROCMASK
53 sigset_t set, old_state;
55 sigaddset (&set, SIGPIPE);
56 sigprocmask (SIG_UNBLOCK, &set, &old_state);
57 SCOPE_EXIT { sigprocmask (SIG_SETMASK, &old_state,
nullptr); };
71 SCOPE_EXIT { close (fd[1]); };
75 auto check_pipe_write = [&] (
bool expect_sig)
80 r = write (fd[1], &c, 1);
81 SELF_CHECK (r == -1 && errno == EPIPE
82 && got_sigpipe == expect_sig);
87 check_pipe_write (
true);
92 scoped_ignore_sigpipe ignore1;
94 check_pipe_write (
false);
98 scoped_ignore_sigpipe ignore2;
100 check_pipe_write (
false);
105 check_pipe_write (
false);
110 check_pipe_write (
true);