From 165c2ea23ee5424390c5e6809232c608dfd63769 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Sat, 9 Jun 2018 10:16:04 +0930 Subject: [PATCH] cmd/revid-cli: handle failure to start netsender --- cmd/revid-cli/main.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 824d5491..58205edb 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -31,6 +31,7 @@ import ( "errors" "flag" "fmt" + "os" "os/exec" "strconv" "strings" @@ -130,7 +131,7 @@ func main() { } // Do we want a netsender session - netSenderFlagPtr := flag.Bool("NetSender", false, "Are we checking vars through netsender?") + useNetsender := flag.Bool("NetSender", false, "Are we checking vars through netsender?") // User might also want to define how long revid runs for runDurationPtr := flag.Duration("runDuration", defaultRunDuration, "How long do you want revid to run for?") @@ -249,12 +250,17 @@ func main() { var ns netsender.Netsender var vs int - if *netSenderFlagPtr { + if *useNetsender { // initialize NetSender and use NetSender's logger config.Logger = netsender.GetLogger() - // FIXME(kortschak): Handle this error appropriately. - ns, _ = netsender.NewNetsender(false, revidReportActions) + var err error + ns, err = netsender.NewNetsender(false, revidReportActions) + if err != nil { + l := smartlogger.New(loggerVerbosity, smartlogger.File, "/var/log/netsender/") + l.Log(progName, "Error", err.Error()) // TODO(kortschak): Make this "Fatal" when that exists. + os.Exit(1) + } vs = ns.GetVarSum() } else { @@ -267,7 +273,7 @@ func main() { paused := false // loop in NetSender mode - for *netSenderFlagPtr { + for *useNetsender { if err := sendTo(ns); err != nil { config.Logger.Log(progName, "Error", err.Error()) time.Sleep(netSendRetryTime)