#
-proc nexec { args } {
+proc nexec_local { args } {
eval exec $args
}
+proc Read_exec_results {sock} {
+ global exec_results exec_results_ready
+ if {[eof $sock] || [catch {gets $sock line}]} {
+ close $sock
+ } else {
+ if {$line=="Kraj"} {
+ set exec_results [string range $exec_results 0 [expr [string length $exec_results] - 2]]
+ set exec_results_ready 1
+ } else {
+ append exec_results $line "\n"
+ }
+ }
+}
+
+proc nexec { args } {
+ global remote_exec editor_only
+ global exec_sock exec_results exec_results_ready
+ global exec_sockets_opened
+
+ if { $editor_only } {
+ tk_messageBox -title "Editor only" \
+ -message "Running in editor only mode. Cannot execute commands. Please report this problem." \
+ -type ok
+ exit 5
+ }
+
+ if { $remote_exec } {
+ if { ! $exec_sockets_opened } { open_exec_sockets }
+ set exec_results ""
+ puts $exec_sock "$args"
+ vwait exec_results_ready
+ return $exec_results
+ } else {
+ eval exec $args
+ }
+}
+
+# And now the same for monitor
+proc Read_monitor_results {sock} {
+ global monitor_results monitor_results_ready
+ if {[eof $sock] || [catch {gets $sock line}]} {
+ close $sock
+ } else {
+ if {$line=="Kraj"} {
+ set monitor_results \
+ [string range $monitor_results 0 \
+ [expr [string length $monitor_results] - 2]]
+ set monitor_results_ready 1
+ } else {
+ append monitor_results $line "\n"
+ }
+ }
+}
+
+proc nexec_monitor { args } {
+ global remote_exec editor_only
+ global monitor_sock monitor_results monitor_results_ready
+ global exec_sockets_opened
+
+ if { $editor_only } {
+ tk_messageBox -title "Editor only" \
+ -message "Running in editor only mode. Cannot execute commands. Please report this problem." \
+ -type ok
+ exit 5
+ }
+
+ if { $remote_exec } {
+ if { ! $exec_sockets_opened } { open_exec_sockets }
+ set monitor_results ""
+ puts $monitor_sock "$args"
+ vwait monitor_results_ready
+ return $monitor_results
+ } else {
+ eval exec $args
+ }
+}
+
+proc open_exec_sockets {} {
+ global exec_hosts remote_exec exec_sockets_opened
+ global exec_host exec_port monitor_port exec_sock monitor_sock
+
+ if { ! $remote_exec } { return }
+
+ set exec_host [lindex [lindex $exec_hosts 0] 0]
+ set exec_port [lindex [lindex $exec_hosts 0] 1]
+ set monitor_port [lindex [lindex $exec_hosts 0] 2]
+
+ set exec_sock [socket -async $exec_host $exec_port]
+ set monitor_sock [socket -async $exec_host $monitor_port]
+
+ set fail true
+ while {$fail} {
+
+ for { set i 1 } { $i <= 4 } { incr i } {
+ if {[lindex [fconfigure $exec_sock -sockname] 0] != "0.0.0.0" &&
+ [lindex [fconfigure $monitor_sock -sockname] 0] != "0.0.0.0" } {
+ set fail false
+ break
+ } else {
+ after 250 ;# Max 2 sec for socket creation
+ }
+ }
+
+ if { $fail } {
+ set sel [tk_dialog .box "Socket problems" \
+ "Cannot open sockets {$exec_host,$exec_port|$monitor_port}" \
+ "" 0 "Retry" "Configure remote hosts" "Editor only mode" ]
+ switch $sel {
+ 1 { configRemoteHosts
+ set exec_host [lindex [lindex $exec_hosts 0] 0]
+ set exec_port [lindex [lindex $exec_hosts 0] 1]
+ set monitor_port [lindex [lindex $exec_hosts 0] 2]
+ set exec_sock [socket -async $exec_host $exec_port]
+ set monitor_sock [socket -async $exec_host $monitor_port] }
+ 2 { set editor_only true; set fail false; return }
+ default { }
+ }
+ }
+ }
+
+ fconfigure $exec_sock -buffering line
+ fileevent $exec_sock readable [list Read_exec_results $exec_sock]
+
+ fconfigure $monitor_sock -buffering line
+ fileevent $monitor_sock readable [list Read_monitor_results $monitor_sock]
+
+ set exec_sockets_opened true
+}
+
proc setOperMode { mode } {
global oper_mode activetool node_list
global nmbufs nmbclusters
+ global editor_only
# Verify that links to external interfaces are properly configured
if { $mode == "exec" } {
.menubar.tools entryconfigure "Rearrange all" -state normal
.menubar.tools entryconfigure "Rearrange selected" -state normal
}
- if {[nexec id -u] == 0} {
- .menubar.experiment entryconfigure "Execute" -state normal
- } else {
+ if { $editor_only } {
.menubar.experiment entryconfigure "Execute" -state disabled
+ } else {
+ .menubar.experiment entryconfigure "Execute" -state normal
}
.menubar.experiment entryconfigure "Terminate" -state disabled
.menubar.edit entryconfigure "Undo" -state normal
global eid
global node_list link_list supp_router_models
global mac_byte4 mac_byte5
+ global exec_host remote_exec
set mac_byte4 0
set mac_byte5 0
set bootcfg [[typemodel $node].cfggen $node]
set bootcmd [[typemodel $node].bootcmd $node]
}
- set fileId [open /tmp/$node_id/boot.conf w]
- foreach line $bootcfg {
- puts $fileId $line
- }
- close $fileId
- catch "nexec vimage $node_id $bootcmd /tmp/$node_id/boot.conf &"
+ if { ! $remote_exec } {
+ set fileId [open /tmp/$node_id/boot.conf w]
+ foreach line $bootcfg {
+ puts $fileId $line
+ }
+ close $fileId
+ } else {
+ nexec nc -l -p 1235 > /tmp/tmp_boot_conf &
+ set s [socket $exec_host 1235]
+ fconfigure $s -buffering line
+ foreach line $bootcfg {
+ puts $s $line
+ }
+ flush $s
+ close $s
+ catch "nexec tr -d '\012' < /tmp/temp_boot_conf > /tmp/$node_id/boot.conf"
+ }
+ catch "nexec vimage $node_id $bootcmd /tmp/$node_id/boot.conf &"
}
}
return
}
- set cpu_load [expr ([lindex [split [nexec sysctl kern.cp_time_avg]] end] + \
+ set cpu_load [expr ([lindex [split [nexec_monitor sysctl kern.cp_time_avg]] end] + \
5000) / 10000]
.bottom.cpu_load config -text "CPU $cpu_load%"
- set nstout [split [nexec netstat -m] ]
+ set nstout [split [nexec_monitor netstat -m] ]
set mbufs [lindex [split [lindex $nstout 0] /] 0]
set clusts [lindex [split [lsearch -inline $nstout "*/$nmbclusters"] /] 0]
set mbufp [expr $mbufs * 100 / $nmbufs]
nexec ngctl msg $ngnode: setcfg "{ $dir={ queuelen=$qlen } }"
}
}
+