Mercurial > hg > toybox
changeset 1403:411cf82cdf77 draft
Default xcreate/xopen to O_CLOEXEC. (Pass O_CLOEXEC in the flags to switch it back off.)
This way we're not leaking filehandles to children from things like find -exec.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 26 Jul 2014 13:27:07 -0500 |
parents | dc254ac8a0e2 |
children | ffc7f606ce5b |
files | lib/dirtree.c lib/xwrap.c |
diffstat | 2 files changed, 2 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/dirtree.c Sat Jul 26 13:22:59 2014 -0500 +++ b/lib/dirtree.c Sat Jul 26 13:27:07 2014 -0500 @@ -115,7 +115,7 @@ if (dir) { if (flags & (DIRTREE_RECURSE|DIRTREE_COMEAGAIN)) { - new->data = openat(dirtree_parentfd(new), new->name, 0); + new->data = openat(dirtree_parentfd(new), new->name, O_CLOEXEC); dirtree_recurse(new, callback, flags & DIRTREE_SYMFOLLOW); if (flags & DIRTREE_COMEAGAIN) flags = callback(new); }
--- a/lib/xwrap.c Sat Jul 26 13:22:59 2014 -0500 +++ b/lib/xwrap.c Sat Jul 26 13:27:07 2014 -0500 @@ -218,7 +218,7 @@ // Die unless we can open/create a file, returning file descriptor. int xcreate(char *path, int flags, int mode) { - int fd = open(path, flags, mode); + int fd = open(path, flags^O_CLOEXEC, mode); if (fd == -1) perror_exit("%s", path); return fd; }