diff options
| author | Paul Eggert | 2014-03-09 15:38:15 -0700 |
|---|---|---|
| committer | Paul Eggert | 2014-03-09 15:38:15 -0700 |
| commit | d050de754c22013db5fb8f57650d22581393ed79 (patch) | |
| tree | bb7394e94411377cfcd621f57a6cf1cf03933bc6 | |
| parent | eb67db411128bd47548e4a62d7272df81b75d29a (diff) | |
| download | emacs-d050de754c22013db5fb8f57650d22581393ed79.tar.gz emacs-d050de754c22013db5fb8f57650d22581393ed79.zip | |
Fix emacsclient terminal corruption when in background.
* emacsclient.c (handle_sigcont): Check for tcgetpgrp failure.
Cancel the continue only if tty. Send SIGTTIN to the process
group, not SIGSTOP to self, as this is what the glibc manual
recommends.
(main): If tty, and if started in the background, send SIGTTIN
to the process group.
Fixes: debbugs:16892
| -rw-r--r-- | lib-src/ChangeLog | 10 | ||||
| -rw-r--r-- | lib-src/emacsclient.c | 16 |
2 files changed, 23 insertions, 3 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 8cf73cea5d6..0c3d7d723c5 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2014-03-09 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Fix emacsclient terminal corruption when in background (Bug#16892). | ||
| 4 | * emacsclient.c (handle_sigcont): Check for tcgetpgrp failure. | ||
| 5 | Cancel the continue only if tty. Send SIGTTIN to the process | ||
| 6 | group, not SIGSTOP to self, as this is what the glibc manual | ||
| 7 | recommends. | ||
| 8 | (main): If tty, and if started in the background, send SIGTTIN | ||
| 9 | to the process group. | ||
| 10 | |||
| 1 | 2014-02-25 Andreas Amann <a.amann@ucc.ie> (tiny change) | 11 | 2014-02-25 Andreas Amann <a.amann@ucc.ie> (tiny change) |
| 2 | 12 | ||
| 3 | Fix emacsclient's handling of SIGCONT (Bug#16883). | 13 | Fix emacsclient's handling of SIGCONT (Bug#16883). |
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 148182a6ccf..cf16874589d 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -1105,16 +1105,18 @@ static void | |||
| 1105 | handle_sigcont (int signalnum) | 1105 | handle_sigcont (int signalnum) |
| 1106 | { | 1106 | { |
| 1107 | int old_errno = errno; | 1107 | int old_errno = errno; |
| 1108 | pid_t pgrp = getpgrp (); | ||
| 1109 | pid_t tcpgrp = tcgetpgrp (1); | ||
| 1108 | 1110 | ||
| 1109 | if (tcgetpgrp (1) == getpgrp ()) | 1111 | if (tcpgrp == pgrp) |
| 1110 | { | 1112 | { |
| 1111 | /* We are in the foreground. */ | 1113 | /* We are in the foreground. */ |
| 1112 | send_to_emacs (emacs_socket, "-resume \n"); | 1114 | send_to_emacs (emacs_socket, "-resume \n"); |
| 1113 | } | 1115 | } |
| 1114 | else if (tty) | 1116 | else if (0 <= tcpgrp && tty) |
| 1115 | { | 1117 | { |
| 1116 | /* We are in the background; cancel the continue. */ | 1118 | /* We are in the background; cancel the continue. */ |
| 1117 | raise (SIGSTOP); | 1119 | kill (-pgrp, SIGTTIN); |
| 1118 | } | 1120 | } |
| 1119 | 1121 | ||
| 1120 | signal (signalnum, handle_sigcont); | 1122 | signal (signalnum, handle_sigcont); |
| @@ -1554,6 +1556,14 @@ main (int argc, char **argv) | |||
| 1554 | exit (EXIT_FAILURE); | 1556 | exit (EXIT_FAILURE); |
| 1555 | } | 1557 | } |
| 1556 | 1558 | ||
| 1559 | if (tty) | ||
| 1560 | { | ||
| 1561 | pid_t pgrp = getpgrp (); | ||
| 1562 | pid_t tcpgrp = tcgetpgrp (1); | ||
| 1563 | if (0 <= tcpgrp && tcpgrp != pgrp) | ||
| 1564 | kill (-pgrp, SIGTTIN); | ||
| 1565 | } | ||
| 1566 | |||
| 1557 | /* If alternate_editor is the empty string, start the emacs daemon | 1567 | /* If alternate_editor is the empty string, start the emacs daemon |
| 1558 | in case of failure to connect. */ | 1568 | in case of failure to connect. */ |
| 1559 | start_daemon_if_needed = (alternate_editor | 1569 | start_daemon_if_needed = (alternate_editor |