2013-03-28 01:09:41 +04:00
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2004-01-18 02:07:40 +03:00
/*
2005-11-05 22:57:48 +03:00
* Copyright ( c ) 2004 - 2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation . All rights reserved .
2008-03-31 22:13:41 +04:00
* Copyright ( c ) 2004 - 2008 The University of Tennessee and The University
2005-11-05 22:57:48 +03:00
* of Tennessee Research Foundation . All rights
* reserved .
2004-11-28 23:09:25 +03:00
* Copyright ( c ) 2004 - 2005 High Performance Computing Center Stuttgart ,
* University of Stuttgart . All rights reserved .
2005-03-24 15:43:37 +03:00
* Copyright ( c ) 2004 - 2005 The Regents of the University of California .
* All rights reserved .
2011-01-14 23:18:06 +03:00
* Copyright ( c ) 2011 Cisco Systems , Inc . All rights reserved .
2004-11-22 04:38:40 +03:00
* $ COPYRIGHT $
*
* Additional copyrights may follow
*
2004-01-18 02:07:40 +03:00
* $ HEADER $
*/
2006-02-12 04:33:29 +03:00
# include "opal_config.h"
2005-09-27 23:27:26 +04:00
2004-01-18 02:07:40 +03:00
# include <stdio.h>
# include <string.h>
2009-07-16 22:27:33 +04:00
# ifdef HAVE_SYSLOG_H
2004-10-22 20:06:05 +04:00
# include <syslog.h>
# endif
2009-07-16 22:27:33 +04:00
# ifdef HAVE_UNISTD_H
2005-09-27 23:27:26 +04:00
# include <unistd.h>
# endif
2005-08-13 00:46:25 +04:00
2007-04-21 04:15:05 +04:00
# include "opal/mca/installdirs/installdirs.h"
2005-07-04 03:31:27 +04:00
# include "opal/util/output.h"
2005-07-04 06:16:57 +04:00
# include "opal/util/printf.h"
2005-08-13 00:46:25 +04:00
# include "opal/mca/mca.h"
# include "opal/mca/base/base.h"
2005-09-01 16:16:36 +04:00
# include "opal/mca/base/mca_base_component_repository.h"
2006-02-12 04:33:29 +03:00
# include "opal/constants.h"
2008-03-31 22:13:41 +04:00
# include "opal/util/opal_environ.h"
2004-01-18 02:07:40 +03:00
/*
* Public variables
*/
2013-03-28 01:09:41 +04:00
char * mca_base_component_path = NULL ;
2004-01-22 03:37:58 +03:00
bool mca_base_opened = false ;
2013-03-28 01:09:41 +04:00
char * mca_base_system_default_path = NULL ;
char * mca_base_user_default_path = NULL ;
bool mca_base_component_show_load_errors = true ;
bool mca_base_component_disable_dlopen = false ;
static char * mca_base_verbose = NULL ;
2004-01-18 02:07:40 +03:00
/*
* Private functions
*/
2005-07-04 03:31:27 +04:00
static void set_defaults ( opal_output_stream_t * lds ) ;
static void parse_verbose ( char * e , opal_output_stream_t * lds ) ;
2004-01-18 02:07:40 +03:00
/*
* Main MCA initialization .
*/
int mca_base_open ( void )
{
2013-03-28 01:09:41 +04:00
char * value ;
opal_output_stream_t lds ;
char hostname [ 64 ] ;
int var_id ;
2004-01-18 02:07:40 +03:00
2013-03-28 01:09:41 +04:00
if ( ! mca_base_opened ) {
mca_base_opened = true ;
} else {
return OPAL_SUCCESS ;
}
2004-01-22 03:37:58 +03:00
2009-12-08 20:32:22 +03:00
/* define the system and user default paths */
# if OPAL_WANT_HOME_CONFIG_FILES
2014-01-08 03:36:33 +04:00
mca_base_system_default_path = strdup ( opal_install_dirs . ompilibdir ) ;
2009-12-08 20:32:22 +03:00
asprintf ( & mca_base_user_default_path , " %s " OPAL_PATH_SEP " .openmpi " OPAL_PATH_SEP " components " , opal_home_directory ( ) ) ;
# else
2014-01-08 03:36:33 +04:00
asprintf ( & mca_base_system_default_path , " %s " , opal_install_dirs . ompilibdir ) ;
2009-12-08 20:32:22 +03:00
# endif
/* see if the user wants to override the defaults */
if ( NULL = = mca_base_user_default_path ) {
value = strdup ( mca_base_system_default_path ) ;
} else {
asprintf ( & value , " %s%c%s " , mca_base_system_default_path ,
OPAL_ENV_SEP , mca_base_user_default_path ) ;
}
2013-03-28 01:09:41 +04:00
mca_base_component_path = value ;
var_id = mca_base_var_register ( " opal " , " mca " , " base " , " component_path " ,
" Path where to look for Open MPI and ORTE components " ,
MCA_BASE_VAR_TYPE_STRING , NULL , 0 , 0 ,
OPAL_INFO_LVL_9 ,
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_base_component_path ) ;
( void ) mca_base_var_register_synonym ( var_id , " opal " , " mca " , NULL , " component_path " ,
MCA_BASE_VAR_SYN_FLAG_DEPRECATED ) ;
2004-08-31 13:49:56 +04:00
free ( value ) ;
2013-03-28 01:09:41 +04:00
mca_base_component_show_load_errors = true ;
var_id = mca_base_var_register ( " opal " , " mca " , " base " , " component_show_load_errors " ,
" Whether to show errors for components that failed to load or not " ,
MCA_BASE_VAR_TYPE_BOOL , NULL , 0 , 0 ,
OPAL_INFO_LVL_9 ,
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_base_component_show_load_errors ) ;
( void ) mca_base_var_register_synonym ( var_id , " opal " , " mca " , NULL , " component_show_load_errors " ,
MCA_BASE_VAR_SYN_FLAG_DEPRECATED ) ;
mca_base_component_disable_dlopen = false ;
var_id = mca_base_var_register ( " opal " , " mca " , " base " , " component_disable_dlopen " ,
" Whether to attempt to disable opening dynamic components or not " ,
MCA_BASE_VAR_TYPE_BOOL , NULL , 0 , 0 ,
OPAL_INFO_LVL_9 ,
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_base_component_disable_dlopen ) ;
( void ) mca_base_var_register_synonym ( var_id , " opal " , " mca " , NULL , " component_disable_dlopen " ,
MCA_BASE_VAR_SYN_FLAG_DEPRECATED ) ;
/* What verbosity level do we want for the default 0 stream? */
mca_base_verbose = " stderr " ;
var_id = mca_base_var_register ( " opal " , " mca " , " base " , " verbose " ,
" 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) " ,
MCA_BASE_VAR_TYPE_STRING , NULL , 0 , 0 ,
OPAL_INFO_LVL_9 ,
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_base_verbose ) ;
( void ) mca_base_var_register_synonym ( var_id , " opal " , " mca " , NULL , " verbose " ,
MCA_BASE_VAR_SYN_FLAG_DEPRECATED ) ;
memset ( & lds , 0 , sizeof ( lds ) ) ;
if ( NULL ! = mca_base_verbose ) {
parse_verbose ( mca_base_verbose , & lds ) ;
} else {
set_defaults ( & lds ) ;
}
gethostname ( hostname , 64 ) ;
asprintf ( & lds . lds_prefix , " [%s:%05d] " , hostname , getpid ( ) ) ;
opal_output_reopen ( 0 , & lds ) ;
opal_output_verbose ( 5 , 0 , " mca: base: opening components " ) ;
free ( lds . lds_prefix ) ;
/* Open up the component repository */
return mca_base_component_repository_init ( ) ;
2004-01-18 02:07:40 +03:00
}
/*
* Set sane default values for the lds
*/
2005-07-04 03:31:27 +04:00
static void set_defaults ( opal_output_stream_t * lds )
2004-01-18 02:07:40 +03:00
{
2005-09-27 23:27:26 +04:00
/* Load up defaults */
2004-01-18 02:07:40 +03:00
2005-09-09 14:46:54 +04:00
OBJ_CONSTRUCT ( lds , opal_output_stream_t ) ;
lds - > lds_syslog_priority = LOG_INFO ;
lds - > lds_syslog_ident = " ompi " ;
lds - > lds_want_stderr = true ;
2004-01-18 02:07:40 +03:00
}
/*
* Parse the value of an environment variable describing verbosity
*/
2005-07-04 03:31:27 +04:00
static void parse_verbose ( char * e , opal_output_stream_t * lds )
2004-01-18 02:07:40 +03:00
{
2013-02-28 21:31:47 +04:00
char * edup ;
char * ptr , * next ;
bool have_output = false ;
2004-01-18 02:07:40 +03:00
2013-02-28 21:31:47 +04:00
if ( NULL = = e ) {
return ;
2005-09-27 23:27:26 +04:00
}
2004-10-22 20:06:05 +04:00
2013-02-28 21:31:47 +04:00
edup = strdup ( e ) ;
ptr = edup ;
/* Now parse the environment variable */
while ( NULL ! = ptr & & strlen ( ptr ) > 0 ) {
next = strchr ( ptr , ' , ' ) ;
if ( NULL ! = next ) {
* next = ' \0 ' ;
}
if ( 0 = = strcasecmp ( ptr , " syslog " ) ) {
lds - > lds_want_syslog = true ;
have_output = true ;
}
else if ( strncasecmp ( ptr , " syslogpri: " , 10 ) = = 0 ) {
lds - > lds_want_syslog = true ;
have_output = true ;
if ( strcasecmp ( ptr + 10 , " notice " ) = = 0 )
lds - > lds_syslog_priority = LOG_NOTICE ;
else if ( strcasecmp ( ptr + 10 , " INFO " ) = = 0 )
lds - > lds_syslog_priority = LOG_INFO ;
else if ( strcasecmp ( ptr + 10 , " DEBUG " ) = = 0 )
lds - > lds_syslog_priority = LOG_DEBUG ;
} else if ( strncasecmp ( ptr , " syslogid: " , 9 ) = = 0 ) {
lds - > lds_want_syslog = true ;
lds - > lds_syslog_ident = ptr + 9 ;
}
else if ( strcasecmp ( ptr , " stdout " ) = = 0 ) {
lds - > lds_want_stdout = true ;
have_output = true ;
} else if ( strcasecmp ( ptr , " stderr " ) = = 0 ) {
lds - > lds_want_stderr = true ;
have_output = true ;
}
else if ( strcasecmp ( ptr , " file " ) = = 0 ) {
lds - > lds_want_file = true ;
have_output = true ;
} else if ( strncasecmp ( ptr , " file: " , 5 ) = = 0 ) {
lds - > lds_want_file = true ;
lds - > lds_file_suffix = ptr + 5 ;
have_output = true ;
} else if ( strcasecmp ( ptr , " fileappend " ) = = 0 ) {
lds - > lds_want_file = true ;
lds - > lds_want_file_append = 1 ;
have_output = true ;
}
else if ( strncasecmp ( ptr , " level " , 5 ) = = 0 ) {
lds - > lds_verbose_level = 0 ;
if ( ptr [ 5 ] = = OPAL_ENV_SEP )
lds - > lds_verbose_level = atoi ( ptr + 6 ) ;
}
if ( NULL = = next ) {
break ;
}
ptr = next + 1 ;
2005-09-27 23:27:26 +04:00
}
2004-01-18 02:07:40 +03:00
2013-02-28 21:31:47 +04:00
/* If we didn't get an output, default to stderr */
2004-01-18 02:07:40 +03:00
2013-02-28 21:31:47 +04:00
if ( ! have_output ) {
lds - > lds_want_stderr = true ;
2004-01-18 02:07:40 +03:00
}
2013-02-28 21:31:47 +04:00
/* All done */
2004-01-21 02:22:44 +03:00
2013-02-28 21:31:47 +04:00
free ( edup ) ;
2004-01-18 02:07:40 +03:00
}