veyron2: Panic if the user tries to use the runtime when it is not set.

Change-Id: I06a1d915c7e42a1fe3701f243054fc334db20153
diff --git a/runtimes/google/rt/rt.go b/runtimes/google/rt/rt.go
index 77f1258..c7bcafa 100644
--- a/runtimes/google/rt/rt.go
+++ b/runtimes/google/rt/rt.go
@@ -137,15 +137,16 @@
 		}
 	}
 
-	// This call to NewClient creates a client that is attached to the context used
-	// by the NewAgentPrincipal call in initSecurity. The context used by NewAgentPrincipal
-	// is incomplete and only works because the agent uses anonymous unix sockets and
+	// This call to NewClient creates a client that is used by the
+	// NewAgentPrincipal call in initSecurity. This client is incomplete
+	// and only works because the agent uses anonymous unix sockets and
 	// VCSecurityNone.
-	if rt.client, err = rt.NewClient(); err != nil {
+	client, err := rt.NewClient()
+	if err != nil {
 		return nil, fmt.Errorf("failed to create new client: %s", err)
 	}
 
-	if err := rt.initSecurity(handle, rt.flags.Credentials); err != nil {
+	if err := rt.initSecurity(handle, rt.flags.Credentials, client); err != nil {
 		return nil, fmt.Errorf("failed to init security: %s", err)
 	}
 
diff --git a/runtimes/google/rt/runtimex.go b/runtimes/google/rt/runtimex.go
index c2a5ac3..ff35b2d 100644
--- a/runtimes/google/rt/runtimex.go
+++ b/runtimes/google/rt/runtimex.go
@@ -166,16 +166,16 @@
 		return nil, nil, nil, err
 	}
 
-	// The client we attach here is incomplete (has a nil principal) and only works
+	// The client we create here is incomplete (has a nil principal) and only works
 	// because the agent uses anonymous unix sockets and VCSecurityNone.
 	// After security is initialized we will attach a real client.
-	ctx, _, err = r.SetNewClient(ctx)
+	_, client, err := r.SetNewClient(ctx)
 	if err != nil {
 		return nil, nil, nil, err
 	}
 
 	// Initialize security.
-	principal, err := initSecurity(ctx, handle, flags.Credentials)
+	principal, err := initSecurity(ctx, handle, flags.Credentials, client)
 	if err != nil {
 		return nil, nil, nil, err
 	}
diff --git a/runtimes/google/rt/security.go b/runtimes/google/rt/security.go
index 5f6a14d..1ea73f4 100644
--- a/runtimes/google/rt/security.go
+++ b/runtimes/google/rt/security.go
@@ -4,6 +4,7 @@
 	"os"
 	"syscall"
 
+	"v.io/core/veyron2/ipc"
 	"v.io/core/veyron2/security"
 
 	"v.io/core/veyron/lib/exec"
@@ -16,8 +17,8 @@
 	return rt.principal
 }
 
-func (rt *vrt) initSecurity(handle *exec.ChildHandle, credentials string) error {
-	if err := rt.setupPrincipal(handle, credentials); err != nil {
+func (rt *vrt) initSecurity(handle *exec.ChildHandle, credentials string, client ipc.Client) error {
+	if err := rt.setupPrincipal(handle, credentials, client); err != nil {
 		return err
 	}
 	stats.NewString("security/principal/key").Set(rt.principal.PublicKey().String())
@@ -26,7 +27,7 @@
 	return nil
 }
 
-func (rt *vrt) setupPrincipal(handle *exec.ChildHandle, credentials string) error {
+func (rt *vrt) setupPrincipal(handle *exec.ChildHandle, credentials string, client ipc.Client) error {
 	if rt.principal != nil {
 		return nil
 	}
@@ -34,7 +35,7 @@
 		return err
 	} else if fd >= 0 {
 		var err error
-		rt.principal, err = rt.connectToAgent(fd)
+		rt.principal, err = rt.connectToAgent(fd, client)
 		return err
 	}
 	if len(credentials) > 0 {
@@ -60,7 +61,7 @@
 	return vsecurity.InitDefaultBlessings(rt.principal, defaultBlessingName())
 }
 
-func (rt *vrt) connectToAgent(fd int) (security.Principal, error) {
+func (rt *vrt) connectToAgent(fd int, client ipc.Client) (security.Principal, error) {
 	// Dup the fd, so we can create multiple runtimes.
 	syscall.ForkLock.Lock()
 	newfd, err := syscall.Dup(fd)
@@ -71,5 +72,5 @@
 	if err != nil {
 		return nil, err
 	}
-	return agent.NewAgentPrincipal(rt.NewContext(), newfd)
+	return agent.NewAgentPrincipal(rt.NewContext(), newfd, client)
 }
diff --git a/runtimes/google/rt/securityx.go b/runtimes/google/rt/securityx.go
index 0c8ca3f..040ca83 100644
--- a/runtimes/google/rt/securityx.go
+++ b/runtimes/google/rt/securityx.go
@@ -8,6 +8,7 @@
 	"syscall"
 
 	"v.io/core/veyron2/context"
+	"v.io/core/veyron2/ipc"
 	"v.io/core/veyron2/mgmt"
 	"v.io/core/veyron2/security"
 
@@ -17,8 +18,8 @@
 	"v.io/core/veyron/security/agent"
 )
 
-func initSecurity(ctx *context.T, handle *exec.ChildHandle, credentials string) (security.Principal, error) {
-	principal, err := setupPrincipal(ctx, handle, credentials)
+func initSecurity(ctx *context.T, handle *exec.ChildHandle, credentials string, client ipc.Client) (security.Principal, error) {
+	principal, err := setupPrincipal(ctx, handle, credentials, client)
 	if err != nil {
 		return nil, err
 	}
@@ -30,7 +31,7 @@
 	return principal, nil
 }
 
-func setupPrincipal(ctx *context.T, handle *exec.ChildHandle, credentials string) (security.Principal, error) {
+func setupPrincipal(ctx *context.T, handle *exec.ChildHandle, credentials string, client ipc.Client) (security.Principal, error) {
 	var err error
 	var principal security.Principal
 	if principal, _ = ctx.Value(principalKey).(security.Principal); principal != nil {
@@ -39,7 +40,7 @@
 	if fd, err := agentFD(handle); err != nil {
 		return nil, err
 	} else if fd >= 0 {
-		return agent.NewAgentPrincipal(ctx, fd)
+		return agent.NewAgentPrincipal(ctx, fd, client)
 	}
 	if len(credentials) > 0 {
 		// TODO(ataly, ashankar): If multiple runtimes are getting