From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#50849: 28.0.50; Proposal for Emacs daemon to signal when being busy Date: Fri, 9 Sep 2022 05:29:17 -0400 Message-ID: References: <86czouksh2.fsf@protected.rcdrun.com> <83ilm1jkss.fsf@gnu.org> <87v8q1b2ij.fsf@gmail.com> <83czc8k7zw.fsf@gnu.org> <83czc7j4bs.fsf@gnu.org> <87leqvbhhg.fsf@gmail.com> <838rmvig8f.fsf@gnu.org> <83wnaefltf.fsf@gnu.org> <87pmg63w8l.fsf@gnus.org> <83zgfadlt8.fsf@gnu.org> <87pmg6yo60.fsf@gnus.org> <83sfl2dkqv.fsf@gnu.org> <8735d2ymzv.fsf@gnus.org> <83pmg6dkb6.fsf@gnu.org> <87czc67xtv.fsf@gmail.com> <83mtb9etw5.fsf@gnu.org> <87czc57x44.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19342"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, 50849@debbugs.gnu.org, bugs@gnu.support, visuweshm@gmail.com To: Robert Pluim , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 09 11:30:13 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oWaKz-0004qo-DS for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 09 Sep 2022 11:30:13 +0200 Original-Received: from localhost ([::1]:34698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oWaKx-0005B5-QU for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 09 Sep 2022 05:30:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oWaKo-0005Ax-EU for bug-gnu-emacs@gnu.org; Fri, 09 Sep 2022 05:30:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43955) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oWaKo-0007HB-3l for bug-gnu-emacs@gnu.org; Fri, 09 Sep 2022 05:30:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oWaKn-0008Uc-Q8 for bug-gnu-emacs@gnu.org; Fri, 09 Sep 2022 05:30:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 09 Sep 2022 09:30:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50849 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 50849-submit@debbugs.gnu.org id=B50849.166271576932585 (code B ref 50849); Fri, 09 Sep 2022 09:30:01 +0000 Original-Received: (at 50849) by debbugs.gnu.org; 9 Sep 2022 09:29:29 +0000 Original-Received: from localhost ([127.0.0.1]:60887 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oWaKH-0008TV-4J for submit@debbugs.gnu.org; Fri, 09 Sep 2022 05:29:29 -0400 Original-Received: from mail-oa1-f54.google.com ([209.85.160.54]:35446) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oWaKB-0008TC-Nh for 50849@debbugs.gnu.org; Fri, 09 Sep 2022 05:29:27 -0400 Original-Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-1225219ee46so2458573fac.2 for <50849@debbugs.gnu.org>; Fri, 09 Sep 2022 02:29:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:from:to:cc:subject:date; bh=egH7PTnhWeFU88C7vJRxediI9ttUkWjptmojVug9Cgo=; b=Tet9dyN+fTkk/TACCe411ZcUiibLktY5rL29GjMZqJY1Ju2WE5+8WY++X9y8FTKL3m mglGCvEb+ksld1Wu7HvBGZoH/RVmxoV+Ev5Z9Lm22Lkk1l+Vd426lxtkJ9TXyotWBw7N k8u+6RHu07/rEVMZ/TEXRj2UbJFSQbvPn07Bx9s5MMx5m1FdvNo5HKA4mVZxO5eKpYsx vRdzpUtgwRdksmArZFnbYUWQUD1DEhyQRIi0Ry7t173WZIediziwlGz7+Ep/pmYFT84c tzYVNBEyx67lz/2gvC0jbraZXPWUQZgqqpO/4RNvtaiWMlO97i1ujB1X+FTqNA8lURVH WRzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:x-gm-message-state:from:to:cc:subject:date; bh=egH7PTnhWeFU88C7vJRxediI9ttUkWjptmojVug9Cgo=; b=le4YEu/L0NTv14Qs064DjwpjNGr0UYQZv6BO9m5EcSenxbVUHotoY7snEzRWRSzpD7 B5dP7SYzJEfJnvRAMngIzGNyrUKecQHYg89UBtgZzmohbiKT0zWMwlJoaxfxaKAoeGi8 RO1MYKBVHhAFFGyic5mJaMXZa1Xnluo58e5HMJtoGS+ypb/OGHVW4CZgafdwEMZ7+Erb p1aNApN7VbihN/6p0P3uCMzdX8sIXmucrgn7NTxdrHUEJfE9dknjycXrBqRfnJaV5zP1 WuXMs2DWe/OTOLBHEQFjrc6JBo18S+Tsj3kalv1LqOd2r7/nCS01X1WZZNBVDiUOdWRn HFQA== X-Gm-Message-State: ACgBeo3tolaPoPUOm0tiV8Wr1aDXDiEv4LNyU8OXJFIzlkyg1MZbnbxa +lQSftgogDIkp2t6rwztGTWdqRfazuPHcW59O18= X-Google-Smtp-Source: AA6agR6OeNNsr4+gVMK1HYms86WuZhNhBIqxt0odDXkz5xI0rl8FCZm+1LfVvHD48fwN3hHczJ/qenYyxjb4uQN44hM= X-Received: by 2002:a05:6808:1688:b0:345:ea9a:2954 with SMTP id bb8-20020a056808168800b00345ea9a2954mr3173564oib.199.1662715757868; Fri, 09 Sep 2022 02:29:17 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Fri, 9 Sep 2022 05:29:17 -0400 In-Reply-To: <87czc57x44.fsf@gmail.com> X-Hashcash: 1:20:220909:50849@debbugs.gnu.org::2orc15Wcun2w0h1k:1wKP X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:241962 Archived-At: Robert Pluim writes: > So this simplifies the code considerably, and in fact removes the > whole retry thing completely. We could do that, yes. It looks good to me. I had a different idea in mind though, which lets us keep the diagnostic message, but only if given a --verbose flag. We could extend --verbose to include more diagnostic output in the future. Please see the attached patch. I'm happy with either your patch or mine, depending on what people prefer. diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 88800b9b2e..cd3069d7a8 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -66,7 +66,9 @@ Copyright (C) 1986-2022 Free Software Foundation, Inc. #endif /* !WINDOWSNT */ -#define DEFAULT_TIMEOUT (30) +/* Seconds to wait before warning that the server hasn't responded. + Only applicable with --verbose and without any --timeout flag. */ +#define DEFAULT_WARN_AFTER (30) #include #include @@ -110,6 +112,9 @@ #define DEFAULT_TIMEOUT (30) /* True means don't print messages for successful operations. --quiet. */ static bool quiet; +/* True means print verbose messages. --verbose. */ +static bool verbose; + /* True means don't print values returned from emacs. --suppress-output. */ static bool suppress_output; @@ -166,6 +171,7 @@ #define DEFAULT_TIMEOUT (30) static struct option const longopts[] = { { "no-wait", no_argument, NULL, 'n' }, + { "verbose", no_argument, NULL, 'v' }, { "quiet", no_argument, NULL, 'q' }, { "suppress-output", no_argument, NULL, 'u' }, { "eval", no_argument, NULL, 'e' }, @@ -191,7 +197,7 @@ #define DEFAULT_TIMEOUT (30) /* Short options, in the same order as the corresponding long options. There is no '-p' short option. */ static char const shortopts[] = - "nqueHVtca:F:w:" + "nqueHVtcva:F:w:" #ifdef SOCKETS_IN_FILE_SYSTEM "s:" #endif @@ -488,6 +494,23 @@ message (bool is_error, const char *format, ...) va_end (args); } +/* Print message only if we got the --verbose flag. */ +static void print_verbose (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2); +static void +print_verbose (const char *format, ...) +{ + va_list args; + va_start (args, format); + + if (verbose) + { + vfprintf (stderr, format, args); + fflush (stderr); + } + + va_end (args); +} + /* Decode the options from argv and argc. The global variable 'optind' will say how many arguments we used up. */ @@ -556,6 +579,10 @@ decode_options (int argc, char **argv) quiet = true; break; + case 'v': + verbose = true; + break; + case 'u': suppress_output = true; break; @@ -2144,40 +2171,49 @@ main (int argc, char **argv) } fflush (stdout); - set_socket_timeout (emacs_socket, timeout > 0 ? timeout : DEFAULT_TIMEOUT); - bool saw_response = false; + bool should_timeout = timeout > 0 || verbose; /* Now, wait for an answer and print any messages. */ while (exit_status == EXIT_SUCCESS) { - bool retry = true; - bool msg_showed = quiet; + if (should_timeout) + set_socket_timeout (emacs_socket, + timeout > 0 ? timeout : DEFAULT_WARN_AFTER); do { + retry_recv: act_on_signals (emacs_socket); rl = recv (emacs_socket, string, BUFSIZ, 0); - retry = check_socket_timeout (rl); - if (retry && !saw_response) + + /* Handle --timeout and --verbose. */ + if (should_timeout + /* Just retry if we got EINTR; it's not a timeout. */ + && errno != EINTR) { - if (timeout > 0) - { - /* Don't retry if we were given a --timeout flag. */ - fprintf (stderr, "\nServer not responding; timed out after %lu seconds", - timeout); - retry = false; - } - else if (!msg_showed) + should_timeout = false; + set_socket_timeout (emacs_socket, 0); + + if (check_socket_timeout (rl)) { - msg_showed = true; - fprintf (stderr, "\nServer not responding; use Ctrl+C to break"); + if (timeout > 0) + { + fprintf (stderr, + "\nServer not responding; timed out after %lu seconds", + timeout); + break; + } + else /* if (verbose) */ + { + print_verbose ("\nServer not responding; use Ctrl+C to break"); + goto retry_recv; + } } } } - while ((rl < 0 && errno == EINTR) || retry); + while (rl < 0 && errno == EINTR); if (rl <= 0) break; - saw_response = true; string[rl] = '\0'; /* Loop over all NL-terminated messages. */