]> Savannah Git Hosting - gnulib.git/commitdiff
relocatable-prog: Make more robust in multithreaded applications.
authorBruno Haible <bruno@clisp.org>
Wed, 27 May 2020 18:35:39 +0000 (20:35 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 28 May 2020 19:40:26 +0000 (21:40 +0200)
* lib/progreloc.c (O_CLOEXEC): Define fallback to 0 when use from module
relocatable-prog-wrapper.
(find_executable): Pass an O_CLOEXEC flag to open().
* modules/relocatable-prog (Depends-on): Add 'open'.

ChangeLog
lib/progreloc.c
modules/relocatable-prog

index 916f9cf94502bb8e46b819ca9215d0dc03fd1cb5..e637b5772c6c7a638547f242241963fb27563785 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-05-28  Bruno Haible  <bruno@clisp.org>
+
+       relocatable-prog: Make more robust in multithreaded applications.
+       * lib/progreloc.c (O_CLOEXEC): Define fallback to 0 when use from module
+       relocatable-prog-wrapper.
+       (find_executable): Pass an O_CLOEXEC flag to open().
+       * modules/relocatable-prog (Depends-on): Add 'open'.
+
 2020-05-28  Bruno Haible  <bruno@clisp.org>
 
        getloadavg: Make more robust in multithreaded applications.
index 45be1ca5a4d6f18b66e28ba75ed6bdabf6046806..de00bf6333aededdd60cb7b20aa58c60954101e1 100644 (file)
 # define O_EXEC O_RDONLY /* This is often close enough in older systems.  */
 #endif
 
+#if defined IN_RELOCWRAPPER && (!defined O_CLOEXEC || GNULIB_defined_O_CLOEXEC)
+# undef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+
 /* Declare canonicalize_file_name.
    The <stdlib.h> included above may be the system's one, not the gnulib
    one.  */
@@ -242,7 +247,7 @@ find_executable (const char *argv0)
     if (link != NULL && link[0] != '[')
       return link;
     if (executable_fd < 0)
-      executable_fd = open ("/proc/self/exe", O_EXEC, 0);
+      executable_fd = open ("/proc/self/exe", O_EXEC | O_CLOEXEC, 0);
 
     {
       char buf[6+10+5];
@@ -251,7 +256,7 @@ find_executable (const char *argv0)
       if (link != NULL && link[0] != '[')
         return link;
       if (executable_fd < 0)
-        executable_fd = open (buf, O_EXEC, 0);
+        executable_fd = open (buf, O_EXEC | O_CLOEXEC, 0);
     }
   }
 # endif
@@ -298,7 +303,7 @@ find_executable (const char *argv0)
      the current directory.  */
   {
     char namebuf[4096];
-    int fd = open ("/proc/self/execname", O_RDONLY, 0);
+    int fd = open ("/proc/self/execname", O_RDONLY | O_CLOEXEC, 0);
     if (fd >= 0)
       {
         size_t len = full_read (fd, namebuf, sizeof (namebuf));
@@ -321,7 +326,7 @@ find_executable (const char *argv0)
     if (link != NULL)
       return link;
     if (executable_fd < 0)
-      executable_fd = open ("/proc/self/exe", O_EXEC, 0);
+      executable_fd = open ("/proc/self/exe", O_EXEC | O_CLOEXEC, 0);
   }
 # endif
 # if HAVE_MACH_O_DYLD_H && HAVE__NSGETEXECUTABLEPATH
index 4111665c339f1393dc6d0ca258207ee5a3ffaa7e..7e21682ecdf34f7ef17095f4cbe8fe4784c66d8b 100644 (file)
@@ -20,6 +20,7 @@ progname
 canonicalize-lgpl
 xalloc
 xreadlink
+open
 stdbool
 unistd
 memcmp