aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysdep.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sysdep.c')
-rw-r--r--src/sysdep.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index 049eb85afe5..158d2f73eec 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -714,6 +714,27 @@ init_foreground_group (void)
714 inherited_pgroup = getpid () == pgrp ? 0 : pgrp; 714 inherited_pgroup = getpid () == pgrp ? 0 : pgrp;
715} 715}
716 716
717/* Block and unblock SIGTTOU. */
718
719void
720block_tty_out_signal (void)
721{
722#ifdef SIGTTOU
723 sigset_t blocked;
724 sigemptyset (&blocked);
725 sigaddset (&blocked, SIGTTOU);
726 pthread_sigmask (SIG_BLOCK, &blocked, 0);
727#endif
728}
729
730void
731unblock_tty_out_signal (void)
732{
733#ifdef SIGTTOU
734 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
735#endif
736}
737
717/* Safely set a controlling terminal FD's process group to PGID. 738/* Safely set a controlling terminal FD's process group to PGID.
718 If we are not in the foreground already, POSIX requires tcsetpgrp 739 If we are not in the foreground already, POSIX requires tcsetpgrp
719 to deliver a SIGTTOU signal, which would stop us. This is an 740 to deliver a SIGTTOU signal, which would stop us. This is an
@@ -725,11 +746,10 @@ static void
725tcsetpgrp_without_stopping (int fd, pid_t pgid) 746tcsetpgrp_without_stopping (int fd, pid_t pgid)
726{ 747{
727#ifdef SIGTTOU 748#ifdef SIGTTOU
728 signal_handler_t handler;
729 block_input (); 749 block_input ();
730 handler = signal (SIGTTOU, SIG_IGN); 750 block_tty_out_signal ();
731 tcsetpgrp (fd, pgid); 751 tcsetpgrp (fd, pgid);
732 signal (SIGTTOU, handler); 752 unblock_tty_out_signal ();
733 unblock_input (); 753 unblock_input ();
734#endif 754#endif
735} 755}