ia64/xen-unstable

changeset 7212:2c9e66555ff4

Explicitly close files.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Tue Oct 04 23:56:42 2005 +0100 (2005-10-04)
parents 00037ba13f0b
children 22449386d38d
files tools/python/xen/xend/server/SrvDaemon.py
line diff
     1.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Tue Oct 04 18:23:58 2005 +0100
     1.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Tue Oct 04 23:56:42 2005 +0100
     1.3 @@ -71,14 +71,17 @@ class Daemon:
     1.4          @param pidfile: file to read
     1.5          @return pid or 0
     1.6          """
     1.7 -        pid = 0
     1.8          if os.path.isfile(pidfile) and os.path.getsize(pidfile):
     1.9              try:
    1.10 -                pid = open(pidfile, 'r').read()
    1.11 -                pid = int(pid)
    1.12 +                f = open(pidfile, 'r')
    1.13 +                try:
    1.14 +                    return int(f.read())
    1.15 +                finally:
    1.16 +                    f.close()
    1.17              except:
    1.18 -                pid = 0
    1.19 -        return pid
    1.20 +                return 0
    1.21 +        else:
    1.22 +            return 0
    1.23  
    1.24      def find_process(self, pid, name):
    1.25          """Search for a process.
    1.26 @@ -146,8 +149,10 @@ class Daemon:
    1.27          if self.child:
    1.28              # Parent
    1.29              pidfile = open(pidfile, 'w')
    1.30 -            pidfile.write(str(self.child))
    1.31 -            pidfile.close()
    1.32 +            try:
    1.33 +                pidfile.write(str(self.child))
    1.34 +            finally:
    1.35 +                pidfile.close()
    1.36  
    1.37          return self.child
    1.38  
    1.39 @@ -200,8 +205,10 @@ class Daemon:
    1.40          if self.fork_pid(XEND_PID_FILE):
    1.41              os.close(w)
    1.42              r = os.fdopen(r, 'r')
    1.43 -            s = r.read()
    1.44 -            r.close()
    1.45 +            try:
    1.46 +                s = r.read()
    1.47 +            finally:
    1.48 +                r.close()
    1.49              if not len(s):
    1.50                  ret = 1
    1.51              else: