]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR java/25330 (A race condition in write_classfile)
authorH.J. Lu <hongjiu.lu@intel.com>
Mon, 12 Dec 2005 15:27:43 +0000 (15:27 +0000)
committerH.J. Lu <hjl@gcc.gnu.org>
Mon, 12 Dec 2005 15:27:43 +0000 (07:27 -0800)
2005-12-12  H.J. Lu  <hongjiu.lu@intel.com>

PR java/25330
* jcf-write.c (write_classfile): Use PID in temporary class
file. Save/restore errno when reporting error.

From-SVN: r108411

gcc/java/ChangeLog
gcc/java/jcf-write.c

index 43859b71bbd47e3a31a66b7527c8144b400a9839..ec7f2ececb88c99e32bc34c9cb95849da178dc0c 100644 (file)
@@ -1,3 +1,9 @@
+2005-12-12  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR java/25330
+       * jcf-write.c (write_classfile): Use PID in temporary class
+       file. Save/restore errno when reporting error.
+
 2005-12-10  Terry Laurenzo  <tlaurenzo@gmail.com>
 
        PR java/9861
index 45764995143ab15451690b988e450f1cd111cd8a..caf57d1e8bc6ba5b3e7b8dbef1203a228f92bcea 100644 (file)
@@ -3522,11 +3522,15 @@ write_classfile (tree clas)
     {
       FILE *stream;
       char *temporary_file_name;
+      char pid [sizeof (long) * 2 + 2];
 
-      /* The .class file is initially written to a ".tmp" file so that
+      /* The .class file is initially written to a ".PID" file so that
         if multiple instances of the compiler are running at once
-        they do not see partially formed class files. */
-      temporary_file_name = concat (class_file_name, ".tmp", NULL);
+        they do not see partially formed class files nor override
+        each other, which may happen in libjava with parallel build.
+       */
+      sprintf (pid, ".%lx", (unsigned long) getpid ());
+      temporary_file_name = concat (class_file_name, pid, NULL);
       stream = fopen (temporary_file_name, "wb");
       if (stream == NULL)
        fatal_error ("can't open %s for writing: %m", temporary_file_name);
@@ -3548,7 +3552,9 @@ write_classfile (tree clas)
 
       if (rename (temporary_file_name, class_file_name) == -1)
        {
+         int errno_saved = errno;
          remove (temporary_file_name);
+         errno = errno_saved;
          fatal_error ("can't create %s: %m", class_file_name);
        }
       free (temporary_file_name);