4 #define _POSIX_C_SOURCE 200809L
15 static void interactive_signals(void (* const handler
)(int)) {
16 try_signal(SIGINT
, handler
);
17 try_signal(SIGQUIT
, handler
);
18 try_signal(SIGTSTP
, handler
);
21 static Pipe
make_pipe() {
24 if (pipe(fds
) == -1) {
32 static void move_fd(int const old
, int const new) {
33 if (dup2(old
, new) == -1) {
39 static int wait_script(pid_t
const pid
) {
40 int status
= try_waitpid(pid
, WUNTRACED
);
41 while (WIFSTOPPED(status
)) {
42 if (WSTOPSIG(status
) == SIGTSTP
) {
43 try_signal(SIGTSTP
, SIG_DFL
);
45 try_signal(SIGTSTP
, SIG_IGN
);
47 status
= try_waitpid(pid
, WUNTRACED
);
49 if (WIFSIGNALED(status
)) {
50 switch (WTERMSIG(status
)) {
52 try_signal(SIGINT
, SIG_DFL
);
54 case SIGQUIT
: exit(EXIT_FAILURE
);