2015-08-16 11:16:02 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package restic
|
|
|
|
|
|
|
|
import (
|
2015-08-16 13:30:36 +00:00
|
|
|
"os"
|
2015-08-16 11:16:02 +00:00
|
|
|
"os/user"
|
|
|
|
"strconv"
|
2015-08-16 13:30:36 +00:00
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/restic/restic/debug"
|
2015-08-16 11:16:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// uidGidInt returns uid, gid of the user as a number.
|
|
|
|
func uidGidInt(u user.User) (uid, gid uint32, err error) {
|
2015-08-16 11:36:21 +00:00
|
|
|
var ui, gi int64
|
2015-08-16 11:16:02 +00:00
|
|
|
ui, err = strconv.ParseInt(u.Uid, 10, 32)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
gi, err = strconv.ParseInt(u.Gid, 10, 32)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
uid = uint32(ui)
|
|
|
|
gid = uint32(gi)
|
|
|
|
return
|
|
|
|
}
|
2015-08-16 13:30:36 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|