github.com/fawick/restic@v0.1.1-0.20171126184616-c02923fbfc79/internal/restic/lock_unix.go (about) 1 // +build !windows 2 3 package restic 4 5 import ( 6 "os" 7 "os/user" 8 "strconv" 9 "syscall" 10 11 "github.com/restic/restic/internal/errors" 12 13 "github.com/restic/restic/internal/debug" 14 ) 15 16 // uidGidInt returns uid, gid of the user as a number. 17 func uidGidInt(u user.User) (uid, gid uint32, err error) { 18 var ui, gi int64 19 ui, err = strconv.ParseInt(u.Uid, 10, 32) 20 if err != nil { 21 return uid, gid, errors.Wrap(err, "ParseInt") 22 } 23 gi, err = strconv.ParseInt(u.Gid, 10, 32) 24 if err != nil { 25 return uid, gid, errors.Wrap(err, "ParseInt") 26 } 27 uid = uint32(ui) 28 gid = uint32(gi) 29 return 30 } 31 32 // checkProcess will check if the process retaining the lock 33 // exists and responds to SIGHUP signal. 34 // Returns true if the process exists and responds. 35 func (l Lock) processExists() bool { 36 proc, err := os.FindProcess(l.PID) 37 if err != nil { 38 debug.Log("error searching for process %d: %v\n", l.PID, err) 39 return false 40 } 41 defer proc.Release() 42 43 debug.Log("sending SIGHUP to process %d\n", l.PID) 44 err = proc.Signal(syscall.SIGHUP) 45 if err != nil { 46 debug.Log("signal error: %v, lock is probably stale\n", err) 47 return false 48 } 49 return true 50 }