locks: fix testing stale locks created on other hosts

Closes #260
This commit is contained in:
Alexander Neumann
2015-08-16 16:24:04 +02:00
parent dc842ffa09
commit fbe746c261
2 changed files with 52 additions and 18 deletions

13
lock.go
View File

@@ -206,6 +206,19 @@ func (l *Lock) Stale() bool {
return true
}
hn, err := os.Hostname()
if err != nil {
debug.Log("Lock.Stale", "unable to find current hostnanme: %v", err)
// since we cannot find the current hostname, assume that the lock is
// not stale.
return false
}
if hn != l.Hostname {
// lock was created on a different host, assume the lock is not stale.
return false
}
proc, err := os.FindProcess(l.PID)
defer proc.Release()
if err != nil {