ia64/xen-unstable

changeset 15267:fc8e40692690

Use name instead of pid in QEMU logs.

Change the logfile name generated by qemu-dm to use the pattern
qemu-dm-[NAME].log instead of qemu-dm-[PID].log. This makes it
easier for the adminsitrator to figure out which log corresponds to
which guest (particularly after a crash where you no long know what
PID the qemu-dm process for your guest had). It also prevents the
number of log files from growing unbounded.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
author kfraser@localhost.localdomain
date Mon Jun 04 15:17:49 2007 +0100 (2007-06-04)
parents edf407a3dd70
children d0dc12484bf2
files tools/ioemu/target-i386-dm/exec-dm.c tools/ioemu/vl.c
line diff
     1.1 --- a/tools/ioemu/target-i386-dm/exec-dm.c	Mon Jun 04 14:49:12 2007 +0100
     1.2 +++ b/tools/ioemu/target-i386-dm/exec-dm.c	Mon Jun 04 15:17:49 2007 +0100
     1.3 @@ -124,7 +124,6 @@ void *io_mem_opaque[IO_MEM_NB_ENTRIES];
     1.4  static int io_mem_nb = 1;
     1.5  
     1.6  /* log support */
     1.7 -char *logfilename = "/tmp/qemu.log";
     1.8  FILE *logfile;
     1.9  int loglevel;
    1.10  
    1.11 @@ -166,29 +165,28 @@ void cpu_exec_init(CPUState *env)
    1.12  void cpu_set_log(int log_flags)
    1.13  {
    1.14      loglevel = log_flags;
    1.15 -    if (!logfile) {
    1.16 -        logfile = fopen(logfilename, "w");
    1.17 -        if (!logfile) {
    1.18 -            perror(logfilename);
    1.19 -            _exit(1);
    1.20 -        }
    1.21 -#if !defined(CONFIG_SOFTMMU)
    1.22 -        /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
    1.23 -        {
    1.24 -            static uint8_t logfile_buf[4096];
    1.25 -            setvbuf(logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
    1.26 -        }
    1.27 -#else
    1.28 -        setvbuf(logfile, NULL, _IOLBF, 0);
    1.29 -#endif
    1.30 -        stdout = logfile;
    1.31 -        stderr = logfile;
    1.32 -    }
    1.33 +    if (!logfile)
    1.34 +      logfile = stderr;
    1.35  }
    1.36  
    1.37  void cpu_set_log_filename(const char *filename)
    1.38  {
    1.39 -    logfilename = strdup(filename);
    1.40 +    logfile = fopen(filename, "w");
    1.41 +    if (!logfile) {
    1.42 +        perror(filename);
    1.43 +	_exit(1);
    1.44 +    }
    1.45 +#if !defined(CONFIG_SOFTMMU)
    1.46 +    /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
    1.47 +    {
    1.48 +        static uint8_t logfile_buf[4096];
    1.49 +	setvbuf(logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
    1.50 +    }
    1.51 +#else
    1.52 +    setvbuf(logfile, NULL, _IOLBF, 0);
    1.53 +#endif
    1.54 +    stdout = logfile;
    1.55 +    stderr = logfile;
    1.56  }
    1.57  
    1.58  /* mask must never be zero, except for A20 change call */
     2.1 --- a/tools/ioemu/vl.c	Mon Jun 04 14:49:12 2007 +0100
     2.2 +++ b/tools/ioemu/vl.c	Mon Jun 04 15:17:49 2007 +0100
     2.3 @@ -7146,9 +7146,7 @@ int main(int argc, char **argv)
     2.4      nb_nics = 0;
     2.5      /* default mac address of the first network interface */
     2.6      
     2.7 -    /* init debug */
     2.8 -    sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm.%ld.log", (long)getpid());
     2.9 -    cpu_set_log_filename(qemu_dm_logfilename);
    2.10 +    /* Init logs to stderr to start with */
    2.11      cpu_set_log(0);
    2.12      
    2.13      optind = 1;
    2.14 @@ -7527,7 +7525,7 @@ int main(int argc, char **argv)
    2.15                  semihosting_enabled = 1;
    2.16                  break;
    2.17              case QEMU_OPTION_domainname:
    2.18 -                strncat(domain_name, optarg, sizeof(domain_name) - 20);
    2.19 +                strncpy(domain_name, optarg, sizeof(domain_name) - 1);
    2.20                  break;
    2.21              case QEMU_OPTION_d:
    2.22                  domid = atoi(optarg);
    2.23 @@ -7550,6 +7548,10 @@ int main(int argc, char **argv)
    2.24          }
    2.25      }
    2.26  
    2.27 +    /* Now send logs to our named config */
    2.28 +    sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm-%s.log", domain_name);
    2.29 +    cpu_set_log_filename(qemu_dm_logfilename);
    2.30 +
    2.31  #ifndef _WIN32
    2.32      if (daemonize && !nographic && vnc_display == NULL && vncunused == 0) {
    2.33  	fprintf(stderr, "Can only daemonize if using -nographic or -vnc\n");