diff options
| author | Paul Eggert | 2018-12-06 10:46:06 -0800 |
|---|---|---|
| committer | Paul Eggert | 2018-12-06 10:48:04 -0800 |
| commit | 46b810081165fecae5086b71fafdb3eb19c30df5 (patch) | |
| tree | 8bce3e5fb56b6040a5f955915b0a76182bd4cd2c /lib-src | |
| parent | 2f985977f691a37a6d45298128b88d0cefcc93a1 (diff) | |
| download | emacs-46b810081165fecae5086b71fafdb3eb19c30df5.tar.gz emacs-46b810081165fecae5086b71fafdb3eb19c30df5.zip | |
emacsclient: avoid background chatter
* lib-src/emacsclient.c (process_grouping): New function.
(act_on_signals, main): Use it.
(main): Omit "Waiting for Emacs..." and later "\n" messages
if in background, since that messes up the screen.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/emacsclient.c | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 653ab955df5..c596fb23aee 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -1095,6 +1095,26 @@ find_tty (const char **tty_type, const char **tty_name, bool noabort) | |||
| 1095 | return true; | 1095 | return true; |
| 1096 | } | 1096 | } |
| 1097 | 1097 | ||
| 1098 | /* Return the process group if in the foreground, the negative of the | ||
| 1099 | process group if in the background, and zero if there is no | ||
| 1100 | foreground process group for the controlling terminal. | ||
| 1101 | Unfortunately, use of this function introduces an unavoidable race, | ||
| 1102 | since whether the process is in the foreground or background can | ||
| 1103 | change at any time. */ | ||
| 1104 | |||
| 1105 | static pid_t | ||
| 1106 | process_grouping (void) | ||
| 1107 | { | ||
| 1108 | #ifdef SOCKETS_IN_FILE_SYSTEM | ||
| 1109 | pid_t tcpgrp = tcgetpgrp (STDOUT_FILENO); | ||
| 1110 | if (0 <= tcpgrp) | ||
| 1111 | { | ||
| 1112 | pid_t pgrp = getpgrp (); | ||
| 1113 | return tcpgrp == pgrp ? pgrp : -pgrp; | ||
| 1114 | } | ||
| 1115 | #endif | ||
| 1116 | return 0; | ||
| 1117 | } | ||
| 1098 | 1118 | ||
| 1099 | #ifdef SOCKETS_IN_FILE_SYSTEM | 1119 | #ifdef SOCKETS_IN_FILE_SYSTEM |
| 1100 | 1120 | ||
| @@ -1253,21 +1273,17 @@ act_on_signals (HSOCKET emacs_socket) | |||
| 1253 | { | 1273 | { |
| 1254 | got_sigcont = 0; | 1274 | got_sigcont = 0; |
| 1255 | took_action = true; | 1275 | took_action = true; |
| 1256 | pid_t tcpgrp = tcgetpgrp (STDOUT_FILENO); | 1276 | pid_t grouping = process_grouping (); |
| 1257 | if (0 <= tcpgrp) | 1277 | if (grouping < 0) |
| 1258 | { | 1278 | { |
| 1259 | pid_t pgrp = getpgrp (); | 1279 | if (tty) |
| 1260 | if (tcpgrp == pgrp) | ||
| 1261 | { | ||
| 1262 | /* We are in the foreground. */ | ||
| 1263 | send_to_emacs (emacs_socket, "-resume \n"); | ||
| 1264 | } | ||
| 1265 | else if (tty) | ||
| 1266 | { | 1280 | { |
| 1267 | /* We are in the background; cancel the continue. */ | 1281 | /* Cancel the continue. */ |
| 1268 | kill (-pgrp, SIGTTIN); | 1282 | kill (grouping, SIGTTIN); |
| 1269 | } | 1283 | } |
| 1270 | } | 1284 | } |
| 1285 | else | ||
| 1286 | send_to_emacs (emacs_socket, "-resume \n"); | ||
| 1271 | } | 1287 | } |
| 1272 | 1288 | ||
| 1273 | if (got_sigtstp) | 1289 | if (got_sigtstp) |
| @@ -1767,13 +1783,12 @@ main (int argc, char **argv) | |||
| 1767 | exit (EXIT_FAILURE); | 1783 | exit (EXIT_FAILURE); |
| 1768 | } | 1784 | } |
| 1769 | 1785 | ||
| 1770 | #ifndef WINDOWSNT | 1786 | #ifdef SOCKETS_IN_FILE_SYSTEM |
| 1771 | if (tty) | 1787 | if (tty) |
| 1772 | { | 1788 | { |
| 1773 | pid_t pgrp = getpgrp (); | 1789 | pid_t grouping = process_grouping (); |
| 1774 | pid_t tcpgrp = tcgetpgrp (STDOUT_FILENO); | 1790 | if (grouping < 0) |
| 1775 | if (0 <= tcpgrp && tcpgrp != pgrp) | 1791 | kill (grouping, SIGTTIN); |
| 1776 | kill (-pgrp, SIGTTIN); | ||
| 1777 | } | 1792 | } |
| 1778 | #endif | 1793 | #endif |
| 1779 | 1794 | ||
| @@ -1946,7 +1961,7 @@ main (int argc, char **argv) | |||
| 1946 | send_to_emacs (emacs_socket, "\n"); | 1961 | send_to_emacs (emacs_socket, "\n"); |
| 1947 | 1962 | ||
| 1948 | /* Wait for an answer. */ | 1963 | /* Wait for an answer. */ |
| 1949 | if (!eval && !tty && !nowait && !quiet) | 1964 | if (!eval && !tty && !nowait && !quiet && 0 <= process_grouping ()) |
| 1950 | { | 1965 | { |
| 1951 | printf ("Waiting for Emacs..."); | 1966 | printf ("Waiting for Emacs..."); |
| 1952 | skiplf = false; | 1967 | skiplf = false; |
| @@ -2052,7 +2067,7 @@ main (int argc, char **argv) | |||
| 2052 | } | 2067 | } |
| 2053 | } | 2068 | } |
| 2054 | 2069 | ||
| 2055 | if (!skiplf) | 2070 | if (!skiplf && 0 <= process_grouping ()) |
| 2056 | printf ("\n"); | 2071 | printf ("\n"); |
| 2057 | 2072 | ||
| 2058 | if (rl < 0) | 2073 | if (rl < 0) |