From e93a3ee7eb6d1aad2cb5afd0e5f77b3ec916a2fe Mon Sep 17 00:00:00 2001
From: tewk <tewk@unknown>
Date: Tue, 6 Aug 2002 22:01:03 +0000
Subject: [PATCH] Added daemonize to slurmd

---
 src/common/slurm_errno.c | 14 ++++++++++++++
 src/slurmd/Makefile.am   |  1 +
 src/slurmd/nbio.c        |  9 ++++++++-
 src/slurmd/slurmd.c      | 25 ++++++++++++++++++-------
 4 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/src/common/slurm_errno.c b/src/common/slurm_errno.c
index 0ea696cceb3..baea5466709 100644
--- a/src/common/slurm_errno.c
+++ b/src/common/slurm_errno.c
@@ -110,7 +110,21 @@ g" },
 	{ ESLURMD_OPENSSL_ERROR,			"Openssl error" },
 	{ ESLURMD_NO_AVAILABLE_JOB_STEP_SLOTS_IN_SHMEM,	"No available job step slots in shmem" },
 	{ ESLURMD_NO_AVAILABLE_TASK_SLOTS_IN_SHMEM,	"No available task slots in shmem" },
+	{ ESLURMD_INVALID_JOB_CREDENTIAL,		"Invalid job credential" },
+	{ ESLURMD_NODE_NAME_NOT_PRESENT_IN_CREDENTIAL,	"This slurmd node name is not int job credential" },
+	{ ESLURMD_CREDENTIAL_EXPIRED,			"Timestamp of this job credential has expired" },
+	{ ESLURMD_CREDENTIAL_REVOKED,			"This job credential has been revoked by slurmd" },
+	{ ESLURMD_CREDENTIAL_TO_EXPIRE_DOESNOT_EXIST, 	"Credential requested to expire doesn't exist" },
+	{ ESLURMD_ERROR_SIGNING_CREDENTIAL, 		"SSL crypto error signing job credential" },
 	{ ESLURMD_ERROR_FINDING_JOB_STEP_IN_SHMEM , 	"Job step not found in shmem" },
+	{ ESLURMD_CIRBUF_POINTER_0, 			"Circular read or write buffer size is 0/ not good" },
+	{ ESLURMD_PIPE_DISCONNECT, 			"Task has closed or dropped its stdio pipes" },
+	{ ESLURMD_EOF_ON_SOCKET, 			"Socket returned EOF, it was closed" },
+	{ ESLURMD_SOCKET_DISCONNECT, 			"Socket disconnected" },
+	{ ESLURMD_UNKNOWN_SOCKET_ERROR, 		"Unknown socket error / this is bad" },
+	/*
+	{ , "" },
+	*/
         /* socket specific SLURM communications error */
 	{ SLURM_PROTOCOL_SOCKET_IMPL_ZERO_RECV_LENGTH,		"Received zero length message" },
 	{ SLURM_PROTOCOL_SOCKET_IMPL_NEGATIVE_RECV_LENGTH,	"Received message length < 0" },
diff --git a/src/slurmd/Makefile.am b/src/slurmd/Makefile.am
index 17028f4a659..35173f8b55b 100644
--- a/src/slurmd/Makefile.am
+++ b/src/slurmd/Makefile.am
@@ -13,6 +13,7 @@ sbin_PROGRAMS = slurmd
 noinst_LIBRARIES = libelan_interconnect.a libno_interconnect.a libforked_io.a  libthreaded_io.a libnbio.a
 
 LDADD = $(top_srcdir)/src/common/libcommon.la \
+	$(top_srcdir)/src/common/libdaemonize.la \
 	$(SSL_LIBS) libno_interconnect.a
 
 
diff --git a/src/slurmd/nbio.c b/src/slurmd/nbio.c
index 2169562ae8f..179184439c9 100644
--- a/src/slurmd/nbio.c
+++ b/src/slurmd/nbio.c
@@ -22,6 +22,8 @@
 #include <src/slurmd/io.h>
 #include <src/slurmd/pipes.h>
 
+#define RECONNECT_TIMEOUT_SECONDS 1
+#define RECONNECT_TIMEOUT_MICROSECONDS 0
 typedef enum 
 {
 	IN_OUT_FD ,
@@ -88,7 +90,12 @@ void * do_nbio ( void * arg )
 
 	while ( true ) 
 	{
-		int rc = slurm_select ( nbio_attr . max_fd , & nbio_attr . init_set[RD_SET] , & nbio_attr . init_set[WR_SET] , & nbio_attr . init_set[ER_SET] , NULL ) ;
+		struct timeval select_timer ;
+		int rc ;
+		select_timer . tv_sec = RECONNECT_TIMEOUT_SECONDS ;
+		select_timer . tv_usec = RECONNECT_TIMEOUT_MICROSECONDS ;
+
+		rc = slurm_select ( nbio_attr . max_fd , & nbio_attr . init_set[RD_SET] , & nbio_attr . init_set[WR_SET] , & nbio_attr . init_set[ER_SET] , NULL ) ;
 
 		nbio_set_init ( & nbio_attr , nbio_attr . next_set ) ;
 
diff --git a/src/slurmd/slurmd.c b/src/slurmd/slurmd.c
index b0971b162d5..e5e6cd2876f 100644
--- a/src/slurmd/slurmd.c
+++ b/src/slurmd/slurmd.c
@@ -61,6 +61,7 @@ typedef struct slurmd_config
 {
 	log_options_t log_opts ;
 	char * slurm_conf ;
+	int daemonize ;
 } slurmd_config_t ;
 
 typedef struct connection_arg
@@ -107,11 +108,17 @@ int main (int argc, char *argv[])
 
 	init_time = time (NULL);
 	slurmd_conf . log_opts = log_opts_def ;
+	slurmd_conf . daemonize = false ;
 
 
 	parse_commandline_args ( argc, argv, & slurmd_conf ) ;
 	log_init(argv[0], slurmd_conf . log_opts, SYSLOG_FACILITY_DAEMON, NULL);
 
+	if ( slurmd_conf . daemonize == true )
+	{
+		daemon ( false , true ) ;
+	}
+
 /*
 	if ( ( error_code = init_slurm_conf () ) ) 
 		fatal ("slurmd: init_slurm_conf error %d", error_code);
@@ -611,6 +618,7 @@ void usage (char *prog_name)
 	printf ("%s [OPTIONS]\n", prog_name);
 	printf ("  -e <errlev>  Set stderr logging to the specified level\n");
 	printf ("  -f <file>    Use specified configuration file name\n");
+	printf ("  -d           daemonize\n");
 	printf ("  -h           Print a help message describing usage\n");
 	printf ("  -l <errlev>  Set logfile logging to the specified level\n");
 	printf ("  -s <errlev>  Set syslog logging to the specified level\n");
@@ -630,16 +638,16 @@ int parse_commandline_args ( int argc , char ** argv , slurmd_config_t * slurmd_
 		int option_index = 0;
 		static struct option long_options[] = 
 		{
-			{"add", 1, 0, 0},
-			{"append", 0, 0, 0},
-			{"delete", 1, 0, 0},
-			{"verbose", 0, 0, 0},
-			{"create", 1, 0, 'c'},
-			{"file", 1, 0, 0},
+			{"error_level", 1, 0, 'e'},
+			{"help", 0, 0, 'h'},
+			{"daemonize", 0, 0, 'd'},
+			{"config_file", 1, 0, 'f'},
+			{"log_level", 1, 0, 'l'},
+			{"syslog_level", 1, 0, 's'},
 			{0, 0, 0, 0}
 		};
 
-		c = getopt_long (argc, argv, "e:hf:l:s:", long_options, &option_index);
+		c = getopt_long (argc, argv, "de:hf:l:s:", long_options, &option_index);
 		if (c == -1)
 			break;
 
@@ -656,6 +664,9 @@ int parse_commandline_args ( int argc , char ** argv , slurmd_config_t * slurmd_
 				}
 				slurmd_config -> log_opts . stderr_level = errlev;
 				break;
+			case 'd':
+				slurmd_config -> daemonize = true ;
+				break;
 			case 'h':
 				usage (argv[0]);
 				exit (0);
-- 
GitLab