ia64/xen-unstable

changeset 12646:ec2af46f9472

Diagnose a failure to open the xend-debug.log, and make the /var/log/xen
directory on startup, which was the most common reason to fail.
Closes bug #823.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Wed Nov 29 10:56:02 2006 +0000 (2006-11-29)
parents a98bec6aacac
children 4dad3420d74a
files tools/python/xen/xend/server/SrvDaemon.py
line diff
     1.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Wed Nov 29 10:48:06 2006 +0000
     1.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Wed Nov 29 10:56:02 2006 +0000
     1.3 @@ -6,7 +6,9 @@
     1.4  ###########################################################
     1.5  
     1.6  import os
     1.7 +import os.path
     1.8  import signal
     1.9 +import stat
    1.10  import sys
    1.11  import threading
    1.12  import time
    1.13 @@ -102,17 +104,32 @@ class Daemon:
    1.14  
    1.15          # Detach from standard file descriptors, and redirect them to
    1.16          # /dev/null or the log as appropriate.
    1.17 +        # We open the log file first, so that we can diagnose a failure to do
    1.18 +        # so _before_ we close stderr.
    1.19 +        try:
    1.20 +            parent = os.path.dirname(XEND_DEBUG_LOG)
    1.21 +            if not os.path.exists(parent):
    1.22 +                os.makedirs(parent, stat.S_IRWXU)
    1.23 +            fd = os.open(XEND_DEBUG_LOG, os.O_WRONLY|os.O_CREAT|os.O_APPEND)
    1.24 +        except Exception, exn:
    1.25 +            print >>sys.stderr, exn
    1.26 +            print >>sys.stderr, ("Xend failed to open %s.  Exiting!" %
    1.27 +                                 XEND_DEBUG_LOG)
    1.28 +            sys.exit(1)
    1.29 +
    1.30          os.close(0)
    1.31          os.close(1)
    1.32          os.close(2)
    1.33          if XEND_DEBUG:
    1.34              os.open('/dev/null', os.O_RDONLY)
    1.35 -            os.open(XEND_DEBUG_LOG, os.O_WRONLY|os.O_CREAT|os.O_APPEND)
    1.36 -            os.dup(1)
    1.37 +            os.dup(fd)
    1.38 +            os.dup(fd)
    1.39          else:
    1.40              os.open('/dev/null', os.O_RDWR)
    1.41              os.dup(0)
    1.42 -            os.open(XEND_DEBUG_LOG, os.O_WRONLY|os.O_CREAT|os.O_APPEND)
    1.43 +            os.dup(fd)
    1.44 +        os.close(fd)
    1.45 +
    1.46          print >>sys.stderr, ("Xend started at %s." %
    1.47                               time.asctime(time.localtime()))
    1.48