~ubuntu-branches/ubuntu/oneiric/dejagnu/oneiric

« back to all changes in this revision

Viewing changes to lib/rsh.exp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Jacobowitz
  • Date: 2006-12-11 09:06:59 UTC
  • mfrom: (2.1.6 edgy)
  • Revision ID: james.westby@ubuntu.com-20061211090659-w586kgi3giz84053
Tags: 1.4.4.cvs20060709-3
* Acknowledge previous NMUs.
* Fix permissions on /usr/share/dejagnu when building without fakeroot
  (Closes: #392589, #379809).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
3
3
#
4
4
# This file is part of DejaGnu.
5
5
#
15
15
#
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.
19
19
 
20
 
#
21
 
# Connect to hostname using rlogin
 
20
# Connect to HOSTNAME using rlogin(1).
22
21
#
23
22
proc rsh_open { hostname } {
24
23
    global spawn_id
26
25
    set tries 0
27
26
    set result -1
28
27
 
29
 
    if ![board_info $hostname exists rsh_prog] {
 
28
    if {![board_info $hostname exists rsh_prog]} {
30
29
        if { [which remsh] != 0 } {
31
30
            set RSH remsh
32
31
        } else {
36
35
        set RSH [board_info $hostname rsh_prog]
37
36
    }
38
37
 
39
 
    if [board_info $hostname exists username] {
 
38
    if {[board_info $hostname exists username]} {
40
39
        set rsh_useropts "-l [board_info $hostname username]"
41
40
    } else {
42
41
        set rsh_useropts ""
43
42
    }
44
43
 
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]
48
47
    }
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]
52
51
    } else {
53
52
        set shell_prompt ".*> "
54
53
    }
55
54
 
56
 
    if [board_info $hostname exists fileid] {
 
55
    if {[board_info $hostname exists fileid]} {
57
56
        unset board_info($hostname,fileid)
58
57
    }
59
58
 
135
134
    }
136
135
 
137
136
    if { $result < 0 } {
138
 
        #       perror "$RSH: couldn't connect after $tries tries."
139
137
        close -i $spawn_id
140
138
        set spawn_id -1
141
139
    } else {
145
143
    return $spawn_id
146
144
}
147
145
 
148
 
#
149
 
# Download $srcfile to $destfile on $desthost.
150
 
#
151
 
 
 
146
# Download SRCFILE to DESTFILE on DESTHOST.
 
147
#
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]
156
152
    } else {
157
153
        set RCP rcp
158
154
    }
159
155
 
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]
162
158
    } else {
163
159
        if { [which remsh] != 0 } {
167
163
        }
168
164
    }
169
165
 
170
 
    if [board_info $desthost exists username] {
 
166
    if {[board_info $desthost exists username]} {
171
167
        set rsh_useropts "-l [board_info $desthost username]"
172
168
        set rcp_user "[board_info $desthost username]@"
173
169
    } else {
175
171
        set rcp_user ""
176
172
    }
177
173
 
178
 
    if [board_info $desthost exists name] {
 
174
    if {[board_info $desthost exists name]} {
179
175
        set desthost [board_info $desthost name]
180
176
    }
181
177
 
182
 
    if [board_info $desthost exists hostname] {
 
178
    if {[board_info $desthost exists hostname]} {
183
179
        set desthost [board_info $desthost hostname]
184
180
    }
185
181
 
195
191
}
196
192
 
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]
200
196
    } else {
201
197
        set RCP rcp
202
198
    }
203
199
 
204
 
    if [board_info $desthost exists username] {
 
200
    if {[board_info $desthost exists username]} {
205
201
        set rcp_user "[board_info $desthost username]@"
206
202
    } else {
207
203
        set rcp_user ""
208
204
    }
209
205
 
210
 
    if [board_info $desthost exists name] {
 
206
    if {[board_info $desthost exists name]} {
211
207
        set desthost [board_info $desthost name]
212
208
    }
213
209
 
214
 
    if [board_info $desthost exists hostname] {
 
210
    if {[board_info $desthost exists hostname]} {
215
211
        set desthost [board_info $desthost hostname]
216
212
    }
217
213
 
225
221
    }
226
222
}
227
223
 
228
 
#
229
 
# Execute "$cmd $args[0]" on $boardname.
230
 
#
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]
236
 
        } else {
237
 
            set inp ""
238
 
        }
239
 
    } else {
240
 
        set pargs ""
241
 
        set inp ""
242
 
    }
243
 
 
244
 
    verbose "Executing $boardname:$cmd $pargs < $inp"
245
 
 
246
 
    if ![board_info $boardname exists rsh_prog] {
 
224
# Execute CMD on BOARDNAME.
 
225
#
 
226
proc rsh_exec { boardname program pargs inp outp } {
 
227
    global timeout
 
228
 
 
229
    verbose "Executing $boardname:$program $pargs < $inp"
 
230
 
 
231
    if {![board_info $boardname exists rsh_prog]} {
247
232
        if { [which remsh] != 0 } {
248
233
            set RSH remsh
249
234
        } else {
253
238
        set RSH [board_info $boardname rsh_prog]
254
239
    }
255
240
 
256
 
    if [board_info $boardname exists username] {
 
241
    if {[board_info $boardname exists username]} {
257
242
        set rsh_useropts "-l [board_info $boardname username]"
258
243
    } else {
259
244
        set rsh_useropts ""
260
245
    }
261
246
 
262
 
    if [board_info $boardname exists name] {
 
247
    if {[board_info $boardname exists name]} {
263
248
        set boardname [board_info $boardname name]
264
249
    }
265
250
 
266
 
    if [board_info $boardname exists hostname] {
 
251
    if {[board_info $boardname exists hostname]} {
267
252
        set hostname [board_info $boardname hostname]
268
253
    } else {
269
254
        set hostname $boardname
270
255
    }
271
256
 
272
 
 
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"
278
262
    }
279
263
 
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]
 
267
 
 
268
    verbose "$RSH status is $status, output is $output"
 
269
 
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"]
287
278
    }
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]
298
289
}