mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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
1 changed files with 7 additions and 7 deletions
|
@ -465,8 +465,13 @@ func (d *Daemon) StopWithError() (err error) {
|
|||
d.log.Logf("[%s] error while stopping daemon: %v", d.id, err)
|
||||
} else {
|
||||
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
|
||||
}()
|
||||
|
||||
|
@ -519,12 +524,7 @@ out2:
|
|||
return err
|
||||
}
|
||||
|
||||
d.cmd.Wait()
|
||||
|
||||
if d.pidFile != "" {
|
||||
_ = os.Remove(d.pidFile)
|
||||
}
|
||||
return nil
|
||||
return d.cmd.Wait()
|
||||
}
|
||||
|
||||
// Restart will restart the daemon by first stopping it and the starting it.
|
||||
|
|
Loading…
Add table
Reference in a new issue