From d2310ccfa75a6da2fdebfc21e5f47d43634d4e51 Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Thu, 30 Nov 2006 16:41:12 +0000
Subject: [PATCH] Fix for correct requid from jobacct plugin

---
 NEWS                      | 1 +
 src/sacct/options.c       | 1 +
 src/sacct/print.c         | 6 ++++--
 src/sacct/process.c       | 5 ++++-
 src/sacct/sacct.c         | 2 +-
 src/sacct/sacct.h         | 3 ++-
 src/slurmctld/job_mgr.c   | 4 ++--
 src/slurmctld/slurmctld.h | 1 -
 src/slurmctld/step_mgr.c  | 2 +-
 9 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/NEWS b/NEWS
index bbec7b9a70f..c0f367ef919 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,7 @@ documents those changes that are of interest to users and admins.
     ionode range instead of quarter nodecard notation. 
     (i.e. bgl000[0-4] instead of bgl000.0.0)
  -- Patch from Hongjia Cao (EINPROGRESS error message change)
+ -- Fix for correct requid for jobacct plugin
 
 * Changes in SLURM 1.2.0-pre7
 =============================
diff --git a/src/sacct/options.c b/src/sacct/options.c
index 4048e928f54..2d159957476 100644
--- a/src/sacct/options.c
+++ b/src/sacct/options.c
@@ -1624,6 +1624,7 @@ void do_fdump(char* f[], int lc)
 
 	char	*term[] = {"totElapsed", /* F_TOT_ELAPSED */
 			   "status",	 /* F_STATUS */ 
+			   "requid",     /* F_JOB_REQUID */
 			   NULL};	 
 		
 	i = atoi(f[F_RECTYPE]);
diff --git a/src/sacct/print.c b/src/sacct/print.c
index f7f96a64265..de0813b72a7 100644
--- a/src/sacct/print.c
+++ b/src/sacct/print.c
@@ -825,7 +825,8 @@ void print_status(type_t type, void *object)
 		break;
 	case JOB:
 		if ( job->status == JOB_CANCELLED) {
-			printf ("%-10s by %6d",decode_status_int(job->status), job->requid);
+			printf ("%-10s by %6d",
+				decode_status_int(job->status), job->requid);
 		}
 		else {
 			printf("%-20s", decode_status_int(job->status));
@@ -833,7 +834,8 @@ void print_status(type_t type, void *object)
 		break;
 	case JOBSTEP:
 		if ( step->status == JOB_CANCELLED) {
-			printf ("%-10s by %6d",decode_status_int(step->status), step->requid);
+			printf ("%-10s by %6d",
+				decode_status_int(step->status), step->requid);
 		}
 		else {
 			printf("%-20s", decode_status_int(step->status));
diff --git a/src/sacct/process.c b/src/sacct/process.c
index f92b160fce2..6a110ab26b2 100644
--- a/src/sacct/process.c
+++ b/src/sacct/process.c
@@ -17,7 +17,7 @@
  *  any later version.
  *
  *  In addition, as a special exception, the copyright holders give permission 
- *  to link the code of portions of this program with the OpenSSL library under 
+ *  to link the code of portions of this program with the OpenSSL library under
  *  certain conditions as described in each individual source file, and 
  *  distribute linked combinations including the two. You must obey the GNU 
  *  General Public License in all respects for all of the code used other than 
@@ -306,6 +306,8 @@ int _parse_line(char *f[], void **data, int len)
 		*job = _init_job_rec(header);
 		(*job)->elapsed = atoi(f[F_TOT_ELAPSED]);
 		(*job)->status = atoi(f[F_STATUS]);		
+		if(len > F_JOB_REQUID) 
+			(*job)->requid = atoi(f[F_JOB_REQUID]);
 		break;
 	default:
 		printf("UNKOWN TYPE %d",i);
@@ -526,6 +528,7 @@ void process_terminated(char *f[], int lc, int show_full, int len)
 	job->elapsed = temp->elapsed;
 	job->end = temp->header.timestamp;
 	job->status = temp->status;
+	job->requid = temp->requid;
 	if(list_count(job->steps) > 1)
 		job->track_steps = 1;
 	job->show_full = show_full;
diff --git a/src/sacct/sacct.c b/src/sacct/sacct.c
index 2227d464815..02b2fdb58b9 100644
--- a/src/sacct/sacct.c
+++ b/src/sacct/sacct.c
@@ -13,7 +13,7 @@
  *  any later version.
  *
  *  In addition, as a special exception, the copyright holders give permission 
- *  to link the code of portions of this program with the OpenSSL library under 
+ *  to link the code of portions of this program with the OpenSSL library under
  *  certain conditions as described in each individual source file, and 
  *  distribute linked combinations including the two. You must obey the GNU 
  *  General Public License in all respects for all of the code used other than 
diff --git a/src/sacct/sacct.h b/src/sacct/sacct.h
index 5d1fb514181..8ea334daab9 100644
--- a/src/sacct/sacct.h
+++ b/src/sacct/sacct.h
@@ -17,7 +17,7 @@
  *  any later version.
  *
  *  In addition, as a special exception, the copyright holders give permission 
- *  to link the code of portions of this program with the OpenSSL library under 
+ *  to link the code of portions of this program with the OpenSSL library under
  *  certain conditions as described in each individual source file, and 
  *  distribute linked combinations including the two. You must obey the GNU 
  *  General Public License in all respects for all of the code used other than 
@@ -162,6 +162,7 @@ enum {	F_JOBSTEP = HEADER_LENGTH,
 /* JOB_TERM / JOB_SUSPEND fields */
 enum {	F_TOT_ELAPSED = HEADER_LENGTH,
 	F_TERM_STATUS,
+	F_JOB_REQUID,
 	JOB_TERM_LENGTH
 };
 
diff --git a/src/slurmctld/job_mgr.c b/src/slurmctld/job_mgr.c
index a0f5e6dccea..c9dd86c91c9 100644
--- a/src/slurmctld/job_mgr.c
+++ b/src/slurmctld/job_mgr.c
@@ -1644,12 +1644,12 @@ extern int job_complete(uint32_t job_id, uid_t uid, bool requeue,
 		job_ptr->job_state  = JOB_CANCELLED;
 		job_ptr->start_time = now;
 		job_ptr->end_time   = now;
+		job_ptr->requid = uid;
 		job_completion_logger(job_ptr);
 	} else {
 		if (job_return_code == NO_VAL) {
 			job_ptr->job_state = JOB_CANCELLED| job_comp_flag;
-			if (job_ptr->requid == -1)
- 				job_ptr->requid = uid;
+			job_ptr->requid = uid;
 		} else if (WEXITSTATUS(job_return_code)) {
 			job_ptr->job_state = JOB_FAILED   | job_comp_flag;
 			job_ptr->exit_code = job_return_code;
diff --git a/src/slurmctld/slurmctld.h b/src/slurmctld/slurmctld.h
index 997dc52c51f..23b4a7cc438 100644
--- a/src/slurmctld/slurmctld.h
+++ b/src/slurmctld/slurmctld.h
@@ -401,7 +401,6 @@ struct 	step_record {
 					   step */
 	slurm_step_layout_t *step_layout;/* info about how tasks are laid out
 					    in the step */
-	uint32_t requid;            	/* requester user ID */
 };
 
 extern List job_list;			/* list of job_record entries */
diff --git a/src/slurmctld/step_mgr.c b/src/slurmctld/step_mgr.c
index 569cf5571e9..d6378fa7e8c 100644
--- a/src/slurmctld/step_mgr.c
+++ b/src/slurmctld/step_mgr.c
@@ -294,7 +294,7 @@ int job_step_signal(uint32_t job_id, uint32_t step_id,
 	
 	/* save user ID of the one who requested the job be cancelled */
 	if(signal == SIGKILL)
-		step_ptr->requid = uid;
+		step_ptr->job_ptr->requid = uid;
 
 	signal_step_tasks(step_ptr, signal);
 	return SLURM_SUCCESS;
-- 
GitLab