1+ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
12/*
23 * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
34 * University Research and Technology
910 * University of Stuttgart. All rights reserved.
1011 * Copyright (c) 2004-2005 The Regents of the University of California.
1112 * All rights reserved.
13+ * Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights
14+ * reserved.
15+ * Copyright (c) 2017 Intel, Inc. All rights reserved.
1216 * $COPYRIGHT$
1317 *
1418 * Additional copyrights may follow
2630#include "orte/constants.h"
2731
2832#include "orte/util/proc_info.h"
33+ #include "orte/util/show_help.h"
2934
3035#include "orte/mca/ess/ess.h"
3136#include "orte/mca/ess/hnp/ess_hnp.h"
37+ #include "orte/runtime/orte_globals.h"
3238
3339extern orte_ess_base_module_t orte_ess_hnp_module ;
40+ static int hnp_component_register (void );
41+ static int hnp_component_open (void );
42+ static int hnp_component_close (void );
43+ static int hnp_component_query (mca_base_module_t * * module , int * priority );
44+
45+ struct known_signal {
46+ /** signal number */
47+ int signal ;
48+ /** signal name */
49+ char * signame ;
50+ /** can this signal be forwarded */
51+ bool can_forward ;
52+ };
53+
54+ static struct known_signal known_signals [] = {
55+ {SIGTERM , "SIGTERM" , false},
56+ {SIGHUP , "SIGHUP" , false},
57+ {SIGINT , "SIGINT" , false},
58+ {SIGKILL , "SIGKILL" , false},
59+ #ifdef SIGSYS
60+ {SIGSYS , "SIGSYS" , true},
61+ #endif
62+ #ifdef SIGXCPU
63+ {SIGXCPU , "SIGXCPU" , true},
64+ #endif
65+ {SIGXFSZ , "SIGXFSZ" , true},
66+ #ifdef SIGVTALRM
67+ {SIGVTALRM , "SIGVTALRM" , true},
68+ #endif
69+ #ifdef SIGPROF
70+ {SIGPROF , "SIGPROF" , true},
71+ #endif
72+ #ifdef SIGINFO
73+ {SIGINFO , "SIGINFO" , true},
74+ #endif
75+ #ifdef SIGPWR
76+ {SIGPWR , "SIGPWR" , true},
77+ #endif
78+ {0 , NULL },
79+ };
3480
3581/*
3682 * Instantiate the public struct with all of our public information
3783 * and pointers to our public functions in it
3884 */
39- orte_ess_base_component_t mca_ess_hnp_component = {
40- {
41- ORTE_ESS_BASE_VERSION_3_0_0 ,
42-
43- /* Component name and version */
44- "hnp" ,
45- ORTE_MAJOR_VERSION ,
46- ORTE_MINOR_VERSION ,
47- ORTE_RELEASE_VERSION ,
48-
49- /* Component open and close functions */
50- orte_ess_hnp_component_open ,
51- orte_ess_hnp_component_close ,
52- orte_ess_hnp_component_query
53- },
54- {
55- /* The component is checkpoint ready */
56- MCA_BASE_METADATA_PARAM_CHECKPOINT
85+ orte_ess_hnp_component_t mca_ess_hnp_component = {
86+ .base = {
87+ {
88+ ORTE_ESS_BASE_VERSION_3_0_0 ,
89+
90+ /* Component name and version */
91+ "hnp" ,
92+ ORTE_MAJOR_VERSION ,
93+ ORTE_MINOR_VERSION ,
94+ ORTE_RELEASE_VERSION ,
95+
96+ /* Component open and close functions */
97+ hnp_component_open ,
98+ hnp_component_close ,
99+ hnp_component_query ,
100+ hnp_component_register ,
101+ },
102+ {
103+ /* The component is checkpoint ready */
104+ MCA_BASE_METADATA_PARAM_CHECKPOINT
105+ }
57106 }
58107};
59108
109+ static char * additional_signals ;
60110
61- int
62- orte_ess_hnp_component_open (void )
111+ static int hnp_component_register (void )
63112{
113+ additional_signals = NULL ;
114+ (void ) mca_base_component_var_register (& mca_ess_hnp_component .base .base_version ,
115+ "forward_signals" , "Comma-delimited list "
116+ "of additional signals (names or integers) to forward to "
117+ "application processes [\"none\" => forward nothing]" , MCA_BASE_VAR_TYPE_STRING ,
118+ NULL , 0 , 0 , OPAL_INFO_LVL_4 , MCA_BASE_VAR_SCOPE_READONLY ,
119+ & additional_signals );
120+
64121 return ORTE_SUCCESS ;
65122}
66123
124+ #define ESS_ADDSIGNAL (x , s ) \
125+ do { \
126+ ess_hnp_signal_t *_sig; \
127+ _sig = OBJ_NEW(ess_hnp_signal_t); \
128+ _sig->signal = (x); \
129+ _sig->signame = strdup((s)); \
130+ opal_list_append(&mca_ess_hnp_component.signals, &_sig->super); \
131+ } while(0)
67132
68- int orte_ess_hnp_component_query (mca_base_module_t * * module , int * priority )
133+ static int hnp_component_open (void )
134+ {
135+ int i , sval ;
136+ char * * signals , * tmp ;
137+ ess_hnp_signal_t * sig ;
138+ bool ignore , found ;
139+
140+ OBJ_CONSTRUCT (& mca_ess_hnp_component .signals , opal_list_t );
141+
142+ /* we know that some signals are (nearly) always defined, regardless
143+ * of environment, so add them here */
144+ ESS_ADDSIGNAL (SIGTSTP , "SIGTSTP" );
145+ ESS_ADDSIGNAL (SIGUSR1 , "SIGUSR1" );
146+ ESS_ADDSIGNAL (SIGUSR2 , "SIGUSR2" );
147+ ESS_ADDSIGNAL (SIGABRT , "SIGABRT" );
148+ ESS_ADDSIGNAL (SIGALRM , "SIGALRM" );
149+ ESS_ADDSIGNAL (SIGCONT , "SIGCONT" );
150+ #ifdef SIGURG
151+ ESS_ADDSIGNAL (SIGURG , "SIGURG" );
152+ #endif
153+
154+ /* see if they asked for anything beyond those - note that they may
155+ * have asked for some we already cover, and so we ignore any duplicates */
156+ if (NULL != additional_signals ) {
157+ /* if they told us "none", then dump the list */
158+ if (0 == strcmp (additional_signals , "none" )) {
159+ OPAL_LIST_DESTRUCT (& mca_ess_hnp_component .signals );
160+ /* need to reconstruct it for when we close */
161+ OBJ_CONSTRUCT (& mca_ess_hnp_component .signals , opal_list_t );
162+ return ORTE_SUCCESS ;
163+ }
164+ signals = opal_argv_split (additional_signals , ',' );
165+ for (i = 0 ; NULL != signals [i ]; i ++ ) {
166+ sval = 0 ;
167+ if (0 != strncmp (signals [i ], "SIG" , 3 )) {
168+ /* treat it like a number */
169+ errno = 0 ;
170+ sval = strtoul (signals [i ], & tmp , 10 );
171+ if (0 != errno || '\0' != * tmp ) {
172+ orte_show_help ("help-ess-hnp.txt" , "ess-hnp:unknown-signal" ,
173+ true, signals [i ], additional_signals );
174+ opal_argv_free (signals );
175+ return OPAL_ERR_SILENT ;
176+ }
177+ }
178+
179+ /* see if it is one we already covered */
180+ ignore = false;
181+ OPAL_LIST_FOREACH (sig , & mca_ess_hnp_component .signals , ess_hnp_signal_t ) {
182+ if (0 == strcasecmp (signals [i ], sig -> signame ) || sval == sig -> signal ) {
183+ /* got it - we will ignore */
184+ ignore = true;
185+ break ;
186+ }
187+ }
188+
189+ if (ignore ) {
190+ continue ;
191+ }
192+
193+ /* see if they gave us a signal name */
194+ found = false;
195+ for (int j = 0 ; known_signals [j ].signame ; ++ j ) {
196+ if (0 == strcasecmp (signals [i ], known_signals [j ].signame ) || sval == known_signals [j ].signal ) {
197+ if (!known_signals [j ].can_forward ) {
198+ orte_show_help ("help-ess-hnp.txt" , "ess-hnp:cannot-forward" ,
199+ true, known_signals [j ].signame , additional_signals );
200+ opal_argv_free (signals );
201+ return OPAL_ERR_SILENT ;
202+ }
203+ found = true;
204+ ESS_ADDSIGNAL (known_signals [j ].signal , known_signals [j ].signame );
205+ break ;
206+ }
207+ }
208+
209+ if (!found ) {
210+ if (0 == strncmp (signals [i ], "SIG" , 3 )) {
211+ orte_show_help ("help-ess-hnp.txt" , "ess-hnp:unknown-signal" ,
212+ true, signals [i ], additional_signals );
213+ opal_argv_free (signals );
214+ return OPAL_ERR_SILENT ;
215+ }
216+
217+ ESS_ADDSIGNAL (sval , signals [i ]);
218+ }
219+ }
220+ opal_argv_free (signals );
221+ }
222+
223+ return ORTE_SUCCESS ;
224+ }
225+
226+ int hnp_component_query (mca_base_module_t * * module , int * priority )
69227{
70228
71229 /* we are the hnp module - we need to be selected
@@ -84,9 +242,22 @@ int orte_ess_hnp_component_query(mca_base_module_t **module, int *priority)
84242}
85243
86244
87- int
88- orte_ess_hnp_component_close (void )
245+ static int hnp_component_close (void )
89246{
90247 return ORTE_SUCCESS ;
91248}
92249
250+ /* instantiate the class */
251+ static void scon (ess_hnp_signal_t * t )
252+ {
253+ t -> signame = NULL ;
254+ }
255+ static void sdes (ess_hnp_signal_t * t )
256+ {
257+ if (NULL != t -> signame ) {
258+ free (t -> signame );
259+ }
260+ }
261+ OBJ_CLASS_INSTANCE (ess_hnp_signal_t ,
262+ opal_list_item_t ,
263+ scon , sdes );
0 commit comments