[rancid] cygwin + long hostname = clogin hang

Lee ler762 at gmail.com
Mon Aug 23 21:44:33 UTC 2010


clogin hangs when I use it from cygwin to ssh into a cisco switch with
a long hostname.

It looks like a bug in cygwin expect causes the timeout.  The
        expect {
            -re $reprompt       { }
at line 611 fails if I've got a long hostname configured on the cisco switch:

expect: does "2ndFloorLibrarySW>" (spawn_id 4) match regular
expression "2ndFloorLib([^#>\r\n]+)?[#>](\([^)\r\n]+\))?"? no
"[\n\r]+"? no
expect: timed out

If I change the pattern to include more of the hostname the match works:
expect: does "2ndFloorLibrarySW>" (spawn_id 4) match regular
expression "2ndFloorLibrar([^#>\r\n]+)?[#>](\([^)\r\n]+\))?"? yes
expect: set expect_out(0,string) "2ndFloorLibrarySW>"
expect: set expect_out(1,string) "ySW"
expect: set expect_out(spawn_id) "4"
expect: set expect_out(buffer) "2ndFloorLibrarySW>"

so my work-around is to use up to 21 characters of the hostname in
reprompt.  Line 610 changes from
  regsub -all {^(.{1,11}).*([#>])$} $prompt
{\1([^#>\r\n]+)?[#>](\\([^)\\r\\n]+\\))?} reprompt
to
  regsub -all {^(.{1,21}).*([#>])$} $prompt
{\1([^#>\r\n]+)?[#>](\\([^)\\r\\n]+\\))?} reprompt


And then at clogin line 423, if a timeout happens clogin hangs until I
open task manager and kill the ssh process (<ctrl>C in the terminal
window doesn't kill it).  The 'catch{close}; catch{wait};' doesn't end
the ssh session.  Adding a 'send "exit\r"' fixes the hang for me:

        # This helps cleanup each expect clause.
        expect_after {
            timeout {
                send_user "\nError: TIMEOUT reached\n"
                send "exit\r"           ;# --LR--
                catch {close}; catch {wait};
                if { $in_proc} {
                    return 1
                } else {
                    continue
                }

Lee


More information about the Rancid-discuss mailing list