1
1
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2
# 2001, 2002, 2003 Free Software Foundation, Inc.
2
# 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
4
4
# This file is part of DejaGnu.
16
16
# You should have received a copy of the GNU General Public License
17
17
# along with DejaGnu; if not, write to the Free Software Foundation,
18
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
21
# Connect to hostname using rlogin
20
# Connect to HOSTNAME using rlogin(1).
23
22
proc rsh_open { hostname } {
36
35
set RSH [board_info $hostname rsh_prog]
39
if [board_info $hostname exists username] {
38
if {[board_info $hostname exists username]} {
40
39
set rsh_useropts "-l [board_info $hostname username]"
42
41
set rsh_useropts ""
45
# get the hostname and port number from the config array
46
if [board_info $hostname exists name] {
44
# Get the hostname and port number from the config array.
45
if {[board_info $hostname exists name]} {
47
46
set hostname [board_info $hostname name]
49
48
set hostname [lindex [split [board_info ${hostname} netport] ":"] 0]
50
if [board_info ${hostname} exists shell_prompt] {
49
if {[board_info ${hostname} exists shell_prompt]} {
51
50
set shell_prompt [board_info ${hostname} shell_prompt]
53
52
set shell_prompt ".*> "
56
if [board_info $hostname exists fileid] {
55
if {[board_info $hostname exists fileid]} {
57
56
unset board_info($hostname,fileid)
149
# Download $srcfile to $destfile on $desthost.
146
# Download SRCFILE to DESTFILE on DESTHOST.
152
148
proc rsh_download {desthost srcfile destfile} {
153
149
# must be done before desthost is rewritten
154
if [board_info $desthost exists rcp_prog] {
150
if {[board_info $desthost exists rcp_prog]} {
155
151
set RCP [board_info $desthost rcp_prog]
160
if [board_info $desthost exists rsh_prog] {
156
if {[board_info $desthost exists rsh_prog]} {
161
157
set RSH [board_info $desthost rsh_prog]
163
159
if { [which remsh] != 0 } {
178
if [board_info $desthost exists name] {
174
if {[board_info $desthost exists name]} {
179
175
set desthost [board_info $desthost name]
182
if [board_info $desthost exists hostname] {
178
if {[board_info $desthost exists hostname]} {
183
179
set desthost [board_info $desthost hostname]
197
193
proc rsh_upload {desthost srcfile destfile} {
198
if [board_info $desthost exists rcp_prog] {
194
if {[board_info $desthost exists rcp_prog]} {
199
195
set RCP [board_info $desthost rcp_prog]
204
if [board_info $desthost exists username] {
200
if {[board_info $desthost exists username]} {
205
201
set rcp_user "[board_info $desthost username]@"
210
if [board_info $desthost exists name] {
206
if {[board_info $desthost exists name]} {
211
207
set desthost [board_info $desthost name]
214
if [board_info $desthost exists hostname] {
210
if {[board_info $desthost exists hostname]} {
215
211
set desthost [board_info $desthost hostname]
229
# Execute "$cmd $args[0]" on $boardname.
231
proc rsh_exec { boardname cmd args } {
232
if { [llength $args] > 0 } {
233
set pargs [lindex $args 0]
234
if { [llength $args] > 1 } {
235
set inp [lindex $args 1]
244
verbose "Executing $boardname:$cmd $pargs < $inp"
246
if ![board_info $boardname exists rsh_prog] {
224
# Execute CMD on BOARDNAME.
226
proc rsh_exec { boardname program pargs inp outp } {
229
verbose "Executing $boardname:$program $pargs < $inp"
231
if {![board_info $boardname exists rsh_prog]} {
247
232
if { [which remsh] != 0 } {
253
238
set RSH [board_info $boardname rsh_prog]
256
if [board_info $boardname exists username] {
241
if {[board_info $boardname exists username]} {
257
242
set rsh_useropts "-l [board_info $boardname username]"
259
244
set rsh_useropts ""
262
if [board_info $boardname exists name] {
247
if {[board_info $boardname exists name]} {
263
248
set boardname [board_info $boardname name]
266
if [board_info $boardname exists hostname] {
251
if {[board_info $boardname exists hostname]} {
267
252
set hostname [board_info $boardname hostname]
269
254
set hostname $boardname
273
# If CMD sends any output to stderr, exec will think it failed. More often
274
# than not that will be true, but it doesn't catch the case where there is
275
# no output but the exit code is non-zero.
257
# If CMD sends any output to stderr, exec will think it failed.
258
# More often than not that will be true, but it doesn't catch the
259
# case where there is no output but the exit code is non-zero.
276
260
if { $inp == "" } {
277
261
set inp "/dev/null"
280
set status [catch "exec cat $inp | $RSH $rsh_useropts $hostname sh -c '$cmd $pargs \\; echo XYZ\\\${?}ZYX' |& cat" output]
281
verbose "$RSH output is $output"
264
set ret [local_exec "$RSH $rsh_useropts $hostname sh -c '$program $pargs \\; echo XYZ\\\${?}ZYX'" $inp $outp $timeout]
265
set status [lindex $ret 0]
266
set output [lindex $ret 1]
268
verbose "$RSH status is $status, output is $output"
282
270
# `status' doesn't mean much here other than rsh worked ok.
283
# What we want is whether $cmd ran ok.
271
# What we want is whether $program ran ok. Return $status;
272
# if the program timed out, status will be 1 indicating that
273
# rsh ran and failed. If rsh fails, we will get FAIL rather
274
# than UNRESOLVED - this will help the problem be noticed.
284
275
if { $status != 0 } {
285
276
regsub "XYZ(\[0-9\]*)ZYX\n?" $output "" output
286
return [list -1 "$RSH to $boardname failed for $cmd, $output"]
277
return [list $status "$RSH to $boardname failed for $program, $output"]
288
279
regexp "XYZ(\[0-9\]*)ZYX" $output junk status
289
280
verbose "rsh_exec: status:$status text:$output" 4
294
285
# Delete one trailing \n because that is what `exec' will do and we want
295
286
# to behave identical to it.
296
287
regsub "\n$" $output "" output
297
return [list [expr $status != 0] $output]
288
return [list [expr {$status != 0}] $output]