diff mbox

[OSSTEST,2/4] tcl/daemonlib: tolerate no $c(...Host)

Message ID 1497527684-21433-2-git-send-email-ian.jackson@eu.citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ian Jackson June 15, 2017, 11:54 a.m. UTC
From: osstest service user <osstest@xenbits.xenproject.org>

We are going to want a daemon that bins to * rather than to a known
address.

We achieve this by simply tolerating the lack of the FooHost config
setting; and, in that case, not passing -myaddr to Tcl's socket
command (and adjusting messages accordingly).

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
 tcl/daemonlib.tcl | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/tcl/daemonlib.tcl b/tcl/daemonlib.tcl
index 1e86d5f..b23caea 100644
--- a/tcl/daemonlib.tcl
+++ b/tcl/daemonlib.tcl
@@ -195,7 +195,7 @@  proc newconn {chan addr port} {
 proc main-daemon {which setup} {
     global c argv
 
-    set host $c(${which}DaemonHost)
+    catch { set host $c(${which}DaemonHost) }
     set port $c(${which}DaemonPort)
 
     foreach arg $argv {
@@ -210,12 +210,21 @@  proc main-daemon {which setup} {
     fconfigure stdout -buffering line
     fconfigure stderr -buffering none
 
-    log "starting $host:$port"
+    set desc $port
+
+    set sockcmd {socket -server newconn}
+    if {[info exists host]} {
+        set desc "$host:$port"
+        lappend sockcmd [list -myaddr $host]
+    }
+    lappend sockcmd $port
+
+    log "starting $desc"
 
     uplevel 1 $setup
 
-    socket -server newconn -myaddr $host $port
-    log "listening $host:$port"
+    eval $sockcmd
+    log "listening $desc"
 
     vwait forever
 }