]> granicus.if.org Git - python/commitdiff
Closes #17795: Reverted backwards-incompatible change in SysLogHandler with Unix...
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 22 Apr 2013 09:14:12 +0000 (10:14 +0100)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 22 Apr 2013 09:14:12 +0000 (10:14 +0100)
1  2 
Lib/logging/handlers.py
Misc/NEWS

index b5478d90217fb9a617c20347755c40fda6f1c476,95e23a8b78bdfee32d28be66a2c83314f37c1835..bed09f05d0eb351eecd7c1c4c68ce7c5a64d197d
@@@ -764,7 -773,7 +764,11 @@@ class SysLogHandler(logging.Handler)
  
          If address is specified as a string, a UNIX socket is used. To log to a
          local syslogd, "SysLogHandler(address="/dev/log")" can be used.
--        If facility is not specified, LOG_USER is used.
++        If facility is not specified, LOG_USER is used. If socktype is
++        specified as socket.SOCK_DGRAM or socket.SOCK_STREAM, that specific
++        socket type will be used. For Unix sockets, you can also specify a
++        socktype of None, in which case socket.SOCK_DGRAM will be used, falling
++        back to socket.SOCK_STREAM.
          """
          logging.Handler.__init__(self)
  
          self.formatter = None
  
      def _connect_unixsocket(self, address):
-         self.socket = socket.socket(socket.AF_UNIX, self.socktype)
+         use_socktype = self.socktype
+         if use_socktype is None:
+             use_socktype = socket.SOCK_DGRAM
+         self.socket = socket.socket(socket.AF_UNIX, use_socktype)
          try:
              self.socket.connect(address)
 -        except socket.error:
+             # it worked, so set self.socktype to the used type
+             self.socktype = use_socktype
 +        except OSError:
              self.socket.close()
-             raise
+             if self.socktype is not None:
+                 # user didn't specify falling back, so fail
+                 raise
+             use_socktype = socket.SOCK_STREAM
+             self.socket = socket.socket(socket.AF_UNIX, use_socktype)
+             try:
+                 self.socket.connect(address)
+                 # it worked, so set self.socktype to the used type
+                 self.socktype = use_socktype
 -            except socket.error:
++            except OSError:
+                 self.socket.close()
+                 raise
  
      def encodePriority(self, facility, priority):
          """
diff --cc Misc/NEWS
index 3b0ef393494db03bf519c9360ebd2ed9df12d31c,e71b6ed016abef49c1fde270a0e7d9a91b88b3be..1416cb4aea0ade419ebc51eb028d75beb5415d3b
+++ b/Misc/NEWS
@@@ -49,15 -36,9 +49,18 @@@ Core and Builtin
  Library
  -------
  
+ - Issue #17795: Reverted backwards-incompatible change in SysLogHandler with
+   Unix domain sockets.
 +- Issue #16694: Add a pure Python implementation of the operator module.
 +  Patch by Zachary Ware.
 +
 +- Issue #11182: remove the unused and undocumented pydoc.Scanner class.
 +  Patch by Martin Morrison.
 +
 +- Issue #17741: Add ElementTree.IncrementalParser, an event-driven parser
 +  for non-blocking applications.
 +
  - Issue #17555: Fix ForkAwareThreadLock so that size of after fork
    registry does not grow exponentially with generation of process.