d90a25cdc313ad3752c2ab1a4de417ccb6622032
markd
  Fri May 22 20:23:15 2015 -0700
fixed race condition on hgsql purging temporary files that caused errors when mulitple hgsql commands were run at the same thing.  This is why /tmp was invented (no redmine)

diff --git src/hg/lib/sqlProg.c src/hg/lib/sqlProg.c
index 0740353..dcadd13 100644
--- src/hg/lib/sqlProg.c
+++ src/hg/lib/sqlProg.c
@@ -167,42 +167,44 @@
 void sqlExecProgLocal(char *prog, char **progArgs, int userArgc, char *userArgv[])
 /* 
  * Exec one of the sql programs using user and password defined in localDb.XXX variables from ~/.hg.conf 
  * progArgs is NULL-terminate array of program-specific arguments to add,
  * which maybe NULL. userArgv are arguments passed in from the command line.
  * The program is execvp-ed, this function does not return. 
  */
 {
 sqlExecProgProfile("localDb", prog, progArgs, userArgc, userArgv);
 }
 
 
 void nukeOldCnfs(char *homeDir)
 /* Remove .hgsql.cnf-* files older than a month */
 {
-struct fileInfo *file, *fileList = listDirX(homeDir, ".hgsql.cnf-*", FALSE);
+// ignoreStatFailures must be TRUE due to race condition between two hgsql
+// commands might trying to purge the same file.
+struct fileInfo *file, *fileList = listDirXExt(homeDir, ".hgsql.cnf-*", FALSE, TRUE);
 time_t now = time(0);
 for (file = fileList; file != NULL; file = file->next)
     {
-    if (difftime(now, file->lastAccess) >  30 * 24 * 60 * 60)  // 30 days in seconds.
+    if ((file->statErrno == 0) && (difftime(now, file->lastAccess) >  30 * 24 * 60 * 60))  // 30 days in seconds.
 	{
 	char homePath[256];
 	safef(homePath, sizeof homePath, "%s/%s", homeDir, file->name);
 	remove(homePath);
 	}
     }
-
+slFreeList(&fileList);
 }
 
 void sqlExecProgProfile(char *profile, char *prog, char **progArgs, int userArgc, char *userArgv[])
 /* 
  * Exec one of the sql programs using user and password defined in localDb.XXX variables from ~/.hg.conf 
  * progArgs is NULL-terminate array of program-specific arguments to add,
  * which maybe NULL. userArgv are arguments passed in from the command line.
  * The program is execvp-ed, this function does not return. 
  */
 {
 int i, j = 0, nargc=cntArgv(progArgs)+userArgc+6, defaultFileNo, returnStatus;
 pid_t child_id;
 char **nargv, defaultFileName[256], defaultFileArg[256], *homeDir;
 
 // install cleanup signal handlers