save-cwd: don't leak a file descriptor when the caller execs
authorJames Youngman <jay@gnu.org>
Mon, 29 Mar 2010 10:30:23 +0000 (12:30 +0200)
committerJim Meyering <meyering@redhat.com>
Mon, 29 Mar 2010 10:30:32 +0000 (12:30 +0200)
* lib/save-cwd.c (save_cwd): set the close-on-exec flag for the
saved file descriptor.
* modules/save-cwd (Depends-on): Depend on cloexec.

ChangeLog
lib/save-cwd.c
modules/save-cwd

index b863db0d9bc18717f952176cd4af33383df4e514..b6f1dc11e5a7a5f8aaa3b903ae1cb92d3834fef5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-03-28  James Youngman  <jay@gnu.org>
+
+       save-cwd: don't leak a file descriptor when the caller execs.
+       * lib/save-cwd.c (save_cwd): set the close-on-exec flag for the
+       saved file descriptor.
+       * modules/save-cwd (Depends-on): Depend on cloexec.
+
 2010-03-29  Bruno Haible  <bruno@clisp.org>
 
        Remove vestiges of fts-lgpl module.
index 7394d50acce33b67a4b6351552d79ba7c799370e..cf43a355006b92c55e05dd40570e1d6b262990a2 100644 (file)
@@ -31,6 +31,7 @@
 #include "chdir-long.h"
 #include "unistd--.h"
 #include "xgetcwd.h"
+#include "cloexec.h"
 
 #if GNULIB_FCNTL_SAFER
 # include "fcntl--.h"
@@ -84,6 +85,7 @@ save_cwd (struct saved_cwd *cwd)
       return cwd->name ? 0 : -1;
     }
 
+  set_cloexec_flag (cwd->desc, true);
   return 0;
 }
 
index 46a1276abd217dff48bc70bc593a436a9c187b36..aab5e5ef49b9294e878cf49977e5c51eb02f7a02 100644 (file)
@@ -8,6 +8,7 @@ m4/save-cwd.m4
 
 Depends-on:
 chdir-long
+cloexec
 stdbool
 unistd-safer
 xgetcwd