File: mca_base_open.c

package info (click to toggle)
openmpi 5.0.8-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 201,684 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (293 lines) | stat: -rw-r--r-- 11,250 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2017 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2011-2022 Cisco Systems, Inc.  All rights reserved
 * Copyright (c) 2015      Los Alamos National Security, LLC. All rights
 *                         reserved.
 * Copyright (c) 2017      IBM Corporation.  All rights reserved.
 * Copyright (c) 2018      Amazon.com, Inc. or its affiliates.  All Rights reserved.
 * Copyright (c) 2018-2019 Triad National Security, LLC. All rights
 *                         reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "opal_config.h"

#include <stdio.h>
#include <string.h>
#ifdef HAVE_SYSLOG_H
#    include <syslog.h>
#endif
#ifdef HAVE_UNISTD_H
#    include <unistd.h>
#endif

#include "opal/constants.h"
#include "opal/mca/base/base.h"
#include "opal/mca/base/mca_base_component_repository.h"
#include "opal/mca/installdirs/installdirs.h"
#include "opal/mca/mca.h"
#include "opal/runtime/opal.h"
#include "opal/util/opal_environ.h"
#include "opal/util/output.h"
#include "opal/util/printf.h"

/*
 * Public variables
 */
char *mca_base_component_path = NULL;
int mca_base_opened = 0;
char *mca_base_system_default_path = NULL;
char *mca_base_user_default_path = NULL;
char *mca_base_component_show_load_errors = NULL;
bool mca_base_component_track_load_errors = false;
bool mca_base_component_disable_dlopen = false;

static char *mca_base_verbose = NULL;

/*
 * Private functions
 */
static void set_defaults(opal_output_stream_t *lds);
static void parse_verbose(char *e, opal_output_stream_t *lds);

/*
 * Main MCA initialization.
 */
int mca_base_open(void)
{
    char *value;
    opal_output_stream_t lds;
    const char *hostname;
    int var_id;

    if (mca_base_opened++) {
        return OPAL_SUCCESS;
    }

    /* define the system and user default paths */
#if OPAL_WANT_HOME_CONFIG_FILES
    mca_base_system_default_path = strdup(opal_install_dirs.opallibdir);
    opal_asprintf(&mca_base_user_default_path,
                  "%s" OPAL_PATH_SEP ".openmpi" OPAL_PATH_SEP "components", opal_home_directory());
#else
    opal_asprintf(&mca_base_system_default_path, "%s", opal_install_dirs.opallibdir);
#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 {
        opal_asprintf(&value, "%s%c%s", mca_base_system_default_path, OPAL_ENV_SEP,
                      mca_base_user_default_path);
    }

    mca_base_component_path = value;
    var_id = mca_base_var_register("opal", "mca", "base", "component_path",
                                   "Path where to look for additional 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);
    free(value);

    mca_base_component_show_load_errors = OPAL_SHOW_LOAD_ERRORS_DEFAULT;
    var_id
        = mca_base_var_register("opal", "mca", "base",
                                "component_show_load_errors",
                                "Whether to show warnings for components that fail to load or not.  Valid values are \"all\" (meaning: all load failures are reported), \"none\" (no load failures are reported), or a comma-delimited list of items, each of which can be a framework/component pair or a framework name (only load failures from the specifically-listed items are reported).  If the comma-delimited list is prefixed with \"^\", then orientation of the list is negated: warn about all load failures *except* for the listed items.",
                                MCA_BASE_VAR_TYPE_STRING, 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);

    // Parse the mca_base_component_show_load_errors value
    int ret = mca_base_show_load_errors_init();
    if (OPAL_SUCCESS != ret) {
        return ret;
    }

    mca_base_component_track_load_errors = false;
    var_id
        = mca_base_var_register("opal", "mca", "base", "component_track_load_errors",
                                "Whether to track 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_track_load_errors);

    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? */
    char *str = getenv("OPAL_OUTPUT_INTERNAL_TO_STDOUT");
    if (NULL != str && str[0] == '1') {
        mca_base_verbose = "stdout";
    } else {
        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);
    }
    hostname = opal_gethostname();
    opal_asprintf(&lds.lds_prefix, "[%s:%05d] ", hostname, getpid());
    opal_output_reopen(0, &lds);
    opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, 0, "mca: base: opening components");
    free(lds.lds_prefix);

    /* Open up the component repository */

    opal_finalize_register_cleanup(mca_base_close);

    return mca_base_component_repository_init();
}

/*
 * Set sane default values for the lds
 */
static void set_defaults(opal_output_stream_t *lds)
{

    /* Load up defaults */

    OBJ_CONSTRUCT(lds, opal_output_stream_t);
#if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H)
    lds->lds_syslog_priority = LOG_INFO;
    lds->lds_syslog_ident = "ompi";
#endif
    lds->lds_want_stderr = true;
}

/*
 * Parse the value of an environment variable describing verbosity
 */
static void parse_verbose(char *e, opal_output_stream_t *lds)
{
    char *edup;
    char *ptr, *next;
    bool have_output = false;

    if (NULL == e) {
        return;
    }

    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")) {
#if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H)
            lds->lds_want_syslog = true;
            have_output = true;
#else
            opal_output(0, "syslog support requested but not available on this system");
#endif /* defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) */
        } else if (strncasecmp(ptr, "syslogpri:", 10) == 0) {
#if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H)
            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
            opal_output(0, "syslog support requested but not available on this system");
#endif /* defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) */
        } else if (strncasecmp(ptr, "syslogid:", 9) == 0) {
#if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H)
            lds->lds_want_syslog = true;
            lds->lds_syslog_ident = ptr + 9;
#else
            opal_output(0, "syslog support requested but not available on this system");
#endif /* defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H) */
        }

        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 || 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 = strdup(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;
    }

    /* If we didn't get an output, default to stderr */

    if (!have_output) {
        lds->lds_want_stderr = true;
    }

    /* All done */

    free(edup);
}