-#if USE_SIGTSTP /* Xenix 2.x doesn't have SIGTSTP, for example */
-static sigaction_t act, oact;
-static int ignore;
-
- if (!ignore)
- {
- if (!enable)
- {
- act.sa_handler = SIG_IGN;
- sigaction(SIGTSTP, &act, &oact);
- }
- else if (act.sa_handler)
- {
- sigaction(SIGTSTP, &oact, NULL);
- }
- else /*initialize */
- {
- sigemptyset(&act.sa_mask);
- act.sa_flags = 0;
-#if USE_SIGWINCH
- act.sa_handler = sigwinch;
- CatchIfDefault(SIGWINCH, &act);
-#endif
-
+ T((T_CALLED("_nc_signal_handler(%d)"), enable));
+#if USE_SIGTSTP /* Xenix 2.x doesn't have SIGTSTP, for example */
+ {
+ static bool ignore_tstp = FALSE;
+
+ if (!ignore_tstp) {
+ static sigaction_t new_sigaction, old_sigaction;
+
+ if (!enable) {
+ new_sigaction.sa_handler = SIG_IGN;
+ sigaction(SIGTSTP, &new_sigaction, &old_sigaction);
+ } else if (new_sigaction.sa_handler != SIG_DFL) {
+ sigaction(SIGTSTP, &old_sigaction, NULL);
+ } else if (sigaction(SIGTSTP, NULL, &old_sigaction) == 0
+ && (old_sigaction.sa_handler == SIG_DFL)) {
+ sigemptyset(&new_sigaction.sa_mask);