veyron/lib/signals: Remove dependence on rt.R()

Change-Id: I451318d807336a157ee3b92cb85921f7f2ce02c4
diff --git a/lib/signals/signals.go b/lib/signals/signals.go
index e24e1c3..35d2965 100644
--- a/lib/signals/signals.go
+++ b/lib/signals/signals.go
@@ -5,7 +5,7 @@
 	"os/signal"
 	"syscall"
 
-	"veyron.io/veyron/veyron2/rt"
+	"veyron.io/veyron/veyron2"
 )
 
 type stopSignal string
@@ -31,7 +31,7 @@
 // none are specified, the default signals.  The first signal received will be
 // made available on the returned channel; upon receiving a second signal, the
 // process will exit.
-func ShutdownOnSignals(signals ...os.Signal) <-chan os.Signal {
+func ShutdownOnSignals(runtime veyron2.Runtime, signals ...os.Signal) <-chan os.Signal {
 	if len(signals) == 0 {
 		signals = defaultSignals()
 	}
@@ -45,9 +45,9 @@
 		case STOP:
 			if !sawStop {
 				sawStop = true
-				if r := rt.R(); r != nil {
+				if runtime != nil {
 					stopWaiter := make(chan string, 1)
-					r.AppCycle().WaitForStop(stopWaiter)
+					runtime.AppCycle().WaitForStop(stopWaiter)
 					go func() {
 						for {
 							ch <- stopSignal(<-stopWaiter)
diff --git a/lib/signals/signals_test.go b/lib/signals/signals_test.go
index e48e373..4220712 100644
--- a/lib/signals/signals_test.go
+++ b/lib/signals/signals_test.go
@@ -41,7 +41,7 @@
 	modules.RegisterChild("handleDefaultsIgnoreChan", "", handleDefaultsIgnoreChan)
 }
 
-func stopLoop(stdin io.Reader, ch chan<- struct{}) {
+func stopLoop(runtime veyron2.Runtime, stdin io.Reader, ch chan<- struct{}) {
 	scanner := bufio.NewScanner(stdin)
 	for scanner.Scan() {
 		switch scanner.Text() {
@@ -49,19 +49,23 @@
 			close(ch)
 			return
 		case "stop":
-			rt.R().AppCycle().Stop()
+			runtime.AppCycle().Stop()
 		}
 	}
 }
 
 func program(stdin io.Reader, stdout io.Writer, signals ...os.Signal) {
-	r := rt.Init()
+	runtime, err := rt.New()
+	if err != nil {
+		panic(err)
+	}
+
 	closeStopLoop := make(chan struct{})
-	go stopLoop(stdin, closeStopLoop)
-	wait := ShutdownOnSignals(signals...)
+	go stopLoop(runtime, stdin, closeStopLoop)
+	wait := ShutdownOnSignals(runtime, signals...)
 	fmt.Fprintf(stdout, "ready\n")
 	fmt.Fprintf(stdout, "received signal %s\n", <-wait)
-	r.Cleanup()
+	runtime.Cleanup()
 	<-closeStopLoop
 }
 
@@ -81,10 +85,14 @@
 }
 
 func handleDefaultsIgnoreChan(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
-	defer rt.Init().Cleanup()
+	runtime, err := rt.New()
+	if err != nil {
+		panic(err)
+	}
+	defer runtime.Cleanup()
 	closeStopLoop := make(chan struct{})
-	go stopLoop(stdin, closeStopLoop)
-	ShutdownOnSignals()
+	go stopLoop(runtime, stdin, closeStopLoop)
+	ShutdownOnSignals(runtime)
 	fmt.Fprintf(stdout, "ready\n")
 	<-closeStopLoop
 	return nil
@@ -287,7 +295,7 @@
 // the input list of signals.
 func TestParseSignalsList(t *testing.T) {
 	list := []os.Signal{STOP, syscall.SIGTERM}
-	ShutdownOnSignals(list...)
+	ShutdownOnSignals(nil, list...)
 	if !isSignalInSet(syscall.SIGTERM, list) {
 		t.Errorf("signal %s not in signal set, as expected: %v", syscall.SIGTERM, list)
 	}
@@ -309,8 +317,8 @@
 
 }
 
-func createConfigServer(t *testing.T) (ipc.Server, string, <-chan string) {
-	server, err := rt.R().NewServer()
+func createConfigServer(t *testing.T, runtime veyron2.Runtime) (ipc.Server, string, <-chan string) {
+	server, err := runtime.NewServer()
 	if err != nil {
 		t.Fatalf("Got error: %v", err)
 	}
@@ -328,8 +336,11 @@
 
 // TestCleanRemoteShutdown verifies that remote shutdown works correctly.
 func TestCleanRemoteShutdown(t *testing.T) {
-	r := rt.Init()
-	defer r.Cleanup()
+	runtime, err := rt.New()
+	if err != nil {
+		panic(err)
+	}
+	defer runtime.Cleanup()
 
 	sh, err := modules.NewShell(nil)
 	if err != nil {
@@ -339,9 +350,9 @@
 
 	// Set the child process up with a blessing from the parent so that
 	// the default authorization works for RPCs between the two.
-	childcreds := security.NewVeyronCredentials(r.Principal(), "child")
+	childcreds := security.NewVeyronCredentials(runtime.Principal(), "child")
 	defer os.RemoveAll(childcreds)
-	configServer, configServiceName, ch := createConfigServer(t)
+	configServer, configServiceName, ch := createConfigServer(t, runtime)
 	defer configServer.Stop()
 	sh.SetVar(consts.VeyronCredentials, childcreds)
 	sh.SetConfigKey(mgmt.ParentNameConfigKey, configServiceName)
@@ -355,7 +366,7 @@
 	appCycleName := <-ch
 	s.Expect("ready")
 	appCycle := appcycle.AppCycleClient(appCycleName)
-	stream, err := appCycle.Stop(r.NewContext())
+	stream, err := appCycle.Stop(runtime.NewContext())
 	if err != nil {
 		t.Fatalf("Got error: %v", err)
 	}