[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 23/29] qemu-log: support simple pid substitution for
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 23/29] qemu-log: support simple pid substitution for logs |
Date: |
Tue, 22 Mar 2016 15:17:03 +0100 |
From: Alex Bennée <address@hidden>
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 <address@hidden>
Reviewed-by: Leandro Dorileo <address@hidden>
Reviewed-by: Aurelien Jarno <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
tests/test-logging.c | 36 +++++++++++++++++++++++++++++++++++-
util/log.c | 21 +++++++++++++++++++--
2 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/tests/test-logging.c b/tests/test-logging.c
index 193fa92..ac8deed 100644
--- a/tests/test-logging.c
+++ b/tests/test-logging.c
@@ -89,7 +89,37 @@ static void test_parse_zero_range(void)
g_test_trap_assert_stdout("");
g_test_trap_assert_stderr("*Failed to parse range in: 0x1000+0\n");
}
-#endif
+
+/* As the only real failure from a bad log filename path spec is
+ * reporting to the user we have to use the g_test_trap_subprocess
+ * mechanism and check no errors reported on stderr.
+ */
+static void test_parse_path_subprocess(void)
+{
+ /* All these should work without issue */
+ qemu_set_log_filename("/tmp/qemu.log");
+ qemu_set_log_filename("/tmp/qemu-%d.log");
+ qemu_set_log_filename("/tmp/qemu.log.%d");
+}
+static void test_parse_path(void)
+{
+ g_test_trap_subprocess ("/logging/parse_path/subprocess", 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stdout("");
+ g_test_trap_assert_stderr("");
+}
+static void test_parse_invalid_path_subprocess(void)
+{
+ qemu_set_log_filename("/tmp/qemu-%d%d.log");
+}
+static void test_parse_invalid_path(void)
+{
+ g_test_trap_subprocess ("/logging/parse_invalid_path/subprocess", 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stdout("");
+ g_test_trap_assert_stderr("Bad logfile format: /tmp/qemu-%d%d.log\n");
+}
+#endif /* CONFIG_HAS_GLIB_SUBPROCESS_TESTS */
int main(int argc, char **argv)
{
@@ -101,6 +131,10 @@ int main(int argc, char **argv)
g_test_add_func("/logging/parse_invalid_range", test_parse_invalid_range);
g_test_add_func("/logging/parse_zero_range/subprocess",
test_parse_zero_range_subprocess);
g_test_add_func("/logging/parse_zero_range", test_parse_zero_range);
+ g_test_add_func("/logging/parse_path", test_parse_path);
+ g_test_add_func("/logging/parse_path/subprocess",
test_parse_path_subprocess);
+ g_test_add_func("/logging/parse_invalid_path", test_parse_invalid_path);
+ g_test_add_func("/logging/parse_invalid_path/subprocess",
test_parse_invalid_path_subprocess);
#endif
return g_test_run();
diff --git a/util/log.c b/util/log.c
index 671b617..b219081e 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);
}
--
2.5.0
- [Qemu-devel] [PULL 12/29] include/crypto: Include qapi-types.h or qemu/bswap.h instead of qemu-common.h, (continued)
- [Qemu-devel] [PULL 12/29] include/crypto: Include qapi-types.h or qemu/bswap.h instead of qemu-common.h, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 13/29] hw: explicitly include qemu-common.h and cpu.h, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 01/29] include/qemu/osdep.h: Don't include qapi/error.h, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 14/29] Replaced get_tick_per_sec() by NANOSECONDS_PER_SECOND, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 16/29] tcg: pass down TranslationBlock to tcg_code_gen, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 21/29] qemu-log: dfilter-ise exec, out_asm, op and opt_op, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 18/29] qemu-log: Avoid function call for disabled qemu_log_mask logging, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 20/29] qemu-log: new option -dfilter to limit output, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 19/29] qemu-log: Improve the "exec" TB execution logging, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 17/29] qemu-log: correct help text for -d cpu, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 23/29] qemu-log: support simple pid substitution for logs,
Paolo Bonzini <=
- [Qemu-devel] [PULL 22/29] target-arm: dfilter support for in_asm, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 26/29] char: translate from QIOChannel error to errno, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 15/29] util: move declarations out of qemu-common.h, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 25/29] exec: fix error handling in file_ram_alloc, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 24/29] cputlb: modernise the debug support, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 28/29] config.status: Pass extra parameters, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 29/29] target-i386: implement PKE for TCG, Paolo Bonzini, 2016/03/22
- [Qemu-devel] [PULL 27/29] char: ensure all clients are in non-blocking mode, Paolo Bonzini, 2016/03/22
- Re: [Qemu-devel] [PULL 00/29] Miscellaneous changes for 2016-03-22, Peter Maydell, 2016/03/22