syscallcompat: Fix Fchownat syscall wrapper on darwin

* Acquire the lock before reading the current directory
* Fix a file descriptor leak
This commit is contained in:
Sebastian Lackner 2017-11-28 00:11:15 +01:00 committed by rfjakob
parent 72b975867a
commit 8c5069c637

View File

@ -134,12 +134,13 @@ func Dup3(oldfd int, newfd int, flags int) (err error) {
// Poor man's Fchownat. // Poor man's Fchownat.
func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) { func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) {
chdirMutex.Lock()
defer chdirMutex.Unlock()
cwd, err := syscall.Open(".", syscall.O_RDONLY, 0) cwd, err := syscall.Open(".", syscall.O_RDONLY, 0)
if err != nil { if err != nil {
return err return err
} }
chdirMutex.Lock() defer syscall.Close(cwd)
defer chdirMutex.Unlock()
err = syscall.Fchdir(dirfd) err = syscall.Fchdir(dirfd)
if err != nil { if err != nil {
return err return err