qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Steve Sistare <steven.sistare@oracle.com>
To: qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
	Michael Roth <michael.roth@amd.com>,
	"Dr. David Alan Gilbert" <dave@treblig.org>,
	Steve Sistare <steven.sistare@oracle.com>
Subject: [PATCH] monitor: flush messages on abort
Date: Fri,  3 Nov 2023 09:01:29 -0700	[thread overview]
Message-ID: <1699027289-213995-1-git-send-email-steven.sistare@oracle.com> (raw)

Buffered monitor output is lost when abort() is called.  The pattern
error_report() followed by abort() occurs about 60 times, so valuable
information is being lost when the abort is called in the context of a
monitor command.

To fix, install a SIGABRT handler to flush the monitor buffer to stderr.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 monitor/monitor.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/monitor/monitor.c b/monitor/monitor.c
index dc352f9..65dace0 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -701,6 +701,43 @@ void monitor_cleanup(void)
     }
 }
 
+#ifdef CONFIG_LINUX
+
+static void monitor_abort(int signal, siginfo_t *info, void *c)
+{
+    Monitor *mon = monitor_cur();
+
+    if (!mon || qemu_mutex_trylock(&mon->mon_lock)) {
+        return;
+    }
+
+    if (mon->outbuf && mon->outbuf->len) {
+        fputs("SIGABRT received: ", stderr);
+        fputs(mon->outbuf->str, stderr);
+        if (mon->outbuf->str[mon->outbuf->len - 1] != '\n') {
+            fputc('\n', stderr);
+        }
+    }
+
+    qemu_mutex_unlock(&mon->mon_lock);
+}
+
+static void monitor_add_abort_handler(void)
+{
+    struct sigaction act;
+
+    memset(&act, 0, sizeof(act));
+    act.sa_sigaction = monitor_abort;
+    act.sa_flags = SA_SIGINFO;
+    sigaction(SIGABRT,  &act, NULL);
+}
+
+#else
+
+static void monitor_add_abort_handler(void) {}
+
+#endif
+
 static void monitor_qapi_event_init(void)
 {
     monitor_qapi_event_state = g_hash_table_new(qapi_event_throttle_hash,
@@ -712,6 +749,7 @@ void monitor_init_globals(void)
     monitor_qapi_event_init();
     qemu_mutex_init(&monitor_lock);
     coroutine_mon = g_hash_table_new(NULL, NULL);
+    monitor_add_abort_handler();
 
     /*
      * The dispatcher BH must run in the main loop thread, since we
-- 
1.8.3.1



             reply	other threads:[~2023-11-03 16:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-03 16:01 Steve Sistare [this message]
2023-11-03 17:33 ` [PATCH] monitor: flush messages on abort Daniel P. Berrangé
2023-11-03 19:51   ` Steven Sistare
2023-11-03 20:28     ` Steven Sistare
2023-11-06 10:10     ` Daniel P. Berrangé
2023-11-15  8:41       ` Markus Armbruster
2023-11-15 15:52         ` Steven Sistare
2023-11-15 16:15           ` Markus Armbruster
2023-11-15 17:41             ` Steven Sistare
2023-11-16 15:14               ` Markus Armbruster
2023-11-16 17:03                 ` Steven Sistare
2023-11-15 15:30       ` Steven Sistare
2023-11-15 16:05         ` Markus Armbruster
2023-11-16 11:21         ` Daniel P. Berrangé

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1699027289-213995-1-git-send-email-steven.sistare@oracle.com \
    --to=steven.sistare@oracle.com \
    --cc=armbru@redhat.com \
    --cc=dave@treblig.org \
    --cc=michael.roth@amd.com \
    --cc=qemu-devel@nongnu.org \
    /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.
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 NNTP newsgroup(s).