Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions orte/mca/ess/hnp/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2017 Los Alamos National Security, LLC. All rights
# reseved.
# Copyright (c) 2017 Intel, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#

dist_ortedata_DATA = help-ess-hnp.txt

sources = \
ess_hnp.h \
ess_hnp_component.c \
Expand Down
19 changes: 15 additions & 4 deletions orte/mca/ess/hnp/ess_hnp.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
* University Research and Technology
Expand All @@ -9,6 +10,9 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2017 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2017 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand All @@ -24,12 +28,19 @@ BEGIN_C_DECLS
/*
* Module open / close
*/
int orte_ess_hnp_component_open(void);
int orte_ess_hnp_component_close(void);
int orte_ess_hnp_component_query(mca_base_module_t **module, int *priority);
typedef struct {
opal_list_item_t super;
char *signame;
int signal;
} ess_hnp_signal_t;
OBJ_CLASS_DECLARATION(ess_hnp_signal_t);

typedef struct {
orte_ess_base_component_t base;
opal_list_t signals;
} orte_ess_hnp_component_t;

ORTE_MODULE_DECLSPEC extern orte_ess_base_component_t mca_ess_hnp_component;
ORTE_MODULE_DECLSPEC extern orte_ess_hnp_component_t mca_ess_hnp_component;

END_C_DECLS

Expand Down
217 changes: 193 additions & 24 deletions orte/mca/ess/hnp/ess_hnp_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
* Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2017 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand All @@ -29,45 +30,200 @@
#include "orte/constants.h"

#include "orte/util/proc_info.h"
#include "orte/util/show_help.h"

#include "orte/mca/ess/ess.h"
#include "orte/mca/ess/hnp/ess_hnp.h"
#include "orte/runtime/orte_globals.h"

extern orte_ess_base_module_t orte_ess_hnp_module;
static int hnp_component_register (void);
static int hnp_component_open(void);
static int hnp_component_close(void);
static int hnp_component_query(mca_base_module_t **module, int *priority);

struct known_signal {
/** signal number */
int signal;
/** signal name */
char *signame;
/** can this signal be forwarded */
bool can_forward;
};

static struct known_signal known_signals[] = {
{SIGTERM, "SIGTERM", false},
{SIGHUP, "SIGHUP", false},
{SIGINT, "SIGINT", false},
{SIGKILL, "SIGKILL", false},
#ifdef SIGSYS
{SIGSYS, "SIGSYS", true},
#endif
#ifdef SIGXCPU
{SIGXCPU, "SIGXCPU", true},
#endif
{SIGXFSZ, "SIGXFSZ", true},
#ifdef SIGVTALRM
{SIGVTALRM, "SIGVTALRM", true},
#endif
#ifdef SIGPROF
{SIGPROF, "SIGPROF", true},
#endif
#ifdef SIGINFO
{SIGINFO, "SIGINFO", true},
#endif
#ifdef SIGPWR
{SIGPWR, "SIGPWR", true},
#endif
{0, NULL},
};

/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
orte_ess_base_component_t mca_ess_hnp_component = {
.base_version = {
ORTE_ESS_BASE_VERSION_3_0_0,

/* Component name and version */
.mca_component_name = "hnp",
MCA_BASE_MAKE_VERSION(component, ORTE_MAJOR_VERSION, ORTE_MINOR_VERSION,
ORTE_RELEASE_VERSION),

/* Component open and close functions */
.mca_open_component = orte_ess_hnp_component_open,
.mca_close_component = orte_ess_hnp_component_close,
.mca_query_component = orte_ess_hnp_component_query,
},
.base_data = {
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
orte_ess_hnp_component_t mca_ess_hnp_component = {
.base = {
.base_version = {
ORTE_ESS_BASE_VERSION_3_0_0,

/* Component name and version */
.mca_component_name = "hnp",
MCA_BASE_MAKE_VERSION(component, ORTE_MAJOR_VERSION, ORTE_MINOR_VERSION,
ORTE_RELEASE_VERSION),

/* Component open and close functions */
.mca_open_component = hnp_component_open,
.mca_close_component = hnp_component_close,
.mca_query_component = hnp_component_query,
.mca_register_component_params = hnp_component_register,
},
.base_data = {
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
}
}
};

static char *additional_signals;

int
orte_ess_hnp_component_open(void)
static int hnp_component_register (void)
{
additional_signals = NULL;
(void) mca_base_component_var_register (&mca_ess_hnp_component.base.base_version,
"forward_signals", "Comma-delimited list "
"of additional signals (names or integers) to forward to "
"application processes [\"none\" => forward nothing]", MCA_BASE_VAR_TYPE_STRING,
NULL, 0, 0, OPAL_INFO_LVL_4, MCA_BASE_VAR_SCOPE_READONLY,
&additional_signals);

return ORTE_SUCCESS;
}

#define ESS_ADDSIGNAL(x, s) \
do { \
ess_hnp_signal_t *_sig; \
_sig = OBJ_NEW(ess_hnp_signal_t); \
_sig->signal = (x); \
_sig->signame = strdup((s)); \
opal_list_append(&mca_ess_hnp_component.signals, &_sig->super); \
} while(0)

static int hnp_component_open(void)
{
int i, sval;
char **signals, *tmp;
ess_hnp_signal_t *sig;
bool ignore, found;

OBJ_CONSTRUCT(&mca_ess_hnp_component.signals, opal_list_t);

/* we know that some signals are (nearly) always defined, regardless
* of environment, so add them here */
ESS_ADDSIGNAL(SIGTSTP, "SIGTSTP");
ESS_ADDSIGNAL(SIGUSR1, "SIGUSR1");
ESS_ADDSIGNAL(SIGUSR2, "SIGUSR2");
ESS_ADDSIGNAL(SIGABRT, "SIGABRT");
ESS_ADDSIGNAL(SIGALRM, "SIGALRM");
ESS_ADDSIGNAL(SIGCONT, "SIGCONT");
#ifdef SIGURG
ESS_ADDSIGNAL(SIGURG, "SIGURG");
#endif

/* see if they asked for anything beyond those - note that they may
* have asked for some we already cover, and so we ignore any duplicates */
if (NULL != additional_signals) {
/* if they told us "none", then dump the list */
if (0 == strcmp(additional_signals, "none")) {
OPAL_LIST_DESTRUCT(&mca_ess_hnp_component.signals);
/* need to reconstruct it for when we close */
OBJ_CONSTRUCT(&mca_ess_hnp_component.signals, opal_list_t);
return ORTE_SUCCESS;
}
signals = opal_argv_split(additional_signals, ',');
for (i=0; NULL != signals[i]; i++) {
sval = 0;
if (0 != strncmp(signals[i], "SIG", 3)) {
/* treat it like a number */
errno = 0;
sval = strtoul(signals[i], &tmp, 10);
if (0 != errno || '\0' != *tmp) {
orte_show_help("help-ess-hnp.txt", "ess-hnp:unknown-signal",
true, signals[i], additional_signals);
opal_argv_free(signals);
return OPAL_ERR_SILENT;
}
}

/* see if it is one we already covered */
ignore = false;
OPAL_LIST_FOREACH(sig, &mca_ess_hnp_component.signals, ess_hnp_signal_t) {
if (0 == strcasecmp(signals[i], sig->signame) || sval == sig->signal) {
/* got it - we will ignore */
ignore = true;
break;
}
}

if (ignore) {
continue;
}

/* see if they gave us a signal name */
found = false;
for (int j = 0 ; known_signals[j].signame ; ++j) {
if (0 == strcasecmp (signals[i], known_signals[j].signame) || sval == known_signals[j].signal) {
if (!known_signals[j].can_forward) {
orte_show_help("help-ess-hnp.txt", "ess-hnp:cannot-forward",
true, known_signals[j].signame, additional_signals);
opal_argv_free(signals);
return OPAL_ERR_SILENT;
}
found = true;
ESS_ADDSIGNAL(known_signals[j].signal, known_signals[j].signame);
break;
}
}

if (!found) {
if (0 == strncmp(signals[i], "SIG", 3)) {
orte_show_help("help-ess-hnp.txt", "ess-hnp:unknown-signal",
true, signals[i], additional_signals);
opal_argv_free(signals);
return OPAL_ERR_SILENT;
}

ESS_ADDSIGNAL(sval, signals[i]);
}
}
opal_argv_free (signals);
}

return ORTE_SUCCESS;
}


int orte_ess_hnp_component_query(mca_base_module_t **module, int *priority)
static int hnp_component_query(mca_base_module_t **module, int *priority)
{

/* we are the hnp module - we need to be selected
Expand All @@ -86,9 +242,22 @@ int orte_ess_hnp_component_query(mca_base_module_t **module, int *priority)
}


int
orte_ess_hnp_component_close(void)
static int hnp_component_close(void)
{
return ORTE_SUCCESS;
}

/* instantiate the class */
static void scon(ess_hnp_signal_t *t)
{
t->signame = NULL;
}
static void sdes(ess_hnp_signal_t *t)
{
if (NULL != t->signame) {
free(t->signame);
}
}
OBJ_CLASS_INSTANCE(ess_hnp_signal_t,
opal_list_item_t,
scon, sdes);
Loading