comparison src/sysdep.c @ 3655:3e6cc11cfe9f

Interact properly with shells lacking job control (sh, rc, es...) * sysdep.c [BSD] (inherited_pgroup): New variable. (narrow_foreground_group, widen_foreground_group): New functions. (init_sys_modes): Call narrow_foreground_group. (reset_sys_modes): Call widen_foreground_group. * emacs.c [BSD] (inherited_pgroup): Add extern declaration. [BSD] (main): Set inherited_pgroup, and put ourselves in our own pgroup.
author Jim Blandy <jimb@redhat.com>
date Fri, 11 Jun 1993 16:22:03 +0000
parents be31c90ee59d
children 674fb551b693
comparison
equal deleted inserted replaced
3654:d9313b9a63ad 3655:3e6cc11cfe9f
754 754
755 #endif /* STRIDE */ 755 #endif /* STRIDE */
756 #endif /* FASYNC */ 756 #endif /* FASYNC */
757 #endif /* F_SETFL */ 757 #endif /* F_SETFL */
758 758
759 /* Saving and restoring the process group of Emacs's terminal. */
760
761 #ifdef BSD
762
763 /* The process group of which Emacs was a member when it initially
764 started.
765
766 If Emacs was in its own process group (i.e. inherited_pgroup ==
767 getpid ()), then we know we're running under a shell with job
768 control (Emacs would never be run as part of a pipeline).
769 Everything is fine.
770
771 If Emacs was not in its own process group, then we know we're
772 running under a shell (or a caller) that doesn't know how to
773 separate itself from Emacs (like sh). Emacs must be in its own
774 process group in order to receive SIGIO correctly. In this
775 situation, we put ourselves in our own pgroup, forcibly set the
776 tty's pgroup to our pgroup, and make sure to restore and reinstate
777 the tty's pgroup just like any other terminal setting. If
778 inherited_group was not the tty's pgroup, then we'll get a
779 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
780 it goes foreground in the future, which is what should happen. */
781 int inherited_pgroup;
782
783 /* Split off the foreground process group to Emacs alone.
784 When we are in the foreground, but not started in our own process
785 group, redirect the TTY to point to our own process group. We need
786 to be in our own process group to receive SIGIO properly. */
787 narrow_foreground_group ()
788 {
789 int me = getpid ();
790
791 setpgrp (0, inherited_pgroup);
792 if (inherited_pgroup != me)
793 EMACS_SET_TTY_PGRP (0, &me);
794 setpgrp (0, me);
795 }
796
797 /* Set the tty to our original foreground group. */
798 widen_foreground_group ()
799 {
800 if (inherited_pgroup != getpid ())
801 EMACS_SET_TTY_PGRP (0, &inherited_pgroup);
802 setpgrp (0, inherited_pgroup);
803 }
804
805 #endif
806
759 /* Getting and setting emacs_tty structures. */ 807 /* Getting and setting emacs_tty structures. */
760 808
761 /* Set *TC to the parameters associated with the terminal FD. 809 /* Set *TC to the parameters associated with the terminal FD.
762 Return zero if all's well, or -1 if we ran into an error we 810 Return zero if all's well, or -1 if we ran into an error we
763 couldn't deal with. */ 811 couldn't deal with. */
979 ((unsigned) 1 << (timer_ef % 32)); 1027 ((unsigned) 1 << (timer_ef % 32));
980 #ifndef VMS4_4 1028 #ifndef VMS4_4
981 sys_access_reinit (); 1029 sys_access_reinit ();
982 #endif 1030 #endif
983 #endif /* not VMS */ 1031 #endif /* not VMS */
1032
1033 #ifdef BSD
1034 if (! read_socket_hook && EQ (Vwindow_system, Qnil))
1035 narrow_foreground_group ();
1036 #endif
984 1037
985 EMACS_GET_TTY (input_fd, &old_tty); 1038 EMACS_GET_TTY (input_fd, &old_tty);
986 1039
987 if (!read_socket_hook && EQ (Vwindow_system, Qnil)) 1040 if (!read_socket_hook && EQ (Vwindow_system, Qnil))
988 { 1041 {
1331 while (EMACS_SET_TTY (input_fd, &old_tty, 0) < 0 && errno == EINTR) 1384 while (EMACS_SET_TTY (input_fd, &old_tty, 0) < 0 && errno == EINTR)
1332 ; 1385 ;
1333 1386
1334 #ifdef AIX 1387 #ifdef AIX
1335 hft_reset (); 1388 hft_reset ();
1389 #endif
1390
1391 #ifdef BSD
1392 widen_foreground_group ();
1336 #endif 1393 #endif
1337 } 1394 }
1338 1395
1339 #ifdef HAVE_PTYS 1396 #ifdef HAVE_PTYS
1340 1397