make qemu.log name unique
PATCH 1/1 make qemu.log name unique
Hello,
I propose this small patch so that the qemu log file has a unique name, to help running several QEmu processes at once (or with different users).
Is it OK?
Thanks
Christophe.
exec.c +4 -1
@@ -1516,7 +1516,10 @@ void cpu_set_log(int log_flags)void cpu_set_log_filename (const char *filename) { - logfilename =strdup (filename); +/* Assume 10 chars is enough to hold pid */ +int len =strlen (filename) +10 +1 ; + logfilename =malloc (len); +sprintf ((char *)logfilename,"%s.%d" , filename,getpid ());if (logfile) {fclose (logfile); logfile =NULL ;
Am 29.06.2010 10:46, schrieb Christophe LYON:
Quoted 6 lines
Hello,
I propose this small patch so that the qemu log file has a unique name, to help running several QEmu processes at once (or with different users).
Is it OK?
I don't think it's a good idea. When debugging things I usually run qemu several times, and each time I'd have to look up which of all the /tmp/qemu.log.* files is the current one instead of just refreshing the qemu.log that I'm viewing.
Maybe adding a -logfile option would allow what you're trying to achieve without affecting other use cases? I've always thought that it's strange that you can only change the logfile location in the monitor and not on the command line.
Kevin
Quoted 8 lines
Maybe adding a -logfile option would allow what you're trying to achieve without affecting other use cases? I've always thought that it's strange that you can only change the logfile location in the monitor and not on the command line.
Kevin
Here is patch that does what you suggest.
Christophe.
linux-user/main.c | 26 ++++++++++++++++---------- 1 files changed, 16 insertions(+), 10 deletions(-)
linux-user/main.c +16 -10
@@ -34,7 +34,8 @@#include "envlist.h" -#define DEBUG_LOGFILE "/tmp/qemu.log" +#define DEFAULTDEBUG_LOGFILE "/tmp/qemu.log" +static const char *debug_logfile =DEFAULTDEBUG_LOGFILE ;char *exec_path;
@@ -2454,7 +2455,8 @@ static void usage(void)#endif "\n" "Debug options:\n" -"-d options activate log (logfile=%s)\n" +"-d options activate logfile\n" +"-logfile filename set log file name to 'filename' (default %s)\n" "-p pagesize set the host page size to 'pagesize'\n" "-singlestep always run in singlestep mode\n" "-strace log system calls\n"
@@ -2472,7 +2474,7 @@ static void usage(void)TARGET_ARCH , interp_prefix, x86_stack_size, - DEBUG_LOGFILE); + debug_logfile);exit (1 ); }
@@ -2531,15 +2533,13 @@ int main(int argc, char **argv, char **envp)const char *argv0 =NULL ;int i;int ret; +int log_mask =0 ;if (argc <=1 )usage ();qemu_cache_utils_init (envp); -/* init debug */ -cpu_set_log_filename (DEBUG_LOGFILE ); -if ((envlist =envlist_create ()) ==NULL ) { (void )fprintf (stderr,"Unable to allocate envlist\n" );exit (1 );
@@ -2562,23 +2562,23 @@ int main(int argc, char **argv, char **envp) r++;if (!strcmp (r,"-" )) {break ; + }else if (!strcmp (r,"logfile" )) { + debug_logfile = argv[optind++]; }else if (!strcmp (r,"d" )) { -int mask;const CPULogItem *item;if (optind >= argc)break ; r = argv[optind++]; - mask =cpu_str_to_log_mask (r); -if (!mask) { + log_mask =cpu_str_to_log_mask (r); +if (!log_mask) {printf ("Log items (comma separated):\n" );for (item = cpu_log_items; item->mask !=0 ; item++) {printf ("%-10s %s\n" , item->name, item->help); }exit (1 ); } -cpu_set_log (mask); }else if (!strcmp (r,"E" )) { r = argv[optind++];if (envlist_setenv (envlist, r) !=0 )
@@ -2648,6 +2648,12 @@ int main(int argc, char **argv, char **envp) filename = argv[optind]; exec_path = argv[optind]; +/* init debug */ +if (log_mask) { +cpu_set_log_filename (debug_logfile); +cpu_set_log (log_mask); + } +/* Zero out regs */ memset (regs,0 ,sizeof (struct target_pt_regs ));
Am 01.07.2010 13:53, schrieb Christophe LYON:
Quoted 6 lines
Quoted 6 lines
Maybe adding a -logfile option would allow what you're trying to achieve without affecting other use cases? I've always thought that it's strange that you can only change the logfile location in the monitor and not on the command line.
Quoted 6 lines
Quoted 2 lines
Kevin
Here is patch that does what you suggest.
Christophe.
Patches need a "Signed-off-by", and for the code review it's better to send them inline.
What about patching the documentation, too?
Regards
Stefan
Quoted 7 lines
Patches need a "Signed-off-by", and for the code review it's better to send them inline.
What about patching the documentation, too?
OK Here is an updated version. I have also patched the bsd and darwin ports, but couldn't actually check it is OK for lack of such platforms. I hope my mailer won't scramble everything.
bsd-user/main.c | 34 ++++++++++++++++++++-------------- darwin-user/main.c | 32 +++++++++++++++++++------------- linux-user/main.c | 32 +++++++++++++++++++------------- qemu-doc.texi | 12 +++++++++--- qemu-options.hx | 11 +++++++++-- 5 files changed, 76 insertions(+), 45 deletions(-)
bsd-user/main.c +2 -1
@@ -34,7 +34,8 @@#include "envlist.h" -#define DEBUG_LOGFILE "/tmp/qemu.log" +#define DEFAULTDEBUG_LOGFILE "/tmp/qemu.log" +static const char *debug_logfile =DEFAULTDEBUG_LOGFILE ;int singlestep;#if defined(CONFIG_USE_GUEST_BASE )
@@ -690,10 +691,11 @@ static void usage(void) "-bsd type select emulated BSD type
FreeBSD/NetBSD/OpenBSD (default)\n"
"\n"
"Debug options:\n"
- "-d options activate log (logfile=%s)\n"
- "-p pagesize set the host page size to 'pagesize'\n"
- "-singlestep always run in singlestep mode\n"
- "-strace log system calls\n"
+ "-d options activate log\n"
+ "-logfile filename set log file name to 'filename' (default %s)\n"
+ "-p pagesize set the host page size to 'pagesize'\n"
+ "-singlestep always run in singlestep mode\n"
+ "-strace log system calls\n" "\n"
"Environment variables:\n"
"QEMU_STRACE Print system calls and arguments similar
to the\n"
@@ -708,7 +710,7 @@ static void usage(void)
TARGET_ARCH,
interp_prefix,
x86_stack_size,
- DEBUG_LOGFILE);
+ debug_logfile);
exit(1);}
@@ -741,13 +743,11 @@ int main(int argc, char **argv)
char **target_environ, **wrk;
envlist_t *envlist = NULL;
bsd_type = target_openbsd;+ int log_mask = 0;
if (argc <= 1)
usage();- /* init debug */
- cpu_set_log_filename(DEBUG_LOGFILE);
-
if ((envlist = envlist_create()) == NULL) {
(void) fprintf(stderr, "Unable to allocate envlist\n");
exit(1);
@@ -770,23 +770,23 @@ int main(int argc, char **argv)
r++;
if (!strcmp(r, "-")) {
break;
+ } else if (!strcmp(r, "logfile")) {
+ debug_logfile = argv[optind++];
} else if (!strcmp(r, "d")) {
- int mask;
const CPULogItem *item;
if (optind >= argc)
break;- r = argv[optind++];
- mask = cpu_str_to_log_mask(r);
- if (!mask) {
+ r = argv[optind++];
+ log_mask = cpu_str_to_log_mask(r);
+ if (!log_mask) {
printf("Log items (comma separated):\n");
for(item = cpu_log_items; item->mask != 0; item++) {
printf("%-10s %s\n", item->name, item->help);
}
exit(1);
}
- cpu_set_log(mask);
} else if (!strcmp(r, "E")) {
r = argv[optind++];
if (envlist_setenv(envlist, r) != 0)
@@ -857,6 +857,12 @@ int main(int argc, char **argv)
usage();
filename = argv[optind];+ /* init debug */
+ if (log_mask) {
+ cpu_set_log_filename(debug_logfile);
+ cpu_set_log(log_mask);
+ }
+
/* Zero out regs */
memset(regs, 0, sizeof(struct target_pt_regs));darwin-user/main.c +19 -13
@@ -29,7 +29,8 @@#include "qemu.h" -#define DEBUG_LOGFILE "/tmp/qemu.log" +#define DEFAULTDEBUG_LOGFILE "/tmp/qemu.log" +static const char *debug_logfile =DEFAULTDEBUG_LOGFILE ;#ifdef __APPLE__#include <crt_externs.h>
@@ -715,15 +716,16 @@ void usage(void)"-s size set the stack size in bytes (default=%ld)\n" "\n" "debug options:\n" -"-d options activate log (logfile='%s')\n" -"-g wait for gdb on port 1234\n" -"-p pagesize set the host page size to 'pagesize'\n" , -"-singlestep always run in singlestep mode\n" +"-d options activate log\n" +"-logfile filename set log file name to 'filename' (default %s)\n" +"-g wait for gdb on port 1234\n" +"-p pagesize set the host page size to 'pagesize'\n" , +"-singlestep always run in singlestep mode\n" TARGET_ARCH ,TARGET_ARCH , interp_prefix, stack_size, - DEBUG_LOGFILE); + debug_logfile);exit (1 ); }
@@ -745,13 +747,11 @@ int main(int argc, char **argv)short use_gdbstub =0 ;const char *r;const char *cpu_model; +int log_mask =0 ;if (argc <=1 )usage (); -/* init debug */ -cpu_set_log_filename (DEBUG_LOGFILE ); - optind =1 ;for (;;) {if (optind >= argc)
@@ -763,23 +763,23 @@ int main(int argc, char **argv) r++;if (!strcmp (r,"-" )) {break ; + }else if (!strcmp (r,"logfile" )) { + debug_logfile = argv[optind++]; }else if (!strcmp (r,"d" )) { -int mask;CPULogItem *item;if (optind >= argc)break ; r = argv[optind++]; - mask =cpu_str_to_log_mask (r); -if (!mask) { + log_mask =cpu_str_to_log_mask (r); +if (!log_mask) {printf ("Log items (comma separated):\n" );for (item = cpu_log_items; item->mask !=0 ; item++) {printf ("%-10s %s\n" , item->name, item->help); }exit (1 ); } -cpu_set_log (mask); }else if (!strcmp (r,"s" )) { r = argv[optind++]; stack_size =strtol (r, (char **)&r,0 );
@@ -821,6 +821,12 @@ int main(int argc, char **argv)usage (); filename = argv[optind]; +/* init debug */ +if (log_mask) { +cpu_set_log_filename (debug_logfile); +cpu_set_log (log_mask); + } +/* Zero out regs */ memset (regs,0 ,sizeof (struct target_pt_regs ));
linux-user/main.c +7 -5
@@ -34,7 +34,8 @@#include "envlist.h" -#define DEBUG_LOGFILE "/tmp/qemu.log" +#define DEFAULTDEBUG_LOGFILE "/tmp/qemu.log" +static const char *debug_logfile =DEFAULTDEBUG_LOGFILE ;char *exec_path;
@@ -2454,10 +2455,11 @@ static void usage(void)#endif "\n" "Debug options:\n" -"-d options activate log (logfile=%s)\n" -"-p pagesize set the host page size to 'pagesize'\n" -"-singlestep always run in singlestep mode\n" -"-strace log system calls\n" +"-d options activate logfile\n" +"-logfile filename set log file name to 'filename' (default %s)\n" +"-p pagesize set the host page size to 'pagesize'\n" +"-singlestep always run in singlestep mode\n" +"-strace log system calls\n" "\n" "Environment variables:\n" "QEMU_STRACE Print system calls and arguments similar
to the\n"
@@ -2472,7 +2474,7 @@ static void usage(void)
TARGET_ARCH,
interp_prefix,
x86_stack_size,
- DEBUG_LOGFILE);
+ debug_logfile);
exit(1);}
@@ -2531,15 +2533,13 @@ int main(int argc, char **argv, char **envp)
const char *argv0 = NULL;
int i;
int ret;+ int log_mask = 0;
if (argc <= 1)
usage();
qemu_cache_utils_init(envp);- /* init debug */
- cpu_set_log_filename(DEBUG_LOGFILE);
-
if ((envlist = envlist_create()) == NULL) {
(void) fprintf(stderr, "Unable to allocate envlist\n");
exit(1);
@@ -2562,23 +2562,23 @@ int main(int argc, char **argv, char **envp)
r++;
if (!strcmp(r, "-")) {
break;
+ } else if (!strcmp(r, "logfile")) {
+ debug_logfile = argv[optind++];
} else if (!strcmp(r, "d")) {
- int mask;
const CPULogItem *item; if (optind >= argc)
break;
r = argv[optind++];
- mask = cpu_str_to_log_mask(r);
- if (!mask) {
+ log_mask = cpu_str_to_log_mask(r);
+ if (!log_mask) {
printf("Log items (comma separated):\n");
for(item = cpu_log_items; item->mask != 0; item++) {
printf("%-10s %s\n", item->name, item->help);
}
exit(1);
}
- cpu_set_log(mask);
} else if (!strcmp(r, "E")) {
r = argv[optind++];
if (envlist_setenv(envlist, r) != 0)
@@ -2648,6 +2648,12 @@ int main(int argc, char **argv, char **envp)
filename = argv[optind];
exec_path = argv[optind];+ /* init debug */
+ if (log_mask) {
+ cpu_set_log_filename(debug_logfile);
+ cpu_set_log(log_mask);
+ }
+
/* Zero out regs */
memset(regs, 0, sizeof(struct target_pt_regs));qemu-doc.texi +9 -3
@@ -2066,7 +2066,9 @@ Debug options: @table @option @item -d -Activate log (logfile=/tmp/qemu.log) +Activate log +@item -logfile filename +Set log file name to 'filename' (defaut /tmp/qemu.log) @item -p pagesize Act as if the host page size was 'pagesize' bytes @item -g port
@@ -2188,7 +2190,9 @@ Debug options: @table @option @item -d -Activate log (logfile=/tmp/qemu.log) +Activate log +@item -logfile filename +Set log file name to 'filename' (defaut /tmp/qemu.log) @item -p pagesize Act as if the host page size was 'pagesize' bytes @item -singlestep
@@ -2252,7 +2256,9 @@ Debug options: @table @option @item -d -Activate log (logfile=/tmp/qemu.log) +Activate log +@item -logfile filename +Set log file name to 'filename' (defaut /tmp/qemu.log) @item -p pagesize Act as if the host page size was 'pagesize' bytes @item -singlestep
qemu-options.hx +9 -2
@@ -1648,10 +1648,17 @@ Shorthand for -gdb tcp::1234, i.e. open a gdbserver on TCP port 1234 ETEXI DEF("d", HAS_ARG, QEMU_OPTION_d, \ - "-d item1,... output log to %s (use -d ? for a list of log items)\n") + "-d item1,... output log (use -d ? for a list of log items)\n") STEXI @item -d -Output log in /tmp/qemu.log +Output log +ETEXI + +DEF("logfile", HAS_ARG, QEMU_OPTION_logfile, \ + "-logfile filename\n Set log file name to 'filename' (defaut %s)\n") +STEXI +@item -logfile +Set log file name to 'filename' (defaut /tmp/qemu.log) ETEXI DEF("hdachs", HAS_ARG, QEMU_OPTION_hdachs, \