From 55f09556cb18fdb082b4c5471d45a1362a8e58d8 Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Mon, 23 Mar 2009 20:58:47 +0000
Subject: [PATCH] svn merge -r16959:16975
 https://eris.llnl.gov/svn/slurm/branches/slurm-1.3

---
 src/common/slurmdbd_defs.c                    | 24 +++++++++++++------
 .../slurmdbd/accounting_storage_slurmdbd.c    |  6 ++---
 src/slurmctld/controller.c                    |  8 +++++--
 src/slurmctld/proc_req.c                      |  3 +--
 src/slurmdbd/proc_req.c                       | 23 +++++++++++++++---
 src/slurmdbd/rpc_mgr.c                        |  2 +-
 6 files changed, 48 insertions(+), 18 deletions(-)

diff --git a/src/common/slurmdbd_defs.c b/src/common/slurmdbd_defs.c
index 47a2c0f2b3c..89b657b276b 100644
--- a/src/common/slurmdbd_defs.c
+++ b/src/common/slurmdbd_defs.c
@@ -207,7 +207,8 @@ extern int slurm_send_slurmdbd_recv_rc_msg(uint16_t rpc_version,
 	} else {	/* resp->msg_type == DBD_RC */
 		dbd_rc_msg_t *msg = resp->data;
 		*resp_code = msg->return_code;
-		if(msg->return_code != SLURM_SUCCESS)
+		if(msg->return_code != SLURM_SUCCESS
+		   && msg->return_code != ACCOUNTING_FIRST_REG)
 			error("slurmdbd(%d): from %u: %s", msg->return_code, 
 			      msg->sent_type, msg->comment);
 		slurmdbd_free_rc_msg(rpc_version, msg);
@@ -2858,12 +2859,21 @@ slurmdbd_unpack_job_start_msg(uint16_t rpc_version,
 		/* then grep for " since that is the delimiter for
 		   the wckey */
 		if((temp = strchr(jname, '\"'))) {
-			/* if we have a wckey set the " to NULL to
-			 * end the jname */
-			temp[0] = '\0';
-			/* increment and copy the remainder */
-			temp++;
-			msg_ptr->wckey = xstrdup(temp);
+			if(strrchr(jname, '\"') != temp) {
+				error("job %u has quotes in it's name '%s', "
+				      "no way to get correct wckey, "
+				      "setting name to 'bad_name'", 
+				      msg_ptr->job_id, jname);
+				xfree(jname);
+				jname = xstrdup("bad_name");
+			} else {			
+				/* if we have a wckey set the " to NULL to
+				 * end the jname */
+				temp[0] = '\0';
+				/* increment and copy the remainder */
+				temp++;
+				msg_ptr->wckey = xstrdup(temp);
+			}
 		}
 		xfree(msg_ptr->name);
 		msg_ptr->name = xstrdup(jname);
diff --git a/src/plugins/accounting_storage/slurmdbd/accounting_storage_slurmdbd.c b/src/plugins/accounting_storage/slurmdbd/accounting_storage_slurmdbd.c
index 7c47fef7e1f..878d09702dd 100644
--- a/src/plugins/accounting_storage/slurmdbd/accounting_storage_slurmdbd.c
+++ b/src/plugins/accounting_storage/slurmdbd/accounting_storage_slurmdbd.c
@@ -1383,6 +1383,7 @@ extern int clusteracct_storage_p_cluster_procs(void *db_conn,
 {
 	slurmdbd_msg_t msg;
 	dbd_cluster_procs_msg_t req;
+	int rc = SLURM_ERROR;
 
 	debug2("Sending info for cluster %s", cluster);
 	req.cluster_name = cluster;
@@ -1392,10 +1393,9 @@ extern int clusteracct_storage_p_cluster_procs(void *db_conn,
 	msg.msg_type     = DBD_CLUSTER_PROCS;
 	msg.data         = &req;
 
-	if (slurm_send_slurmdbd_msg(SLURMDBD_VERSION, &msg) < 0)
-		return SLURM_ERROR;
+	slurm_send_slurmdbd_recv_rc_msg(SLURMDBD_VERSION, &msg, &rc);
 
-	return SLURM_SUCCESS;
+	return rc;
 }
 
 extern int clusteracct_storage_p_register_ctld(void *db_conn,
diff --git a/src/slurmctld/controller.c b/src/slurmctld/controller.c
index 76aee382ac8..7170920d3be 100644
--- a/src/slurmctld/controller.c
+++ b/src/slurmctld/controller.c
@@ -1350,9 +1350,10 @@ extern void send_all_to_accounting(time_t event_time)
 	   push the requests on the queue and process them when the
 	   database server comes back up.
 	*/
-	send_jobs_to_accounting(event_time);
+	debug2("send_all_to_accounting: called");
+	send_jobs_to_accounting();
 	send_nodes_to_accounting(event_time);
-	send_resvs_to_accounting(event_time);
+	send_resvs_to_accounting();
 }
 
 /* 
@@ -1750,5 +1751,8 @@ static void *_assoc_cache_mgr(void *no_data)
 	}
 	list_iterator_destroy(itr);
 	unlock_slurmctld(job_write_lock);
+	/* This needs to be after the lock and after we update the
+	   jobs so if we need to send them we are set. */
+	_accounting_cluster_ready();
 	return NULL;
 }
diff --git a/src/slurmctld/proc_req.c b/src/slurmctld/proc_req.c
index 3d1515a73fe..5534f636a73 100644
--- a/src/slurmctld/proc_req.c
+++ b/src/slurmctld/proc_req.c
@@ -3305,8 +3305,7 @@ inline static void  _slurm_rpc_accounting_first_reg(slurm_msg_t *msg)
 		return;
 	}
 	
-	send_jobs_to_accounting(event_time);
-	send_nodes_to_accounting(event_time);
+	send_all_to_accounting(event_time);
 	
 	END_TIMER2("_slurm_rpc_accounting_first_reg");
 }
diff --git a/src/slurmdbd/proc_req.c b/src/slurmdbd/proc_req.c
index cee4fbbbfcc..29ecd5f73f9 100644
--- a/src/slurmdbd/proc_req.c
+++ b/src/slurmdbd/proc_req.c
@@ -403,6 +403,23 @@ unpack_error:
 	return SLURM_ERROR;
 }
 
+/* replace \" with \` return is the same as what is given */
+static char * _replace_double_quotes(char *option)
+{
+	int i=0;
+
+	if(!option)
+		return NULL;
+
+	while(option[i]) {
+		if(option[i] == '\"')
+			option[i] = '`';
+		i++;
+	}
+	return option;
+}
+
+
 static int _add_accounts(slurmdbd_conn_t *slurmdbd_conn,
 			 Buf in_buffer, Buf *out_buffer, uint32_t *uid)
 {
@@ -1619,7 +1636,7 @@ static int  _job_start(slurmdbd_conn_t *slurmdbd_conn,
 
 	job.total_procs = job_start_msg->alloc_cpus;
 	job.node_cnt = job_start_msg->alloc_nodes;
-	job.account = job_start_msg->account;
+	job.account = _replace_double_quotes(job_start_msg->account);
 	job.assoc_id = job_start_msg->assoc_id;
 	job.comment = job_start_msg->block_id;
 	job.db_index = job_start_msg->db_index;
@@ -1628,7 +1645,7 @@ static int  _job_start(slurmdbd_conn_t *slurmdbd_conn,
 	job.group_id = job_start_msg->gid;
 	job.job_id = job_start_msg->job_id;
 	job.job_state = job_start_msg->job_state;
-	job.name = job_start_msg->name;
+	job.name = _replace_double_quotes(job_start_msg->name);
 	job.nodes = job_start_msg->nodes;
 	job.network = job_start_msg->node_inx;
 	job.partition = job_start_msg->partition;
@@ -1636,7 +1653,7 @@ static int  _job_start(slurmdbd_conn_t *slurmdbd_conn,
 	job.resv_id = job_start_msg->resv_id;
 	job.priority = job_start_msg->priority;
 	job.start_time = job_start_msg->start_time;
-	job.wckey = job_start_msg->wckey;
+	job.wckey = _replace_double_quotes(job_start_msg->wckey);
 	details.submit_time = job_start_msg->submit_time;
 
 	job.details = &details;
diff --git a/src/slurmdbd/rpc_mgr.c b/src/slurmdbd/rpc_mgr.c
index 609f07b92c6..708c84439e0 100644
--- a/src/slurmdbd/rpc_mgr.c
+++ b/src/slurmdbd/rpc_mgr.c
@@ -223,7 +223,7 @@ static void * _service_connection(void *arg)
 			rc = proc_req(
 				conn, msg, msg_size, first, &buffer, &uid);
 			first = false;
-			if (rc != SLURM_SUCCESS) {
+			if (rc != SLURM_SUCCESS && rc != ACCOUNTING_FIRST_REG) {
 				error("Processing last message from "
 				      "connection %d(%s) uid(%d)",
 				      conn->newsockfd, conn->ip, uid);
-- 
GitLab