diff options
| author | Jim Blandy | 1993-06-11 16:22:03 +0000 |
|---|---|---|
| committer | Jim Blandy | 1993-06-11 16:22:03 +0000 |
| commit | 9ae8f99795aca3345dec8e258d126f571ac118c3 (patch) | |
| tree | b3ef7db4f8bf30161365c91f082a92dccfa34162 /src | |
| parent | 9b37b1c26c4f4aa46aece198382e24b40ec4cc82 (diff) | |
| download | emacs-9ae8f99795aca3345dec8e258d126f571ac118c3.tar.gz emacs-9ae8f99795aca3345dec8e258d126f571ac118c3.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/emacs.c | 20 | ||||
| -rw-r--r-- | src/sysdep.c | 57 |
2 files changed, 70 insertions, 7 deletions
diff --git a/src/emacs.c b/src/emacs.c index 3f9420f2d0a..026d669cf0d 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -81,6 +81,11 @@ int inhibit_window_system; | |||
| 81 | priority; Those functions have their own extern declaration. */ | 81 | priority; Those functions have their own extern declaration. */ |
| 82 | int emacs_priority; | 82 | int emacs_priority; |
| 83 | 83 | ||
| 84 | #ifdef BSD | ||
| 85 | /* See sysdep.c. */ | ||
| 86 | extern int inherited_pgroup; | ||
| 87 | #endif | ||
| 88 | |||
| 84 | #ifdef HAVE_X_WINDOWS | 89 | #ifdef HAVE_X_WINDOWS |
| 85 | /* If non-zero, -d was specified, meaning we're using some window system. */ | 90 | /* If non-zero, -d was specified, meaning we're using some window system. */ |
| 86 | int display_arg; | 91 | int display_arg; |
| @@ -292,18 +297,19 @@ main (argc, argv, envp) | |||
| 292 | #endif | 297 | #endif |
| 293 | 298 | ||
| 294 | clearerr (stdin); | 299 | clearerr (stdin); |
| 295 | #if 0 /* Without EMACS_SET_TTY_PGRP, this causes Emacs to hang | 300 | |
| 296 | when run under a non-job-control shell. | ||
| 297 | EMACS_SET_TTY_PGRP seems correct, but breaks even more. */ | ||
| 298 | #ifdef BSD | 301 | #ifdef BSD |
| 299 | { | 302 | { |
| 300 | int pid = getpid (); | 303 | #ifdef GETPGRP_NO_ARG |
| 301 | setpgrp (0, pid); | 304 | inherited_pgroup = getpgrp (0); |
| 302 | EMACS_SET_TTY_PGRP (0, &pid); | 305 | #else /* THISSENTENCE_NO_VERB */ |
| 303 | } | 306 | inherited_pgroup = getpgrp (0); |
| 304 | #endif | 307 | #endif |
| 308 | setpgrp (0, getpid ()); | ||
| 309 | } | ||
| 305 | #endif | 310 | #endif |
| 306 | 311 | ||
| 312 | |||
| 307 | #ifdef APOLLO | 313 | #ifdef APOLLO |
| 308 | #ifndef APOLLO_SR10 | 314 | #ifndef APOLLO_SR10 |
| 309 | /* If USE_DOMAIN_ACLS environment variable exists, | 315 | /* If USE_DOMAIN_ACLS environment variable exists, |
diff --git a/src/sysdep.c b/src/sysdep.c index 49744430560..247b9b2314f 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -756,6 +756,54 @@ unrequest_sigio () | |||
| 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. |
| @@ -982,6 +1030,11 @@ init_sys_modes () | |||
| 982 | #endif | 1030 | #endif |
| 983 | #endif /* not VMS */ | 1031 | #endif /* not VMS */ |
| 984 | 1032 | ||
| 1033 | #ifdef BSD | ||
| 1034 | if (! read_socket_hook && EQ (Vwindow_system, Qnil)) | ||
| 1035 | narrow_foreground_group (); | ||
| 1036 | #endif | ||
| 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)) |
| @@ -1334,6 +1387,10 @@ reset_sys_modes () | |||
| 1334 | #ifdef AIX | 1387 | #ifdef AIX |
| 1335 | hft_reset (); | 1388 | hft_reset (); |
| 1336 | #endif | 1389 | #endif |
| 1390 | |||
| 1391 | #ifdef BSD | ||
| 1392 | widen_foreground_group (); | ||
| 1393 | #endif | ||
| 1337 | } | 1394 | } |
| 1338 | 1395 | ||
| 1339 | #ifdef HAVE_PTYS | 1396 | #ifdef HAVE_PTYS |