haskell / file-io

File IO (read/write/open) for OsPath API
11 stars 4 forks source link

Should O_CLOEXEC be set on POSIX? #21

Closed Rufflewind closed 4 months ago

Rufflewind commented 5 months ago

Another diff observed while trying to migrate directory to file-io (https://github.com/hasufell/file-io/issues/4#issue-1365527787):

Should files opened by file-io set O_CLOEXEC to prevent them from being inherited by child processes?

hasufell commented 5 months ago

I think we discussed this already in https://github.com/hasufell/file-io/pull/5 and the verdict was that this library tries to stay as close to base behavior as possible.

You can use setCloseOnExec explicitly.

Rufflewind commented 4 months ago

You can use setCloseOnExec explicitly.

It isn't thread-safe since another thread can fork the executable between open and setCloseOnExec.

hasufell commented 4 months ago

We can provide a variant openFileWithCloseOnExec, possibly through a .Internal module.

Internal modules still follow PVP, but may not have deprecation periods.

Rufflewind commented 4 months ago

Sounds good.

hasufell commented 4 months ago

https://hackage.haskell.org/package/file-io-0.1.2/candidate

Rufflewind commented 4 months ago

Updated https://github.com/haskell/directory/pull/179 to use openFileWithCloseOnExec: https://github.com/haskell/directory/pull/179/files#diff-cc810a2a20a0b2c54800a706eb4890b14eff0d57b2777d520d64a0c73fa7f140R247

hasufell commented 3 months ago

Published it: https://hackage.haskell.org/package/file-io-0.1.2