From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: emacsclient not working on RHEL 6.8 (non-sudo) [master branch] Date: Thu, 6 Dec 2018 10:52:31 -0800 Organization: UCLA Computer Science Department Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------43C834A4E8949AAEB0FB1253" X-Trace: blaine.gmane.org 1544122444 5072 195.159.176.226 (6 Dec 2018 18:54:04 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 6 Dec 2018 18:54:04 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 To: Kaushal Modi , Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 06 19:53:59 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gUymb-00018d-4x for ged-emacs-devel@m.gmane.org; Thu, 06 Dec 2018 19:53:57 +0100 Original-Received: from localhost ([::1]:42561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUyoh-0002L3-5i for ged-emacs-devel@m.gmane.org; Thu, 06 Dec 2018 13:56:07 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUylS-0007cK-DC for emacs-devel@gnu.org; Thu, 06 Dec 2018 13:52:48 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gUylO-0006yq-BW for emacs-devel@gnu.org; Thu, 06 Dec 2018 13:52:46 -0500 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:52216) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gUylK-0006uX-Eh for emacs-devel@gnu.org; Thu, 06 Dec 2018 13:52:40 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 8B5161605D5; Thu, 6 Dec 2018 10:52:33 -0800 (PST) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id T74g9FpTvmE5; Thu, 6 Dec 2018 10:52:32 -0800 (PST) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 24777160603; Thu, 6 Dec 2018 10:52:32 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id NrKxTzEdcZoM; Thu, 6 Dec 2018 10:52:32 -0800 (PST) Original-Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 0307D160612; Thu, 6 Dec 2018 10:52:32 -0800 (PST) Openpgp: preference=signencrypt Autocrypt: addr=eggert@cs.ucla.edu; prefer-encrypt=mutual; keydata= xsFNBEyAcmQBEADAAyH2xoTu7ppG5D3a8FMZEon74dCvc4+q1XA2J2tBy2pwaTqfhpxxdGA9 Jj50UJ3PD4bSUEgN8tLZ0san47l5XTAFLi2456ciSl5m8sKaHlGdt9XmAAtmXqeZVIYX/UFS 96fDzf4xhEmm/y7LbYEPQdUdxu47xA5KhTYp5bltF3WYDz1Ygd7gx07Auwp7iw7eNvnoDTAl KAl8KYDZzbDNCQGEbpY3efZIvPdeI+FWQN4W+kghy+P6au6PrIIhYraeua7XDdb2LS1en3Ss mE3QjqfRqI/A2ue8JMwsvXe/WK38Ezs6x74iTaqI3AFH6ilAhDqpMnd/msSESNFt76DiO1ZK QMr9amVPknjfPmJISqdhgB1DlEdw34sROf6V8mZw0xfqT6PKE46LcFefzs0kbg4GORf8vjG2 Sf1tk5eU8MBiyN/bZ03bKNjNYMpODDQQwuP84kYLkX2wBxxMAhBxwbDVZudzxDZJ1C2VXujC OJVxq2kljBM9ETYuUGqd75AW2LXrLw6+MuIsHFAYAgRr7+KcwDgBAfwhPBYX34nSSiHlmLC+ KaHLeCLF5ZI2vKm3HEeCTtlOg7xZEONgwzL+fdKo+D6SoC8RRxJKs8a3sVfI4t6CnrQzvJbB n6gxdgCu5i29J1QCYrCYvql2UyFPAK+do99/1jOXT4m2836j1wARAQABzSBQYXVsIEVnZ2Vy dCA8ZWdnZXJ0QGNzLnVjbGEuZWR1PsLBfgQTAQIAKAUCTIByZAIbAwUJEswDAAYLCQgHAwIG FQgCCQoLBBYCAwECH In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:231690 Archived-At: This is a multi-part message in MIME format. --------------43C834A4E8949AAEB0FB1253 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thanks, I reproduced the problem and installed the following patches. The first should fix the bug. The second should fix some display glitches I noticed while fixing the bug, where emacsclient wrote to the terminal even though it was started with a trailing '&'. --------------43C834A4E8949AAEB0FB1253 Content-Type: text/x-patch; name="0001-Fix-emacsclient-hang-when-backgrounded.patch" Content-Disposition: attachment; filename="0001-Fix-emacsclient-hang-when-backgrounded.patch" Content-Transfer-Encoding: quoted-printable >From 2f985977f691a37a6d45298128b88d0cefcc93a1 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 6 Dec 2018 08:54:00 -0800 Subject: [PATCH 1/2] Fix emacsclient hang when backgrounded MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit Problem reported by Kaushal Modi in: https://lists.gnu.org/r/emacs-devel/2018-12/msg00083.html The tcdrain call replaced an fdatasync call which had no effect on the tty, so removing it entirely shouldn=E2=80=99t cause problems. The fdatasync call replaced an fsync call which also had no effect on the tty, and the fsync call seems to be badly-merged revenant of emacsclient=E2=80=99s old (circa 2004) way of communicating to and from Emacs via FILE * streams, where fsync was apparently needed when talking to sockets. * lib-src/emacsclient.c [!DOS_NT]: Don=E2=80=99t include termios.h. (flush_stdout): Remove. All callers removed. (main): Do not drain the tty after "Waiting for Emacs..." message. There should be no need to drain, and draining it might send us a SIGTTOU. Do not fflush stdout just before exiting, as exiting does that for us. --- lib-src/emacsclient.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 7de3665114..653ab955df 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -66,10 +66,6 @@ char *w32_getenv (const char *); =20 #endif /* !WINDOWSNT */ =20 -#ifndef DOS_NT -# include -#endif - #include #include #include @@ -1740,15 +1736,6 @@ start_daemon_and_retry_set_socket (void) return emacs_socket; } =20 -/* Flush standard output and its underlying file descriptor. */ -static void -flush_stdout (HSOCKET emacs_socket) -{ - fflush (stdout); - while (tcdrain (STDOUT_FILENO) !=3D 0 && errno =3D=3D EINTR) - act_on_signals (emacs_socket); -} - int main (int argc, char **argv) { @@ -1964,7 +1951,7 @@ main (int argc, char **argv) printf ("Waiting for Emacs..."); skiplf =3D false; } - flush_stdout (emacs_socket); + fflush (stdout); =20 /* Now, wait for an answer and print any messages. */ while (exit_status =3D=3D EXIT_SUCCESS) @@ -2067,7 +2054,6 @@ main (int argc, char **argv) =20 if (!skiplf) printf ("\n"); - flush_stdout (emacs_socket); =20 if (rl < 0) exit_status =3D EXIT_FAILURE; --=20 2.19.2 --------------43C834A4E8949AAEB0FB1253 Content-Type: text/x-patch; name="0002-emacsclient-avoid-background-chatter.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0002-emacsclient-avoid-background-chatter.patch" >From 46b810081165fecae5086b71fafdb3eb19c30df5 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 6 Dec 2018 10:46:06 -0800 Subject: [PATCH 2/2] 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. --- lib-src/emacsclient.c | 51 ++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 653ab955df..c596fb23ae 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) return true; } +/* Return the process group if in the foreground, the negative of the + process group if in the background, and zero if there is no + foreground process group for the controlling terminal. + Unfortunately, use of this function introduces an unavoidable race, + since whether the process is in the foreground or background can + change at any time. */ + +static pid_t +process_grouping (void) +{ +#ifdef SOCKETS_IN_FILE_SYSTEM + pid_t tcpgrp = tcgetpgrp (STDOUT_FILENO); + if (0 <= tcpgrp) + { + pid_t pgrp = getpgrp (); + return tcpgrp == pgrp ? pgrp : -pgrp; + } +#endif + return 0; +} #ifdef SOCKETS_IN_FILE_SYSTEM @@ -1253,21 +1273,17 @@ act_on_signals (HSOCKET emacs_socket) { got_sigcont = 0; took_action = true; - pid_t tcpgrp = tcgetpgrp (STDOUT_FILENO); - if (0 <= tcpgrp) + pid_t grouping = process_grouping (); + if (grouping < 0) { - pid_t pgrp = getpgrp (); - if (tcpgrp == pgrp) - { - /* We are in the foreground. */ - send_to_emacs (emacs_socket, "-resume \n"); - } - else if (tty) + if (tty) { - /* We are in the background; cancel the continue. */ - kill (-pgrp, SIGTTIN); + /* Cancel the continue. */ + kill (grouping, SIGTTIN); } } + else + send_to_emacs (emacs_socket, "-resume \n"); } if (got_sigtstp) @@ -1767,13 +1783,12 @@ main (int argc, char **argv) exit (EXIT_FAILURE); } -#ifndef WINDOWSNT +#ifdef SOCKETS_IN_FILE_SYSTEM if (tty) { - pid_t pgrp = getpgrp (); - pid_t tcpgrp = tcgetpgrp (STDOUT_FILENO); - if (0 <= tcpgrp && tcpgrp != pgrp) - kill (-pgrp, SIGTTIN); + pid_t grouping = process_grouping (); + if (grouping < 0) + kill (grouping, SIGTTIN); } #endif @@ -1946,7 +1961,7 @@ main (int argc, char **argv) send_to_emacs (emacs_socket, "\n"); /* Wait for an answer. */ - if (!eval && !tty && !nowait && !quiet) + if (!eval && !tty && !nowait && !quiet && 0 <= process_grouping ()) { printf ("Waiting for Emacs..."); skiplf = false; @@ -2052,7 +2067,7 @@ main (int argc, char **argv) } } - if (!skiplf) + if (!skiplf && 0 <= process_grouping ()) printf ("\n"); if (rl < 0) -- 2.19.2 --------------43C834A4E8949AAEB0FB1253--