x/ref: reapply changes undone inadvertently by v.io/c/14672

Because of a bug in our tools
(https://groups.google.com/a/google.com/forum/#!topic/veyron-team/XCFJi84XWEw),
some changes got reverted by other changes that got submitted without syncing
with remote.

Change-Id: I8b9f2442f982dd318deb93fc2257854423e3cca4
diff --git a/runtime/internal/discovery/advertise.go b/runtime/internal/discovery/advertise.go
new file mode 100644
index 0000000..1422760
--- /dev/null
+++ b/runtime/internal/discovery/advertise.go
@@ -0,0 +1,16 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package discovery
+
+import (
+	"v.io/v23/context"
+	"v.io/v23/discovery"
+	"v.io/v23/security/access"
+)
+
+// Advertise implements discovery.Advertiser.
+func (ds *ds) Advertise(ctx *context.T, service discovery.Service, perms access.Permissions) error {
+	return nil
+}
diff --git a/runtime/internal/discovery/discovery.go b/runtime/internal/discovery/discovery.go
new file mode 100644
index 0000000..53501d7
--- /dev/null
+++ b/runtime/internal/discovery/discovery.go
@@ -0,0 +1,9 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package discovery
+
+// ds is an implementation of discovery.T.
+type ds struct {
+}
diff --git a/runtime/internal/discovery/plugin.go b/runtime/internal/discovery/plugin.go
new file mode 100644
index 0000000..c275d89
--- /dev/null
+++ b/runtime/internal/discovery/plugin.go
@@ -0,0 +1,9 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package discovery
+
+// Plugin is the basic interface for a plugin to discovery service.
+type Plugin interface {
+}
diff --git a/runtime/internal/discovery/scan.go b/runtime/internal/discovery/scan.go
new file mode 100644
index 0000000..f955326
--- /dev/null
+++ b/runtime/internal/discovery/scan.go
@@ -0,0 +1,15 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package discovery
+
+import (
+	"v.io/v23/context"
+	"v.io/v23/discovery"
+)
+
+// Scan implements discovery.Scanner.
+func (ds *ds) Scan(ctx *context.T, query string) (<-chan discovery.Update, error) {
+	return nil, nil
+}
diff --git a/services/device/mgmt_v23_test.go b/services/device/mgmt_v23_test.go
index 23345a4..70593ad 100644
--- a/services/device/mgmt_v23_test.go
+++ b/services/device/mgmt_v23_test.go
@@ -39,6 +39,7 @@
 	"errors"
 	"flag"
 	"fmt"
+	"io"
 	"io/ioutil"
 	"math/rand"
 	"os"
@@ -46,6 +47,7 @@
 	"path/filepath"
 	"regexp"
 	"strings"
+	"sync"
 	"time"
 
 	"v.io/x/ref"
@@ -102,7 +104,6 @@
 
 func testCore(i *v23tests.T, appUser, deviceUser string, withSuid bool) {
 	defer fmt.Fprintf(os.Stderr, "--------------- SHUTDOWN ---------------\n")
-	userFlag := "--single_user"
 	tempDir := ""
 
 	if withSuid {
@@ -214,7 +215,7 @@
 	if withSuid {
 		deviceScriptArguments = append(deviceScriptArguments, "--devuser="+deviceUser)
 	} else {
-		deviceScriptArguments = append(deviceScriptArguments, userFlag)
+		deviceScriptArguments = append(deviceScriptArguments, "--single_user")
 	}
 
 	deviceScriptArguments = append(deviceScriptArguments, []string{
@@ -226,9 +227,24 @@
 
 	deviceScript.Start(deviceScriptArguments...).WaitOrDie(os.Stdout, os.Stderr)
 	deviceScript.Start("start").WaitOrDie(os.Stdout, os.Stderr)
+	dmLog := filepath.Join(dmInstallDir, "dmroot/device-manager/logs/deviced.INFO")
+	stopDevMgr := func() {
+		deviceScript.Run("stop")
+		if dmLogF, err := os.Open(dmLog); err != nil {
+			i.Errorf("Failed to read dm log: %v", err)
+		} else {
+			fmt.Fprintf(os.Stderr, "--------------- START DM LOG ---------------\n")
+			defer dmLogF.Close()
+			if _, err := io.Copy(os.Stderr, dmLogF); err != nil {
+				i.Errorf("Error dumping dm log: %v", err)
+			}
+			fmt.Fprintf(os.Stderr, "--------------- END DM LOG ---------------\n")
+		}
+	}
+	var stopDevMgrOnce sync.Once
+	defer stopDevMgrOnce.Do(stopDevMgr)
 	// Grab the endpoint for the claimable service from the device manager's
 	// log.
-	dmLog := filepath.Join(dmInstallDir, "dmroot/device-manager/logs/deviced.INFO")
 	var claimableEP string
 	expiry := time.Now().Add(30 * time.Second)
 	for {
@@ -496,7 +512,7 @@
 	mtEP = resolveChange(mtName, mtEP)
 
 	// Shut down the device manager.
-	deviceScript.Run("stop")
+	stopDevMgrOnce.Do(stopDevMgr)
 
 	// Wait for the mounttable entry to go away.
 	resolveGone := func(name string) string {