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
1 changed files with 3 additions and 2 deletions

View File

@ -134,12 +134,13 @@ func Dup3(oldfd int, newfd int, flags int) (err error) {
// Poor man's Fchownat.
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)
if err != nil {
return err
}
chdirMutex.Lock()
defer chdirMutex.Unlock()
defer syscall.Close(cwd)
err = syscall.Fchdir(dirfd)
if err != nil {
return err