global rename of MOUNTTABLE_ROOT to NAMESPACE_ROOT. This affects
scripts and Makefiles in JS land as well as go.

veyron/runtimes/google/rt: allow multiple roots to be specified.

Change-Id: I2bdfa600dddf69f8911af0c0c33139ba8cb0c42e
diff --git a/examples/pipetobrowser/Makefile b/examples/pipetobrowser/Makefile
index 07a4bc8..2acdaf0 100644
--- a/examples/pipetobrowser/Makefile
+++ b/examples/pipetobrowser/Makefile
@@ -45,7 +45,7 @@
 	export VEYRON_IDENTITY=$(VEYRON_IDENTITY_PATH) ; \
 	$(VEYRON_IDENTITYD) --port=$(VEYRON_IDENTITY_PORT) & \
 	$(VEYRON_MOUNTTABLE) --address=:$(VEYRON_MOUNTTABLE_PORT) & \
-	export MOUNTTABLE_ROOT=/localhost:$(VEYRON_MOUNTTABLE_PORT)/mt ; \
+	export NAMESPACE_ROOT=/localhost:$(VEYRON_MOUNTTABLE_PORT)/mt ; \
 	$(VEYRON_PROXY) -address=$(VEYRON_PROXY_ADDR) & \
 	$(VEYRON_WSPR) --v=1 -logtostderr=true -vproxy=$(VEYRON_PROXY_ADDR) --port $(VEYRON_WSPR_PORT) & \
 	$(VEYRON_STORE) --address=:$(VEYRON_STORE_PORT) --name=global/$(USER)/store &
diff --git a/examples/unresolve/unresolve_test.go b/examples/unresolve/unresolve_test.go
index 251bf95..200861c 100644
--- a/examples/unresolve/unresolve_test.go
+++ b/examples/unresolve/unresolve_test.go
@@ -120,7 +120,7 @@
 
 	idFile := testutil.SaveIdentityToFile(testutil.NewBlessedIdentity(idA, "test"))
 	defer os.Remove(idFile)
-	b.Cmd.Env = append(b.Cmd.Env, fmt.Sprintf("VEYRON_IDENTITY=%v", idFile), fmt.Sprintf("MOUNTTABLE_ROOT=%v", aOA))
+	b.Cmd.Env = append(b.Cmd.Env, fmt.Sprintf("VEYRON_IDENTITY=%v", idFile), fmt.Sprintf("NAMESPACE_ROOT=%v", aOA))
 	b.Cmd.Start()
 	b.Expect("ready")
 
@@ -143,7 +143,7 @@
 	defer shutdown(c)
 	idFile = testutil.SaveIdentityToFile(testutil.NewBlessedIdentity(idA, "test"))
 	defer os.Remove(idFile)
-	c.Cmd.Env = append(c.Cmd.Env, fmt.Sprintf("VEYRON_IDENTITY=%v", idFile), fmt.Sprintf("MOUNTTABLE_ROOT=%v", bOA))
+	c.Cmd.Env = append(c.Cmd.Env, fmt.Sprintf("VEYRON_IDENTITY=%v", idFile), fmt.Sprintf("NAMESPACE_ROOT=%v", bOA))
 	c.Cmd.Start()
 	c.Expect("ready")
 	cEP := resolveStep(t, naming.JoinAddressName(bAddr, "//mt/c"))
@@ -154,7 +154,7 @@
 	defer shutdown(d)
 	idFile = testutil.SaveIdentityToFile(testutil.NewBlessedIdentity(idA, "test"))
 	defer os.Remove(idFile)
-	d.Cmd.Env = append(d.Cmd.Env, fmt.Sprintf("VEYRON_IDENTITY=%v", idFile), fmt.Sprintf("MOUNTTABLE_ROOT=%v", bOA))
+	d.Cmd.Env = append(d.Cmd.Env, fmt.Sprintf("VEYRON_IDENTITY=%v", idFile), fmt.Sprintf("NAMESPACE_ROOT=%v", bOA))
 	d.Cmd.Start()
 	d.Expect("ready")
 	dEP := resolveStep(t, naming.JoinAddressName(bAddr, "//mt/d"))
@@ -165,7 +165,7 @@
 	defer shutdown(e)
 	idFile = testutil.SaveIdentityToFile(testutil.NewBlessedIdentity(idA, "test"))
 	defer os.Remove(idFile)
-	e.Cmd.Env = append(e.Cmd.Env, fmt.Sprintf("VEYRON_IDENTITY=%v", idFile), fmt.Sprintf("MOUNTTABLE_ROOT=%v", bOA))
+	e.Cmd.Env = append(e.Cmd.Env, fmt.Sprintf("VEYRON_IDENTITY=%v", idFile), fmt.Sprintf("NAMESPACE_ROOT=%v", bOA))
 	e.Cmd.Start()
 	e.Expect("ready")
 	eEP := resolveStep(t, naming.JoinAddressName(bAddr, "//mt/e1"))
@@ -176,7 +176,7 @@
 	defer shutdown(f)
 	idFile = testutil.SaveIdentityToFile(testutil.NewBlessedIdentity(idA, "test"))
 	defer os.Remove(idFile)
-	f.Cmd.Env = append(f.Cmd.Env, fmt.Sprintf("VEYRON_IDENTITY=%v", idFile), fmt.Sprintf("MOUNTTABLE_ROOT=%v", naming.Join(aOA, "b/mt")))
+	f.Cmd.Env = append(f.Cmd.Env, fmt.Sprintf("VEYRON_IDENTITY=%v", idFile), fmt.Sprintf("NAMESPACE_ROOT=%v", naming.Join(aOA, "b/mt")))
 	f.Cmd.Start()
 	f.Expect("ready")
 	fEP := resolveStep(t, naming.JoinAddressName(bAddr, "//mt/f"))
@@ -187,7 +187,7 @@
 	defer shutdown(g)
 	idFile = testutil.SaveIdentityToFile(testutil.NewBlessedIdentity(idA, "test"))
 	defer os.Remove(idFile)
-	g.Cmd.Env = append(g.Cmd.Env, fmt.Sprintf("VEYRON_IDENTITY=%v", idFile), fmt.Sprintf("MOUNTTABLE_ROOT=%v", bOA))
+	g.Cmd.Env = append(g.Cmd.Env, fmt.Sprintf("VEYRON_IDENTITY=%v", idFile), fmt.Sprintf("NAMESPACE_ROOT=%v", bOA))
 	g.Cmd.Start()
 	g.Expect("ready")
 	gEP := resolveStep(t, naming.JoinAddressName(bAddr, "//mt/g"))
diff --git a/lib/testutil/modules/mounttable.go b/lib/testutil/modules/mounttable.go
index e269882..2516c65 100644
--- a/lib/testutil/modules/mounttable.go
+++ b/lib/testutil/modules/mounttable.go
@@ -59,7 +59,7 @@
 	name := map[bool]string{true: "rootMT", false: "nodeMT"}[mt.root]
 	var env []string
 	if !mt.root {
-		env = append(env, "MOUNTTABLE_ROOT="+args[0])
+		env = append(env, "NAMESPACE_ROOT="+args[0])
 		args = args[1:]
 	}
 	c, v, r, err := bbSpawn(name, args, env)
diff --git a/lib/testutil/modules/servers.go b/lib/testutil/modules/servers.go
index 9d93685..bfb2c43 100644
--- a/lib/testutil/modules/servers.go
+++ b/lib/testutil/modules/servers.go
@@ -175,7 +175,7 @@
 }
 
 func runServer(name string, args []string) (Variables, []string, Handle, error) {
-	env := []string{"MOUNTTABLE_ROOT=" + args[0]}
+	env := []string{"NAMESPACE_ROOT=" + args[0]}
 	c, v, r, err := bbSpawn(name, args, env)
 	if err != nil {
 		return v, r, nil, err
diff --git a/runtimes/google/naming/namespace/namespace.go b/runtimes/google/naming/namespace/namespace.go
index 92c486c..bc64e1f 100644
--- a/runtimes/google/naming/namespace/namespace.go
+++ b/runtimes/google/naming/namespace/namespace.go
@@ -47,6 +47,7 @@
 	}
 	ns.Lock()
 	defer ns.Unlock()
+	// TODO(cnicolaou): filter out duplicate values.
 	ns.roots = roots
 	return nil
 }
diff --git a/runtimes/google/rt/rt.go b/runtimes/google/rt/rt.go
index b8fbe63..ff6aadd 100644
--- a/runtimes/google/rt/rt.go
+++ b/runtimes/google/rt/rt.go
@@ -4,6 +4,7 @@
 	"flag"
 	"fmt"
 	"os"
+	"strings"
 	"sync"
 
 	"veyron/lib/exec"
@@ -94,16 +95,24 @@
 	}
 
 	if len(nsRoots) == 0 {
-		// TODO(cnicolaou,caprita): remove this when NAMESPACE_ROOT is in use.
-		if nsRoot := os.Getenv("MOUNTTABLE_ROOT"); nsRoot != "" {
-			nsRoots = append(nsRoots, nsRoot)
+		found := false
+		for _, ev := range os.Environ() {
+			p := strings.SplitN(ev, "=", 2)
+			if len(p) != 2 {
+				continue
+			}
+			k, v := p[0], p[1]
+			if strings.HasPrefix(k, "NAMESPACE_ROOT") {
+				nsRoots = append(nsRoots, v)
+				found = true
+			}
 		}
-		// TODO(cnicolaou,caprita): rename this to NAMESPACE_ROOT.
-		if nsRoot := os.Getenv("NAMESPACE_ROOT"); nsRoot != "" {
-			nsRoots = append(nsRoots, nsRoot)
+		if !found {
+			// TODO(cnicolaou,caprita): remove this when NAMESPACE_ROOT is in use.
+			if nsRoot := os.Getenv("MOUNTTABLE_ROOT"); nsRoot != "" {
+				nsRoots = append(nsRoots, nsRoot)
+			}
 		}
-		// TODO(cnicolaou,caprita): decide if want to allow NAMESPACE_ROOTS
-		// e.g. comma separated list of roots.
 	}
 
 	if ns, err := namespace.New(rt, nsRoots...); err != nil {
diff --git a/services/mgmt/node/impl/impl_test.go b/services/mgmt/node/impl/impl_test.go
index 4651016..6044630 100644
--- a/services/mgmt/node/impl/impl_test.go
+++ b/services/mgmt/node/impl/impl_test.go
@@ -228,7 +228,7 @@
 func spawnNodeManager(t *testing.T, mtName string, idFile string) *blackbox.Child {
 	root := filepath.Join(os.TempDir(), "noded")
 	child := blackbox.HelperCommand(t, "nodeManager")
-	child.Cmd.Env = exec.Setenv(child.Cmd.Env, "MOUNTTABLE_ROOT", mtName)
+	child.Cmd.Env = exec.Setenv(child.Cmd.Env, "NAMESPACE_ROOT", mtName)
 	child.Cmd.Env = exec.Setenv(child.Cmd.Env, "VEYRON_IDENTITY", idFile)
 	child.Cmd.Env = exec.Setenv(child.Cmd.Env, impl.ORIGIN_ENV, "ar")
 	child.Cmd.Env = exec.Setenv(child.Cmd.Env, impl.ROOT_ENV, root)
diff --git a/services/wspr/wsprd/lib/wspr.go b/services/wspr/wsprd/lib/wspr.go
index e01021a..4251ed9 100644
--- a/services/wspr/wsprd/lib/wspr.go
+++ b/services/wspr/wsprd/lib/wspr.go
@@ -439,7 +439,7 @@
 
 // Upon first connect, we send a message with the wsprConfig.
 func (wsp *websocketPipe) sendInitialMessage() {
-	mounttableRoots := strings.Split(os.Getenv("MOUNTTABLE_ROOT"), ",")
+	mounttableRoots := strings.Split(os.Getenv("NAMESPACE_ROOT"), ",")
 	if len(mounttableRoots) == 1 && mounttableRoots[0] == "" {
 		mounttableRoots = []string{}
 	}
diff --git a/tools/naming/simulator/mt.scr b/tools/naming/simulator/mt.scr
index 4ebbb1a..cdb8b07 100644
--- a/tools/naming/simulator/mt.scr
+++ b/tools/naming/simulator/mt.scr
@@ -76,15 +76,12 @@
 # internal suffix (mt in the USA/UK trees, empty in the France tree) is
 # empty!!
 #
-# ls using the local MountTable on a rooted name doesn't seem to work either,
+# ls using the local namespace on a rooted name doesn't seem to work either,
 # thus making it impossible to see the whole name space without setting the
-# local MountTable's root which will clearly cause problems for concurrent
+# local namespace's root which will clearly cause problems for concurrent
 # clients.
 #
-# I find the distinction between the "local MountTable client" and
-# "remote MountTable or local MountTable server" awkward. Maybe we should
-# call the "local MountTable client" the "Resolver?".
-#
+
 
 
 
diff --git a/tools/playground/builder/vbuild.go b/tools/playground/builder/vbuild.go
index e53980d..42999b3 100644
--- a/tools/playground/builder/vbuild.go
+++ b/tools/playground/builder/vbuild.go
@@ -286,7 +286,7 @@
 			log.Fatal("mounttable died")
 		}
 		Log("mount at ", endpoint)
-		return os.Setenv("MOUNTTABLE_ROOT", endpoint)
+		return os.Setenv("NAMESPACE_ROOT", endpoint)
 	}
 	return err
 }