diff options
author | Josh Marshall <catchjosh@gmail.com> | 2011-02-26 14:01:40 -0600 |
---|---|---|
committer | Josh Marshall <catchjosh@gmail.com> | 2011-02-26 14:01:40 -0600 |
commit | 86551ed6358b39aff532462f1cbd6b89e61817d2 (patch) | |
tree | 610c0fe30589233640ea35c42382d159558d8a6d /jsonrpclib/SimpleJSONRPCServer.py | |
parent | bcd9a5ca2ae751a057d967fc39c1841483cabbb8 (diff) | |
download | jsonrpclib-86551ed6358b39aff532462f1cbd6b89e61817d2.tar.gz |
Added minimal discovery for whether unix sockets are supported, and prevented access if they are missing.
Diffstat (limited to 'jsonrpclib/SimpleJSONRPCServer.py')
-rw-r--r-- | jsonrpclib/SimpleJSONRPCServer.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/jsonrpclib/SimpleJSONRPCServer.py b/jsonrpclib/SimpleJSONRPCServer.py index 854697b..d76da73 100644 --- a/jsonrpclib/SimpleJSONRPCServer.py +++ b/jsonrpclib/SimpleJSONRPCServer.py @@ -1,8 +1,10 @@ import jsonrpclib from jsonrpclib import Fault +from jsonrpclib.jsonrpc import USE_UNIX_SOCKETS import SimpleXMLRPCServer import SocketServer import socket +import logging import os import types import traceback @@ -192,14 +194,15 @@ class SimpleJSONRPCServer(SocketServer.TCPServer, SimpleJSONRPCDispatcher): # check Python version and decide on how to call it vi = sys.version_info self.address_family = address_family - if address_family == socket.AF_UNIX: + if USE_UNIX_SOCKETS and address_family == socket.AF_UNIX: # Unix sockets can't be bound if they already exist in the # filesystem. The convention of e.g. X11 is to unlink # before binding again. - try: - os.unlink(addr) - except OSError: - pass + if os.path.exists(addr): + try: + os.unlink(addr) + except OSError: + logging.warning("Could not unlink socket %s", addr) # if python 2.5 and lower if vi[0] < 3 and vi[1] < 6: SocketServer.TCPServer.__init__(self, addr, requestHandler) |