fix #1554: use AF_INET instead of AF_UNIX, and write port number to lockfile

This commit is contained in:
ThomasV 2015-11-19 12:42:11 +01:00
parent 34c2010e63
commit b727824eed
1 changed files with 10 additions and 15 deletions

View File

@ -30,7 +30,6 @@ import socket
import Queue
from collections import defaultdict
DAEMON_SOCKET = 'daemon.sock'
script_dir = os.path.dirname(os.path.realpath(__file__))
is_bundle = getattr(sys, 'frozen', False)
@ -350,13 +349,11 @@ class NetworkServer(util.DaemonThread):
print_error("client quit:", len(self.clients))
def run(self):
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
daemon_socket = os.path.join(self.config.path, DAEMON_SOCKET)
if os.path.exists(daemon_socket):
os.remove(daemon_socket)
daemon_timeout = self.config.get('daemon_timeout', None)
s.bind(daemon_socket)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 0))
lockfile = os.path.join(self.config.path, 'lock')
with open(lockfile, 'w') as f:
f.write("%d"%s.getsockname()[1])
s.listen(5)
s.settimeout(0.1)
while self.is_running():
@ -370,19 +367,17 @@ class NetworkServer(util.DaemonThread):
def get_daemon(config):
daemon_socket = os.path.join(config.path, DAEMON_SOCKET)
lockfile = os.path.join(config.path, 'lock')
try:
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect(daemon_socket)
with open(lockfile) as f:
num = int(f.read())
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('', num))
return s
except socket.error:
return False
except:
# do not use daemon if AF_UNIX is not available (windows)
return False
if __name__ == '__main__':
# make sure that certificates are here