This way we're not leaking filehandles to children from things like find -exec.
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);
}
// 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;
}