#include <getopt.h>
#include <signal.h>
+/* Use SA_NOCLDSTOP as a proxy for whether the sigaction machinery is
+ present. */
#ifndef SA_NOCLDSTOP
+# define SA_NOCLDSTOP 0
# define sigprocmask(How, Set, Oset) /* empty */
# define sigset_t int
+# if ! HAVE_SIGINTERRUPT
+# define siginterrupt(sig, flag) /* empty */
+# endif
#endif
/* Get mbstate_t, mbrtowc(), mbsinit(), wcwidth(). */
static void
sighandler (int sig)
{
-#ifndef SA_NOCLDSTOP
- signal (sig, SIG_IGN);
-#endif
-
+ if (! SA_NOCLDSTOP)
+ signal (sig, SIG_IGN);
if (! interrupt_signal)
interrupt_signal = sig;
}
static void
stophandler (int sig)
{
-#ifndef SA_NOCLDSTOP
- signal (sig, stophandler);
-#endif
-
+ if (! SA_NOCLDSTOP)
+ signal (sig, stophandler);
if (! interrupt_signal)
stop_signal_count++;
}
SIGQUIT, SIGTERM, SIGTSTP };
enum { nsigs = sizeof sig / sizeof sig[0] };
-#ifndef SA_NOCLDSTOP
+#if ! SA_NOCLDSTOP
bool caught_sig[nsigs];
#endif
if (0 <= tcgetpgrp (STDOUT_FILENO))
{
int j;
-#ifdef SA_NOCLDSTOP
+#if SA_NOCLDSTOP
struct sigaction act;
sigemptyset (&caught_signals);
{
caught_sig[j] = (signal (sig[j], SIG_IGN) != SIG_IGN);
if (caught_sig[j])
- signal (sig[j], sig[j] == SIGTSTP ? stophandler : sighandler);
+ {
+ signal (sig[j], sig[j] == SIGTSTP ? stophandler : sighandler);
+ siginterrupt (sig[j], 0);
+ }
}
#endif
}
fflush (stdout);
/* Restore the default signal handling. */
-#ifdef SA_NOCLDSTOP
+#if SA_NOCLDSTOP
for (j = 0; j < nsigs; j++)
if (sigismember (&caught_signals, sig[j]))
signal (sig[j], SIG_DFL);