b884446cb0720217e7cdcfa7aa3e061d76fe9f18
markd
  Wed Feb 8 20:22:49 2017 -0800
allow trackDb make update and alpha to use multiple cores with the make -j option.  This required hgTrackDb and hgFindSpec to have unique, temporary tab files

diff --git src/lib/osunix.c src/lib/osunix.c
index dbc3ee5..58f134e 100644
--- src/lib/osunix.c
+++ src/lib/osunix.c
@@ -331,30 +331,58 @@
 int pid = getpid();
 int num = time(NULL)&0xFFFFF;
 char host[512];
 strcpy(host, getHost());
 char *s = strchr(host, '.');
 if (s != NULL)
      *s = 0;
 subChar(host, '-', '_');
 subChar(host, ':', '_');
 static char name[PATH_LEN];
 safef(name, sizeof(name), "%s_%s_%x_%x",
 	base, host, pid, num);
 return name;
 }
 
+char *getTempDir(void)
+/* get temporary directory to use for programs.  This first checks TMPDIR environment
+ * variable, then /data/tmp, /scratch/tmp, /var/tmp, /tmp.  Return is static and
+ * only set of first call */
+{
+static char *checkTmpDirs[] = {"/data/tmp", "/scratch/tmp", "/var/tmp", "/tmp", NULL};
+
+static char* tmpDir = NULL;
+if (tmpDir == NULL)
+    {
+    tmpDir = getenv("TMPDIR");
+    if (tmpDir != NULL)
+        tmpDir = cloneString(tmpDir);  // make sure it's stable
+    else
+        {
+        int i;
+        for (i = 0; (checkTmpDirs[i] != NULL) && (tmpDir == NULL); i++)
+            {
+            if (fileSize(checkTmpDirs[i]) >= 0)
+                tmpDir = checkTmpDirs[i];
+            }
+        }
+    }
+if (tmpDir == NULL)
+    errAbort("BUG: can't find a tmp directory");
+return tmpDir;
+}
+
 char *rTempName(char *dir, char *base, char *suffix)
 /* Make a temp name that's almost certainly unique. */
 {
 char *x;
 static char fileName[PATH_LEN];
 int i;
 char *lastSlash = (lastChar(dir) == '/' ? "" : "/");
 for (i=0;;++i)
     {
     x = semiUniqName(base);
     safef(fileName, sizeof(fileName), "%s%s%s%d%s",
     	dir, lastSlash, x, i, suffix);
     if (!fileExists(fileName))
         break;
     }