Explorar o código

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>
Sebastiaan van Stijn %!s(int64=5) %!d(string=hai) anos
pai
achega
c56bfdf10a
Modificáronse 1 ficheiros con 7 adicións e 7 borrados
  1. 7 7
      testutil/daemon/daemon.go

+ 7 - 7
testutil/daemon/daemon.go

@@ -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()
-
-	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.
 // Restart will restart the daemon by first stopping it and the starting it.