BIND 10 trac1828, updated. e295b40a31dedb3671705ab44c2683624f3d541c [1828] Make code safer in case socket.socket() raises an exception

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Jun 14 21:22:32 UTC 2012


The branch, trac1828 has been updated
       via  e295b40a31dedb3671705ab44c2683624f3d541c (commit)
       via  c37cc2d18c1b4b99432d0436603631a99377a0e6 (commit)
       via  c4b20d7ad5fce1557edfb53bfab66c26e1933d20 (commit)
      from  6ad0070daba5438c84dd869afe260538bae2c55e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e295b40a31dedb3671705ab44c2683624f3d541c
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri Jun 15 02:52:02 2012 +0530

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

commit c37cc2d18c1b4b99432d0436603631a99377a0e6
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri Jun 15 02:50:37 2012 +0530

    [1828] Rename variable to better match its use

commit c4b20d7ad5fce1557edfb53bfab66c26e1933d20
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri Jun 15 02:41:51 2012 +0530

    [1828] Add comments about the close() calls

-----------------------------------------------------------------------

Summary of changes:
 src/bin/msgq/tests/msgq_test.py |    8 ++++++++
 src/bin/xfrout/xfrout.py.in     |   18 +++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/msgq/tests/msgq_test.py b/src/bin/msgq/tests/msgq_test.py
index cc078f4..6dc7d1c 100644
--- a/src/bin/msgq/tests/msgq_test.py
+++ b/src/bin/msgq/tests/msgq_test.py
@@ -155,6 +155,10 @@ class SendNonblock(unittest.TestCase):
                 sender(msgq, write)
         except socket.error:
             pass
+
+        # Explicitly close temporary socket pair as the Python
+        # interpreter expects it.  It may not be 100% exception safe,
+        # but since this is only for tests we prefer brevity.
         read.close()
         write.close()
 
@@ -219,6 +223,10 @@ class SendNonblock(unittest.TestCase):
                 finally:
                     os.kill(queue_pid, signal.SIGTERM)
         self.terminate_check(run)
+
+        # Explicitly close temporary socket pair as the Python
+        # interpreter expects it.  It may not be 100% exception safe,
+        # but since this is only for tests we prefer brevity.
         queue.close()
         out.close()
 
diff --git a/src/bin/xfrout/xfrout.py.in b/src/bin/xfrout/xfrout.py.in
index 2a19ca7..0a9f122 100755
--- a/src/bin/xfrout/xfrout.py.in
+++ b/src/bin/xfrout/xfrout.py.in
@@ -741,13 +741,13 @@ class UnixSockServer(socketserver_mixin.NoPollMixIn,
         # to care about the SOCK_STREAM parameter at all (which it really is,
         # except for testing)
         if socket.has_ipv6:
-            socktype = socket.AF_INET6
+            sock_domain = socket.AF_INET6
         else:
             # To make it work even on hosts without IPv6 support
             # (Any idea how to simulate this in test?)
-            socktype = socket.AF_INET
+            sock_domain = socket.AF_INET
 
-        with socket.fromfd(sock_fd, socktype, socket.SOCK_STREAM) as sock:
+        with socket.fromfd(sock_fd, sock_domain, socket.SOCK_STREAM) as sock:
             peer = sock.getpeername()
 
         # Identify the correct socket family.  Due to the above "trick",
@@ -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



More information about the bind10-changes mailing list