Split out process check as separate function.

This will allow the checks to be changed for different operating systems.

Issue #260 is related to this, but this does not change any current behaviour.
This commit is contained in:
Klaus Post 2015-08-16 15:30:36 +02:00
parent 347e800b4e
commit 35bd8f80c0
3 changed files with 43 additions and 15 deletions

View file

@ -3,8 +3,12 @@
package restic
import (
"os"
"os/user"
"strconv"
"syscall"
"github.com/restic/restic/debug"
)
// uidGidInt returns uid, gid of the user as a number.
@ -22,3 +26,23 @@ func uidGidInt(u user.User) (uid, gid uint32, err error) {
gid = uint32(gi)
return
}
// checkProcess will check if the process retaining the lock
// exists and responds to SIGHUP signal.
// Returns true if the process exists and responds.
func (l Lock) processExists() bool {
proc, err := os.FindProcess(l.PID)
if err != nil {
debug.Log("Lock.Stale", "error searching for process %d: %v\n", l.PID, err)
return false
}
defer proc.Release()
debug.Log("Lock.Stale", "sending SIGHUP to process %d\n", l.PID)
err = proc.Signal(syscall.SIGHUP)
if err != nil {
debug.Log("Lock.Stale", "signal error: %v, lock is probably stale\n", err)
return false
}
return true
}