We skip printing timestamp when _any_ monitor is active. But
then, in production (where QMP is usually used) we lack timestamps
in logs.

Let's go a bit further, and use same logic to detect HMP monitor
in the whole util/error-report.c like in error_vprintf().

Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
---
 stubs/monitor-core.c           |  5 +++++
 tests/unit/test-util-sockets.c |  1 +
 util/error-report.c            | 23 ++++++++++++++---------
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c
index 1894cdfe1f..275cb0cbfa 100644
--- a/stubs/monitor-core.c
+++ b/stubs/monitor-core.c
@@ -7,6 +7,11 @@ Monitor *monitor_cur(void)
     return NULL;
 }
 
+bool monitor_cur_is_hmp(void)
+{
+    return false;
+}
+
 Monitor *monitor_set_cur(Coroutine *co, Monitor *mon)
 {
     return NULL;
diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c
index ee66d727c3..4b7f408902 100644
--- a/tests/unit/test-util-sockets.c
+++ b/tests/unit/test-util-sockets.c
@@ -74,6 +74,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error 
**errp)
 Monitor *monitor_cur(void) { return cur_mon; }
 Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { abort(); }
 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); }
+bool monitor_cur_is_hmp(void) { return false; }
 
 #ifndef _WIN32
 static void test_socket_fd_pass_name_good(void)
diff --git a/util/error-report.c b/util/error-report.c
index 1b17c11de1..7ffbcf2123 100644
--- a/util/error-report.c
+++ b/util/error-report.c
@@ -144,7 +144,7 @@ static void print_loc(void)
     int i;
     const char *const *argp;
 
-    if (!monitor_cur() && g_get_prgname()) {
+    if (!monitor_cur_is_hmp() && g_get_prgname()) {
         error_printf("%s:", g_get_prgname());
         sep = " ";
     }
@@ -188,15 +188,20 @@ static void vreport(report_type type, const char *fmt, 
va_list ap)
 {
     gchar *timestr;
 
-    if (message_with_timestamp && !monitor_cur()) {
-        timestr = real_time_iso8601();
-        error_printf("%s ", timestr);
-        g_free(timestr);
-    }
+    if (!monitor_cur_is_hmp()) {
+        if (message_with_timestamp) {
+            timestr = real_time_iso8601();
+            error_printf("%s ", timestr);
+            g_free(timestr);
+        }
 
-    /* Only prepend guest name if -msg guest-name and -name guest=... are set 
*/
-    if (error_with_guestname && error_guest_name && !monitor_cur()) {
-        error_printf("%s ", error_guest_name);
+        /*
+         * Only prepend guest name if -msg guest-name and -name guest=...
+         * are set.
+         */
+        if (error_with_guestname && error_guest_name) {
+            error_printf("%s ", error_guest_name);
+        }
     }
 
     print_loc();
-- 
2.48.1


Reply via email to