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
*/
2004-08-02 04:24:22 +04:00
int mca_base_param_component_path = - 1 ;
2004-01-22 03:37:58 +03:00
bool mca_base_opened = false ;
2009-12-08 20:32:22 +03:00
char * mca_base_system_default_path = NULL ;
char * mca_base_user_default_path = 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 )
{
2008-03-31 22:13:41 +04:00
char * value ;
2005-07-04 03:31:27 +04:00
opal_output_stream_t lds ;
2006-08-23 03:48:54 +04:00
char hostname [ 64 ] ;
2004-01-18 02:07:40 +03:00
2004-01-22 03:37:58 +03:00
if ( ! mca_base_opened ) {
mca_base_opened = true ;
} else {
2006-02-12 04:33:29 +03:00
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
mca_base_system_default_path = strdup ( opal_install_dirs . pkglibdir ) ;
asprintf ( & mca_base_user_default_path , " %s " OPAL_PATH_SEP " .openmpi " OPAL_PATH_SEP " components " , opal_home_directory ( ) ) ;
# else
asprintf ( & mca_base_system_default_path , " %s " , opal_install_dirs . pkglibdir ) ;
# 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 ) ;
}
2004-08-02 04:24:22 +04:00
mca_base_param_component_path =
2005-08-02 02:38:17 +04:00
mca_base_param_reg_string_name ( " mca " , " component_path " ,
" Path where to look for Open MPI and ORTE components " ,
2009-12-08 20:32:22 +03:00
false , false , value , NULL ) ;
2004-08-31 13:49:56 +04:00
free ( value ) ;
2011-01-14 23:18:06 +03:00
2005-08-02 02:38:17 +04:00
mca_base_param_reg_int_name ( " mca " , " component_show_load_errors " ,
" Whether to show errors for components that failed to load or not " ,
false , false , 1 , NULL ) ;
2004-10-15 14:54:39 +04:00
2005-08-02 02:38:17 +04:00
mca_base_param_reg_int_name ( " mca " , " component_disable_dlopen " ,
" Whether to attempt to disable opening dynamic components or not " ,
false , false , 0 , NULL ) ;
2005-07-14 22:05:30 +04:00
2011-01-14 23:18:06 +03:00
/* What verbosity level do we want for the default 0 stream? */
2004-01-18 02:07:40 +03:00
2011-01-14 23:18:06 +03:00
mca_base_param_reg_string_name ( " mca " , " 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) " ,
false , false , " stderr " , & value ) ;
2004-01-18 02:07:40 +03:00
memset ( & lds , 0 , sizeof ( lds ) ) ;
2004-01-21 02:22:44 +03:00
if ( NULL ! = value ) {
parse_verbose ( value , & lds ) ;
2004-08-31 13:49:56 +04:00
free ( value ) ;
2004-01-21 02:22:44 +03:00
} else {
set_defaults ( & lds ) ;
}
2011-11-30 03:24:52 +04:00
gethostname ( hostname , 64 ) ;
2005-09-27 23:27:26 +04:00
asprintf ( & lds . lds_prefix , " [%s:%05d] " , hostname , getpid ( ) ) ;
2005-07-04 03:31:27 +04:00
opal_output_reopen ( 0 , & lds ) ;
opal_output_verbose ( 5 , 0 , " mca: base: opening components " ) ;
2008-01-09 23:37:02 +03:00
free ( lds . lds_prefix ) ;
2011-01-14 23:18:06 +03:00
2004-08-02 04:24:22 +04:00
/* Open up the component repository */
2004-01-18 02:07:40 +03:00
2005-09-01 16:16:36 +04:00
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
}