aboutsummaryrefslogtreecommitdiff
path: root/util/log.c
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2016-03-15 14:30:23 +0000
committerPaolo Bonzini <pbonzini@redhat.com>2016-03-22 22:20:18 +0100
commitf6880b7f48ffd4aa038d7a964a3820b1c18d5307 (patch)
tree7b66d60ea95a3eb3bee2a99bbd622d157ece35a4 /util/log.c
parent064860778bf1539f95c886fef86080aa132ca1e2 (diff)
qemu-log: support simple pid substitution for logs
When debugging stuff that occurs over several forks it would be useful not to keep overwriting the one logfile you've set-up. This allows a simple %d to be included once in the logfile parameter which is substituted with getpid(). As the test cases involve checking user output they need g_test_trap_subprocess() support. As a result they are currently skipped on Travis builds due to the older glib involved. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Leandro Dorileo <l@dorileo.org> Reviewed-by: Aurelien Jarno <aurelien@aurel32.net> Reviewed-by: Richard Henderson <rth@twiddle.net> Message-Id: <1458052224-9316-10-git-send-email-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util/log.c')
-rw-r--r--util/log.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/util/log.c b/util/log.c
index 671b6174e4..b219081e91 100644
--- a/util/log.c
+++ b/util/log.c
@@ -89,11 +89,28 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers)
qemu_log_close();
}
}
-
+/*
+ * Allow the user to include %d in their logfile which will be
+ * 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)
{
+ char *pidstr;
g_free(logfilename);
- logfilename = g_strdup(filename);
+
+ pidstr = strstr(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;
+ } else {
+ logfilename = g_strdup_printf(filename, getpid());
+ }
+ } else {
+ logfilename = g_strdup(filename);
+ }
qemu_log_close();
qemu_set_log(qemu_loglevel);
}