From: Mike Lundy Date: Thu, 18 Apr 2013 23:52:17 -0700 Subject: [PATCH] Restore SysLogHandler fallback for AF_UNIX sockets --- Lib/logging/handlers.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 26dfe4a..b778fe5 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -737,7 +737,7 @@ class SysLogHandler(logging.Handler): } def __init__(self, address=('localhost', SYSLOG_UDP_PORT), - facility=LOG_USER, socktype=socket.SOCK_DGRAM): + facility=LOG_USER, socktype=None): """ Initialize a handler. @@ -756,18 +756,34 @@ class SysLogHandler(logging.Handler): self._connect_unixsocket(address) else: self.unixsocket = 0 - self.socket = socket.socket(socket.AF_INET, socktype) - if socktype == socket.SOCK_STREAM: + if socktype is None: + self.socktype = socket.SOCK_DGRAM + + self.socket = socket.socket(socket.AF_INET, self.socktype) + if self.socktype == socket.SOCK_STREAM: self.socket.connect(address) self.formatter = None def _connect_unixsocket(self, address): - self.socket = socket.socket(socket.AF_UNIX, self.socktype) + if self.socktype is None: + socktype = socket.SOCK_DGRAM + else: + socktype = self.socktype + + self.socket = socket.socket(socket.AF_UNIX, socktype) try: self.socket.connect(address) except socket.error: self.socket.close() - raise + if self.socktype is not None: + raise + + self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + try: + self.socket.connect(address) + except socket.error: + self.socket.close() + raise # curious: when talking to the unix-domain '/dev/log' socket, a # zero-terminator seems to be required. this string is placed -- 1.8.1.5