e722802227fa7daf858238de5a1cad2531a9d469
kent
  Sat Dec 28 08:02:44 2013 -0800
Changing ownership of batch file to job owner.
diff --git src/parasol/paraHub/paraHub.c src/parasol/paraHub/paraHub.c
index fadbec6..14b70c0 100644
--- src/parasol/paraHub/paraHub.c
+++ src/parasol/paraHub/paraHub.c
@@ -1545,52 +1545,65 @@
 }
 
 
 void flushResults(char *batchName)
 /* Flush all results files. batchName can be NULL for all. */
 {
 struct resultQueue *rq;
 for (rq = resultQueues; rq != NULL; rq = rq->next)
     {
     if (!batchName || (rq->name == batchName))
 	if (rq->f != NULL)
 	   fflush(rq->f);
     }
 }
 
+void changeFileOwner(char *fileName, char *newOwner)
+/* Attempt to change ownership of file. */
+{
+struct passwd *pwd = getpwnam(newOwner);
+if (pwd == NULL)
+    {
+    perror("getpwnam");
+    return;
+    }
+if (chown(fileName, pwd->pw_uid, -1) == -1)
+    perror("chown");
+}
 
 void writeResults(char *fileName, char *userName, char *machineName,
 	int jobId, char *exe, time_t submitTime, time_t startTime,
 	char *errFile, char *cmd,
 	char *status, char *uTime, char *sTime)
 /* Write out job results to output queue.  This
  * will create the output queue if it doesn't yet
  * exist. */
 {
 struct resultQueue *rq;
 for (rq = resultQueues; rq != NULL; rq = rq->next)
     if (sameString(fileName, rq->name))
         break;
 if (rq == NULL)
     {
     AllocVar(rq);
     slAddHead(&resultQueues, rq);
     rq->name = fileName;
     rq->f = fopen(rq->name, "a");
     if (rq->f == NULL)
         warn("hub: couldn't open results file %s", rq->name);
     rq->lastUsed = now;
+    changeFileOwner(fileName, userName);
     }
 if (rq->f != NULL)
     {
     fprintf(rq->f, "%s %s %d %s %s %s %lu %lu %lu %s %s '%s'\n",
         status, machineName, jobId, exe, 
 	uTime, sTime, 
 	submitTime, startTime, now,
 	userName, errFile, cmd);
     fflush(rq->f);
     rq->lastUsed = now;
     }
 }
 
 void writeJobResults(struct job *job, char *status,
 	char *uTime, char *sTime)