veyron/services/mgmt/debug: Use callback for logdir

At the time debug.NewDispatcher() is called, the vlog library hasn't
been initialized yet. So, instead of trying to figure out the correct
log dir at that time, use a callback function that will be called after
the runtime initialization has completed.

Change-Id: Ieed799b4b3b0dfd6e53b04b79ebe51e60c0adcf4
diff --git a/profiles/roaming/roaminginit.go b/profiles/roaming/roaminginit.go
index 8b9eb01..3e6de0b 100644
--- a/profiles/roaming/roaminginit.go
+++ b/profiles/roaming/roaminginit.go
@@ -57,7 +57,7 @@
 		Addrs: ipc.ListenAddrs(lf.Addrs),
 		Proxy: lf.ListenProxy,
 	}
-	reservedDispatcher := debug.NewDispatcher(vlog.Log.LogDir(), sflag.NewAuthorizerOrDie())
+	reservedDispatcher := debug.NewDispatcher(vlog.Log.LogDir, sflag.NewAuthorizerOrDie())
 
 	ac := appcycle.New()
 
diff --git a/profiles/static/staticinit.go b/profiles/static/staticinit.go
index f477d21..966b0dc 100644
--- a/profiles/static/staticinit.go
+++ b/profiles/static/staticinit.go
@@ -41,7 +41,7 @@
 		Addrs: ipc.ListenAddrs(lf.Addrs),
 		Proxy: lf.ListenProxy,
 	}
-	reservedDispatcher := debug.NewDispatcher(vlog.Log.LogDir(), sflag.NewAuthorizerOrDie())
+	reservedDispatcher := debug.NewDispatcher(vlog.Log.LogDir, sflag.NewAuthorizerOrDie())
 
 	ac := appcycle.New()
 
diff --git a/runtimes/google/ipc/debug_test.go b/runtimes/google/ipc/debug_test.go
index e1bf356..e351242 100644
--- a/runtimes/google/ipc/debug_test.go
+++ b/runtimes/google/ipc/debug_test.go
@@ -30,7 +30,7 @@
 	pclient.AddToRoots(bclient)                    // Client recognizes "server" as a root of blessings.
 	pclient.BlessingStore().Set(bclient, "server") // Client presents bclient to server
 
-	debugDisp := debug.NewDispatcher(vlog.Log.LogDir(), nil)
+	debugDisp := debug.NewDispatcher(vlog.Log.LogDir, nil)
 
 	sm := manager.InternalNew(naming.FixedRoutingID(0x555555555))
 	defer sm.Shutdown()
diff --git a/services/mgmt/debug/dispatcher.go b/services/mgmt/debug/dispatcher.go
index 205ae58..4a8d9b0 100644
--- a/services/mgmt/debug/dispatcher.go
+++ b/services/mgmt/debug/dispatcher.go
@@ -15,14 +15,14 @@
 
 // dispatcher holds the state of the debug dispatcher.
 type dispatcher struct {
-	logsDir string // The root of the logs directory.
-	auth    security.Authorizer
+	logsDirFunc func() string // The function returns the root of the logs directory.
+	auth        security.Authorizer
 }
 
 var _ ipc.Dispatcher = (*dispatcher)(nil)
 
-func NewDispatcher(logsDir string, authorizer security.Authorizer) ipc.Dispatcher {
-	return &dispatcher{logsDir, authorizer}
+func NewDispatcher(logsDirFunc func() string, authorizer security.Authorizer) ipc.Dispatcher {
+	return &dispatcher{logsDirFunc, authorizer}
 }
 
 // The first part of the names of the objects served by this dispatcher.
@@ -49,7 +49,7 @@
 	}
 	switch parts[0] {
 	case "logs":
-		return logreaderimpl.NewLogFileService(d.logsDir, suffix), d.auth, nil
+		return logreaderimpl.NewLogFileService(d.logsDirFunc(), suffix), d.auth, nil
 	case "pprof":
 		return pprofimpl.NewPProfService(), d.auth, nil
 	case "stats":
diff --git a/services/mgmt/debug/dispatcher_test.go b/services/mgmt/debug/dispatcher_test.go
index aa21ced..f6c62d6 100644
--- a/services/mgmt/debug/dispatcher_test.go
+++ b/services/mgmt/debug/dispatcher_test.go
@@ -32,7 +32,7 @@
 	if len(logsDir) == 0 {
 		return "", nil, fmt.Errorf("logs directory missing")
 	}
-	disp := NewDispatcher(logsDir, nil)
+	disp := NewDispatcher(func() string { return logsDir }, nil)
 	server, err := veyron2.NewServer(ctx)
 	if err != nil {
 		return "", nil, fmt.Errorf("failed to start debug server: %v", err)