OSDN Git Service

Default xcreate/xopen to O_CLOEXEC. (Pass O_CLOEXEC in the flags to switch it back...
authorRob Landley <rob@landley.net>
Sat, 26 Jul 2014 18:27:07 +0000 (13:27 -0500)
committerRob Landley <rob@landley.net>
Sat, 26 Jul 2014 18:27:07 +0000 (13:27 -0500)
This way we're not leaking filehandles to children from things like find -exec.

lib/dirtree.c
lib/xwrap.c

index 85b1a3c..7ad699e 100644 (file)
@@ -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);
     }
index 583a4ca..4516250 100644 (file)
@@ -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;
 }