From daa76aa416b1e18ab1fac650ff53d966d8f21f68 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 15 Jun 2016 19:27:16 +0200 Subject: log: Fix qemu_set_log_filename() error handling When qemu_set_log_filename() detects an invalid file name, it reports an error, closes the log file (if any), and starts logging to stderr (unless daemonized or nothing is being logged). This is wrong. Asking for an invalid log file on the command line should be fatal. Asking for one in the monitor should fail without messing up an existing logfile. Fix by converting qemu_set_log_filename() to Error. Pass it &error_fatal, except for hmp_logfile report errors. This also permits testing without a subprocess, so do that. Signed-off-by: Markus Armbruster Message-Id: <1466011636-6112-4-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake --- util/log.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'util') diff --git a/util/log.c b/util/log.c index fcf85c6253..32e416051c 100644 --- a/util/log.c +++ b/util/log.c @@ -103,7 +103,7 @@ void qemu_log_needs_buffers(void) * substituted with the current PID. This is useful for debugging many * nested linux-user tasks but will result in lots of logs. */ -void qemu_set_log_filename(const char *filename) +void qemu_set_log_filename(const char *filename, Error **errp) { char *pidstr; g_free(logfilename); @@ -112,8 +112,8 @@ void qemu_set_log_filename(const char *filename) if (pidstr) { /* We only accept one %d, no other format strings */ if (pidstr[1] != 'd' || strchr(pidstr + 2, '%')) { - error_report("Bad logfile format: %s", filename); - logfilename = NULL; + error_setg(errp, "Bad logfile format: %s", filename); + return; } else { logfilename = g_strdup_printf(filename, getpid()); } -- cgit v1.2.3