veyron/security/agent/agentd: Fix missing panic
Refactor main() such that os.Exit is not called from a deferred
function, which caused the output of panic() to be suppressed.
Change-Id: I9fc55815f4312e0bfba8fbca84a95b83c4139b44
diff --git a/security/agent/agentd/main.go b/security/agent/agentd/main.go
index ec7babd..58ab4d6 100644
--- a/security/agent/agentd/main.go
+++ b/security/agent/agentd/main.go
@@ -35,6 +35,10 @@
)
func main() {
+ os.Exit(Main())
+}
+
+func Main() int {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, `Usage: %s [agent options] command command_args...
@@ -45,23 +49,17 @@
`, os.Args[0], consts.VeyronCredentials)
flag.PrintDefaults()
}
- exitCode := 0
- defer func() {
- os.Exit(exitCode)
- }()
flag.Parse()
if len(flag.Args()) < 1 {
fmt.Fprintln(os.Stderr, "Need at least one argument.")
flag.Usage()
- exitCode = 1
- return
+ return 1
}
var restartOpts restartOptions
if err := restartOpts.parse(); err != nil {
fmt.Fprintln(os.Stderr, err)
flag.Usage()
- exitCode = 1
- return
+ return 1
}
dir := flag.Lookup("veyron.credentials").Value.String()
@@ -107,6 +105,7 @@
}
}
+ exitCode := 0
for {
// Run the client and wait for it to finish.
cmd := exec.Command(flag.Args()[0], flag.Args()[1:]...)
@@ -148,6 +147,7 @@
// right after cmd.Start().
sock.Close()
mgrSock.Close()
+ return exitCode
}
func newPrincipalFromDir(dir string) (security.Principal, []byte, error) {