]> thyrsus.com Git - ssh-installkeys.git/commitdiff
Die gracefully on broken ptys.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 26 Mar 2012 11:45:22 +0000 (07:45 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 26 Mar 2012 11:45:22 +0000 (07:45 -0400)
ssh-installkeys
ssh-installkeys.xml

index 4ef12f75cc5afad8ad9a04536a84f8b35f626807..4ef8f27b2ce8f145c4dde51657007c871c801ea1 100755 (executable)
@@ -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
index 768d33337014ee715bbf6ccea408b77971a5bf29..55a0c416d8dac4393202ae7e081c857ad8d64495 100644 (file)
@@ -100,13 +100,13 @@ will not work under Python 1.5.2. </para>
 </refsect1>
 
 <refsect1><title>Bugs</title>
-<para>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.</para>
+<para>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"</para>
 
 <para>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.</para>
 </refsect1>