Skip to content

Commit

Permalink
Merge pull request snabbco#205 from lukego/close-fd-safely
Browse files Browse the repository at this point in the history
Add more protection against fd double-close
  • Loading branch information
justincormack authored Nov 26, 2016
2 parents c8baf9e + ad91aa9 commit 0b266e8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion syscall/syscalls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ local function retiter(ret, err, array)
end

-- generic system calls
function S.close(fd) return retbool(C.close(getfd(fd))) end
function S.close(fd)
if fd == getfd(fd) then -- fd number
return retbool(C.close(getfd(fd)))
else -- fd object: avoid mulitple close
return fd:close()
end
end
function S.chdir(path) return retbool(C.chdir(path)) end
function S.fchdir(fd) return retbool(C.fchdir(getfd(fd))) end
function S.fchmod(fd, mode) return retbool(C.fchmod(getfd(fd), c.MODE[mode])) end
Expand Down

0 comments on commit 0b266e8

Please sign in to comment.