Skip to content

Commit 2116c91

Browse files
authored
Merge pull request #3717 from rhc54/cmr20/signal
Shift the signal forwarding code to ess/base
2 parents 4846629 + 881bc55 commit 2116c91

File tree

11 files changed

+341
-243
lines changed

11 files changed

+341
-243
lines changed

orte/mca/ess/base/Makefile.am

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Copyright (c) 2004-2005 The Regents of the University of California.
1111
# All rights reserved.
1212
# Copyright (c) 2013 Los Alamos National Security, LLC. All rights reserved.
13-
# Copyright (c) 2015 Intel, Inc. All rights reserved.
13+
# Copyright (c) 2015-2017 Intel, Inc. All rights reserved.
1414
# $COPYRIGHT$
1515
#
1616
# Additional copyrights may follow
@@ -26,10 +26,9 @@ headers += \
2626
libmca_ess_la_SOURCES += \
2727
base/ess_base_frame.c \
2828
base/ess_base_select.c \
29-
base/ess_base_get.c \
30-
base/ess_base_std_tool.c \
31-
base/ess_base_std_app.c \
32-
base/ess_base_std_orted.c \
29+
base/ess_base_get.c \
30+
base/ess_base_std_tool.c \
31+
base/ess_base_std_app.c \
32+
base/ess_base_std_orted.c \
3333
base/ess_base_std_prolog.c \
3434
base/ess_base_fns.c
35-

orte/mca/ess/base/base.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
1313
* Copyright (c) 2012 Oak Ridge National Labs. All rights reserved.
1414
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights reserved.
15-
* Copyright (c) 2013 Intel, Inc. All rights reserved.
15+
* Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
1616
* $COPYRIGHT$
1717
*
1818
* Additional copyrights may follow
@@ -52,6 +52,7 @@ ORTE_DECLSPEC extern int orte_ess_base_std_buffering;
5252
ORTE_DECLSPEC extern int orte_ess_base_num_procs;
5353
ORTE_DECLSPEC extern char *orte_ess_base_jobid;
5454
ORTE_DECLSPEC extern char *orte_ess_base_vpid;
55+
ORTE_DECLSPEC extern opal_list_t orte_ess_base_signals;
5556

5657
/*
5758
* Internal helper functions used by components
@@ -82,6 +83,13 @@ ORTE_DECLSPEC int orte_ess_env_put(orte_std_cntr_t num_procs,
8283
orte_std_cntr_t num_local_procs,
8384
char ***env);
8485

86+
typedef struct {
87+
opal_list_item_t super;
88+
char *signame;
89+
int signal;
90+
} orte_ess_base_signal_t;
91+
OBJ_CLASS_DECLARATION(orte_ess_base_signal_t);
92+
8593
END_C_DECLS
8694

8795
#endif

orte/mca/ess/base/ess_base_frame.c

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* All rights reserved.
1212
* Copyright (c) 2011 Cisco Systems, Inc. All rights reserved.
1313
* Copyright (c) 2012 Oak Ridge National Labs. All rights reserved.
14+
* Copyright (c) 2017 Intel, Inc. All rights reserved.
1415
* $COPYRIGHT$
1516
*
1617
* Additional copyrights may follow
@@ -23,8 +24,10 @@
2324
#include "orte/constants.h"
2425

2526
#include "orte/mca/mca.h"
27+
#include "opal/util/argv.h"
2628
#include "opal/util/output.h"
2729
#include "opal/mca/base/base.h"
30+
#include "orte/util/show_help.h"
2831

2932
#include "orte/mca/ess/base/base.h"
3033

@@ -46,6 +49,7 @@ int orte_ess_base_std_buffering = -1;
4649
int orte_ess_base_num_procs = -1;
4750
char *orte_ess_base_jobid = NULL;
4851
char *orte_ess_base_vpid = NULL;
52+
opal_list_t orte_ess_base_signals = {0};
4953

5054
static mca_base_var_enum_value_t stream_buffering_values[] = {
5155
{-1, "default"},
@@ -55,6 +59,9 @@ static mca_base_var_enum_value_t stream_buffering_values[] = {
5559
{0, NULL}
5660
};
5761

62+
static int setup_signals(void);
63+
static char *forwarded_signals = NULL;
64+
5865
static int orte_ess_base_register(mca_base_register_flag_t flags)
5966
{
6067
mca_base_var_enum_t *new_enum;
@@ -96,21 +103,200 @@ static int orte_ess_base_register(mca_base_register_flag_t flags)
96103
MCA_BASE_VAR_SCOPE_READONLY, &orte_ess_base_num_procs);
97104
mca_base_var_register_synonym(ret, "orte", "orte", "ess", "num_procs", 0);
98105

106+
forwarded_signals = NULL;
107+
ret = mca_base_var_register ("orte", "ess", "base", "forward_signals",
108+
"Comma-delimited list of additional signals (names or integers) to forward to "
109+
"application processes [\"none\" => forward nothing]. Signals provided by "
110+
"default include SIGTSTP, SIGUSR1, SIGUSR2, SIGABRT, SIGALRM, and SIGCONT",
111+
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
112+
OPAL_INFO_LVL_4, MCA_BASE_VAR_SCOPE_READONLY,
113+
&forwarded_signals);
114+
mca_base_var_register_synonym(ret, "orte", "ess", "hnp", "forward_signals", 0);
115+
116+
99117
return ORTE_SUCCESS;
100118
}
101119

102120
static int orte_ess_base_close(void)
103121
{
122+
OPAL_LIST_DESTRUCT(&orte_ess_base_signals);
123+
104124
return mca_base_framework_components_close(&orte_ess_base_framework, NULL);
105125
}
106126

107127
static int orte_ess_base_open(mca_base_open_flag_t flags)
108128
{
129+
int rc;
130+
131+
OBJ_CONSTRUCT(&orte_ess_base_signals, opal_list_t);
132+
133+
if (ORTE_PROC_IS_HNP || ORTE_PROC_IS_DAEMON) {
134+
if (ORTE_SUCCESS != (rc = setup_signals())) {
135+
return rc;
136+
}
137+
}
109138
return mca_base_framework_components_open(&orte_ess_base_framework, flags);
110139
}
111140

112141
MCA_BASE_FRAMEWORK_DECLARE(orte, ess, "ORTE Environmenal System Setup",
113142
orte_ess_base_register, orte_ess_base_open, orte_ess_base_close,
114143
mca_ess_base_static_components, 0);
115144

145+
/* signal forwarding */
146+
147+
/* setup signal forwarding list */
148+
struct known_signal {
149+
/** signal number */
150+
int signal;
151+
/** signal name */
152+
char *signame;
153+
/** can this signal be forwarded */
154+
bool can_forward;
155+
};
156+
157+
static struct known_signal known_signals[] = {
158+
{SIGTERM, "SIGTERM", false},
159+
{SIGHUP, "SIGHUP", false},
160+
{SIGINT, "SIGINT", false},
161+
{SIGKILL, "SIGKILL", false},
162+
#ifdef SIGSYS
163+
{SIGSYS, "SIGSYS", true},
164+
#endif
165+
#ifdef SIGXCPU
166+
{SIGXCPU, "SIGXCPU", true},
167+
#endif
168+
{SIGXFSZ, "SIGXFSZ", true},
169+
#ifdef SIGVTALRM
170+
{SIGVTALRM, "SIGVTALRM", true},
171+
#endif
172+
#ifdef SIGPROF
173+
{SIGPROF, "SIGPROF", true},
174+
#endif
175+
#ifdef SIGINFO
176+
{SIGINFO, "SIGINFO", true},
177+
#endif
178+
#ifdef SIGPWR
179+
{SIGPWR, "SIGPWR", true},
180+
#endif
181+
#ifdef SIGURG
182+
{SIGURG, "SIGURG", true},
183+
#endif
184+
#ifdef SIGUSR1
185+
{SIGUSR1, "SIGUSR1", true},
186+
#endif
187+
#ifdef SIGUSR2
188+
{SIGUSR2, "SIGUSR2", true},
189+
#endif
190+
{0, NULL},
191+
};
192+
193+
#define ESS_ADDSIGNAL(x, s) \
194+
do { \
195+
orte_ess_base_signal_t *_sig; \
196+
_sig = OBJ_NEW(orte_ess_base_signal_t); \
197+
_sig->signal = (x); \
198+
_sig->signame = strdup((s)); \
199+
opal_list_append(&orte_ess_base_signals, &_sig->super); \
200+
} while(0)
201+
202+
static int setup_signals(void)
203+
{
204+
int i, sval, nsigs;
205+
char **signals, *tmp;
206+
orte_ess_base_signal_t *sig;
207+
bool ignore, found;
208+
209+
/* if they told us "none", then nothing to do */
210+
if (NULL != forwarded_signals &&
211+
0 == strcmp(forwarded_signals, "none")) {
212+
return ORTE_SUCCESS;
213+
}
116214

215+
/* we know that some signals are (nearly) always defined, regardless
216+
* of environment, so add them here */
217+
nsigs = sizeof(known_signals) / sizeof(struct known_signal);
218+
for (i=0; i < nsigs; i++) {
219+
if (known_signals[i].can_forward) {
220+
ESS_ADDSIGNAL(known_signals[i].signal, known_signals[i].signame);
221+
}
222+
}
223+
224+
/* see if they asked for anything beyond those - note that they may
225+
* have asked for some we already cover, and so we ignore any duplicates */
226+
if (NULL != forwarded_signals) {
227+
/* if they told us "none", then dump the list */
228+
signals = opal_argv_split(forwarded_signals, ',');
229+
for (i=0; NULL != signals[i]; i++) {
230+
sval = 0;
231+
if (0 != strncmp(signals[i], "SIG", 3)) {
232+
/* treat it like a number */
233+
errno = 0;
234+
sval = strtoul(signals[i], &tmp, 10);
235+
if (0 != errno || '\0' != *tmp) {
236+
orte_show_help("help-ess-base.txt", "ess-base:unknown-signal",
237+
true, signals[i], forwarded_signals);
238+
opal_argv_free(signals);
239+
return OPAL_ERR_SILENT;
240+
}
241+
}
242+
243+
/* see if it is one we already covered */
244+
ignore = false;
245+
OPAL_LIST_FOREACH(sig, &orte_ess_base_signals, orte_ess_base_signal_t) {
246+
if (0 == strcasecmp(signals[i], sig->signame) || sval == sig->signal) {
247+
/* got it - we will ignore */
248+
ignore = true;
249+
break;
250+
}
251+
}
252+
253+
if (ignore) {
254+
continue;
255+
}
256+
257+
/* see if they gave us a signal name */
258+
found = false;
259+
for (int j = 0 ; known_signals[j].signame ; ++j) {
260+
if (0 == strcasecmp (signals[i], known_signals[j].signame) || sval == known_signals[j].signal) {
261+
if (!known_signals[j].can_forward) {
262+
orte_show_help("help-ess-base.txt", "ess-base:cannot-forward",
263+
true, known_signals[j].signame, forwarded_signals);
264+
opal_argv_free(signals);
265+
return OPAL_ERR_SILENT;
266+
}
267+
found = true;
268+
ESS_ADDSIGNAL(known_signals[j].signal, known_signals[j].signame);
269+
break;
270+
}
271+
}
272+
273+
if (!found) {
274+
if (0 == strncmp(signals[i], "SIG", 3)) {
275+
orte_show_help("help-ess-base.txt", "ess-base:unknown-signal",
276+
true, signals[i], forwarded_signals);
277+
opal_argv_free(signals);
278+
return OPAL_ERR_SILENT;
279+
}
280+
281+
ESS_ADDSIGNAL(sval, signals[i]);
282+
}
283+
}
284+
opal_argv_free (signals);
285+
}
286+
return ORTE_SUCCESS;
287+
}
288+
289+
/* instantiate the class */
290+
static void scon(orte_ess_base_signal_t *t)
291+
{
292+
t->signame = NULL;
293+
}
294+
static void sdes(orte_ess_base_signal_t *t)
295+
{
296+
if (NULL != t->signame) {
297+
free(t->signame);
298+
}
299+
}
300+
OBJ_CLASS_INSTANCE(orte_ess_base_signal_t,
301+
opal_list_item_t,
302+
scon, sdes);

orte/mca/ess/base/help-ess-base.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# University of Stuttgart. All rights reserved.
1111
# Copyright (c) 2004-2005 The Regents of the University of California.
1212
# All rights reserved.
13+
# Copyright (c) 2017 Intel, Inc. All rights reserved.
1314
# $COPYRIGHT$
1415
#
1516
# Additional copyrights may follow
@@ -32,3 +33,19 @@ and got the error %s.
3233
This could mean that your PATH or executable name is wrong, or that you do not
3334
have the necessary permissions. Please ensure that the executable is able to be
3435
found and executed as it is required for singleton operations.
36+
[ess-base:cannot-forward]
37+
The system does not support trapping and forwarding of the
38+
specified signal:
39+
40+
signal: %s
41+
param: %s
42+
43+
Please remove that signal from the ess_base_forward_signals MCA parameter.
44+
[ess-base:unknown-signal]
45+
The following signal was included in the ess_base_forward_signals
46+
MCA parameter:
47+
48+
signal: %s
49+
param: %s
50+
51+
This is not a recognized signal value. Please fix or remove it.

orte/mca/ess/hnp/Makefile.am

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
# $HEADER$
2121
#
2222

23-
dist_ortedata_DATA = help-ess-hnp.txt
24-
2523
sources = \
2624
ess_hnp.h \
2725
ess_hnp_component.c \

orte/mca/ess/hnp/ess_hnp.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,8 @@ BEGIN_C_DECLS
2828
/*
2929
* Module open / close
3030
*/
31-
typedef struct {
32-
opal_list_item_t super;
33-
char *signame;
34-
int signal;
35-
} ess_hnp_signal_t;
36-
OBJ_CLASS_DECLARATION(ess_hnp_signal_t);
3731

38-
typedef struct {
39-
orte_ess_base_component_t base;
40-
opal_list_t signals;
41-
} orte_ess_hnp_component_t;
42-
43-
ORTE_MODULE_DECLSPEC extern orte_ess_hnp_component_t mca_ess_hnp_component;
32+
ORTE_MODULE_DECLSPEC extern orte_ess_base_component_t mca_ess_hnp_component;
4433

4534
END_C_DECLS
4635

0 commit comments

Comments
 (0)