From 34a3ccd619725d341dc7befa245e9c18ee88f945 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Mon, 7 Jan 2013 07:20:29 +0100 Subject: [PATCH] Improved sshsock error handling somewhat. --- pdm/sshsock.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pdm/sshsock.py b/pdm/sshsock.py index feb2f9f..44fd113 100644 --- a/pdm/sshsock.py +++ b/pdm/sshsock.py @@ -12,6 +12,22 @@ class sshsocket(object): args += ["python", "-m", "pdm.sshsock", path] self.proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) fcntl.fcntl(self.proc.stdout, fcntl.F_SETFL, fcntl.fcntl(self.proc.stdout, fcntl.F_GETFL) | os.O_NONBLOCK) + head = self.recv(5) + if head != "SSOCK": + raise socket.error("unexpected reply from %s: %r" % (host, head)) + head = self.recv(1) + if head == "+": + return + elif head == "-": + buf = "" + while True: + r = self.recv(1) + if r in ("\n", ""): + break + buf += r + raise socket.error(buf) + else: + raise socket.error("unexpected reply from %s: %r" % (host, head)) def close(self): if self.proc is not None: @@ -39,7 +55,12 @@ def cli(): fcntl.fcntl(sys.stdin, fcntl.F_SETFL, fcntl.fcntl(sys.stdin, fcntl.F_GETFL) | os.O_NONBLOCK) sk = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) try: - sk.connect(sys.argv[1]) + try: + sk.connect(sys.argv[1]) + except socket.error as err: + sys.stdout.write("SSOCK-connect: %s\n" % err) + return + sys.stdout.write("SSOCK+\n") buf1 = "" buf2 = "" while True: -- 2.11.0