Browse Source

[1828] Make code safer in case socket.socket() raises an exception

Mukund Sivaraman 13 years ago
parent
commit
e295b40a31
1 changed files with 6 additions and 6 deletions
  1. 6 6
      src/bin/xfrout/xfrout.py.in

+ 6 - 6
src/bin/xfrout/xfrout.py.in

@@ -798,13 +798,13 @@ class UnixSockServer(socketserver_mixin.NoPollMixIn,
         '''Check whether the socket file 'sock_file' exists and
         is being used by one running xfrout process. If it is,
         return True, or else return False. '''
-        with socket.socket(socket.AF_UNIX) as sock:
-            try:
+        try:
+            with socket.socket(socket.AF_UNIX) as sock:
                 sock.connect(sock_file)
-            except socket.error as err:
-                return False
-            else:
-                return True
+        except socket.error as err:
+            return False
+        else:
+            return True
 
     def shutdown(self):
         self._write_sock.send(b"shutdown") #terminate the xfrout session thread