diff --git a/cmd/certspotter/main.go b/cmd/certspotter/main.go index 9f6de1f..34ba4eb 100644 --- a/cmd/certspotter/main.go +++ b/cmd/certspotter/main.go @@ -190,5 +190,5 @@ func main() { } } - cmd.Main(*stateDir, processEntry) + os.Exit(cmd.Main(*stateDir, processEntry)) } diff --git a/cmd/common.go b/cmd/common.go index 7f9aa37..a5379f1 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -122,7 +122,7 @@ func saveEvidence (logUri string, firstSTH *ct.SignedTreeHead, secondSTH *ct.Sig return firstFilename, secondFilename, proofFilename, nil } -func Main (argStateDir string, processCallback certspotter.ProcessCallback) { +func Main (argStateDir string, processCallback certspotter.ProcessCallback) int { stateDir = argStateDir var logs []certspotter.LogInfo @@ -130,13 +130,13 @@ func Main (argStateDir string, processCallback certspotter.ProcessCallback) { logFile, err := os.Open(*logsFilename) if err != nil { fmt.Fprintf(os.Stderr, "%s: Error opening logs file for reading: %s: %s\n", os.Args[0], *logsFilename, err) - os.Exit(1) + return 1 } defer logFile.Close() var logFileObj certspotter.LogInfoFile if err := json.NewDecoder(logFile).Decode(&logFileObj); err != nil { fmt.Fprintf(os.Stderr, "%s: Error decoding logs file: %s: %s\n", os.Args[0], *logsFilename, err) - os.Exit(1) + return 1 } logs = logFileObj.Logs } else if *underwater { @@ -147,13 +147,13 @@ func Main (argStateDir string, processCallback certspotter.ProcessCallback) { if err := os.Mkdir(stateDir, 0777); err != nil && !os.IsExist(err) { fmt.Fprintf(os.Stderr, "%s: Error creating state directory: %s: %s\n", os.Args[0], stateDir, err) - os.Exit(1) + return 1 } for _, subdir := range []string{"certs", "sths", "evidence"} { path := filepath.Join(stateDir, subdir) if err := os.Mkdir(path, 0777); err != nil && !os.IsExist(err) { fmt.Fprintf(os.Stderr, "%s: Error creating state directory: %s: %s\n", os.Args[0], path, err) - os.Exit(1) + return 1 } } @@ -268,5 +268,5 @@ func Main (argStateDir string, processCallback certspotter.ProcessCallback) { } } - os.Exit(exitCode) + return exitCode } diff --git a/cmd/ctparsewatch/main.go b/cmd/ctparsewatch/main.go index a66fe9e..4a971ab 100644 --- a/cmd/ctparsewatch/main.go +++ b/cmd/ctparsewatch/main.go @@ -48,5 +48,5 @@ func processEntry (scanner *certspotter.Scanner, entry *ct.LogEntry) { func main() { flag.Parse() - cmd.Main(*stateDir, processEntry) + os.Exit(cmd.Main(*stateDir, processEntry)) }