Fix typo in reference manual
[dejagnu.git] / lib / rlogin.exp
blobe086d83f2bd2c7019378cb6f375310cf0480deca
1 # Copyright (C) 1992-2019, 2020 Free Software Foundation, Inc.
3 # This file is part of DejaGnu.
5 # DejaGnu is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # DejaGnu is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with DejaGnu. If not, see <http://www.gnu.org/licenses/>.
18 # Connect to ARG using rlogin. This is for systems using rlogin to
19 # braindead targets. It returns either the spawn_id or a -1.
21 proc rlogin_open { arg } {
22 global board_info
24 set tries 0
25 set result -1
27 if {[board_info $arg exists fileid]} {
28 return [board_info $arg fileid]
31 # get the hostname and port number from the config array
32 if {[board_info $arg exists netport]} {
33 set hostname [lindex [split [board_info $arg netport] ":"] 0]
34 } else {
35 set hostname $arg
38 if {![board_info $arg exists shell_prompt]} {
39 # if no prompt, then set it to something generic
40 set shell_prompt ".*> "
41 } else {
42 set shell_prompt [board_info $arg shell_prompt]
45 if {[board_info $arg exists fileid]} {
46 unset board_info($arg,fileid)
48 # get the right version of rlogin
49 if {![board_info $arg exists rlogin_prog]} {
50 set RLOGIN rlogin
51 } else {
52 set RLOGIN [board_info $arg rlogin_prog]
55 # start connection and store the spawn_id
56 verbose "Opening a $RLOGIN connection to $hostname" 2
57 spawn $RLOGIN $hostname
58 if { $spawn_id < 0 } {
59 perror "invalid spawn id from rlogin"
60 return -1
62 set board_info($arg,fileid) $spawn_id
64 # Try to connect to the target. We give up after 3 attempts.
65 while { $tries <= 3 } {
66 expect {
67 -re ".*$shell_prompt.*$" {
68 verbose "Got prompt\n"
69 set result 0
70 break
72 -re {TERM = .*\)[ ]*$} {
73 send "dumb\r\n"
74 expect {
75 "Terminal type is*$" {
76 verbose "rlogin: set the terminal to dumb" 2
78 default {
79 warning "rlogin: couldn't set terminmal type"
82 set result 10
83 break
85 "unknown host" {
86 perror "rlogin: unknown host"
87 break
89 "has logged on from" {
90 exp_continue
92 "Terminal type is" {
93 verbose "rlogin: connected, got terminal prompt" 2
94 set result 0
95 break
97 -re "Maximum number of users already logged in.*$" {
98 warning "rlogin: maximum number of users already logged in"
100 -re "Sorry, shell is locked.*Connection closed.*$" {
101 warning "rlogin: lready connected."
103 -re "Sorry, this system is engaged.*Connection closed.*$" {
104 warning "rlogin: system engaged."
106 timeout {
107 warning "rlogin: timed out trying to connect."
109 eof {
110 perror "rlogin: got EOF while trying to connect."
111 break
114 incr tries
117 # see if we maxed out on errors
118 if { $result < 0 } {
119 catch "close -i $spawn_id"
120 catch "wait -i $spawn_id"
121 set spawn_id -1
122 } else {
123 verbose "rlogin: connected to $hostname" 2
126 return $spawn_id
129 # Start CMDLINE running on DEST. Return the shell_id associated with
130 # the command.
132 proc rlogin_spawn { dest cmdline } {
133 if {![board_info $dest exists shell_prompt]} {
134 set shell_prompt "(^|\[\r\n\])\[^\r\n\]*>"
135 } else {
136 set shell_prompt [board_info $dest shell_prompt]
138 set prefix ""
139 set ok 0
140 for { set i 0 } {$i <= 2 && ! $ok} { incr i } {
141 set shell_id [remote_open $dest]
142 if { $shell_id ne "" && $shell_id > 0 } {
143 remote_send $dest "echo k\r"
144 remote_expect $dest 20 {
145 -re {\(gdb\)} {
146 set shell_prompt {\(gdb\)}
147 # gdb uses 'shell command'.
148 set prefix "shell "
149 set ok 1
151 -re ".*$shell_prompt" {
152 set ok 1
154 default { }
157 if { ! $ok } {
158 remote_close $dest
159 remote_reboot $dest
162 if { ! $ok } {
163 return "unable to start command"
164 } else {
165 remote_send $dest "$prefix$cmdline\n"
166 return [board_info $dest fileid]