From 240787cad9d9338f5e354717a88f2948e795beaa Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Tue, 19 Nov 2002 21:30:53 +0000
Subject: [PATCH] log made to function properly without pthreads. Major
 clean-up of slurm_protocol_pack (not finished, but about half done).

---
 src/common/log.c                 |  66 ++++----
 src/common/log.h                 |   2 +-
 src/common/slurm_protocol_pack.c | 258 +++++++++++++++++++------------
 src/common/slurm_protocol_pack.h | 136 ++++++++++------
 4 files changed, 289 insertions(+), 173 deletions(-)

diff --git a/src/common/log.c b/src/common/log.c
index 26b356fe198..2727deab372 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -92,7 +92,11 @@ typedef struct {
 }	log_t;
 
 /* static variables */
-static pthread_mutex_t  log_lock;
+#ifdef WITH_PTHREADS
+  static pthread_mutex_t  log_lock;
+#else
+  static int	log_lock;
+#endif /* WITH_PTHREADS */
 static log_t            *log = NULL;
 
 #define LOG_INITIALIZED ((log != NULL) && log->initialized)
@@ -144,7 +148,7 @@ _log_init(char *prog, log_options_t opt, log_facility_t fac, char *logfile )
 
 		if (!fp) {
 			char *errmsg = NULL;
-			pthread_mutex_unlock(&log_lock);
+			slurm_mutex_unlock(&log_lock);
 			xslurm_strerrorcat(errmsg);
 			fprintf(stderr, 
 			        "%s: log_init(): Unable to open logfile"
@@ -168,16 +172,16 @@ int log_init(char *prog, log_options_t opt, log_facility_t fac, char *logfile)
 {
 	int rc = 0;
 
-	pthread_mutex_init(&log_lock, NULL);
-	pthread_mutex_lock(&log_lock);
+	slurm_mutex_init(&log_lock);
+	slurm_mutex_lock(&log_lock);
 	rc = _log_init(prog, opt, fac, logfile);
-	pthread_mutex_unlock(&log_lock);
+	slurm_mutex_unlock(&log_lock);
 	return rc;
 }
 
-int log_reinit()
+void log_reinit()
 {
-	return pthread_mutex_init(&log_lock, NULL);
+	slurm_mutex_init(&log_lock);
 }
 
 /* reinitialize log data structures. Like log_init, but do not init
@@ -186,9 +190,9 @@ int log_reinit()
 int log_alter(log_options_t opt, log_facility_t fac, char *logfile)
 {	
 	int rc = 0;
-	pthread_mutex_lock(&log_lock);
+	slurm_mutex_lock(&log_lock);
 	rc = _log_init(NULL, opt, fac, logfile);
-	pthread_mutex_unlock(&log_lock);
+	slurm_mutex_unlock(&log_lock);
 	return rc;
 }
 
@@ -197,12 +201,12 @@ int log_alter(log_options_t opt, log_facility_t fac, char *logfile)
 FILE *log_fp(void)
 {
 	FILE *fp;
-	pthread_mutex_lock(&log_lock);
+	slurm_mutex_lock(&log_lock);
 	if (log->logfp)
 		fp = log->logfp;
 	else
 		fp = stderr;
-	pthread_mutex_unlock(&log_lock);
+	slurm_mutex_unlock(&log_lock);
 	return fp;
 }
 
@@ -344,12 +348,12 @@ static void log_msg(log_level_t level, const char *fmt, va_list args)
 		log_init(NULL, opts, 0, NULL);
 	}
 
-	pthread_mutex_lock(&log_lock);
+	slurm_mutex_lock(&log_lock);
 
 	if (level > log->opt.syslog_level  && 
 	    level > log->opt.logfile_level && 
 	    level > log->opt.stderr_level) {
-		pthread_mutex_unlock(&log_lock);
+		slurm_mutex_unlock(&log_lock);
 		return;
 	}
 
@@ -427,7 +431,7 @@ static void log_msg(log_level_t level, const char *fmt, va_list args)
 		xfree(msgbuf);
 	}
 
-	pthread_mutex_unlock(&log_lock);
+	slurm_mutex_unlock(&log_lock);
 
 	xfree(buf);
 }
@@ -513,7 +517,11 @@ struct fatal_cleanup {
 };
 
 /* static variables */
-static pthread_mutex_t  fatal_lock = PTHREAD_MUTEX_INITIALIZER;    
+#ifdef WITH_PTHREADS
+  static pthread_mutex_t  fatal_lock = PTHREAD_MUTEX_INITIALIZER;    
+#else
+  static int	fatal_lock;
+#endif /* WITH_PTHREADS */
 static struct fatal_cleanup *fatal_cleanups = NULL;
 
 /* Registers a cleanup function to be called by fatal() for this thread 
@@ -523,14 +531,14 @@ fatal_add_cleanup(void (*proc) (void *), void *context)
 {
 	struct fatal_cleanup *cu;
 
-	pthread_mutex_lock(&fatal_lock);
+	slurm_mutex_lock(&fatal_lock);
 	cu = xmalloc(sizeof(*cu));
 	cu->thread_id = pthread_self();
 	cu->proc = proc;
 	cu->context = context;
 	cu->next = fatal_cleanups;
 	fatal_cleanups = cu;
-	pthread_mutex_unlock(&fatal_lock);
+	slurm_mutex_unlock(&fatal_lock);
 }
 
 /* Registers a cleanup function to be called by fatal() for all threads 
@@ -540,14 +548,14 @@ fatal_add_cleanup_job(void (*proc) (void *), void *context)
 {
 	struct fatal_cleanup *cu;
 
-	pthread_mutex_lock(&fatal_lock);
+	slurm_mutex_lock(&fatal_lock);
 	cu = xmalloc(sizeof(*cu));
 	cu->thread_id = 0;
 	cu->proc = proc;
 	cu->context = context;
 	cu->next = fatal_cleanups;
 	fatal_cleanups = cu;
-	pthread_mutex_unlock(&fatal_lock);
+	slurm_mutex_unlock(&fatal_lock);
 }
 
 /* Removes a cleanup frunction to be called at fatal() for this thread. */
@@ -557,7 +565,7 @@ fatal_remove_cleanup(void (*proc) (void *context), void *context)
 	struct fatal_cleanup **cup, *cu;
 	pthread_t my_thread_id = pthread_self();
 
-	pthread_mutex_lock(&fatal_lock);
+	slurm_mutex_lock(&fatal_lock);
 	for (cup = &fatal_cleanups; *cup; cup = &cu->next) {
 		cu = *cup;
 		if (cu->thread_id == my_thread_id &&
@@ -565,11 +573,11 @@ fatal_remove_cleanup(void (*proc) (void *context), void *context)
 		    cu->context == context) {
 			*cup = cu->next;
 			xfree(cu);
-			pthread_mutex_unlock(&fatal_lock);
+			slurm_mutex_unlock(&fatal_lock);
 			return;
 		}
 	}
-	pthread_mutex_unlock(&fatal_lock);
+	slurm_mutex_unlock(&fatal_lock);
 	fatal("fatal_remove_cleanup: no such cleanup function: 0x%lx 0x%lx",
 	    (u_long) proc, (u_long) context);
 }
@@ -581,7 +589,7 @@ fatal_remove_cleanup_job(void (*proc) (void *context), void *context)
 {
 	struct fatal_cleanup **cup, *cu;
 
-	pthread_mutex_lock(&fatal_lock);
+	slurm_mutex_lock(&fatal_lock);
 	for (cup = &fatal_cleanups; *cup; cup = &cu->next) {
 		cu = *cup;
 		if (cu->thread_id == 0 &&
@@ -589,11 +597,11 @@ fatal_remove_cleanup_job(void (*proc) (void *context), void *context)
 		    cu->context == context) {
 			*cup = cu->next;
 			xfree(cu);
-			pthread_mutex_unlock(&fatal_lock);
+			slurm_mutex_unlock(&fatal_lock);
 			return;
 		}
 	}
-	pthread_mutex_unlock(&fatal_lock);
+	slurm_mutex_unlock(&fatal_lock);
 	fatal(
 	    "fatal_remove_cleanup_job: no such cleanup function: 0x%lx 0x%lx",
 	    (u_long) proc, (u_long) context);
@@ -607,7 +615,7 @@ fatal_cleanup(void)
 	struct fatal_cleanup **cup, *cu;
 	pthread_t my_thread_id = pthread_self();
 
-	pthread_mutex_lock(&fatal_lock);
+	slurm_mutex_lock(&fatal_lock);
 	for (cup = &fatal_cleanups; *cup; ) {
 		cu = *cup;
 		if (cu->thread_id != my_thread_id) {
@@ -628,7 +636,7 @@ fatal_cleanup(void)
 		      (u_long) cu->proc, (u_long) cu->context);
 		(*cu->proc) (cu->context);
 	}
-	pthread_mutex_unlock(&fatal_lock);
+	slurm_mutex_unlock(&fatal_lock);
 }
 
 /* Print a list of cleanup frunctions to be called at fatal(). */
@@ -637,12 +645,12 @@ dump_cleanup_list(void)
 {
 	struct fatal_cleanup **cup, *cu;
 
-	pthread_mutex_lock(&fatal_lock);
+	slurm_mutex_lock(&fatal_lock);
 	for (cup = &fatal_cleanups; *cup; cup = &cu->next) {
 		cu = *cup;
 		info ("loc=%ld thread_id=%ld proc=%ld, context=%ld, next=%ld",
 			(long)cu, (long)cu->thread_id, (long)cu->proc, 
 			(long)cu->context, (long)cu->next);
 	}
-	pthread_mutex_unlock(&fatal_lock);
+	slurm_mutex_unlock(&fatal_lock);
 }
diff --git a/src/common/log.h b/src/common/log.h
index a30a1ee8e45..0962e08307d 100644
--- a/src/common/log.h
+++ b/src/common/log.h
@@ -129,7 +129,7 @@ int log_init(char *argv0, log_options_t opts,
  * that protects the log. This call is needed after a fork() in a threaded
  * program
  */
-int log_reinit(void);
+void log_reinit(void);
 
 /* Alter log facility, options are like log_init() above, except that
  * an argv0 argument is not passed. 
diff --git a/src/common/slurm_protocol_pack.c b/src/common/slurm_protocol_pack.c
index 29dfaa2c598..4b52de23fd4 100644
--- a/src/common/slurm_protocol_pack.c
+++ b/src/common/slurm_protocol_pack.c
@@ -24,28 +24,74 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 \*****************************************************************************/
 
+#if HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
 
-#include <src/common/bitstring.h>
-#include <src/common/slurm_protocol_pack.h>
-#include <src/common/slurm_protocol_api.h>
-#include <src/common/slurm_protocol_defs.h>
-#include <src/common/slurm_auth.h>
-#include <src/common/pack.h>
-#include <src/common/log.h>
-#include <src/common/xmalloc.h>
+#include "src/common/bitstring.h"
+#include "src/common/log.h"
+#include "src/common/pack.h"
+#include "src/common/slurm_auth.h"
+#include "src/common/slurm_protocol_api.h"
+#include "src/common/slurm_protocol_defs.h"
+#include "src/common/slurm_protocol_pack.h"
+#include "src/common/xmalloc.h"
+
+static void _pack_node_registration_status_msg ( 
+		slurm_node_registration_status_msg_t * msg, 
+		Buf buffer );
+static int _unpack_node_registration_status_msg ( 
+		slurm_node_registration_status_msg_t ** msg , 
+		Buf buffer );
+
+static void _pack_resource_allocation_and_run_response_msg ( 
+		resource_allocation_and_run_response_msg_t * msg, 
+		Buf buffer );
+static int _unpack_resource_allocation_and_run_response_msg ( 
+		resource_allocation_and_run_response_msg_t ** msg , 
+		Buf buffer );
+
+static void _pack_resource_allocation_response_msg ( 
+		resource_allocation_response_msg_t * msg, Buf buffer );
+static int _unpack_resource_allocation_response_msg ( 
+		resource_allocation_response_msg_t ** msg , Buf buffer );
+
+static void _pack_update_node_msg ( update_node_msg_t * msg, Buf buffer );
+static int _unpack_update_node_msg ( update_node_msg_t ** msg , Buf buffer );
+
+static void _pack_submit_response_msg ( submit_response_msg_t * msg, 
+                                        Buf buffer );
+static int _unpack_submit_response_msg ( submit_response_msg_t ** msg , 
+                                         Buf buffer );
 
+static void _pack_node_info_msg ( slurm_msg_t * msg, Buf buffer );
+static int _unpack_node_info_msg ( node_info_msg_t ** msg , Buf buffer );
+static int _unpack_node_info_members ( node_info_t * node , Buf buffer );
 
-void pack_job_credential ( slurm_job_credential_t* cred , Buf buffer );
-int unpack_job_credential( slurm_job_credential_t** msg , Buf buffer );
+static void _pack_update_partition_msg ( update_part_msg_t * msg , 
+                                         Buf buffer );
+static int _unpack_update_partition_msg ( update_part_msg_t ** msg , 
+                                          Buf buffer );
+
+static void _pack_job_step_create_request_msg ( 
+		job_step_create_request_msg_t* msg , Buf buffer );
+static int _unpack_job_step_create_request_msg ( 
+		job_step_create_request_msg_t** msg , Buf buffer );
+
+static void _pack_revoke_credential_msg ( revoke_credential_msg_t* msg , 
+                                          Buf buffer );
+static int _unpack_revoke_credential_msg ( revoke_credential_msg_t** msg , 
+                                           Buf buffer );
 
 /* pack_header
  * packs a slurm protocol header that proceeds every slurm message
- * header 	- the header structure to pack
- * buffer	- destination of the pack, contains pointers that are
+ * IN header - the header structure to pack
+ * IN/OUT buffer - destination of the pack, contains pointers that are
  *			automatically updated
  */
 void pack_header ( header_t * header, Buf buffer )
@@ -61,9 +107,10 @@ void pack_header ( header_t * header, Buf buffer )
 
 /* unpack_header
  * unpacks a slurm protocol header that proceeds every slurm message
- * header 	- the header structure to unpack
- * buffer	- destination of the pack, contains pointers that are 
+ * OUT header - the header structure to unpack
+ * IN/OUT buffer - source of the unpack data, contains pointers that are
  *			automatically updated
+ * RET 0 or error code
  */
 int unpack_header ( header_t * header , Buf buffer )
 {
@@ -84,32 +131,49 @@ int unpack_header ( header_t * header , Buf buffer )
 	return SLURM_ERROR;
 }
 
+/* size_io_stream_header - get the size of an I/O stream header
+ * RET number of bytes in an I/O steam header
+ */
 int size_io_stream_header (void)
 {	/* must match un/pack_io_stream_header and size_io_stream_header */
 	return (SLURM_SSL_SIGNATURE_LENGTH + 
 		2 * sizeof(uint16_t) + sizeof(uint32_t));
 }
 
-void pack_io_stream_header ( slurm_io_stream_header_t * msg , Buf buffer )
+/* pack_io_stream_header
+ * packs an i/o stream protocol header used for stdin/out/err
+ * IN header - the header structure to pack
+ * IN/OUT buffer - destination of the pack, contains pointers that are
+ *			automatically updated
+ */
+void pack_io_stream_header ( slurm_io_stream_header_t * header , Buf buffer )
 {	/* must match un/pack_io_stream_header and size_io_stream_header */
 
-	assert ( msg != NULL );
+	assert ( header != NULL );
 
-	pack16( msg->version, buffer ) ;
-	packmem_array( msg->key, (uint32_t) SLURM_SSL_SIGNATURE_LENGTH, 
+	pack16( header->version, buffer ) ;
+	packmem_array( header->key, (uint32_t) SLURM_SSL_SIGNATURE_LENGTH, 
 			buffer ) ; 
-	pack32( msg->task_id, buffer ) ;	
-	pack16( msg->type, buffer ) ;
+	pack32( header->task_id, buffer ) ;	
+	pack16( header->type, buffer ) ;
 }
 
-int unpack_io_stream_header ( slurm_io_stream_header_t * msg , Buf buffer )
+/* unpack_io_stream_header
+ * unpacks an i/o stream protocol header used for stdin/out/err
+ * OUT header - the header structure to unpack
+ * IN/OUT buffer - source of the unpack data, contains pointers that are
+ *			automatically updated
+ * RET 0 or error code
+ */
+int unpack_io_stream_header ( slurm_io_stream_header_t * header , Buf buffer )
 {	/* must match un/pack_io_stream_header and size_io_stream_header */
 
-	safe_unpack16( & msg->version, buffer ) ;
-	safe_unpackmem_array( msg->key, 
-			(uint32_t) SLURM_SSL_SIGNATURE_LENGTH , buffer ) ; 
-	safe_unpack32( & msg->task_id, buffer ) ;	
-	safe_unpack16( & msg->type, buffer ) ;
+	safe_unpack16( & header->version, buffer ) ;
+	safe_unpackmem_array( header->key, 
+			      (uint32_t) SLURM_SSL_SIGNATURE_LENGTH , 
+			      buffer ) ; 
+	safe_unpack32( & header->task_id, buffer ) ;	
+	safe_unpack16( & header->type, buffer ) ;
 	return SLURM_SUCCESS;
 
     unpack_error:
@@ -118,10 +182,11 @@ int unpack_io_stream_header ( slurm_io_stream_header_t * msg , Buf buffer )
 
 
 /* pack_msg
- * packs a slurm protocol mesg body
- * header 	- the body structure to pack
- * buffer	- destination of the pack, contains pointers that are 
+ * packs a generic slurm protocol message body
+ * IN msg - the body structure to pack (note: includes message type)
+ * IN/OUT buffer - destination of the pack, contains pointers that are 
  *			automatically updated
+ * RET 0 or error code
  */
 int pack_msg ( slurm_msg_t const * msg , Buf buffer )
 {
@@ -148,11 +213,11 @@ int pack_msg ( slurm_msg_t const * msg , Buf buffer )
 				( slurm_msg_t * ) msg , buffer ) ;
 			break ;
 		case RESPONSE_NODE_INFO:
-			pack_node_info_msg ( 
+			_pack_node_info_msg ( 
 				( slurm_msg_t * ) msg , buffer ) ;
 			break ;
 		case MESSAGE_NODE_REGISTRATION_STATUS :
-			pack_node_registration_status_msg ( 
+			_pack_node_registration_status_msg ( 
 				( slurm_node_registration_status_msg_t * ) 
 				msg -> data , buffer );
 			break ;
@@ -181,21 +246,22 @@ int pack_msg ( slurm_msg_t const * msg , Buf buffer )
 				(shutdown_msg_t *) msg -> data, buffer )  ;
 			break;
 		case RESPONSE_SUBMIT_BATCH_JOB:
-			pack_submit_response_msg ( 
+			_pack_submit_response_msg ( 
 				( submit_response_msg_t * ) msg -> data , 
 				buffer ) ;
 			break ;
 		case RESPONSE_RESOURCE_ALLOCATION :
 		case RESPONSE_IMMEDIATE_RESOURCE_ALLOCATION : 
 		case RESPONSE_JOB_WILL_RUN :
-			pack_resource_allocation_response_msg ( 
+			_pack_resource_allocation_response_msg ( 
 				( resource_allocation_response_msg_t * ) 
 				msg -> data , 
 				buffer ) ;
 			break ;
 		case RESPONSE_ALLOCATION_AND_RUN_JOB_STEP :
-			pack_resource_allocation_and_run_response_msg ( ( resource_allocation_and_run_response_msg_t * ) msg -> data , 
-				buffer ) ;
+			_pack_resource_allocation_and_run_response_msg ( 
+				(resource_allocation_and_run_response_msg_t *) 
+				msg -> data , buffer ) ;
 			break ;
 		case REQUEST_UPDATE_JOB :
 			pack_job_desc ( 
@@ -203,11 +269,11 @@ int pack_msg ( slurm_msg_t const * msg , Buf buffer )
 			break ;
 			break ;
 		case REQUEST_UPDATE_NODE :
-			pack_update_node_msg ( 
+			_pack_update_node_msg ( 
 				 (update_node_msg_t * ) msg-> data , buffer ) ;
 			break ;
 		case REQUEST_UPDATE_PARTITION :
-			pack_update_partition_msg ( 
+			_pack_update_partition_msg ( 
 				( update_part_msg_t * ) msg->data , buffer ) ;
 			break ;
 		case REQUEST_REATTACH_TASKS_STREAMS :
@@ -242,11 +308,12 @@ int pack_msg ( slurm_msg_t const * msg , Buf buffer )
 			break ;
 		case REQUEST_COMPLETE_JOB_STEP :
 			pack_complete_job_step ( 
-				( complete_job_step_msg_t * ) msg->data , buffer ) ;
+				( complete_job_step_msg_t * ) msg->data , 
+				buffer ) ;
 			break ;
 
 		case REQUEST_REVOKE_JOB_CREDENTIAL :
-			pack_revoke_credential_msg ( 
+			_pack_revoke_credential_msg ( 
 				( revoke_credential_msg_t * ) msg->data , 
 				buffer ) ;
 			break ;
@@ -300,7 +367,7 @@ int pack_msg ( slurm_msg_t const * msg , Buf buffer )
 				msg -> data , buffer ) ;	
 			break;
 		case REQUEST_JOB_STEP_CREATE:
-			pack_job_step_create_request_msg(
+			_pack_job_step_create_request_msg(
 				( job_step_create_request_msg_t * ) 
 				msg -> data , buffer ) ;	
 			break;
@@ -315,10 +382,11 @@ int pack_msg ( slurm_msg_t const * msg , Buf buffer )
 }
 
 /* unpack_msg
- * unpacks a slurm protocol msg body
- * header 	- the body structure to unpack
- * buffer	- source of the unpack, contains pointers that are 
+ * unpacks a generic slurm protocol message body
+ * OUT msg - the body structure to unpack (note: includes message type)
+ * IN/OUT buffer - source of the unpack, contains pointers that are 
  *			automatically updated
+ * RET 0 or error code
  */
 int unpack_msg ( slurm_msg_t * msg , Buf buffer )
 {
@@ -350,12 +418,12 @@ int unpack_msg ( slurm_msg_t * msg , Buf buffer )
 				buffer ) ;
 			break;
 		case RESPONSE_NODE_INFO:
-			rc = unpack_node_info_msg (
+			rc = _unpack_node_info_msg (
 				( node_info_msg_t ** ) &(msg -> data) , 
 				buffer) ;
 			break;
 		case MESSAGE_NODE_REGISTRATION_STATUS :
-			rc = unpack_node_registration_status_msg ( 
+			rc = _unpack_node_registration_status_msg ( 
 				( slurm_node_registration_status_msg_t ** ) 
 				&( msg -> data ), buffer );
 			break ;
@@ -386,20 +454,20 @@ int unpack_msg ( slurm_msg_t * msg , Buf buffer )
 				buffer ) ;
 			break ;
 		case RESPONSE_SUBMIT_BATCH_JOB :
-			rc = unpack_submit_response_msg ( 
+			rc = _unpack_submit_response_msg ( 
 				( submit_response_msg_t ** ) 
 				& ( msg -> data ) , buffer ) ;
 			break ;
 		case RESPONSE_RESOURCE_ALLOCATION :
 		case RESPONSE_IMMEDIATE_RESOURCE_ALLOCATION : 
 		case RESPONSE_JOB_WILL_RUN :
-			rc = unpack_resource_allocation_response_msg ( 
+			rc = _unpack_resource_allocation_response_msg ( 
 				( resource_allocation_response_msg_t ** ) 
 				& ( msg -> data ) , buffer ) ;
 			break ;
 		case RESPONSE_ALLOCATION_AND_RUN_JOB_STEP :
-			rc = unpack_resource_allocation_and_run_response_msg ( 
-				( resource_allocation_and_run_response_msg_t ** ) 
+			rc = _unpack_resource_allocation_and_run_response_msg (
+				(resource_allocation_and_run_response_msg_t **)
 				& ( msg -> data ) , buffer ) ;
 			break ;
 		case REQUEST_UPDATE_JOB :
@@ -408,12 +476,12 @@ int unpack_msg ( slurm_msg_t * msg , Buf buffer )
 				buffer ) ;
 			break ;
 		case REQUEST_UPDATE_NODE :
-			rc = unpack_update_node_msg ( 
+			rc = _unpack_update_node_msg ( 
 				( update_node_msg_t ** ) & ( msg-> data ) , 
 				buffer ) ;
 			break ;
 		case REQUEST_UPDATE_PARTITION :
-			rc = unpack_update_partition_msg ( 
+			rc = _unpack_update_partition_msg ( 
 				( update_part_msg_t ** ) & ( msg->data ) , 
 				buffer ) ;
 			break ;
@@ -455,7 +523,7 @@ int unpack_msg ( slurm_msg_t * msg , Buf buffer )
 				buffer ) ;
 			break ;
 		case REQUEST_REVOKE_JOB_CREDENTIAL :
-			rc = unpack_revoke_credential_msg ( 
+			rc = _unpack_revoke_credential_msg ( 
 				( revoke_credential_msg_t ** ) 
 				& ( msg->data ) , buffer ) ;
 			break ;
@@ -510,7 +578,7 @@ int unpack_msg ( slurm_msg_t * msg , Buf buffer )
 				&msg -> data , buffer ) ;	
 			break;
 		case REQUEST_JOB_STEP_CREATE:
-			rc = unpack_job_step_create_request_msg(
+			rc = _unpack_job_step_create_request_msg(
 				( job_step_create_request_msg_t ** ) 
 				&msg -> data , buffer ) ;	
 			break;
@@ -528,7 +596,7 @@ int unpack_msg ( slurm_msg_t * msg , Buf buffer )
 	return rc ;
 }
 
-void pack_update_node_msg ( update_node_msg_t * msg, Buf buffer )
+static void _pack_update_node_msg ( update_node_msg_t * msg, Buf buffer )
 {
 	assert ( msg != NULL );
 
@@ -536,7 +604,7 @@ void pack_update_node_msg ( update_node_msg_t * msg, Buf buffer )
 	pack16 ( msg -> node_state , buffer ) ;
 }
 
-int unpack_update_node_msg ( update_node_msg_t ** msg , Buf buffer )
+static int _unpack_update_node_msg ( update_node_msg_t ** msg , Buf buffer )
 {
 	uint16_t uint16_tmp;
 	update_node_msg_t * tmp_ptr ;
@@ -559,7 +627,7 @@ int unpack_update_node_msg ( update_node_msg_t ** msg , Buf buffer )
 	return SLURM_ERROR;
 }
 
-void pack_node_registration_status_msg ( 
+static void _pack_node_registration_status_msg ( 
 		slurm_node_registration_status_msg_t * msg, 
 		Buf buffer )
 {
@@ -580,7 +648,7 @@ void pack_node_registration_status_msg (
 	}
 }
 
-int unpack_node_registration_status_msg ( 
+static int _unpack_node_registration_status_msg ( 
 		slurm_node_registration_status_msg_t ** msg , 
 		Buf buffer )
 {
@@ -627,7 +695,7 @@ int unpack_node_registration_status_msg (
 	return SLURM_ERROR;
 }
 
-void pack_resource_allocation_response_msg ( 
+static void _pack_resource_allocation_response_msg ( 
 		resource_allocation_response_msg_t * msg, Buf buffer )
 {
 	assert ( msg != NULL );
@@ -646,7 +714,7 @@ void pack_resource_allocation_response_msg (
 			buffer ) ;
 }
 
-int unpack_resource_allocation_response_msg ( 
+static int _unpack_resource_allocation_response_msg ( 
 		resource_allocation_response_msg_t ** msg , Buf buffer )
 {
 	uint16_t uint16_tmp;
@@ -708,7 +776,7 @@ int unpack_resource_allocation_response_msg (
 	return SLURM_ERROR;
 }
 
-void pack_resource_allocation_and_run_response_msg ( 
+static void _pack_resource_allocation_and_run_response_msg ( 
 		resource_allocation_and_run_response_msg_t * msg, 
 		Buf buffer )
 {
@@ -733,7 +801,7 @@ void pack_resource_allocation_and_run_response_msg (
 #endif
 }
 
-int unpack_resource_allocation_and_run_response_msg ( 
+static int _unpack_resource_allocation_and_run_response_msg ( 
 		resource_allocation_and_run_response_msg_t ** msg , 
 		Buf buffer )
 {
@@ -801,16 +869,16 @@ int unpack_resource_allocation_and_run_response_msg (
 	return SLURM_ERROR;
 }
 
-void pack_submit_response_msg ( submit_response_msg_t * msg, 
-                                Buf buffer )
+static void _pack_submit_response_msg ( submit_response_msg_t * msg, 
+                                        Buf buffer )
 {
 	assert ( msg != NULL );
 	
 	pack32 ( msg->job_id , buffer ) ;
 }
 
-int unpack_submit_response_msg ( submit_response_msg_t ** msg , 
-                                 Buf buffer )
+static int _unpack_submit_response_msg ( submit_response_msg_t ** msg , 
+                                         Buf buffer )
 {
 	submit_response_msg_t * tmp_ptr ;
 
@@ -828,12 +896,12 @@ int unpack_submit_response_msg ( submit_response_msg_t ** msg ,
 	*msg = NULL;
 	return SLURM_ERROR;
 }
-void pack_node_info_msg ( slurm_msg_t * msg, Buf buffer )
+static void _pack_node_info_msg ( slurm_msg_t * msg, Buf buffer )
 {
 	packmem_array ( msg->data , msg->data_size, buffer );
 }
 
-int unpack_node_info_msg ( node_info_msg_t ** msg , Buf buffer )
+static int _unpack_node_info_msg ( node_info_msg_t ** msg , Buf buffer )
 {
 	int i;
 	node_info_t *node = NULL;
@@ -850,7 +918,7 @@ int unpack_node_info_msg ( node_info_msg_t ** msg , Buf buffer )
 
 	/* load individual job info */
 	for (i = 0; i < (*msg)->record_count ; i++) {
-		if (unpack_node_info_members ( & node[i] , buffer ) )
+		if (_unpack_node_info_members ( & node[i] , buffer ) )
 			goto unpack_error;
 
 	}
@@ -864,21 +932,7 @@ int unpack_node_info_msg ( node_info_msg_t ** msg , Buf buffer )
 	return SLURM_ERROR;
 }
 
-
-int unpack_node_info ( node_info_t ** node , Buf buffer )
-{
-	assert ( node != NULL );
-
-	*node = xmalloc ( sizeof(node_info_t) );
-	if (unpack_node_info_members ( *node , buffer )) {
-		xfree (*node);
-		*node = NULL;
-		return SLURM_ERROR;
-	} else
-		return SLURM_SUCCESS ;
-}
-
-int unpack_node_info_members ( node_info_t * node , Buf buffer )
+static int _unpack_node_info_members ( node_info_t * node , Buf buffer )
 {
 	uint16_t uint16_tmp;
 
@@ -912,8 +966,8 @@ int unpack_node_info_members ( node_info_t * node , Buf buffer )
 }
 
 
-void
-pack_update_partition_msg ( update_part_msg_t * msg , Buf buffer )
+static void _pack_update_partition_msg ( update_part_msg_t * msg , 
+                                         Buf buffer )
 {
 	assert ( msg != NULL );
 
@@ -928,7 +982,8 @@ pack_update_partition_msg ( update_part_msg_t * msg , Buf buffer )
 	packstr ( msg -> allow_groups, buffer ) ;
 }
 
-int unpack_update_partition_msg ( update_part_msg_t ** msg , Buf buffer  )
+static int _unpack_update_partition_msg ( update_part_msg_t ** msg , 
+                                          Buf buffer  )
 {
 	uint16_t uint16_tmp;
 	update_part_msg_t * tmp_ptr ;
@@ -963,7 +1018,7 @@ int unpack_update_partition_msg ( update_part_msg_t ** msg , Buf buffer  )
 	return SLURM_ERROR;
 }
 
-void pack_job_step_create_request_msg ( 
+static void _pack_job_step_create_request_msg ( 
 		job_step_create_request_msg_t* msg , Buf buffer )
 {
 	assert ( msg != NULL );
@@ -977,7 +1032,7 @@ void pack_job_step_create_request_msg (
 	packstr ( msg -> node_list, buffer ) ;
 }
 
-int unpack_job_step_create_request_msg ( 
+static int _unpack_job_step_create_request_msg ( 
 		job_step_create_request_msg_t** msg , Buf buffer )
 {
 	uint16_t uint16_tmp;
@@ -1007,8 +1062,8 @@ int unpack_job_step_create_request_msg (
 	return SLURM_ERROR;
 }
 
-void pack_revoke_credential_msg ( revoke_credential_msg_t* msg , 
-                                  Buf buffer )
+static void _pack_revoke_credential_msg ( revoke_credential_msg_t* msg , 
+                                          Buf buffer )
 {
 	assert ( msg != NULL );
 
@@ -1019,8 +1074,8 @@ void pack_revoke_credential_msg ( revoke_credential_msg_t* msg ,
                        buffer ) ; 
 }
 
-int unpack_revoke_credential_msg ( revoke_credential_msg_t** msg , 
-                                   Buf buffer )
+static int _unpack_revoke_credential_msg ( revoke_credential_msg_t** msg , 
+                                           Buf buffer )
 {
 	revoke_credential_msg_t* tmp_ptr ;
 
@@ -1043,6 +1098,12 @@ int unpack_revoke_credential_msg ( revoke_credential_msg_t** msg ,
 	return SLURM_ERROR;
 }
 
+/* pack_job_credential
+ * packs a slurm job credential
+ * IN cred - pointer to the credential
+ * IN/OUT buffer - destination of the pack, contains pointers that are 
+ *			automatically updated
+ */
 void pack_job_credential ( slurm_job_credential_t* cred , Buf buffer )
 {
 	assert ( cred != NULL );
@@ -1056,14 +1117,21 @@ void pack_job_credential ( slurm_job_credential_t* cred , Buf buffer )
                        buffer ) ; 
 }
 
-int unpack_job_credential( slurm_job_credential_t** msg , Buf buffer )
+/* unpack_job_credential
+ * unpacks a slurm job credential
+ * OUT cred - pointer to the credential pointer
+ * IN/OUT buffer - source of the unpack, contains pointers that are 
+ *			automatically updated
+ * RET 0 or error code
+ */
+int unpack_job_credential( slurm_job_credential_t** cred , Buf buffer )
 {
 	uint16_t uint16_tmp;
 	slurm_job_credential_t* tmp_ptr ;
 
 	/* alloc memory for structure */	
 	tmp_ptr = xmalloc ( sizeof ( slurm_job_credential_t ) ) ;
-	*msg = tmp_ptr;
+	*cred = tmp_ptr;
 
 	safe_unpack32( &(tmp_ptr->job_id), buffer ) ;
 	safe_unpack16( (uint16_t*) &(tmp_ptr->user_id), buffer ) ;
@@ -1080,7 +1148,7 @@ int unpack_job_credential( slurm_job_credential_t** msg , Buf buffer )
 	if (tmp_ptr->node_list)
 		xfree (tmp_ptr->node_list);
 	xfree (tmp_ptr);
-	*msg = NULL;
+	*cred = NULL;
 	return SLURM_ERROR;
 }
 
diff --git a/src/common/slurm_protocol_pack.h b/src/common/slurm_protocol_pack.h
index eead8bf9698..94ed88a3f34 100644
--- a/src/common/slurm_protocol_pack.h
+++ b/src/common/slurm_protocol_pack.h
@@ -43,24 +43,99 @@
 #include "src/common/pack.h"
 #include "src/common/slurm_protocol_defs.h"
 
-/* Pack / Unpack methods for slurm protocol header */
-void pack_header ( header_t  * header , Buf buffer );
-int  unpack_header ( header_t * header , Buf buffer );
+/****************************/
+/* Message header functions */
+/****************************/
+/* pack_header
+ * packs a slurm protocol header that proceeds every slurm message
+ * IN header - the header structure to pack
+ * IN/OUT buffer - destination of the pack, contains pointers that are
+ *			automatically updated
+ */
+extern void pack_header ( header_t  * header , Buf buffer );
+
+/* unpack_header
+ * unpacks a slurm protocol header that proceeds every slurm message
+ * OUT header - the header structure to unpack
+ * IN/OUT buffer - source of the unpack data, contains pointers that are
+ *			automatically updated
+ * RET 0 or error code
+ */
+extern int unpack_header ( header_t * header , Buf buffer );
 
-/* Pack / Unpack methods for slurm io pipe streams header */
-int size_io_stream_header (void);
-void pack_io_stream_header ( slurm_io_stream_header_t * msg , Buf buffer ) ;
-int unpack_io_stream_header ( slurm_io_stream_header_t * msg , Buf buffer ) ;
 
+/****************************/
+/* Stream header functions  */
+/****************************/
+/* size_io_stream_header - get the size of an I/O stream header
+ * RET number of bytes in an I/O steam header
+ */
+extern int size_io_stream_header ( void );
+
+/* pack_io_stream_header
+ * packs an i/o stream protocol header used for stdin/out/err
+ * IN header - the header structure to pack
+ * IN/OUT buffer - destination of the pack, contains pointers that are
+ *			automatically updated
+ */
+extern void pack_io_stream_header ( slurm_io_stream_header_t * header , 
+                                    Buf buffer ) ;
+
+/* unpack_io_stream_header
+ * unpacks an i/o stream protocol header used for stdin/out/err
+ * OUT header - the header structure to unpack
+ * IN/OUT buffer - source of the unpack data, contains pointers that are
+ *			automatically updated
+ * RET 0 or error code
+ */
+extern int unpack_io_stream_header ( slurm_io_stream_header_t * header , 
+                                     Buf buffer ) ;
+
+/**************************************************************************/
 /* generic case statement Pack / Unpack methods for slurm protocol bodies */
-int pack_msg ( slurm_msg_t const * msg , Buf buffer );
-int unpack_msg ( slurm_msg_t * msgi , Buf buffer );
+/**************************************************************************/
+
+/* pack_msg
+ * packs a generic slurm protocol message body
+ * IN msg - the body structure to pack (note: includes message type)
+ * IN/OUT buffer - destination of the pack, contains pointers that are 
+ *			automatically updated
+ * RET 0 or error code
+ */
+extern int pack_msg ( slurm_msg_t const * msg , Buf buffer );
+
+/* unpack_msg
+ * unpacks a generic slurm protocol message body
+ * OUT msg - the body structure to unpack (note: includes message type)
+ * IN/OUT buffer - source of the unpack, contains pointers that are 
+ *			automatically updated
+ * RET 0 or error code
+ */
+extern int unpack_msg ( slurm_msg_t * msgi , Buf buffer );
+
+/***************************************************************************/
+/* specific case statement Pack / Unpack methods for slurm protocol bodies */
+/***************************************************************************/
+/* pack_job_credential
+ * packs a slurm job credential
+ * IN cred - pointer to the credential
+ * IN/OUT buffer - destination of the pack, contains pointers that are 
+ *			automatically updated
+ */
+void pack_job_credential ( slurm_job_credential_t* cred , Buf buffer ) ;
+
+/* unpack_job_credential
+ * unpacks a slurm job credential
+ * OUT cred - pointer to the credential pointer
+ * IN/OUT buffer - source of the unpack, contains pointers that are 
+ *			automatically updated
+ * RET 0 or error code
+ */
+int unpack_job_credential( slurm_job_credential_t** cred , Buf buffer ) ;
+
+
 
-/* specific Pack / Unpack methods for slurm protocol bodies */
-void pack_node_registration_status_msg ( 
-	slurm_node_registration_status_msg_t * msg , Buf buffer );
 
-int unpack_node_registration_status_msg ( slurm_node_registration_status_msg_t ** msg ,  Buf buffer );
 
 void pack_job_desc ( job_desc_msg_t *job_desc_msg_ptr, Buf buffer );
 int unpack_job_desc ( job_desc_msg_t **job_desc_msg_ptr, Buf buffer );
@@ -72,11 +147,6 @@ int unpack_old_job_desc ( old_job_alloc_msg_t **job_desc_buffer_ptr,
 void pack_last_update ( last_update_msg_t * msg , Buf buffer );
 int unpack_last_update ( last_update_msg_t ** msg , Buf buffer );
 
-void pack_job_step_create_request_msg ( job_step_create_request_msg_t* msg , 
-                                        Buf buffer );
-int unpack_job_step_create_request_msg ( job_step_create_request_msg_t** msg , 
-                                         Buf buffer );
-
 void pack_job_step_create_response_msg (  job_step_create_response_msg_t* msg , 
                                           Buf buffer );
 int unpack_job_step_create_response_msg (job_step_create_response_msg_t** msg , 
@@ -115,11 +185,6 @@ int unpack_partition_info_msg ( partition_info_msg_t ** , Buf buffer );
 int unpack_partition_info ( partition_info_t ** part , Buf buffer );
 int unpack_partition_info_members ( partition_info_t * part , Buf buffer );
 
-void pack_node_info_msg ( slurm_msg_t * msg, Buf buffer );
-int unpack_node_info_msg ( node_info_msg_t ** msg , Buf buffer );
-int unpack_node_info ( node_info_t ** node , Buf buffer );
-int unpack_node_info_members ( node_info_t * node , Buf buffer );
-
 void pack_cancel_job_msg ( job_id_msg_t * msg , Buf buffer );
 int unpack_cancel_job_msg ( job_id_msg_t ** msg_ptr , Buf buffer );
 
@@ -157,28 +222,9 @@ int  unpack_complete_job_step ( complete_job_step_msg_t ** msg_ptr ,
 void pack_cancel_tasks_msg ( kill_tasks_msg_t * msg , Buf buffer );
 int unpack_cancel_tasks_msg ( kill_tasks_msg_t ** msg_ptr , Buf buffer );
 
-void pack_resource_allocation_response_msg ( 
-	resource_allocation_response_msg_t * msg, Buf buffer );
-int unpack_resource_allocation_response_msg ( 
-	resource_allocation_response_msg_t ** msg , Buf buffer );
-
-void pack_resource_allocation_and_run_response_msg ( 
-	resource_allocation_and_run_response_msg_t * msg, Buf buffer );
-int unpack_resource_allocation_and_run_response_msg ( 
-	resource_allocation_and_run_response_msg_t ** msg , Buf buffer );
-
-void pack_submit_response_msg ( submit_response_msg_t * msg, Buf buffer );
-int unpack_submit_response_msg ( submit_response_msg_t ** msg , Buf buffer );
-
-void pack_update_node_msg ( update_node_msg_t * msg, Buf buffer );
-int unpack_update_node_msg ( update_node_msg_t ** msg , Buf buffer );
-
 void pack_partition_table_msg ( partition_desc_msg_t *  msg , Buf buffer );
 int unpack_partition_table_msg ( partition_desc_msg_t **  msg_ptr , Buf buffer );
 
-void pack_update_partition_msg ( update_part_msg_t * msg , Buf buffer );
-int unpack_update_partition_msg ( update_part_msg_t ** msg_ptr , Buf buffer );
-
 void pack_shutdown_msg ( shutdown_msg_t * msg , Buf buffer );
 int unpack_shutdown_msg ( shutdown_msg_t ** msg_ptr , Buf buffer );
 
@@ -211,15 +257,9 @@ void pack_reattach_tasks_streams_msg (
 int unpack_reattach_tasks_streams_msg ( 
 	reattach_tasks_streams_msg_t ** msg_ptr , Buf buffer ) ;
 
-void pack_revoke_credential_msg ( revoke_credential_msg_t* msg , Buf buffer ) ;
-int unpack_revoke_credential_msg ( revoke_credential_msg_t** msg , Buf buffer ) ;
-
 void pack_task_exit_msg ( task_exit_msg_t * msg , Buf buffer ) ;
 int unpack_task_exit_msg ( task_exit_msg_t ** msg_ptr , Buf buffer ) ;
 
-void pack_job_credential ( slurm_job_credential_t* cred , Buf buffer ) ;
-int unpack_job_credential( slurm_job_credential_t** msg , Buf buffer ) ;
-
 void pack_batch_job_launch ( batch_job_launch_msg_t* cred , Buf buffer ) ;
 int  unpack_batch_job_launch( batch_job_launch_msg_t** msg , Buf buffer ) ;
 
-- 
GitLab