diff --git a/main.go b/main.go index 4286e3a..a4dae11 100644 --- a/main.go +++ b/main.go @@ -34,8 +34,8 @@ var ( type notifyType string const ( - DaemonStarted notifyType = "READY=1" - DaemonStopping notifyType = "STOPPING=1" + DaemonStarted =notifyType("READY=1") + DaemonStopping =notifyType("STOPPING=1") ) @@ -132,7 +132,7 @@ func CpuTempetureMonitoring(info *Processor, notifier chan<- TempetureChange, ct } } } -func CpuTempetureScraper(processorCount int, notifier <-chan TempetureChange, ctx context.Context, waiter *sync.WaitGroup) { +func CpuTempetureScraper(processorCount int, notifier <-chan TempetureChange,errorChan chan<- error, ctx context.Context, waiter *sync.WaitGroup) { waiter.Add(1) defer waiter.Done() pastFan := make([]int, processorCount) @@ -167,7 +167,8 @@ func CpuTempetureScraper(processorCount int, notifier <-chan TempetureChange, ct ) cmd := exec.Command("ipmitool", args...) if err := cmd.Run(); err != nil { - fmt.Printf(err.Error()) + errorChan <- err + return } case <-ctx.Done(): return @@ -181,6 +182,7 @@ func main() { ctx, canceled = context.WithCancel(context.Background()) waiter = &sync.WaitGroup{} exitSignal = make(chan os.Signal, 1) + errorChan = make(chan error, 1) tempetureChange = make(chan TempetureChange) ) @@ -188,7 +190,7 @@ func main() { info := getProcessorInfo(i) go CpuTempetureMonitoring(info, tempetureChange, ctx, waiter) } - go CpuTempetureScraper(processorCount, tempetureChange, ctx, waiter) + go CpuTempetureScraper(processorCount, tempetureChange,errorChan, ctx, waiter) defer waiter.Wait() signal.Notify(exitSignal, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) NotifyDaemon(DaemonStarted) @@ -198,10 +200,12 @@ func main() { case <-ctx.Done(): fmt.Println("Service request to close this application") return + case err:= <-errorChan: + canceled() + fmt.Printf("error! %s", error.Error()) case sysSignal := <-exitSignal: canceled() fmt.Printf("SYSCALL! %s", sysSignal.String()) - break } }