From: Stefan Kangas <stefankangas@gmail.com>
To: Robert Pluim <rpluim@gmail.com>, Eli Zaretskii <eliz@gnu.org>
Cc: larsi@gnus.org, 50849@debbugs.gnu.org, bugs@gnu.support,
visuweshm@gmail.com
Subject: bug#50849: 28.0.50; Proposal for Emacs daemon to signal when being busy
Date: Fri, 9 Sep 2022 05:29:17 -0400 [thread overview]
Message-ID: <CADwFkmnQp8fhd7uFh5qfodkJpqtF+5AxrLD4eSLqSshDrnF+GQ@mail.gmail.com> (raw)
In-Reply-To: <87czc57x44.fsf@gmail.com>
Robert Pluim <rpluim@gmail.com> 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 <ctype.h>
#include <errno.h>
@@ -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. */
next prev parent reply other threads:[~2022-09-09 9:29 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-27 14:23 bug#50849: 28.0.50; Proposal for Emacs daemon to signal when being busy Jean Louis
2021-09-27 15:27 ` Eli Zaretskii
2021-09-28 5:56 ` Lars Ingebrigtsen
2021-09-28 7:08 ` Eli Zaretskii
2022-09-02 11:09 ` Lars Ingebrigtsen
2022-09-02 11:21 ` Eli Zaretskii
2022-09-02 12:28 ` Lars Ingebrigtsen
2022-09-02 12:39 ` Eli Zaretskii
2022-09-02 12:44 ` Robert Pluim
2022-09-02 13:02 ` Lars Ingebrigtsen
2022-09-02 13:54 ` Visuwesh
2022-09-02 14:02 ` Eli Zaretskii
2022-09-03 9:48 ` Lars Ingebrigtsen
2022-09-03 15:40 ` Stefan Kangas
2022-09-03 15:57 ` Eli Zaretskii
2022-09-04 10:59 ` Lars Ingebrigtsen
2022-09-05 13:56 ` Stefan Kangas
2022-09-05 19:07 ` Lars Ingebrigtsen
2022-09-06 0:19 ` Stefan Kangas
2022-09-06 2:31 ` Eli Zaretskii
2022-09-06 3:33 ` Visuwesh
2022-09-06 12:22 ` Eli Zaretskii
2022-09-06 14:02 ` Robert Pluim
2022-09-06 14:12 ` Eli Zaretskii
2022-09-06 14:20 ` Robert Pluim
2022-09-07 1:05 ` Stefan Kangas
2022-09-07 2:39 ` Eli Zaretskii
2022-09-07 8:18 ` Stefan Kangas
2022-09-07 10:34 ` Robert Pluim
2022-09-07 11:19 ` Eli Zaretskii
2022-09-08 1:47 ` Stefan Kangas
2022-09-08 5:59 ` Eli Zaretskii
2022-09-08 12:07 ` Lars Ingebrigtsen
2022-09-08 13:42 ` Eli Zaretskii
2022-09-08 13:46 ` Lars Ingebrigtsen
2022-09-08 14:05 ` Eli Zaretskii
2022-09-08 14:11 ` Lars Ingebrigtsen
2022-09-08 14:15 ` Eli Zaretskii
2022-09-08 14:19 ` Robert Pluim
2022-09-08 16:02 ` Eli Zaretskii
2022-09-09 8:47 ` Robert Pluim
2022-09-09 9:29 ` Stefan Kangas [this message]
2022-09-09 9:35 ` Robert Pluim
2022-09-09 9:38 ` Stefan Kangas
2022-09-09 11:31 ` Eli Zaretskii
2022-09-06 8:20 ` Robert Pluim
2022-09-06 8:52 ` Lars Ingebrigtsen
2022-09-03 1:07 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-03 9:49 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADwFkmnQp8fhd7uFh5qfodkJpqtF+5AxrLD4eSLqSshDrnF+GQ@mail.gmail.com \
--to=stefankangas@gmail.com \
--cc=50849@debbugs.gnu.org \
--cc=bugs@gnu.support \
--cc=eliz@gnu.org \
--cc=larsi@gnus.org \
--cc=rpluim@gmail.com \
--cc=visuweshm@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).