Merge pull request #3930 from rhc54/topic/signal
Fix signal forwarding on ORTE daemons
Этот коммит содержится в:
Коммит
83d21e3130
@ -161,13 +161,34 @@ static struct known_signal known_signals[] = {
|
|||||||
{SIGHUP, "SIGHUP", false},
|
{SIGHUP, "SIGHUP", false},
|
||||||
{SIGINT, "SIGINT", false},
|
{SIGINT, "SIGINT", false},
|
||||||
{SIGKILL, "SIGKILL", false},
|
{SIGKILL, "SIGKILL", false},
|
||||||
|
{SIGPIPE, "SIGPIPE", false},
|
||||||
|
#ifdef SIGQUIT
|
||||||
|
{SIGQUIT, "SIGQUIT", false},
|
||||||
|
#endif
|
||||||
|
#ifdef SIGTRAP
|
||||||
|
{SIGTRAP, "SIGTRAP", true},
|
||||||
|
#endif
|
||||||
|
#ifdef SIGTSTP
|
||||||
|
{SIGTSTP, "SIGTSTP", true},
|
||||||
|
#endif
|
||||||
|
#ifdef SIGABRT
|
||||||
|
{SIGABRT, "SIGABRT", true},
|
||||||
|
#endif
|
||||||
|
#ifdef SIGCONT
|
||||||
|
{SIGCONT, "SIGCONT", true},
|
||||||
|
#endif
|
||||||
#ifdef SIGSYS
|
#ifdef SIGSYS
|
||||||
{SIGSYS, "SIGSYS", true},
|
{SIGSYS, "SIGSYS", true},
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGXCPU
|
#ifdef SIGXCPU
|
||||||
{SIGXCPU, "SIGXCPU", true},
|
{SIGXCPU, "SIGXCPU", true},
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SIGXFSZ
|
||||||
{SIGXFSZ, "SIGXFSZ", true},
|
{SIGXFSZ, "SIGXFSZ", true},
|
||||||
|
#endif
|
||||||
|
#ifdef SIGALRM
|
||||||
|
{SIGALRM, "SIGALRM", true},
|
||||||
|
#endif
|
||||||
#ifdef SIGVTALRM
|
#ifdef SIGVTALRM
|
||||||
{SIGVTALRM, "SIGVTALRM", true},
|
{SIGVTALRM, "SIGVTALRM", true},
|
||||||
#endif
|
#endif
|
||||||
|
@ -88,12 +88,11 @@ static bool signals_set=false;
|
|||||||
static opal_event_t term_handler;
|
static opal_event_t term_handler;
|
||||||
static opal_event_t int_handler;
|
static opal_event_t int_handler;
|
||||||
static opal_event_t epipe_handler;
|
static opal_event_t epipe_handler;
|
||||||
static opal_event_t sigusr1_handler;
|
|
||||||
static opal_event_t sigusr2_handler;
|
|
||||||
static char *log_path = NULL;
|
static char *log_path = NULL;
|
||||||
static void shutdown_signal(int fd, short flags, void *arg);
|
static void shutdown_signal(int fd, short flags, void *arg);
|
||||||
static void signal_callback(int fd, short flags, void *arg);
|
|
||||||
static void epipe_signal_callback(int fd, short flags, void *arg);
|
static void epipe_signal_callback(int fd, short flags, void *arg);
|
||||||
|
static void signal_forward_callback(int fd, short event, void *arg);
|
||||||
|
static opal_event_t *forward_signals_events = NULL;
|
||||||
|
|
||||||
static void setup_sighandler(int signal, opal_event_t *ev,
|
static void setup_sighandler(int signal, opal_event_t *ev,
|
||||||
opal_event_cbfunc_t cbfunc)
|
opal_event_cbfunc_t cbfunc)
|
||||||
@ -119,6 +118,8 @@ int orte_ess_base_orted_setup(void)
|
|||||||
unsigned i, j;
|
unsigned i, j;
|
||||||
orte_topology_t *t;
|
orte_topology_t *t;
|
||||||
opal_list_t transports;
|
opal_list_t transports;
|
||||||
|
orte_ess_base_signal_t *sig;
|
||||||
|
int idx;
|
||||||
|
|
||||||
/* my name is set, xfer it to the OPAL layer */
|
/* my name is set, xfer it to the OPAL layer */
|
||||||
orte_process_info.super.proc_name = *(opal_process_name_t*)ORTE_PROC_MY_NAME;
|
orte_process_info.super.proc_name = *(opal_process_name_t*)ORTE_PROC_MY_NAME;
|
||||||
@ -128,6 +129,7 @@ int orte_ess_base_orted_setup(void)
|
|||||||
opal_proc_local_set(&orte_process_info.super);
|
opal_proc_local_set(&orte_process_info.super);
|
||||||
|
|
||||||
plm_in_use = false;
|
plm_in_use = false;
|
||||||
|
|
||||||
/* setup callback for SIGPIPE */
|
/* setup callback for SIGPIPE */
|
||||||
setup_sighandler(SIGPIPE, &epipe_handler, epipe_signal_callback);
|
setup_sighandler(SIGPIPE, &epipe_handler, epipe_signal_callback);
|
||||||
/* Set signal handlers to catch kill signals so we can properly clean up
|
/* Set signal handlers to catch kill signals so we can properly clean up
|
||||||
@ -135,11 +137,23 @@ int orte_ess_base_orted_setup(void)
|
|||||||
*/
|
*/
|
||||||
setup_sighandler(SIGTERM, &term_handler, shutdown_signal);
|
setup_sighandler(SIGTERM, &term_handler, shutdown_signal);
|
||||||
setup_sighandler(SIGINT, &int_handler, shutdown_signal);
|
setup_sighandler(SIGINT, &int_handler, shutdown_signal);
|
||||||
/** setup callbacks for signals we should ignore */
|
/** setup callbacks for signals we should forward */
|
||||||
setup_sighandler(SIGUSR1, &sigusr1_handler, signal_callback);
|
if (0 < (idx = opal_list_get_size(&orte_ess_base_signals))) {
|
||||||
setup_sighandler(SIGUSR2, &sigusr2_handler, signal_callback);
|
forward_signals_events = (opal_event_t*)malloc(sizeof(opal_event_t) * idx);
|
||||||
|
if (NULL == forward_signals_events) {
|
||||||
|
ret = ORTE_ERR_OUT_OF_RESOURCE;
|
||||||
|
error = "unable to malloc";
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
idx = 0;
|
||||||
|
OPAL_LIST_FOREACH(sig, &orte_ess_base_signals, orte_ess_base_signal_t) {
|
||||||
|
setup_sighandler(sig->signal, forward_signals_events + idx, signal_forward_callback);
|
||||||
|
++idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
signals_set = true;
|
signals_set = true;
|
||||||
|
|
||||||
|
|
||||||
/* get the local topology */
|
/* get the local topology */
|
||||||
if (NULL == opal_hwloc_topology) {
|
if (NULL == opal_hwloc_topology) {
|
||||||
if (OPAL_SUCCESS != (ret = opal_hwloc_base_get_topology())) {
|
if (OPAL_SUCCESS != (ret = opal_hwloc_base_get_topology())) {
|
||||||
@ -653,14 +667,24 @@ int orte_ess_base_orted_setup(void)
|
|||||||
|
|
||||||
int orte_ess_base_orted_finalize(void)
|
int orte_ess_base_orted_finalize(void)
|
||||||
{
|
{
|
||||||
|
orte_ess_base_signal_t *sig;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
if (signals_set) {
|
if (signals_set) {
|
||||||
/* Release all local signal handlers */
|
|
||||||
opal_event_del(&epipe_handler);
|
opal_event_del(&epipe_handler);
|
||||||
opal_event_del(&term_handler);
|
opal_event_del(&term_handler);
|
||||||
opal_event_del(&int_handler);
|
opal_event_del(&int_handler);
|
||||||
opal_event_signal_del(&sigusr1_handler);
|
/** Remove the USR signal handlers */
|
||||||
opal_event_signal_del(&sigusr2_handler);
|
i = 0;
|
||||||
|
OPAL_LIST_FOREACH(sig, &orte_ess_base_signals, orte_ess_base_signal_t) {
|
||||||
|
opal_event_signal_del(forward_signals_events + i);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
free (forward_signals_events);
|
||||||
|
forward_signals_events = NULL;
|
||||||
|
signals_set = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
if (NULL != log_path) {
|
if (NULL != log_path) {
|
||||||
unlink(log_path);
|
unlink(log_path);
|
||||||
@ -717,7 +741,51 @@ static void epipe_signal_callback(int fd, short flags, void *arg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void signal_callback(int fd, short event, void *arg)
|
/* Pass user signals to the local application processes */
|
||||||
|
static void signal_forward_callback(int fd, short event, void *arg)
|
||||||
{
|
{
|
||||||
/* just ignore these signals */
|
opal_event_t *signal = (opal_event_t*)arg;
|
||||||
|
int32_t signum, rc;
|
||||||
|
opal_buffer_t *cmd;
|
||||||
|
orte_daemon_cmd_flag_t command=ORTE_DAEMON_SIGNAL_LOCAL_PROCS;
|
||||||
|
orte_jobid_t job = ORTE_JOBID_WILDCARD;
|
||||||
|
|
||||||
|
signum = OPAL_EVENT_SIGNAL(signal);
|
||||||
|
if (!orte_execute_quiet){
|
||||||
|
fprintf(stderr, "%s: Forwarding signal %d to job\n",
|
||||||
|
orte_basename, signum);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = OBJ_NEW(opal_buffer_t);
|
||||||
|
|
||||||
|
/* pack the command */
|
||||||
|
if (ORTE_SUCCESS != (rc = opal_dss.pack(cmd, &command, 1, ORTE_DAEMON_CMD))) {
|
||||||
|
ORTE_ERROR_LOG(rc);
|
||||||
|
OBJ_RELEASE(cmd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pack the jobid */
|
||||||
|
if (ORTE_SUCCESS != (rc = opal_dss.pack(cmd, &job, 1, ORTE_JOBID))) {
|
||||||
|
ORTE_ERROR_LOG(rc);
|
||||||
|
OBJ_RELEASE(cmd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pack the signal */
|
||||||
|
if (ORTE_SUCCESS != (rc = opal_dss.pack(cmd, &signum, 1, OPAL_INT32))) {
|
||||||
|
ORTE_ERROR_LOG(rc);
|
||||||
|
OBJ_RELEASE(cmd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send it to ourselves */
|
||||||
|
if (0 > (rc = orte_rml.send_buffer_nb(orte_mgmt_conduit,
|
||||||
|
ORTE_PROC_MY_NAME, cmd,
|
||||||
|
ORTE_RML_TAG_DAEMON,
|
||||||
|
NULL, NULL))) {
|
||||||
|
ORTE_ERROR_LOG(rc);
|
||||||
|
OBJ_RELEASE(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -59,24 +59,10 @@ orte_ess_base_module_t orte_ess_slurm_module = {
|
|||||||
NULL /* ft_event */
|
NULL /* ft_event */
|
||||||
};
|
};
|
||||||
|
|
||||||
static void signal_forward_callback(int fd, short event, void *arg);
|
|
||||||
static opal_event_t *forward_signals_events = NULL;
|
|
||||||
static bool signals_set=false;
|
|
||||||
|
|
||||||
static void setup_sighandler(int signal, opal_event_t *ev,
|
|
||||||
opal_event_cbfunc_t cbfunc)
|
|
||||||
{
|
|
||||||
opal_event_signal_set(orte_event_base, ev, signal, cbfunc, ev);
|
|
||||||
opal_event_set_priority(ev, ORTE_ERROR_PRI);
|
|
||||||
opal_event_signal_add(ev, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int rte_init(void)
|
static int rte_init(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char *error = NULL;
|
char *error = NULL;
|
||||||
orte_ess_base_signal_t *sig;
|
|
||||||
int idx;
|
|
||||||
|
|
||||||
/* run the prolog */
|
/* run the prolog */
|
||||||
if (ORTE_SUCCESS != (ret = orte_ess_base_std_prolog())) {
|
if (ORTE_SUCCESS != (ret = orte_ess_base_std_prolog())) {
|
||||||
@ -91,29 +77,11 @@ static int rte_init(void)
|
|||||||
* default procedure
|
* default procedure
|
||||||
*/
|
*/
|
||||||
if (ORTE_PROC_IS_DAEMON) {
|
if (ORTE_PROC_IS_DAEMON) {
|
||||||
/** setup callbacks for signals we should forward */
|
|
||||||
if (0 < (idx = opal_list_get_size(&orte_ess_base_signals))) {
|
|
||||||
forward_signals_events = (opal_event_t*)malloc(sizeof(opal_event_t) * idx);
|
|
||||||
if (NULL == forward_signals_events) {
|
|
||||||
ret = ORTE_ERR_OUT_OF_RESOURCE;
|
|
||||||
error = "unable to malloc";
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
idx = 0;
|
|
||||||
OPAL_LIST_FOREACH(sig, &orte_ess_base_signals, orte_ess_base_signal_t) {
|
|
||||||
setup_sighandler(sig->signal, forward_signals_events + idx, signal_forward_callback);
|
|
||||||
++idx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
signals_set = true;
|
|
||||||
|
|
||||||
if (ORTE_SUCCESS != (ret = orte_ess_base_orted_setup())) {
|
if (ORTE_SUCCESS != (ret = orte_ess_base_orted_setup())) {
|
||||||
ORTE_ERROR_LOG(ret);
|
ORTE_ERROR_LOG(ret);
|
||||||
error = "orte_ess_base_orted_setup";
|
error = "orte_ess_base_orted_setup";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
/* setup the signal handlers */
|
|
||||||
|
|
||||||
return ORTE_SUCCESS;
|
return ORTE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,23 +113,9 @@ error:
|
|||||||
static int rte_finalize(void)
|
static int rte_finalize(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
orte_ess_base_signal_t *sig;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
/* if I am a daemon, finalize using the default procedure */
|
/* if I am a daemon, finalize using the default procedure */
|
||||||
if (ORTE_PROC_IS_DAEMON) {
|
if (ORTE_PROC_IS_DAEMON) {
|
||||||
if (signals_set) {
|
|
||||||
/** Remove the USR signal handlers */
|
|
||||||
i = 0;
|
|
||||||
OPAL_LIST_FOREACH(sig, &orte_ess_base_signals, orte_ess_base_signal_t) {
|
|
||||||
opal_event_signal_del(forward_signals_events + i);
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
free (forward_signals_events);
|
|
||||||
forward_signals_events = NULL;
|
|
||||||
signals_set = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ORTE_SUCCESS != (ret = orte_ess_base_orted_finalize())) {
|
if (ORTE_SUCCESS != (ret = orte_ess_base_orted_finalize())) {
|
||||||
ORTE_ERROR_LOG(ret);
|
ORTE_ERROR_LOG(ret);
|
||||||
return ret;
|
return ret;
|
||||||
@ -246,52 +200,3 @@ static int slurm_set_name(void)
|
|||||||
|
|
||||||
return ORTE_SUCCESS;
|
return ORTE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pass user signals to the local application processes */
|
|
||||||
static void signal_forward_callback(int fd, short event, void *arg)
|
|
||||||
{
|
|
||||||
opal_event_t *signal = (opal_event_t*)arg;
|
|
||||||
int32_t signum, rc;
|
|
||||||
opal_buffer_t *cmd;
|
|
||||||
orte_daemon_cmd_flag_t command=ORTE_DAEMON_SIGNAL_LOCAL_PROCS;
|
|
||||||
orte_jobid_t job = ORTE_JOBID_WILDCARD;
|
|
||||||
|
|
||||||
signum = OPAL_EVENT_SIGNAL(signal);
|
|
||||||
if (!orte_execute_quiet){
|
|
||||||
fprintf(stderr, "%s: Forwarding signal %d to job\n",
|
|
||||||
orte_basename, signum);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd = OBJ_NEW(opal_buffer_t);
|
|
||||||
|
|
||||||
/* pack the command */
|
|
||||||
if (ORTE_SUCCESS != (rc = opal_dss.pack(cmd, &command, 1, ORTE_DAEMON_CMD))) {
|
|
||||||
ORTE_ERROR_LOG(rc);
|
|
||||||
OBJ_RELEASE(cmd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pack the jobid */
|
|
||||||
if (ORTE_SUCCESS != (rc = opal_dss.pack(cmd, &job, 1, ORTE_JOBID))) {
|
|
||||||
ORTE_ERROR_LOG(rc);
|
|
||||||
OBJ_RELEASE(cmd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pack the signal */
|
|
||||||
if (ORTE_SUCCESS != (rc = opal_dss.pack(cmd, &signum, 1, OPAL_INT32))) {
|
|
||||||
ORTE_ERROR_LOG(rc);
|
|
||||||
OBJ_RELEASE(cmd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* send it to ourselves */
|
|
||||||
if (0 > (rc = orte_rml.send_buffer_nb(orte_mgmt_conduit,
|
|
||||||
ORTE_PROC_MY_NAME, cmd,
|
|
||||||
ORTE_RML_TAG_DAEMON,
|
|
||||||
NULL, NULL))) {
|
|
||||||
ORTE_ERROR_LOG(rc);
|
|
||||||
OBJ_RELEASE(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user