root/opal/mca/pmix/pmix4x/pmix/src/mca/base/pmix_mca_base_open.c

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

DEFINITIONS

This source file includes following definitions.
  1. pmix_mca_base_open
  2. set_defaults
  3. parse_verbose

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2008 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2011      Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2015      Los Alamos National Security, LLC. All rights
  15  *                         reserved.
  16  * Copyright (c) 2016-2017 Intel, Inc. All rights reserved.
  17  * $COPYRIGHT$
  18  *
  19  * Additional copyrights may follow
  20  *
  21  * $HEADER$
  22  */
  23 
  24 #include <src/include/pmix_config.h>
  25 
  26 #include <stdio.h>
  27 #include <string.h>
  28 #ifdef HAVE_SYSLOG_H
  29 #include <syslog.h>
  30 #endif
  31 #ifdef HAVE_UNISTD_H
  32 #include <unistd.h>
  33 #endif
  34 
  35 #include "src/mca/pinstalldirs/pinstalldirs.h"
  36 #include "src/util/output.h"
  37 #include "src/util/printf.h"
  38 #include "src/mca/mca.h"
  39 #include "src/mca/base/base.h"
  40 #include "src/mca/base/pmix_mca_base_component_repository.h"
  41 #include "pmix_common.h"
  42 #include "src/util/pmix_environ.h"
  43 
  44 /*
  45  * Public variables
  46  */
  47 char *pmix_mca_base_component_path = NULL;
  48 int pmix_mca_base_opened = 0;
  49 char *pmix_mca_base_system_default_path = NULL;
  50 char *pmix_mca_base_user_default_path = NULL;
  51 bool pmix_mca_base_component_show_load_errors = (bool) PMIX_SHOW_LOAD_ERRORS_DEFAULT;
  52 bool pmix_mca_base_component_track_load_errors = false;
  53 bool pmix_mca_base_component_disable_dlopen = false;
  54 
  55 static char *pmix_mca_base_verbose = NULL;
  56 
  57 /*
  58  * Private functions
  59  */
  60 static void set_defaults(pmix_output_stream_t *lds);
  61 static void parse_verbose(char *e, pmix_output_stream_t *lds);
  62 
  63 
  64 /*
  65  * Main MCA initialization.
  66  */
  67 int pmix_mca_base_open(void)
  68 {
  69     char *value;
  70     pmix_output_stream_t lds;
  71     char hostname[64];
  72     int var_id;
  73     int rc;
  74 
  75     if (pmix_mca_base_opened++) {
  76         return PMIX_SUCCESS;
  77     }
  78 
  79     /* define the system and user default paths */
  80 #if PMIX_WANT_HOME_CONFIG_FILES
  81     pmix_mca_base_system_default_path = strdup(pmix_pinstall_dirs.pmixlibdir);
  82     rc = asprintf(&pmix_mca_base_user_default_path, "%s"PMIX_PATH_SEP".pmix"PMIX_PATH_SEP"components", pmix_home_directory());
  83 #else
  84     rc = asprintf(&pmix_mca_base_system_default_path, "%s", pmix_pinstall_dirs.pmixlibdir);
  85 #endif
  86 
  87     if (0 > rc) {
  88         return PMIX_ERR_OUT_OF_RESOURCE;
  89     }
  90 
  91     /* see if the user wants to override the defaults */
  92     if (NULL == pmix_mca_base_user_default_path) {
  93         value = strdup(pmix_mca_base_system_default_path);
  94     } else {
  95         rc = asprintf(&value, "%s%c%s", pmix_mca_base_system_default_path,
  96                       PMIX_ENV_SEP, pmix_mca_base_user_default_path);
  97         if (0 > rc) {
  98             return PMIX_ERR_OUT_OF_RESOURCE;
  99         }
 100     }
 101 
 102     pmix_mca_base_component_path = value;
 103     var_id = pmix_mca_base_var_register("pmix", "mca", "base", "component_path",
 104                                    "Path where to look for additional components",
 105                                    PMIX_MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
 106                                    PMIX_INFO_LVL_9,
 107                                    PMIX_MCA_BASE_VAR_SCOPE_READONLY,
 108                                    &pmix_mca_base_component_path);
 109     (void) pmix_mca_base_var_register_synonym(var_id, "pmix", "mca", NULL, "component_path",
 110                                               PMIX_MCA_BASE_VAR_SYN_FLAG_DEPRECATED);
 111     free(value);
 112 
 113     pmix_mca_base_component_show_load_errors = (bool) PMIX_SHOW_LOAD_ERRORS_DEFAULT;;
 114     var_id = pmix_mca_base_var_register("pmix", "mca", "base", "component_show_load_errors",
 115                                    "Whether to show errors for components that failed to load or not",
 116                                    PMIX_MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
 117                                    PMIX_INFO_LVL_9,
 118                                    PMIX_MCA_BASE_VAR_SCOPE_READONLY,
 119                                    &pmix_mca_base_component_show_load_errors);
 120     (void) pmix_mca_base_var_register_synonym(var_id, "pmix", "mca", NULL, "component_show_load_errors",
 121                                               PMIX_MCA_BASE_VAR_SYN_FLAG_DEPRECATED);
 122 
 123     pmix_mca_base_component_track_load_errors = false;
 124     var_id = pmix_mca_base_var_register("pmix", "mca", "base", "component_track_load_errors",
 125                                         "Whether to track errors for components that failed to load or not",
 126                                         PMIX_MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
 127                                         PMIX_INFO_LVL_9,
 128                                         PMIX_MCA_BASE_VAR_SCOPE_READONLY,
 129                                         &pmix_mca_base_component_track_load_errors);
 130 
 131     pmix_mca_base_component_disable_dlopen = false;
 132     var_id = pmix_mca_base_var_register("pmix", "mca", "base", "component_disable_dlopen",
 133                                    "Whether to attempt to disable opening dynamic components or not",
 134                                    PMIX_MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
 135                                    PMIX_INFO_LVL_9,
 136                                    PMIX_MCA_BASE_VAR_SCOPE_READONLY,
 137                                    &pmix_mca_base_component_disable_dlopen);
 138     (void) pmix_mca_base_var_register_synonym(var_id, "pmix", "mca", NULL, "component_disable_dlopen",
 139                                               PMIX_MCA_BASE_VAR_SYN_FLAG_DEPRECATED);
 140 
 141     /* What verbosity level do we want for the default 0 stream? */
 142     pmix_mca_base_verbose = "stderr";
 143     var_id = pmix_mca_base_var_register("pmix", "mca", "base", "verbose",
 144                                    "Specifies where the default error output stream goes (this is separate from distinct help messages).  Accepts a comma-delimited list of: stderr, stdout, syslog, syslogpri:<notice|info|debug>, syslogid:<str> (where str is the prefix string for all syslog notices), file[:filename] (if filename is not specified, a default filename is used), fileappend (if not specified, the file is opened for truncation), level[:N] (if specified, integer verbose level; otherwise, 0 is implied)",
 145                                    PMIX_MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
 146                                    PMIX_INFO_LVL_9,
 147                                    PMIX_MCA_BASE_VAR_SCOPE_READONLY,
 148                                    &pmix_mca_base_verbose);
 149     (void) pmix_mca_base_var_register_synonym(var_id, "pmix", "mca", NULL, "verbose",
 150                                               PMIX_MCA_BASE_VAR_SYN_FLAG_DEPRECATED);
 151 
 152     memset(&lds, 0, sizeof(lds));
 153     if (NULL != pmix_mca_base_verbose) {
 154         parse_verbose(pmix_mca_base_verbose, &lds);
 155     } else {
 156         set_defaults(&lds);
 157     }
 158     gethostname(hostname, 64);
 159     rc = asprintf(&lds.lds_prefix, "[%s:%05d] ", hostname, getpid());
 160     if (0 > rc) {
 161         return PMIX_ERR_OUT_OF_RESOURCE;
 162     }
 163     pmix_output_reopen(0, &lds);
 164     pmix_output_verbose (PMIX_MCA_BASE_VERBOSE_COMPONENT, 0,
 165                          "mca: base: opening components at %s", pmix_mca_base_component_path);
 166     free(lds.lds_prefix);
 167 
 168     /* Open up the component repository */
 169 
 170     return pmix_mca_base_component_repository_init();
 171 }
 172 
 173 
 174 /*
 175  * Set sane default values for the lds
 176  */
 177 static void set_defaults(pmix_output_stream_t *lds)
 178 {
 179 
 180     /* Load up defaults */
 181 
 182     PMIX_CONSTRUCT(lds, pmix_output_stream_t);
 183 #if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H)
 184     lds->lds_syslog_priority = LOG_INFO;
 185 #endif  /* defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) */
 186     lds->lds_syslog_ident = "ompi";
 187     lds->lds_want_stderr = true;
 188 }
 189 
 190 
 191 /*
 192  * Parse the value of an environment variable describing verbosity
 193  */
 194 static void parse_verbose(char *e, pmix_output_stream_t *lds)
 195 {
 196     char *edup;
 197     char *ptr, *next;
 198     bool have_output = false;
 199 
 200     if (NULL == e) {
 201         return;
 202     }
 203 
 204     edup = strdup(e);
 205     ptr = edup;
 206 
 207     /* Now parse the environment variable */
 208 
 209     while (NULL != ptr && strlen(ptr) > 0) {
 210         next = strchr(ptr, ',');
 211         if (NULL != next) {
 212             *next = '\0';
 213         }
 214 
 215         if (0 == strcasecmp(ptr, "syslog")) {
 216 #if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H)
 217             lds->lds_want_syslog = true;
 218             have_output = true;
 219 #else
 220             pmix_output(0, "syslog support requested but not available on this system");
 221 #endif  /* defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) */
 222         }
 223         else if (strncasecmp(ptr, "syslogpri:", 10) == 0) {
 224 #if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H)
 225             lds->lds_want_syslog = true;
 226             have_output = true;
 227             if (strcasecmp(ptr + 10, "notice") == 0)
 228                 lds->lds_syslog_priority = LOG_NOTICE;
 229             else if (strcasecmp(ptr + 10, "INFO") == 0)
 230                 lds->lds_syslog_priority = LOG_INFO;
 231             else if (strcasecmp(ptr + 10, "DEBUG") == 0)
 232                 lds->lds_syslog_priority = LOG_DEBUG;
 233 #else
 234             pmix_output(0, "syslog support requested but not available on this system");
 235 #endif  /* defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) */
 236         } else if (strncasecmp(ptr, "syslogid:", 9) == 0) {
 237 #if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H)
 238             lds->lds_want_syslog = true;
 239             lds->lds_syslog_ident = ptr + 9;
 240 #else
 241             pmix_output(0, "syslog support requested but not available on this system");
 242 #endif  /* defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) */
 243         }
 244 
 245         else if (strcasecmp(ptr, "stdout") == 0) {
 246             lds->lds_want_stdout = true;
 247             have_output = true;
 248         } else if (strcasecmp(ptr, "stderr") == 0) {
 249             lds->lds_want_stderr = true;
 250             have_output = true;
 251         }
 252 
 253         else if (strcasecmp(ptr, "file") == 0 || strcasecmp(ptr, "file:") == 0) {
 254             lds->lds_want_file = true;
 255             have_output = true;
 256         } else if (strncasecmp(ptr, "file:", 5) == 0) {
 257             lds->lds_want_file = true;
 258             lds->lds_file_suffix = strdup(ptr + 5);
 259             have_output = true;
 260         } else if (strcasecmp(ptr, "fileappend") == 0) {
 261             lds->lds_want_file = true;
 262             lds->lds_want_file_append = 1;
 263             have_output = true;
 264         }
 265 
 266         else if (strncasecmp(ptr, "level", 5) == 0) {
 267             lds->lds_verbose_level = 0;
 268             if (ptr[5] == PMIX_ENV_SEP)
 269                 lds->lds_verbose_level = atoi(ptr + 6);
 270         }
 271 
 272         if (NULL == next) {
 273             break;
 274         }
 275         ptr = next + 1;
 276     }
 277 
 278     /* If we didn't get an output, default to stderr */
 279 
 280     if (!have_output) {
 281         lds->lds_want_stderr = true;
 282     }
 283 
 284     /* All done */
 285 
 286     free(edup);
 287 }

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