* [Qemu-devel] [PATCH v6 1/2] qemu-io: Use error_[gs]et_progname()
@ 2019-01-25 17:22 Christophe Fergeau
2019-01-25 17:22 ` [Qemu-devel] [PATCH v6 2/2] log: Make glib logging go through QEMU Christophe Fergeau
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Christophe Fergeau @ 2019-01-25 17:22 UTC (permalink / raw)
To: qemu-devel
Cc: Markus Armbruster, Max Reitz, Stefan Hajnoczi, Daniel P . Berrangé
qemu-io reimplements itself what
error_get_progname()/error_set_progname() already does.
This commit switches it to use this API from qemu-error.h
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
---
qemu-io.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/qemu-io.c b/qemu-io.c
index 6df7731af4..2c52ac0ade 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -34,8 +34,6 @@
#define CMD_NOFILE_OK 0x01
-static char *progname;
-
static BlockBackend *qemuio_blk;
static bool quit_qemu_io;
@@ -312,7 +310,7 @@ static char *get_prompt(void)
static char prompt[FILENAME_MAX + 2 /*"> "*/ + 1 /*"\0"*/ ];
if (!prompt[0]) {
- snprintf(prompt, sizeof(prompt), "%s> ", progname);
+ snprintf(prompt, sizeof(prompt), "%s> ", error_get_progname());
}
return prompt;
@@ -525,7 +523,7 @@ int main(int argc, char **argv)
#endif
module_call_init(MODULE_INIT_TRACE);
- progname = g_path_get_basename(argv[0]);
+ error_set_progname(argv[0]);
qemu_init_exec_dir(argv[0]);
qcrypto_init(&error_fatal);
@@ -580,10 +578,10 @@ int main(int argc, char **argv)
break;
case 'V':
printf("%s version " QEMU_FULL_VERSION "\n"
- QEMU_COPYRIGHT "\n", progname);
+ QEMU_COPYRIGHT "\n", error_get_progname());
exit(0);
case 'h':
- usage(progname);
+ usage(error_get_progname());
exit(0);
case 'U':
force_share = true;
@@ -600,13 +598,13 @@ int main(int argc, char **argv)
imageOpts = true;
break;
default:
- usage(progname);
+ usage(error_get_progname());
exit(1);
}
}
if ((argc - optind) > 1) {
- usage(progname);
+ usage(error_get_progname());
exit(1);
}
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH v6 2/2] log: Make glib logging go through QEMU
2019-01-25 17:22 [Qemu-devel] [PATCH v6 1/2] qemu-io: Use error_[gs]et_progname() Christophe Fergeau
@ 2019-01-25 17:22 ` Christophe Fergeau
2019-01-29 3:34 ` Stefan Hajnoczi
2019-01-29 18:17 ` Markus Armbruster
2019-01-25 20:37 ` [Qemu-devel] [PATCH v6 1/2] qemu-io: Use error_[gs]et_progname() Eric Blake
2019-01-29 3:34 ` Stefan Hajnoczi
2 siblings, 2 replies; 6+ messages in thread
From: Christophe Fergeau @ 2019-01-25 17:22 UTC (permalink / raw)
To: qemu-devel
Cc: Markus Armbruster, Max Reitz, Stefan Hajnoczi, Daniel P . Berrangé
This commit adds a qemu_init_logging() helper which calls
g_log_set_default_handler() so that glib logs (g_log, g_warning, ...)
are handled similarly to other QEMU logs. This means they will get a
timestamp if timestamps are enabled, and they will go through the
HMP monitor if one is configured.
This commit also adds a call to qemu_init_logging() to the binaries
installed by QEMU.
glib debug messages are enabled through G_MESSAGES_DEBUG similarly to
glib default log handler.
At the moment, this change will mostly impact SPICE logging if your
spice version is >= 0.14.1. With older spice versions, this is not going
to work as expected, but will not have any ill effect, so this call is
not conditional on the SPICE version.
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
---
bsd-user/main.c | 2 ++
include/qemu/error-report.h | 3 ++-
linux-user/main.c | 2 ++
qemu-img.c | 2 +-
qemu-io.c | 2 +-
qemu-nbd.c | 2 +-
scsi/qemu-pr-helper.c | 1 +
util/qemu-error.c | 48 ++++++++++++++++++++++++++++++++++++-
vl.c | 2 +-
9 files changed, 58 insertions(+), 6 deletions(-)
diff --git a/bsd-user/main.c b/bsd-user/main.c
index 0d3156974c..8fd8ae4127 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -24,6 +24,7 @@
#include "qapi/error.h"
#include "qemu.h"
#include "qemu/config-file.h"
+#include "qemu/error-report.h"
#include "qemu/path.h"
#include "qemu/help_option.h"
#include "cpu.h"
@@ -743,6 +744,7 @@ int main(int argc, char **argv)
if (argc <= 1)
usage();
+ error_init(argv[0]);
module_call_init(MODULE_INIT_TRACE);
qemu_init_cpu_list();
module_call_init(MODULE_INIT_QOM);
diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index 0a8d9cc9ea..ce43c02314 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -34,7 +34,6 @@ void error_vprintf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
void error_vprintf_unless_qmp(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
-void error_set_progname(const char *argv0);
void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
void warn_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
@@ -49,6 +48,8 @@ bool error_report_once_cond(bool *printed, const char *fmt, ...)
bool warn_report_once_cond(bool *printed, const char *fmt, ...)
GCC_FMT_ATTR(2, 3);
+void error_init(const char *argv0);
+
/*
* Similar to error_report(), except it prints the message just once.
* Return true when it prints, false otherwise.
diff --git a/linux-user/main.c b/linux-user/main.c
index a0aba9cb1e..f9efe9ff6e 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -27,6 +27,7 @@
#include "qemu/path.h"
#include "qemu/config-file.h"
#include "qemu/cutils.h"
+#include "qemu/error-report.h"
#include "qemu/help_option.h"
#include "cpu.h"
#include "exec/exec-all.h"
@@ -600,6 +601,7 @@ int main(int argc, char **argv, char **envp)
int ret;
int execfd;
+ error_init(argv[0]);
module_call_init(MODULE_INIT_TRACE);
qemu_init_cpu_list();
module_call_init(MODULE_INIT_QOM);
diff --git a/qemu-img.c b/qemu-img.c
index ad04f59565..0af9cac244 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -4912,8 +4912,8 @@ int main(int argc, char **argv)
signal(SIGPIPE, SIG_IGN);
#endif
+ error_init(argv[0]);
module_call_init(MODULE_INIT_TRACE);
- error_set_progname(argv[0]);
qemu_init_exec_dir(argv[0]);
if (qemu_init_main_loop(&local_error)) {
diff --git a/qemu-io.c b/qemu-io.c
index 2c52ac0ade..8d5d5911cb 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -522,8 +522,8 @@ int main(int argc, char **argv)
signal(SIGPIPE, SIG_IGN);
#endif
+ error_init(argv[0]);
module_call_init(MODULE_INIT_TRACE);
- error_set_progname(argv[0]);
qemu_init_exec_dir(argv[0]);
qcrypto_init(&error_fatal);
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 1f7b2a03f5..39849f1692 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -685,8 +685,8 @@ int main(int argc, char **argv)
signal(SIGPIPE, SIG_IGN);
#endif
+ error_init(argv[0]);
module_call_init(MODULE_INIT_TRACE);
- error_set_progname(argv[0]);
qcrypto_init(&error_fatal);
module_call_init(MODULE_INIT_QOM);
diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
index e7af637232..2541fbbd1b 100644
--- a/scsi/qemu-pr-helper.c
+++ b/scsi/qemu-pr-helper.c
@@ -895,6 +895,7 @@ int main(int argc, char **argv)
signal(SIGPIPE, SIG_IGN);
+ error_init(argv[0]);
module_call_init(MODULE_INIT_TRACE);
module_call_init(MODULE_INIT_QOM);
qemu_add_opts(&qemu_trace_opts);
diff --git a/util/qemu-error.c b/util/qemu-error.c
index fcbe8a1f74..2684870683 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -142,7 +142,7 @@ static const char *progname;
/*
* Set the program name for error_print_loc().
*/
-void error_set_progname(const char *argv0)
+static void error_set_progname(const char *argv0)
{
const char *p = strrchr(argv0, '/');
progname = p ? p + 1 : argv0;
@@ -345,3 +345,49 @@ bool warn_report_once_cond(bool *printed, const char *fmt, ...)
va_end(ap);
return true;
}
+
+static char *qemu_glog_domains;
+
+static void qemu_log_func(const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer user_data)
+{
+ switch (log_level & G_LOG_LEVEL_MASK) {
+ case G_LOG_LEVEL_DEBUG:
+ case G_LOG_LEVEL_INFO:
+ /* Use same G_MESSAGES_DEBUG logic as glib to enable/disable debug
+ * messages */
+ if (qemu_glog_domains == NULL) {
+ break;
+ }
+ if (strcmp(qemu_glog_domains, "all") != 0 &&
+ (log_domain == NULL || !strstr(qemu_glog_domains, log_domain))) {
+ break;
+ }
+ /* Fall through */
+ case G_LOG_LEVEL_MESSAGE:
+ info_report("%s: %s", log_domain?:"", message);
+ break;
+ case G_LOG_LEVEL_WARNING:
+ warn_report("%s: %s", log_domain?:"", message);
+ break;
+ case G_LOG_LEVEL_CRITICAL:
+ /* Fall through */
+ case G_LOG_LEVEL_ERROR:
+ error_report("%s: %s", log_domain?:"", message);
+ break;
+ }
+}
+
+void error_init(const char *argv0)
+{
+ /* Set the program name for error_print_loc(). */
+ error_set_progname(argv0);
+
+ /* This sets up glib logging so libraries using it also print their logs
+ * through error_report(), warn_report(), info_report(). */
+ g_log_set_default_handler(qemu_log_func, NULL);
+ g_warn_if_fail(qemu_glog_domains == NULL);
+ qemu_glog_domains = g_strdup(g_getenv("G_MESSAGES_DEBUG"));
+}
diff --git a/vl.c b/vl.c
index bc9fbec654..bfef38c3a3 100644
--- a/vl.c
+++ b/vl.c
@@ -3039,6 +3039,7 @@ int main(int argc, char **argv, char **envp)
QSIMPLEQ_HEAD(, BlockdevOptions_queue) bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
+ error_init(argv[0]);
module_call_init(MODULE_INIT_TRACE);
qemu_init_cpu_list();
@@ -3047,7 +3048,6 @@ int main(int argc, char **argv, char **envp)
qemu_mutex_lock_iothread();
atexit(qemu_run_exit_notifiers);
- error_set_progname(argv[0]);
qemu_init_exec_dir(argv[0]);
module_call_init(MODULE_INIT_QOM);
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v6 1/2] qemu-io: Use error_[gs]et_progname()
2019-01-25 17:22 [Qemu-devel] [PATCH v6 1/2] qemu-io: Use error_[gs]et_progname() Christophe Fergeau
2019-01-25 17:22 ` [Qemu-devel] [PATCH v6 2/2] log: Make glib logging go through QEMU Christophe Fergeau
@ 2019-01-25 20:37 ` Eric Blake
2019-01-29 3:34 ` Stefan Hajnoczi
2 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2019-01-25 20:37 UTC (permalink / raw)
To: Christophe Fergeau, qemu-devel
Cc: Markus Armbruster, Stefan Hajnoczi, Max Reitz
[-- Attachment #1: Type: text/plain, Size: 594 bytes --]
On 1/25/19 11:22 AM, Christophe Fergeau wrote:
Don't forget the 0/2 cover letter for series :)
> qemu-io reimplements itself what
> error_get_progname()/error_set_progname() already does.
> This commit switches it to use this API from qemu-error.h
>
> Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
> ---
> qemu-io.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v6 1/2] qemu-io: Use error_[gs]et_progname()
2019-01-25 17:22 [Qemu-devel] [PATCH v6 1/2] qemu-io: Use error_[gs]et_progname() Christophe Fergeau
2019-01-25 17:22 ` [Qemu-devel] [PATCH v6 2/2] log: Make glib logging go through QEMU Christophe Fergeau
2019-01-25 20:37 ` [Qemu-devel] [PATCH v6 1/2] qemu-io: Use error_[gs]et_progname() Eric Blake
@ 2019-01-29 3:34 ` Stefan Hajnoczi
2 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2019-01-29 3:34 UTC (permalink / raw)
To: Christophe Fergeau
Cc: qemu-devel, Markus Armbruster, Stefan Hajnoczi, Max Reitz
[-- Attachment #1: Type: text/plain, Size: 435 bytes --]
On Fri, Jan 25, 2019 at 06:22:28PM +0100, Christophe Fergeau wrote:
> qemu-io reimplements itself what
> error_get_progname()/error_set_progname() already does.
> This commit switches it to use this API from qemu-error.h
>
> Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
> ---
> qemu-io.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v6 2/2] log: Make glib logging go through QEMU
2019-01-25 17:22 ` [Qemu-devel] [PATCH v6 2/2] log: Make glib logging go through QEMU Christophe Fergeau
@ 2019-01-29 3:34 ` Stefan Hajnoczi
2019-01-29 18:17 ` Markus Armbruster
1 sibling, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2019-01-29 3:34 UTC (permalink / raw)
To: Christophe Fergeau
Cc: qemu-devel, Markus Armbruster, Stefan Hajnoczi, Max Reitz
[-- Attachment #1: Type: text/plain, Size: 1415 bytes --]
On Fri, Jan 25, 2019 at 06:22:29PM +0100, Christophe Fergeau wrote:
> This commit adds a qemu_init_logging() helper which calls
> g_log_set_default_handler() so that glib logs (g_log, g_warning, ...)
> are handled similarly to other QEMU logs. This means they will get a
> timestamp if timestamps are enabled, and they will go through the
> HMP monitor if one is configured.
> This commit also adds a call to qemu_init_logging() to the binaries
> installed by QEMU.
> glib debug messages are enabled through G_MESSAGES_DEBUG similarly to
> glib default log handler.
>
> At the moment, this change will mostly impact SPICE logging if your
> spice version is >= 0.14.1. With older spice versions, this is not going
> to work as expected, but will not have any ill effect, so this call is
> not conditional on the SPICE version.
>
> Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
> ---
> bsd-user/main.c | 2 ++
> include/qemu/error-report.h | 3 ++-
> linux-user/main.c | 2 ++
> qemu-img.c | 2 +-
> qemu-io.c | 2 +-
> qemu-nbd.c | 2 +-
> scsi/qemu-pr-helper.c | 1 +
> util/qemu-error.c | 48 ++++++++++++++++++++++++++++++++++++-
> vl.c | 2 +-
> 9 files changed, 58 insertions(+), 6 deletions(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v6 2/2] log: Make glib logging go through QEMU
2019-01-25 17:22 ` [Qemu-devel] [PATCH v6 2/2] log: Make glib logging go through QEMU Christophe Fergeau
2019-01-29 3:34 ` Stefan Hajnoczi
@ 2019-01-29 18:17 ` Markus Armbruster
1 sibling, 0 replies; 6+ messages in thread
From: Markus Armbruster @ 2019-01-29 18:17 UTC (permalink / raw)
To: Christophe Fergeau; +Cc: qemu-devel, Stefan Hajnoczi, Max Reitz
Christophe Fergeau <cfergeau@redhat.com> writes:
> This commit adds a qemu_init_logging() helper which calls
> g_log_set_default_handler() so that glib logs (g_log, g_warning, ...)
> are handled similarly to other QEMU logs. This means they will get a
> timestamp if timestamps are enabled, and they will go through the
> HMP monitor if one is configured.
> This commit also adds a call to qemu_init_logging() to the binaries
> installed by QEMU.
> glib debug messages are enabled through G_MESSAGES_DEBUG similarly to
> glib default log handler.
>
> At the moment, this change will mostly impact SPICE logging if your
> spice version is >= 0.14.1. With older spice versions, this is not going
> to work as expected, but will not have any ill effect, so this call is
> not conditional on the SPICE version.
>
> Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
> ---
> bsd-user/main.c | 2 ++
> include/qemu/error-report.h | 3 ++-
> linux-user/main.c | 2 ++
> qemu-img.c | 2 +-
> qemu-io.c | 2 +-
> qemu-nbd.c | 2 +-
> scsi/qemu-pr-helper.c | 1 +
> util/qemu-error.c | 48 ++++++++++++++++++++++++++++++++++++-
> vl.c | 2 +-
> 9 files changed, 58 insertions(+), 6 deletions(-)
>
> diff --git a/bsd-user/main.c b/bsd-user/main.c
> index 0d3156974c..8fd8ae4127 100644
> --- a/bsd-user/main.c
> +++ b/bsd-user/main.c
> @@ -24,6 +24,7 @@
> #include "qapi/error.h"
> #include "qemu.h"
> #include "qemu/config-file.h"
> +#include "qemu/error-report.h"
> #include "qemu/path.h"
> #include "qemu/help_option.h"
> #include "cpu.h"
> @@ -743,6 +744,7 @@ int main(int argc, char **argv)
> if (argc <= 1)
> usage();
>
> + error_init(argv[0]);
> module_call_init(MODULE_INIT_TRACE);
> qemu_init_cpu_list();
> module_call_init(MODULE_INIT_QOM);
This changes output of error_report() & friends in this program.
Probably in a good way. Should it be a separate commit? If not, it
should at least be mentioned in the commit message.
> diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
> index 0a8d9cc9ea..ce43c02314 100644
> --- a/include/qemu/error-report.h
> +++ b/include/qemu/error-report.h
> @@ -34,7 +34,6 @@ void error_vprintf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
> void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
> void error_vprintf_unless_qmp(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
> void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
> -void error_set_progname(const char *argv0);
>
> void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
> void warn_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
> @@ -49,6 +48,8 @@ bool error_report_once_cond(bool *printed, const char *fmt, ...)
> bool warn_report_once_cond(bool *printed, const char *fmt, ...)
> GCC_FMT_ATTR(2, 3);
>
> +void error_init(const char *argv0);
> +
> /*
> * Similar to error_report(), except it prints the message just once.
> * Return true when it prints, false otherwise.
> diff --git a/linux-user/main.c b/linux-user/main.c
> index a0aba9cb1e..f9efe9ff6e 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -27,6 +27,7 @@
> #include "qemu/path.h"
> #include "qemu/config-file.h"
> #include "qemu/cutils.h"
> +#include "qemu/error-report.h"
> #include "qemu/help_option.h"
> #include "cpu.h"
> #include "exec/exec-all.h"
> @@ -600,6 +601,7 @@ int main(int argc, char **argv, char **envp)
> int ret;
> int execfd;
>
> + error_init(argv[0]);
> module_call_init(MODULE_INIT_TRACE);
> qemu_init_cpu_list();
> module_call_init(MODULE_INIT_QOM);
Likewise.
> diff --git a/qemu-img.c b/qemu-img.c
> index ad04f59565..0af9cac244 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -4912,8 +4912,8 @@ int main(int argc, char **argv)
> signal(SIGPIPE, SIG_IGN);
> #endif
>
> + error_init(argv[0]);
> module_call_init(MODULE_INIT_TRACE);
> - error_set_progname(argv[0]);
> qemu_init_exec_dir(argv[0]);
>
> if (qemu_init_main_loop(&local_error)) {
> diff --git a/qemu-io.c b/qemu-io.c
> index 2c52ac0ade..8d5d5911cb 100644
> --- a/qemu-io.c
> +++ b/qemu-io.c
> @@ -522,8 +522,8 @@ int main(int argc, char **argv)
> signal(SIGPIPE, SIG_IGN);
> #endif
>
> + error_init(argv[0]);
> module_call_init(MODULE_INIT_TRACE);
> - error_set_progname(argv[0]);
> qemu_init_exec_dir(argv[0]);
>
> qcrypto_init(&error_fatal);
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index 1f7b2a03f5..39849f1692 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -685,8 +685,8 @@ int main(int argc, char **argv)
> signal(SIGPIPE, SIG_IGN);
> #endif
>
> + error_init(argv[0]);
> module_call_init(MODULE_INIT_TRACE);
> - error_set_progname(argv[0]);
> qcrypto_init(&error_fatal);
>
> module_call_init(MODULE_INIT_QOM);
> diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
> index e7af637232..2541fbbd1b 100644
> --- a/scsi/qemu-pr-helper.c
> +++ b/scsi/qemu-pr-helper.c
> @@ -895,6 +895,7 @@ int main(int argc, char **argv)
>
> signal(SIGPIPE, SIG_IGN);
>
> + error_init(argv[0]);
> module_call_init(MODULE_INIT_TRACE);
> module_call_init(MODULE_INIT_QOM);
> qemu_add_opts(&qemu_trace_opts);
Likewise.
> diff --git a/util/qemu-error.c b/util/qemu-error.c
> index fcbe8a1f74..2684870683 100644
> --- a/util/qemu-error.c
> +++ b/util/qemu-error.c
> @@ -142,7 +142,7 @@ static const char *progname;
> /*
> * Set the program name for error_print_loc().
> */
> -void error_set_progname(const char *argv0)
> +static void error_set_progname(const char *argv0)
> {
> const char *p = strrchr(argv0, '/');
> progname = p ? p + 1 : argv0;
> @@ -345,3 +345,49 @@ bool warn_report_once_cond(bool *printed, const char *fmt, ...)
> va_end(ap);
> return true;
> }
> +
> +static char *qemu_glog_domains;
> +
> +static void qemu_log_func(const gchar *log_domain,
> + GLogLevelFlags log_level,
> + const gchar *message,
> + gpointer user_data)
> +{
> + switch (log_level & G_LOG_LEVEL_MASK) {
> + case G_LOG_LEVEL_DEBUG:
> + case G_LOG_LEVEL_INFO:
> + /* Use same G_MESSAGES_DEBUG logic as glib to enable/disable debug
> + * messages */
Let's wing this comment.
> + if (qemu_glog_domains == NULL) {
> + break;
> + }
> + if (strcmp(qemu_glog_domains, "all") != 0 &&
> + (log_domain == NULL || !strstr(qemu_glog_domains, log_domain))) {
> + break;
> + }
> + /* Fall through */
> + case G_LOG_LEVEL_MESSAGE:
> + info_report("%s: %s", log_domain?:"", message);
Spaces around ?:, please.
If log_domain is null, the message will look like
info: : MESSAGE text
which is ugly. What about
info_report("%s%s%s",
log_domain ? ": " : "", log_domain ?: "", message);
More of the same below.
> + break;
> + case G_LOG_LEVEL_WARNING:
> + warn_report("%s: %s", log_domain?:"", message);
> + break;
> + case G_LOG_LEVEL_CRITICAL:
> + /* Fall through */
> + case G_LOG_LEVEL_ERROR:
> + error_report("%s: %s", log_domain?:"", message);
> + break;
> + }
> +}
> +
> +void error_init(const char *argv0)
> +{
> + /* Set the program name for error_print_loc(). */
> + error_set_progname(argv0);
> +
> + /* This sets up glib logging so libraries using it also print their logs
> + * through error_report(), warn_report(), info_report(). */
Let's wing this comment.
> + g_log_set_default_handler(qemu_log_func, NULL);
> + g_warn_if_fail(qemu_glog_domains == NULL);
> + qemu_glog_domains = g_strdup(g_getenv("G_MESSAGES_DEBUG"));
> +}
> diff --git a/vl.c b/vl.c
> index bc9fbec654..bfef38c3a3 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -3039,6 +3039,7 @@ int main(int argc, char **argv, char **envp)
> QSIMPLEQ_HEAD(, BlockdevOptions_queue) bdo_queue
> = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
>
> + error_init(argv[0]);
> module_call_init(MODULE_INIT_TRACE);
>
> qemu_init_cpu_list();
> @@ -3047,7 +3048,6 @@ int main(int argc, char **argv, char **envp)
> qemu_mutex_lock_iothread();
>
> atexit(qemu_run_exit_notifiers);
> - error_set_progname(argv[0]);
> qemu_init_exec_dir(argv[0]);
>
> module_call_init(MODULE_INIT_QOM);
Almost ready.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-01-29 18:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-25 17:22 [Qemu-devel] [PATCH v6 1/2] qemu-io: Use error_[gs]et_progname() Christophe Fergeau
2019-01-25 17:22 ` [Qemu-devel] [PATCH v6 2/2] log: Make glib logging go through QEMU Christophe Fergeau
2019-01-29 3:34 ` Stefan Hajnoczi
2019-01-29 18:17 ` Markus Armbruster
2019-01-25 20:37 ` [Qemu-devel] [PATCH v6 1/2] qemu-io: Use error_[gs]et_progname() Eric Blake
2019-01-29 3:34 ` Stefan Hajnoczi
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).