Skip to content
Snippets Groups Projects
Commit c0735a97 authored by Mark Grondona's avatar Mark Grondona
Browse files

o change slurmd daemonization to not close all fds

parent 5cf35ce4
No related branches found
No related tags found
No related merge requests found
...@@ -71,15 +71,35 @@ daemon(int nochdir, int noclose) ...@@ -71,15 +71,35 @@ daemon(int nochdir, int noclose)
default: _exit(0); /* exit parent */ default: _exit(0); /* exit parent */
} }
if(!nochdir && chdir("/") < 0) if(!nochdir && chdir("/") < 0) {
fatal("chdir(/): %m"); error("chdir(/): %m");
return -1;
}
/* Close all file descriptors if requested
*/
if (!noclose) { if (!noclose) {
closeall(0); closeall(0);
open("/dev/null", O_RDWR); open("/dev/null", O_RDWR);
dup(0); dup2(0, STDOUT_FILENO);
dup(0); dup2(0, STDERR_FILENO);
} else {
/*
* Otherwise, dup stdin, stdout, and stderr onto /dev/null
*/
int devnull = open("/dev/null", O_RDWR);
if (devnull < 0)
error("Unable to open /dev/null: %m");
if (dup2(devnull, STDIN_FILENO) < 0)
error("Unable to dup /dev/null onto stdin: %m");
if (dup2(devnull, STDOUT_FILENO) < 0)
error("Unable to dup /dev/null onto stdout: %m");
if (dup2(devnull, STDERR_FILENO) < 0)
error("Unable to dup /dev/null onto stderr: %m");
if (close(devnull) < 0)
error("Unable to close /dev/null: %m");
} }
return 0; return 0;
} }
......
...@@ -983,6 +983,8 @@ _shm_reopen() ...@@ -983,6 +983,8 @@ _shm_reopen()
return SLURM_FAILURE; return SLURM_FAILURE;
} }
debug3("successfully attached to slurmd shm");
/* /*
* Lock and unlock semaphore to ensure data is initialized * Lock and unlock semaphore to ensure data is initialized
*/ */
...@@ -996,6 +998,7 @@ _shm_reopen() ...@@ -996,6 +998,7 @@ _shm_reopen()
} }
_shm_unlock(); _shm_unlock();
debug3("leaving shm_init()");
return retval; return retval;
} }
...@@ -1046,7 +1049,7 @@ _shm_sane(void) ...@@ -1046,7 +1049,7 @@ _shm_sane(void)
sem_getvalue(shm_lock, &val); sem_getvalue(shm_lock, &val);
debug("shm lock val = %d, last accessed at %s", debug3("shm lock val = %d, last accessed at %s",
val, ctime(&st.st_atime)); val, ctime(&st.st_atime));
if ((val == 0) && ((time(NULL) - st.st_atime) > 30)) if ((val == 0) && ((time(NULL) - st.st_atime) > 30))
......
...@@ -138,13 +138,23 @@ main (int argc, char *argv[]) ...@@ -138,13 +138,23 @@ main (int argc, char *argv[])
*/ */
if (_slurmd_init() < 0) { if (_slurmd_init() < 0) {
error( "slurmd initialization failed" ); error( "slurmd initialization failed" );
fflush( NULL );
exit(1); exit(1);
} }
debug3("slurmd initialization successful");
/*
* Become a daemon if desired.
* Do not chdir("/") or close all fd's
*/
if (conf->daemonize) if (conf->daemonize)
daemon(1,0); daemon(1,1);
debug3("finished daemonize");
_kill_old_slurmd(); _kill_old_slurmd();
_create_msg_socket(); _create_msg_socket();
conf->pid = getpid(); conf->pid = getpid();
...@@ -550,6 +560,8 @@ _create_msg_socket() ...@@ -550,6 +560,8 @@ _create_msg_socket()
conf->lfd = ld; conf->lfd = ld;
debug3("succesfully opened slurm listen port %d", conf->port);
return; return;
} }
...@@ -584,6 +596,13 @@ _slurmd_init() ...@@ -584,6 +596,13 @@ _slurmd_init()
setrlimit(RLIMIT_NOFILE,&rlim); setrlimit(RLIMIT_NOFILE,&rlim);
} }
#ifndef NDEBUG
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
rlim.rlim_cur = rlim.rlim_max;
setrlimit(RLIMIT_CORE, &rlim);
}
#endif /* !NDEBUG */
/* /*
* Create a context for verifying slurm job credentials * Create a context for verifying slurm job credentials
*/ */
...@@ -599,8 +618,15 @@ _slurmd_init() ...@@ -599,8 +618,15 @@ _slurmd_init()
/* /*
* Cleanup shared memory if so configured * Cleanup shared memory if so configured
*/ */
if (conf->shm_cleanup) if (conf->shm_cleanup) {
/*
* Need to kill any running slurmd's here so they do
* not fail to lock shared memory on exit
*/
_kill_old_slurmd();
shm_cleanup(); shm_cleanup();
}
/* /*
* Initialize slurmd shared memory * Initialize slurmd shared memory
...@@ -764,6 +790,7 @@ _usage() ...@@ -764,6 +790,7 @@ _usage()
static int static int
_set_slurmd_spooldir(void) _set_slurmd_spooldir(void)
{ {
debug3("initializing slurmd spool directory");
if ((mkdir(conf->spooldir, 0755) < 0) && (errno != EEXIST)) { if ((mkdir(conf->spooldir, 0755) < 0) && (errno != EEXIST)) {
error("mkdir(%s): %m", conf->spooldir); error("mkdir(%s): %m", conf->spooldir);
return SLURM_ERROR; return SLURM_ERROR;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment