diff options
author | Valery Piashchynski <[email protected]> | 2021-04-19 00:00:41 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-04-19 00:00:41 +0300 |
commit | 112b7b60bbc045f4935e1766be9d2266abf68b31 (patch) | |
tree | dac0b683ced9dd4b97db8d24dedafbea079699e9 /plugins/service | |
parent | 4931146022a644a69e73f241e094966bdb5cb51f (diff) |
- Fix gosimple warnings
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/service')
-rw-r--r-- | plugins/service/process.go | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/plugins/service/process.go b/plugins/service/process.go index 040f88e0..06d0b4c2 100644 --- a/plugins/service/process.go +++ b/plugins/service/process.go @@ -19,12 +19,12 @@ type Process struct { // command to execute command *exec.Cmd // rawCmd from the plugin - rawCmd string + rawCmd string // root plugin error chan errCh chan error // logger - log logger.Logger + log logger.Logger ExecTimeout time.Duration RestartAfterExit bool @@ -111,37 +111,34 @@ func (p *Process) stop() { func (p *Process) execHandler() { tt := time.NewTicker(time.Second) - for { - select { - case <-tt.C: - // lock here, because p.startTime could be changed during the check - p.Lock() - // if the exec timeout is set - if p.ExecTimeout != 0 { - // if stopped -> kill the process (SIGINT-> SIGKILL) and exit - if atomic.CompareAndSwapUint64(&p.stopped, 1, 1) { - err := p.command.Process.Signal(syscall.SIGINT) - if err != nil { - _ = p.command.Process.Signal(syscall.SIGKILL) - } - tt.Stop() - p.Unlock() - return + for range tt.C { + // lock here, because p.startTime could be changed during the check + p.Lock() + // if the exec timeout is set + if p.ExecTimeout != 0 { + // if stopped -> kill the process (SIGINT-> SIGKILL) and exit + if atomic.CompareAndSwapUint64(&p.stopped, 1, 1) { + err := p.command.Process.Signal(syscall.SIGINT) + if err != nil { + _ = p.command.Process.Signal(syscall.SIGKILL) } + tt.Stop() + p.Unlock() + return + } - // check the running time for the script - if time.Now().After(p.startTime.Add(p.ExecTimeout)) { - err := p.command.Process.Signal(syscall.SIGINT) - if err != nil { - _ = p.command.Process.Signal(syscall.SIGKILL) - } - p.Unlock() - tt.Stop() - return + // check the running time for the script + if time.Now().After(p.startTime.Add(p.ExecTimeout)) { + err := p.command.Process.Signal(syscall.SIGINT) + if err != nil { + _ = p.command.Process.Signal(syscall.SIGKILL) } + p.Unlock() + tt.Stop() + return } - p.Unlock() } + p.Unlock() } } |