WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Explicitly close files.

# HG changeset patch
# User emellor@ewan
# Node ID 2c9e66555ff44f5d3654cad25efffc593bda9b01
# Parent  00037ba13f0bb8efe4b2c3efe40200eac21c68dd
Explicitly close files.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r 00037ba13f0b -r 2c9e66555ff4 tools/python/xen/xend/server/SrvDaemon.py
--- a/tools/python/xen/xend/server/SrvDaemon.py Tue Oct  4 17:23:58 2005
+++ b/tools/python/xen/xend/server/SrvDaemon.py Tue Oct  4 22:56:42 2005
@@ -71,14 +71,17 @@
         @param pidfile: file to read
         @return pid or 0
         """
-        pid = 0
         if os.path.isfile(pidfile) and os.path.getsize(pidfile):
             try:
-                pid = open(pidfile, 'r').read()
-                pid = int(pid)
+                f = open(pidfile, 'r')
+                try:
+                    return int(f.read())
+                finally:
+                    f.close()
             except:
-                pid = 0
-        return pid
+                return 0
+        else:
+            return 0
 
     def find_process(self, pid, name):
         """Search for a process.
@@ -146,8 +149,10 @@
         if self.child:
             # Parent
             pidfile = open(pidfile, 'w')
-            pidfile.write(str(self.child))
-            pidfile.close()
+            try:
+                pidfile.write(str(self.child))
+            finally:
+                pidfile.close()
 
         return self.child
 
@@ -200,8 +205,10 @@
         if self.fork_pid(XEND_PID_FILE):
             os.close(w)
             r = os.fdopen(r, 'r')
-            s = r.read()
-            r.close()
+            try:
+                s = r.read()
+            finally:
+                r.close()
             if not len(s):
                 ret = 1
             else:

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Explicitly close files., Xen patchbot -unstable <=