src/parasol/paraNode/paraNode.c 1.82

1.82 2009/11/21 01:07:58 markd
added option to allow setting arbitrary environment variable for jobs
Index: src/parasol/paraNode/paraNode.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/parasol/paraNode/paraNode.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -b -B -U 4 -r1.81 -r1.82
--- src/parasol/paraNode/paraNode.c	7 Jun 2008 09:59:56 -0000	1.81
+++ src/parasol/paraNode/paraNode.c	21 Nov 2009 01:07:58 -0000	1.82
@@ -26,8 +26,9 @@
     {"hub", OPTION_STRING},
     {"umask", OPTION_INT},
     {"userPath", OPTION_STRING},
     {"sysPath", OPTION_STRING},
+    {"env", OPTION_STRING|OPTION_MULTI},
     {"randomDelay", OPTION_INT},
     {"cpu", OPTION_INT},
     {"localhost", OPTION_STRING},
     {NULL, 0}
@@ -49,8 +50,9 @@
 	 "    -hub=host  Restrict access to connections from hub.\n"
 	 "    -umask=000  Set umask to run under - default 002.\n"
 	 "    -userPath=bin:bin/i386  User dirs to add to path.\n"
 	 "    -sysPath=/sbin:/local/bin  System dirs to add to path.\n"
+         "    -env=name=value - add environment variable to jobs.  Maybe repeated.\n"
 	 "    -randomDelay=N  Up to this many milliseconds of random delay before\n"
 	 "        starting a job.  This is mostly to avoid swamping NFS with\n"
 	 "        file opens when loading up an idle cluster.  Also it limits\n"
 	 "        the impact on the hub of very short jobs. Default 5000.\n"
@@ -66,8 +68,9 @@
 int umaskVal = 0002;		/* File creation mask. */
 int maxProcs = 1;		/* Number of processers allowed to use. */
 char *userPath = "";		/* User stuff to add to path. */
 char *sysPath = "";		/* System stuff to add to path. */
+struct slName *envExtra = NULL; /* Add to environment */ 
 int randomDelay = 5000;		/* How much to delay job startup. */
 
 /* Other globals. */
 char *hostName;			/* Name of this machine. */
@@ -287,8 +290,27 @@
 freez(&userPath);
 dyStringFree(&dy);
 }
 
+void addEnvExtra(struct hash *hash, char *nameVal)
+/* parse and add one of the environment extra entries */
+{
+char *eq = strchr(nameVal, '=');
+if (eq == NULL)
+    errAbort("invalid -env argument, expected -env=name=value, got -env=%s", nameVal);
+*eq = '\0';
+hashUpdate(hash, nameVal, eq+1);
+*eq = '=';
+}
+
+void addEnvExtras(struct hash *hash)
+/* add environment extras */
+{
+struct slName *nameVal;
+for (nameVal = envExtra; nameVal != NULL; nameVal = nameVal->next)
+    addEnvExtra(hash, nameVal->name);
+}
+
 void getTicksToHundreths()
 /* Return number of hundreths of seconds per system tick.
  * It used to be CLK_TCK would work for this, but
  * under recent Linux's it doesn't. */
@@ -367,8 +389,9 @@
 	hashUpdate(hash, "HOME", homeDir);
 	hashUpdate(hash, "HOST", hostName);
 	hashUpdate(hash, "PARASOL", "7");
 	updatePath(hash, userPath, homeDir, sysPath);
+        addEnvExtras(hash);
 	environ = hashToEnviron(hash);
 	freeHashAndVals(&hash);
 	}
 
@@ -839,8 +862,9 @@
 maxProcs = optionInt("cpu", 1);
 umaskVal = optionInt("umask", 0002);
 userPath = optionVal("userPath", userPath);
 sysPath = optionVal("sysPath", sysPath);
+envExtra = optionMultiVal("env", NULL);
 randomDelay = optionInt("randomDelay", randomDelay);
 
 /* Look up IP addresses. */
 localIp = lookupIp("localhost");