From 16bbb9c4bc8362ffd4b0dd91b28af2d0cdc8592a Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Fri, 8 Sep 2006 21:39:12 +0000
Subject: [PATCH] Restore some code removed in v1.2. Required for test1.57 and
 moab use.

---
 src/srun/allocate.c | 27 ++++++++++++++++++++++++++-
 src/srun/allocate.h |  8 ++++++++
 src/srun/srun.c     |  3 ++-
 3 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/src/srun/allocate.c b/src/srun/allocate.c
index 98fcdfc33fd..f776e3d4ec8 100644
--- a/src/srun/allocate.c
+++ b/src/srun/allocate.c
@@ -114,7 +114,7 @@ allocate_nodes(void)
 
 	/* Do not re-use existing job id when submitting new job
 	 * from within a running job */
-	if (getenv("SLURM_JOBID") != NULL) {
+	if ((j->job_id != NO_VAL) && !opt.jobid_set) {
 		info("WARNING: Creating SLURM job allocation from within "
 			"another allocation");
 		info("WARNING: You are attempting to initiate a second job");
@@ -158,6 +158,31 @@ allocate_nodes(void)
 	return resp;
 }
 
+resource_allocation_response_msg_t *
+existing_allocation(void)
+{
+	uint32_t old_job_id;
+        resource_allocation_response_msg_t *resp = NULL;
+
+        if ((old_job_id = jobid_from_env()) == 0)
+                return NULL;
+
+        if (slurm_allocation_lookup(old_job_id, &resp) < 0) {
+                if (opt.parallel_debug || opt.jobid_set)
+                        return NULL;    /* create new allocation as needed */
+                if (errno == ESLURM_ALREADY_DONE)
+                        error ("SLURM job %u has expired.", old_job_id);
+                else
+                        error ("Unable to confirm allocation for job %u: %m",
+                              old_job_id);
+                info ("Check SLURM_JOBID environment variable "
+                      "for expired or invalid job.");
+                exit(1);
+        }
+
+        return resp;
+}
+
 /* 
  * Returns jobid if SLURM_JOBID was set in the user's environment
  *  or if --jobid option was given, else returns 0
diff --git a/src/srun/allocate.h b/src/srun/allocate.h
index 1a8f6f16738..0ca9bf7ec7d 100644
--- a/src/srun/allocate.h
+++ b/src/srun/allocate.h
@@ -72,6 +72,14 @@ job_desc_msg_t * job_desc_msg_create_from_opts (char *script);
  */
 void job_desc_msg_destroy (job_desc_msg_t *j);
 
+/*
+ * Check for SLURM_JOBID environment variable, and if it is a valid
+ * jobid, return a pseudo allocation response pointer.
+ *
+ * Returns NULL if SLURM_JOBID is not present or is invalid.
+ */
+resource_allocation_response_msg_t * existing_allocation(void);
+
 /*
  * Return the jobid number stored in SLURM_JOBID env var
  *
diff --git a/src/srun/srun.c b/src/srun/srun.c
index 5dcd88d275d..64945bd4dc2 100644
--- a/src/srun/srun.c
+++ b/src/srun/srun.c
@@ -238,7 +238,8 @@ int srun(int ac, char **av)
 		xfree(env);
 		exit (exitcode);
 
-	} else if ((job_id = jobid_from_env())) {
+	} else if ((resp = existing_allocation())) {
+		slurm_free_resource_allocation_response_msg(resp);
 		if (opt.allocate) {
 			error("job %u already has an allocation",
 			      job_id);
-- 
GitLab