From 6f42d3115baae0815e6e8dbaf5943df5cfe2e810 Mon Sep 17 00:00:00 2001
From: "Christopher J. Morrone" <morrone2@llnl.gov>
Date: Fri, 15 Sep 2006 01:57:31 +0000
Subject: [PATCH] Fix srun --jobid for an existing allocations. Fixes test1.58,
 and hopefully test7.4 as well.

---
 src/srun/allocate.c | 17 +++--------------
 src/srun/srun.c     | 18 +++++++++++++-----
 2 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/src/srun/allocate.c b/src/srun/allocate.c
index 868ae4c890d..cbbdf404e7b 100644
--- a/src/srun/allocate.c
+++ b/src/srun/allocate.c
@@ -164,7 +164,9 @@ existing_allocation(void)
 	uint32_t old_job_id;
         resource_allocation_response_msg_t *resp = NULL;
 
-        if ((old_job_id = jobid_from_env()) == 0)
+	if (opt.jobid != NO_VAL)
+		old_job_id = (uint32_t)opt.jobid;
+	else
                 return NULL;
 
         if (slurm_allocation_lookup_lite(old_job_id, &resp) < 0) {
@@ -183,19 +185,6 @@ existing_allocation(void)
         return resp;
 }
 
-/* 
- * Returns jobid if SLURM_JOBID was set in the user's environment
- *  or if --jobid option was given, else returns 0
- */
-uint32_t
-jobid_from_env(void)
-{
-	if (opt.jobid != NO_VAL)
-		return ((uint32_t) opt.jobid);
-	else 
-		return (0);
-}
-
 static void
 _wait_for_resources(resource_allocation_response_msg_t **resp)
 {
diff --git a/src/srun/srun.c b/src/srun/srun.c
index 62852140d96..4fc771128f1 100644
--- a/src/srun/srun.c
+++ b/src/srun/srun.c
@@ -100,12 +100,10 @@
 #define	TYPE_SCRIPT	2
 
 
-typedef resource_allocation_response_msg_t         allocation_resp;
-
 /*
  * forward declaration of static funcs
  */
-static void  _print_job_information(allocation_resp *resp);
+static void  _print_job_information(resource_allocation_response_msg_t *resp);
 static char *_build_script (char *pathname, int file_type);
 static char *_get_shell (void);
 static void  _send_options(const int argc, char **argv);
@@ -127,7 +125,7 @@ static int   _run_srun_script (srun_job_t *job, char *script);
 
 int srun(int ac, char **av)
 {
-	allocation_resp *resp;
+	resource_allocation_response_msg_t *resp;
 	srun_job_t *job = NULL;
 	int exitcode = 0;
 	env_t *env = xmalloc(sizeof(env_t));
@@ -239,6 +237,16 @@ int srun(int ac, char **av)
 
 	} else if ((resp = existing_allocation())) {
 		job_id = resp->job_id;
+
+		/* If opt.nodelist isn't set we initialize it from the
+		 * allocation info, but only if the env variable SLURM_HOSTFILE
+		 * ISN'T set, because SLURM_HOSTFILE isn't parsed until
+		 * job_step_create_allocation is called (bad design, all env
+		 * variable parsing should happen up front in opt.c with the
+		 * rest of the option parsing).
+		 */
+		if (opt.nodelist == NULL && getenv("SLURM_HOSTFILE") == NULL)
+			opt.nodelist = xstrdup(resp->node_list);
 		slurm_free_resource_allocation_response_msg(resp);
 		if (opt.allocate) {
 			error("job %u already has an allocation",
@@ -474,7 +482,7 @@ _switch_standalone(srun_job_t *job)
 
 
 static void 
-_print_job_information(allocation_resp *resp)
+_print_job_information(resource_allocation_response_msg_t *resp)
 {
 	int i;
 	char tmp_str[10], job_details[4096];
-- 
GitLab