From: Eric S. Raymond Date: Mon, 26 Mar 2012 11:45:22 +0000 (-0400) Subject: Die gracefully on broken ptys. X-Git-Tag: 1.7~2 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=6250dc02a4362619df0d1609ac18a64c44a894e0;p=ssh-installkeys.git Die gracefully on broken ptys. --- diff --git a/ssh-installkeys b/ssh-installkeys index 4ef12f7..4ef8f27 100755 --- a/ssh-installkeys +++ b/ssh-installkeys @@ -623,6 +623,9 @@ class ssh_session: def exists(self, fn): "Retrieve file permissions of specified remote file." seen = self.ssh("/bin/ls -ld %s" % fn) + if not seen.strip(): + sys.stderr.write("Remote ls returned empty string, bailing out.\n") + raise SystemExit, 2 if self.verbose: sys.stderr.write("Existence check on %s gave %s\n" % (fn, repr(seen))) if seen.find("No such file") > -1: @@ -776,7 +779,7 @@ if __name__ == '__main__': if delete: os.system('ssh -l %s %s "rm -fr .ssh"' % (login, host)) config.forget(host) - print "Keys for %s on %s have been deleted." % (login, host) + print "Keys for %s@%s have been deleted." % (login, host) raise SystemExit, 0 # Update or check @@ -799,20 +802,19 @@ if __name__ == '__main__': if session.exists("~/.ssh/authorized_keys"): print "authorized_keys already exists on", host config.remember(session) - elif not check: + elif check: + print "Check of %s@%s is complete." % (login, host) + else: print "Copying your public keys to", host session.scp(keyfile, "~/.ssh/authorized_keys") config.remember(session) + print "Keys for %s@%s have been installed." % (login, host) except SystemExit: pass except RuntimeError: sys.exit(-1) # It's all over now... os.remove(keyfile) - if check: - print "Check is complete." - else: - print "Keys for %s on %s have been installed." % (login, host) config.save() # End diff --git a/ssh-installkeys.xml b/ssh-installkeys.xml index 768d333..55a0c41 100644 --- a/ssh-installkeys.xml +++ b/ssh-installkeys.xml @@ -100,13 +100,13 @@ will not work under Python 1.5.2. Bugs -There are persistent reports that seem to indicate that this -script occasionally chokes on a bogus, empty return from ls -ld, but -I don't know what can cause ls -ld to do that and am reluctant to -paper over the problem rather than actually fixing it. +This program relies on ptys to work correctly in combination with exec, +but some implementations (notably under FreeBSD) don't. Suspect this if +you see termination with the message "Remote ls returned empty string, +bailing out" If you encounter this or any other bug, the first thing to do is -run with -v and see if that clarifies matters. If not, send me a +run with -v and see if that clarifies matters. If not, send the maintainer a session transcript.