root/orte/mca/ess/base/ess_base_frame.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. orte_ess_base_register
  2. orte_ess_base_close
  3. orte_ess_base_open
  4. setup_signals
  5. scon
  6. sdes

   1 /*
   2  * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2011 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2011-2017 Cisco Systems, Inc.  All rights reserved
  13  * Copyright (c) 2012      Oak Ridge National Labs.  All rights reserved.
  14  * Copyright (c) 2017      Intel, Inc. All rights reserved.
  15  * Copyright (c) 2017      Research Organization for Information Science
  16  *                         and Technology (RIST). All rights reserved.
  17  * $COPYRIGHT$
  18  *
  19  * Additional copyrights may follow
  20  *
  21  * $HEADER$
  22  */
  23 
  24 
  25 #include "orte_config.h"
  26 #include "orte/constants.h"
  27 
  28 #include <signal.h>
  29 
  30 #include "orte/mca/mca.h"
  31 #include "opal/util/argv.h"
  32 #include "opal/util/output.h"
  33 #include "opal/mca/base/base.h"
  34 #include "orte/util/show_help.h"
  35 
  36 #include "orte/mca/ess/base/base.h"
  37 
  38 /*
  39  * The following file was created by configure.  It contains extern
  40  * statements and the definition of an array of pointers to each
  41  * module's public mca_base_module_t struct.
  42  */
  43 
  44 #include "orte/mca/ess/base/static-components.h"
  45 
  46 orte_ess_base_module_t orte_ess = {
  47     NULL,  /* init */
  48     NULL,  /* finalize */
  49     NULL,  /* abort */
  50     NULL   /* ft_event */
  51 };
  52 int orte_ess_base_std_buffering = -1;
  53 int orte_ess_base_num_procs = -1;
  54 char *orte_ess_base_jobid = NULL;
  55 char *orte_ess_base_vpid = NULL;
  56 opal_list_t orte_ess_base_signals = {{0}};
  57 
  58 static mca_base_var_enum_value_t stream_buffering_values[] = {
  59   {-1, "default"},
  60   {0, "unbuffered"},
  61   {1, "line_buffered"},
  62   {2, "fully_buffered"},
  63   {0, NULL}
  64 };
  65 
  66 static int setup_signals(void);
  67 static char *forwarded_signals = NULL;
  68 
  69 static int orte_ess_base_register(mca_base_register_flag_t flags)
  70 {
  71     mca_base_var_enum_t *new_enum;
  72     int ret;
  73 
  74     orte_ess_base_std_buffering = -1;
  75     (void) mca_base_var_enum_create("ess_base_stream_buffering", stream_buffering_values, &new_enum);
  76     (void) mca_base_var_register("orte", "ess", "base", "stream_buffering",
  77                                  "Adjust buffering for stdout/stderr "
  78                                 "[-1 system default] [0 unbuffered] [1 line buffered] [2 fully buffered] "
  79                                  "(Default: -1)",
  80                                  MCA_BASE_VAR_TYPE_INT, new_enum, 0, 0,
  81                                  OPAL_INFO_LVL_9,
  82                                  MCA_BASE_VAR_SCOPE_READONLY, &orte_ess_base_std_buffering);
  83     OBJ_RELEASE(new_enum);
  84 
  85     orte_ess_base_jobid = NULL;
  86     ret = mca_base_var_register("orte", "ess", "base", "jobid", "Process jobid",
  87                                 MCA_BASE_VAR_TYPE_STRING, NULL, 0,
  88                                 MCA_BASE_VAR_FLAG_INTERNAL,
  89                                 OPAL_INFO_LVL_9,
  90                                 MCA_BASE_VAR_SCOPE_READONLY, &orte_ess_base_jobid);
  91     mca_base_var_register_synonym(ret, "orte", "orte", "ess", "jobid", 0);
  92 
  93     orte_ess_base_vpid = NULL;
  94     ret = mca_base_var_register("orte", "ess", "base", "vpid", "Process vpid",
  95                                 MCA_BASE_VAR_TYPE_STRING, NULL, 0,
  96                                 MCA_BASE_VAR_FLAG_INTERNAL,
  97                                 OPAL_INFO_LVL_9,
  98                                 MCA_BASE_VAR_SCOPE_READONLY, &orte_ess_base_vpid);
  99     mca_base_var_register_synonym(ret, "orte", "orte", "ess", "vpid", 0);
 100 
 101     orte_ess_base_num_procs = -1;
 102     ret = mca_base_var_register("orte", "ess", "base", "num_procs",
 103                                 "Used to discover the number of procs in the job",
 104                                 MCA_BASE_VAR_TYPE_INT, NULL, 0,
 105                                 MCA_BASE_VAR_FLAG_INTERNAL,
 106                                 OPAL_INFO_LVL_9,
 107                                 MCA_BASE_VAR_SCOPE_READONLY, &orte_ess_base_num_procs);
 108     mca_base_var_register_synonym(ret, "orte", "orte", "ess", "num_procs", 0);
 109 
 110     forwarded_signals = NULL;
 111     ret = mca_base_var_register ("orte", "ess", "base", "forward_signals",
 112                                  "Comma-delimited list of additional signals (names or integers) to forward to "
 113                                  "application processes [\"none\" => forward nothing]. Signals provided by "
 114                                  "default include SIGTSTP, SIGUSR1, SIGUSR2, SIGABRT, SIGALRM, and SIGCONT",
 115                                  MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
 116                                  OPAL_INFO_LVL_4, MCA_BASE_VAR_SCOPE_READONLY,
 117                                  &forwarded_signals);
 118     mca_base_var_register_synonym(ret, "orte", "ess", "hnp", "forward_signals", 0);
 119 
 120 
 121     return ORTE_SUCCESS;
 122 }
 123 
 124 static int orte_ess_base_close(void)
 125 {
 126     OPAL_LIST_DESTRUCT(&orte_ess_base_signals);
 127 
 128     return mca_base_framework_components_close(&orte_ess_base_framework, NULL);
 129 }
 130 
 131 static int orte_ess_base_open(mca_base_open_flag_t flags)
 132 {
 133     int rc;
 134 
 135     OBJ_CONSTRUCT(&orte_ess_base_signals, opal_list_t);
 136 
 137     if (ORTE_PROC_IS_HNP || ORTE_PROC_IS_DAEMON) {
 138         if (ORTE_SUCCESS != (rc = setup_signals())) {
 139             return rc;
 140         }
 141     }
 142     return mca_base_framework_components_open(&orte_ess_base_framework, flags);
 143 }
 144 
 145 MCA_BASE_FRAMEWORK_DECLARE(orte, ess, "ORTE Environmenal System Setup",
 146                            orte_ess_base_register, orte_ess_base_open, orte_ess_base_close,
 147                            mca_ess_base_static_components, 0);
 148 
 149 /* signal forwarding */
 150 
 151 /* setup signal forwarding list */
 152 struct known_signal {
 153     /** signal number */
 154     int signal;
 155     /** signal name */
 156     char *signame;
 157     /** can this signal be forwarded */
 158     bool can_forward;
 159 };
 160 
 161 static struct known_signal known_signals[] = {
 162     {SIGTERM, "SIGTERM", false},
 163     {SIGHUP, "SIGHUP", false},
 164     {SIGINT, "SIGINT", false},
 165     {SIGKILL, "SIGKILL", false},
 166     {SIGPIPE, "SIGPIPE", false},
 167 #ifdef SIGQUIT
 168     {SIGQUIT, "SIGQUIT", false},
 169 #endif
 170 #ifdef SIGTRAP
 171     {SIGTRAP, "SIGTRAP", true},
 172 #endif
 173 #ifdef SIGTSTP
 174     {SIGTSTP, "SIGTSTP", true},
 175 #endif
 176 #ifdef SIGABRT
 177     {SIGABRT, "SIGABRT", true},
 178 #endif
 179 #ifdef SIGCONT
 180     {SIGCONT, "SIGCONT", true},
 181 #endif
 182 #ifdef SIGSYS
 183     {SIGSYS, "SIGSYS", true},
 184 #endif
 185 #ifdef SIGXCPU
 186     {SIGXCPU, "SIGXCPU", true},
 187 #endif
 188 #ifdef SIGXFSZ
 189     {SIGXFSZ, "SIGXFSZ", true},
 190 #endif
 191 #ifdef SIGALRM
 192     {SIGALRM, "SIGALRM", true},
 193 #endif
 194 #ifdef SIGVTALRM
 195     {SIGVTALRM, "SIGVTALRM", true},
 196 #endif
 197 #ifdef SIGPROF
 198     {SIGPROF, "SIGPROF", true},
 199 #endif
 200 #ifdef SIGINFO
 201     {SIGINFO, "SIGINFO", true},
 202 #endif
 203 #ifdef SIGPWR
 204     {SIGPWR, "SIGPWR", true},
 205 #endif
 206 #ifdef SIGURG
 207     {SIGURG, "SIGURG", true},
 208 #endif
 209 #ifdef SIGUSR1
 210     {SIGUSR1, "SIGUSR1", true},
 211 #endif
 212 #ifdef SIGUSR2
 213     {SIGUSR2, "SIGUSR2", true},
 214 #endif
 215     {0, NULL},
 216 };
 217 
 218 #define ESS_ADDSIGNAL(x, s)                                                 \
 219     do {                                                                    \
 220         orte_ess_base_signal_t *_sig;                                       \
 221         _sig = OBJ_NEW(orte_ess_base_signal_t);                             \
 222         _sig->signal = (x);                                                 \
 223         _sig->signame = strdup((s));                                        \
 224         opal_list_append(&orte_ess_base_signals, &_sig->super);             \
 225     } while(0)
 226 
 227 static int setup_signals(void)
 228 {
 229     int i, sval, nsigs;
 230     char **signals, *tmp;
 231     orte_ess_base_signal_t *sig;
 232     bool ignore, found;
 233 
 234     /* if they told us "none", then nothing to do */
 235     if (NULL != forwarded_signals &&
 236         0 == strcmp(forwarded_signals, "none")) {
 237         return ORTE_SUCCESS;
 238     }
 239 
 240     /* we know that some signals are (nearly) always defined, regardless
 241      * of environment, so add them here */
 242     nsigs = sizeof(known_signals) / sizeof(struct known_signal);
 243     for (i=0; i < nsigs; i++) {
 244         if (known_signals[i].can_forward) {
 245             ESS_ADDSIGNAL(known_signals[i].signal, known_signals[i].signame);
 246         }
 247     }
 248 
 249     /* see if they asked for anything beyond those - note that they may
 250      * have asked for some we already cover, and so we ignore any duplicates */
 251     if (NULL != forwarded_signals) {
 252         /* if they told us "none", then dump the list */
 253         signals = opal_argv_split(forwarded_signals, ',');
 254         for (i=0; NULL != signals[i]; i++) {
 255             sval = 0;
 256             if (0 != strncmp(signals[i], "SIG", 3)) {
 257                 /* treat it like a number */
 258                 errno = 0;
 259                 sval = strtoul(signals[i], &tmp, 10);
 260                 if (0 != errno || '\0' != *tmp) {
 261                     orte_show_help("help-ess-base.txt", "ess-base:unknown-signal",
 262                                    true, signals[i], forwarded_signals);
 263                     opal_argv_free(signals);
 264                     return OPAL_ERR_SILENT;
 265                 }
 266             }
 267 
 268             /* see if it is one we already covered */
 269             ignore = false;
 270             OPAL_LIST_FOREACH(sig, &orte_ess_base_signals, orte_ess_base_signal_t) {
 271                 if (0 == strcasecmp(signals[i], sig->signame) || sval == sig->signal) {
 272                     /* got it - we will ignore */
 273                     ignore = true;
 274                     break;
 275                 }
 276             }
 277 
 278             if (ignore) {
 279                 continue;
 280             }
 281 
 282             /* see if they gave us a signal name */
 283             found = false;
 284             for (int j = 0 ; known_signals[j].signame ; ++j) {
 285                 if (0 == strcasecmp (signals[i], known_signals[j].signame) || sval == known_signals[j].signal) {
 286                     if (!known_signals[j].can_forward) {
 287                         orte_show_help("help-ess-base.txt", "ess-base:cannot-forward",
 288                                        true, known_signals[j].signame, forwarded_signals);
 289                         opal_argv_free(signals);
 290                         return OPAL_ERR_SILENT;
 291                     }
 292                     found = true;
 293                     ESS_ADDSIGNAL(known_signals[j].signal, known_signals[j].signame);
 294                     break;
 295                 }
 296             }
 297 
 298             if (!found) {
 299                 if (0 == strncmp(signals[i], "SIG", 3)) {
 300                     orte_show_help("help-ess-base.txt", "ess-base:unknown-signal",
 301                                    true, signals[i], forwarded_signals);
 302                     opal_argv_free(signals);
 303                     return OPAL_ERR_SILENT;
 304                 }
 305 
 306                 ESS_ADDSIGNAL(sval, signals[i]);
 307             }
 308         }
 309         opal_argv_free (signals);
 310     }
 311     return ORTE_SUCCESS;
 312 }
 313 
 314 /* instantiate the class */
 315 static void scon(orte_ess_base_signal_t *t)
 316 {
 317     t->signame = NULL;
 318 }
 319 static void sdes(orte_ess_base_signal_t *t)
 320 {
 321     if (NULL != t->signame) {
 322         free(t->signame);
 323     }
 324 }
 325 OBJ_CLASS_INSTANCE(orte_ess_base_signal_t,
 326                    opal_list_item_t,
 327                    scon, sdes);

/* [<][>][^][v][top][bottom][index][help] */