]> git.cworth.org Git - tar/blobdiff - gnu/save-cwd.c
Imported Upstream version 1.24
[tar] / gnu / save-cwd.c
index 6cb3c36bbe8dc7b71d01d42f8ade5652b93f59af..c6b6342999119818cdd84ccc43294f81039193f3 100644 (file)
@@ -33,6 +33,7 @@
 #include "chdir-long.h"
 #include "unistd--.h"
 #include "xgetcwd.h"
+#include "cloexec.h"
 
 #if GNULIB_FCNTL_SAFER
 # include "fcntl--.h"
@@ -77,7 +78,7 @@ save_cwd (struct saved_cwd *cwd)
 {
   cwd->name = NULL;
 
-  cwd->desc = open (".", O_RDONLY);
+  cwd->desc = open (".", O_SEARCH);
   if (!GNULIB_FCNTL_SAFER)
     cwd->desc = fd_safer (cwd->desc);
   if (cwd->desc < 0)
@@ -86,6 +87,7 @@ save_cwd (struct saved_cwd *cwd)
       return cwd->name ? 0 : -1;
     }
 
+  set_cloexec_flag (cwd->desc, true);
   return 0;
 }