made it TCL8.0 compatible

exit if programm dies very early
This commit is contained in:
zimoch
2003-03-10 10:04:57 +00:00
parent ebdc5d3da7
commit 98dfa0523a
+16 -7
View File
@@ -19,11 +19,11 @@
#
# The box intercepts the following commands:
# exit or quit disconnect from the box
# clients dives a list of all connected clients
# clients gives a list of all connected clients
# kill terminates the shell
#
set version {$Id: shellbox.tcl,v 1.2 2002/10/23 09:22:46 zimoch Exp $}
set version {$Id: shellbox.tcl,v 1.3 2003/03/10 10:04:57 zimoch Exp $}
proc createServer {port {paranoid 0}} {
if [catch {
@@ -102,7 +102,11 @@ proc forwardInput {data} {
proc outputHandler {channel} {
set data [read $channel]
if [eof $channel] {
global command
global command diedyoung
if $diedyoung {
forwardOutput "**** first run of '$command' died within first 10 seconds. I will quit. ****\n"
exit 4
}
forwardOutput "**** '$command' died ****\n"
startProgram
return
@@ -127,18 +131,23 @@ proc getClientlist {} {
return $result
}
set diedyoung 1
proc startProgram {} {
global command pipe
global command pipe diedyoung
catch {close $pipe}
after 10000 set diedyoung 0
if [catch {
set pipe [open "|$command" RDWR]
set pipe [open |$command RDWR]
} msg] {
puts stderr $msg
exit 3
}
fconfigure $pipe -blocking no -buffering line
gets $pipe
if [eof $pipe] exit
if [eof $pipe] {
forwardOutput "**** '$command' died immediately. I will quit ****\n"
exit 5
}
fileevent $pipe readable "outputHandler $pipe"
forwardOutput "**** '$command' started ****\n"
}
@@ -164,7 +173,7 @@ if {[lindex $argv 0] == "-paranoid"} {
set port [lindex $argv 0]
set command [lrange $argv 1 end]
if {![string is integer $port] || [llength $command] == 0} {
if {![regexp {^[0-9]+$} $port] || [llength $command] == 0} {
puts stderr "usage: [file tail $argv0] \[-paranoid\] <port> <command> \[args\]"
exit 1
}