testutil/daemon: always remove pidfile after daemon is stopped
If the daemon was stopped successfully in one of the retry-loops, the function would return early; ```go for { select { case err := <-d.Wait: ---> the function returns here, both on "success" and on "fail" return err case <-time.After(20 * time.Second): ... ``` In that case, the pidfile would not be cleaned up. This patch changes the function to clean-up the pidfile in a defer, so that it will always be removed after succesfully stopping the daemon. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
f6842327b0
commit
c56bfdf10a
|
@ -465,8 +465,13 @@ func (d *Daemon) StopWithError() (err error) {
|
||||||
d.log.Logf("[%s] error while stopping daemon: %v", d.id, err)
|
d.log.Logf("[%s] error while stopping daemon: %v", d.id, err)
|
||||||
} else {
|
} else {
|
||||||
d.log.Logf("[%s] daemon stopped", d.id)
|
d.log.Logf("[%s] daemon stopped", d.id)
|
||||||
|
if d.pidFile != "" {
|
||||||
|
_ = os.Remove(d.pidFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := d.logFile.Close(); err != nil {
|
||||||
|
d.log.Logf("[%s] failed to close daemon logfile: %v", d.id, err)
|
||||||
}
|
}
|
||||||
d.logFile.Close()
|
|
||||||
d.cmd = nil
|
d.cmd = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -519,12 +524,7 @@ out2:
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
d.cmd.Wait()
|
return d.cmd.Wait()
|
||||||
|
|
||||||
if d.pidFile != "" {
|
|
||||||
_ = os.Remove(d.pidFile)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restart will restart the daemon by first stopping it and the starting it.
|
// Restart will restart the daemon by first stopping it and the starting it.
|
||||||
|
|
Loading…
Reference in New Issue