diff options
author | Rob Landley <rob@landley.net> | 2014-07-26 13:27:07 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2014-07-26 13:27:07 -0500 |
commit | ccb73f8bf9191c01c90975958a210c47175bd98c (patch) | |
tree | 135401e239d48af41faabf2fc484d05be1dbde71 | |
parent | dc62a012d7ce3e9a397e28022ab1fb6568a867c2 (diff) | |
download | toybox-ccb73f8bf9191c01c90975958a210c47175bd98c.tar.gz |
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.
-rw-r--r-- | lib/dirtree.c | 2 | ||||
-rw-r--r-- | lib/xwrap.c | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c index 85b1a3cf..7ad699e1 100644 --- a/lib/dirtree.c +++ b/lib/dirtree.c @@ -115,7 +115,7 @@ struct dirtree *dirtree_handle_callback(struct dirtree *new, 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); } diff --git a/lib/xwrap.c b/lib/xwrap.c index 583a4cae..4516250f 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -218,7 +218,7 @@ void xunlink(char *path) // 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; } |