From: miljenko Date: Mon, 2 Jan 2006 16:15:06 +0000 (+0000) Subject: Boot file creation is started with command: create_conf_file and stopped with X-Git-Url: https://git.entuzijast.net/?a=commitdiff_plain;h=302814444b555400034fd95a627c611e1c2fa775;p=imunes.git Boot file creation is started with command: create_conf_file and stopped with command close_conf_file. Bug found by: Submitted by: Requested by: Reviewed by: Approved by: Obtained from: --- diff --git a/exec_server.tcl b/exec_server.tcl index 2b1ff5e..4fdbd11 100755 --- a/exec_server.tcl +++ b/exec_server.tcl @@ -8,36 +8,22 @@ if { [llength $argv] == 0 || ! [string is integer [lindex $argv 0]] } { puts stderr \ - "Script should be called with one argument, server's port number:\n\ - ./exec_server 2547" + "Script should be called with at least one argument, server's port number:\ + \n ./exec_server 2547 \[debug\]" exit 2 } -set server_port [lindex $argv 0] - set debug_output false -if { [llength $argv] == 2 || [lindex $argv 1] == "debug" } { +if { [llength $argv] == 2 && [lindex $argv 1] == "debug" } { set debug_output true } +set spremam_conf_fajl false -####### -# Exec_Server -- -# Open the server listening socket and enter the Tcl event loop -# -# Arguments: -# port The server's port number - -proc Exec_Server {port} { - set s [socket -server ExecAccept $port] - vwait forever -} ####### -# Exec_Accept -- -# Accept a connection from a new client. -# This is called after a new socket connection -# has been created by Tcl. +# Exec_Accept -- Accept a connection from a new client. +# This is called after a new socket connection has been created by Tcl. # # Arguments: # sock The new socket connection to the client @@ -59,14 +45,13 @@ proc ExecAccept {sock addr port} { ####### # Exec_command -- -# This procedure is called when the server -# can read data from the client +# This procedure is called when the server can read data from the client # # Arguments: # sock The socket connection to the client proc Exec_command {sock} { - global client server_port debug_output + global client server_port debug_output fileId spremam_conf_fajl # Check end of file or abnormal connection drop, # then send result of exec command back to the client. @@ -75,26 +60,60 @@ proc Exec_command {sock} { close $sock puts "Close $client(addr,$sock)" unset client(addr,$sock) - } else { - if { $line == "Kraj" } { - puts "Kraj rada." - puts $sock "Kraj" - close $sock - exit 0 + return + } + + if { $debug_output } { puts "$server_port/K: >$line<" } + + if { $line == "Kraj" } { + puts "Kraj rada." + puts $sock "Kraj" + close $sock + exit 0 + } + + set command [lindex $line 0] + switch -exact $command { + + "create_conf_file" { + set conf_fajl [lindex $line 1] + if { $debug_output} { puts "Spremam conf fajl: $conf_fajl" } + set fileId [open "$conf_fajl" w] + ;# dodati provjeru!!! + set spremam_conf_fajl true + } + + "close_conf_file" { + if { $debug_output} { puts "Zatvaram conf fajl" } + close $fileId + set spremam_conf_fajl false + } + + default { + if { $spremam_conf_fajl } { + catch {eval puts $fileId "$line"} odg + if { $debug_output && ($odg != "") } { + puts "$server_port/puts greska: $odg" + } + } else { + if { [llength $line] == 0 } { return} + catch {eval exec $line} odg + if { $debug_output } { puts "$server_port/O: $odg" } + puts $sock $odg } - if { $debug_output } { puts "$server_port/Kom >$line<" } - if { [llength $line] == 0 } {return} - catch {eval exec $line} odg - if { $debug_output } { puts "$server_port/Odg: $odg" } - puts $sock $odg - puts $sock "Kraj" - ;# prije: flush $sock - catch {flush $sock} rez - if { $rez != "" } { - puts "Socket closed on remote.\n$rez" - } + } + } + puts $sock "Kraj" + catch {flush $sock} rez + if { $rez != "" } { + puts "Socket closed on remote.\n$rez" } } -Exec_Server $server_port +####### +# Open the server listening socket and enter the Tcl event loop + +set server_port [lindex $argv 0] +set s [socket -server ExecAccept $server_port] +vwait forever