2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-02 11:46:36 +00:00
restic/internal/lock_unix.go

51 lines
1.1 KiB
Go
Raw Normal View History

// +build !windows
package restic
import (
"os"
"os/user"
"strconv"
"syscall"
2017-07-23 12:21:03 +00:00
"github.com/restic/restic/internal/errors"
2016-08-29 19:38:34 +00:00
2017-07-23 12:21:03 +00:00
"github.com/restic/restic/internal/debug"
)
// 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
ui, err = strconv.ParseInt(u.Uid, 10, 32)
if err != nil {
2016-08-29 19:38:34 +00:00
return uid, gid, errors.Wrap(err, "ParseInt")
}
gi, err = strconv.ParseInt(u.Gid, 10, 32)
if err != nil {
2016-08-29 19:38:34 +00:00
return uid, gid, errors.Wrap(err, "ParseInt")
}
uid = uint32(ui)
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 {
2016-09-27 20:35:08 +00:00
debug.Log("error searching for process %d: %v\n", l.PID, err)
return false
}
defer proc.Release()
2016-09-27 20:35:08 +00:00
debug.Log("sending SIGHUP to process %d\n", l.PID)
err = proc.Signal(syscall.SIGHUP)
if err != nil {
2016-09-27 20:35:08 +00:00
debug.Log("signal error: %v, lock is probably stale\n", err)
return false
}
return true
}