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 <armbru@redhat.com>
Message-Id: <1466011636-6112-4-git-send-email-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
diff --git a/monitor.c b/monitor.c
index a5d054b..6f960f1 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1111,7 +1111,12 @@
static void hmp_logfile(Monitor *mon, const QDict *qdict)
{
- qemu_set_log_filename(qdict_get_str(qdict, "filename"));
+ Error *err = NULL;
+
+ qemu_set_log_filename(qdict_get_str(qdict, "filename"), &err);
+ if (err) {
+ error_report_err(err);
+ }
}
static void hmp_log(Monitor *mon, const QDict *qdict)