diff --git a/lock_file_posix.go b/lock_file_posix.go index 095eabb..b4087b7 100644 --- a/lock_file_posix.go +++ b/lock_file_posix.go @@ -105,30 +105,6 @@ func (file *LockFile) Remove() error { return err } - name, err := GetFdName(file.Fd()) - if err != nil { - return err - } - - err = syscall.Unlink(name) + err := syscall.Unlink(file.Name()) return err } - -// GetFdName returns file name for given descriptor. -func GetFdName(fd uintptr) (name string, err error) { - path := fmt.Sprintf("/proc/self/fd/%d", int(fd)) - - var ( - fi os.FileInfo - n int - ) - if fi, err = os.Lstat(path); err != nil { - return - } - buf := make([]byte, fi.Size()+1) - - if n, err = syscall.Readlink(path, buf); err == nil { - name = string(buf[:n]) - } - return -} diff --git a/lock_file_test.go b/lock_file_test.go index bb5e1da..5d333dc 100644 --- a/lock_file_test.go +++ b/lock_file_test.go @@ -55,22 +55,6 @@ func TestNewLockFile(test *testing.T) { } } -func TestGetFdName(test *testing.T) { - name, err := GetFdName(0) - if err != nil { - test.Error(err) - } else { - if name != "/dev/null" { - test.Errorf("Filename of fd 0: `%s'", name) - } - } - - name, err = GetFdName(1011) - if err == nil { - test.Errorf("GetFdName(): Error was not detected on invalid fd, name: `%s'", name) - } -} - func TestReadPid(test *testing.T) { lock, err := CreatePidFile(filename, fileperm) if err != nil { @@ -118,6 +102,7 @@ func TestLockFileLock(test *testing.T) { if err != nil { test.Fatal(err) } + fmt.Print(msg) if msg != "locked" { test.Fatal("script can not lock file") }