Try to cleanup unix socket
#1 - Forward using iptables, pr0xy and custom DNS
This commit is contained in:
@@ -63,6 +63,9 @@ class UnixSocketServer(socketserver.ThreadingMixIn, socketserver.UnixStreamServe
|
||||
"""
|
||||
|
||||
def __init__(self, socket_path, request_handler_class, bind_and_activate=True):
|
||||
self._socket_path = socket_path
|
||||
# Remove old socket if it's not being used
|
||||
self._rm_socket()
|
||||
super().__init__(socket_path, request_handler_class, bind_and_activate)
|
||||
self.thread = threading.Thread(target=self.serve_forever)
|
||||
self.thread.daemon = True
|
||||
@@ -73,6 +76,17 @@ class UnixSocketServer(socketserver.ThreadingMixIn, socketserver.UnixStreamServe
|
||||
def stop(self):
|
||||
self.shutdown()
|
||||
self.server_close()
|
||||
# Attempt to remove socket before exiting
|
||||
self._rm_socket(True)
|
||||
|
||||
def _rm_socket(self, log_error=False):
|
||||
try:
|
||||
os.unlink(self._socket_path)
|
||||
except Exception as e:
|
||||
if log_error:
|
||||
logging.getLogger("UnixSocketServer").warn(
|
||||
"Couldn't remove unix socket: %s", e
|
||||
)
|
||||
|
||||
def isAlive(self):
|
||||
return self.thread.isAlive()
|
||||
|
Reference in New Issue
Block a user