clach04 committed 1dba091

Added retry logic to Windows (only) JAMSHELL file creation code.

We've seen problems with VMWare (ESX) virtual machines under Windows (2003 and 7) where the unlink of the sub batch file succeeded BUT file creation of the same file name fails with (errno=13) permission denied. Occurs on both single and multiple CPU machines, in each case Jam was being ran with number of jobs of 1 (-j1), i.e. not a parallel jam build. This appears to be some sort of odd race condition in VMWare/Windows, every time this happens the file delete was fine. Retry logic is simply try-five-times (but quit if failure is not access denied) with a small sleep.

The logic could be extended to a configurable retry and even a progressively longer sleep but this has not been needed yet.

Comments (0)

Files changed (1)

 	if( p && *p || strlen( string ) > MAXLINE || shell )
-	    FILE *f;
+	    FILE *f = NULL;
+	    int retry = 5;
 	    /* Write command to bat file. */
-	    f = fopen( cmdtab[ slot ].tempfile, "w" );
+	    while (f == NULL && retry-- >= 0)
+	    {
+	        f = fopen( cmdtab[ slot ].tempfile, "w" );
+	        if (f == NULL)
+	            if (errno == EACCES)
+	            {
+	                printf("Jam EACCES creating shell batch file, %s, retry %d sleep\n", cmdtab[ slot ].tempfile, retry);
+	                Sleep(100);
+	            }
+	            else
+	                break;
+	    }
 	    if (f == NULL)
 	        printf("Unable to open file %s for writing, errno = %d\n", cmdtab[ slot ].tempfile, errno);