Skip to content

Commit

Permalink
Restore echo-signal sigaction for OpenBSD
Browse files Browse the repository at this point in the history
I was excited about having less junk here but unfortunately OpenBSD
seems to treat (at least) SIGTSTP and SIGCONT as if they were SIG_IGN,
which means they'll be discarded instead of marked pending, so we need
to install a signal handler anyway.
  • Loading branch information
tokenrove committed Nov 27, 2023
1 parent b616a73 commit 8576be0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion helpers/echo-signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,24 @@ static int int_of_signal_name(char *name)
abort();
}


static sig_atomic_t got;
static void handler(int n) { got = n; }

int main(int argc, char **argv)
{
if (2 != argc) abort();
int sig = int_of_signal_name(argv[1]);

// This handler _should_ be unnecessary for these signals and
// sigwait, except that OpenBSD seems to consider TSTP and CONT as
// being ignored by default (though POSIX says otherwise).
sigaction(sig, &(struct sigaction){.sa_handler=handler}, NULL);
sigset_t set, prev;
sigemptyset(&set);
sigaddset(&set, sig);
sigprocmask(SIG_BLOCK, &set, &prev);
write(1, "ready\n", 6);
int got;
do { sigwait(&set, &got); } while (sig != got);
puts(argv[1]);
return 0;
Expand Down

0 comments on commit 8576be0

Please sign in to comment.