This source file includes following definitions.
- mca_base_open
- set_defaults
- parse_verbose
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 #include "opal_config.h"
28
29 #include <stdio.h>
30 #include <string.h>
31 #ifdef HAVE_SYSLOG_H
32 #include <syslog.h>
33 #endif
34 #ifdef HAVE_UNISTD_H
35 #include <unistd.h>
36 #endif
37
38 #include "opal/runtime/opal.h"
39 #include "opal/mca/installdirs/installdirs.h"
40 #include "opal/util/output.h"
41 #include "opal/util/printf.h"
42 #include "opal/mca/mca.h"
43 #include "opal/mca/base/base.h"
44 #include "opal/mca/base/mca_base_component_repository.h"
45 #include "opal/constants.h"
46 #include "opal/util/opal_environ.h"
47
48
49
50
51 char *mca_base_component_path = NULL;
52 int mca_base_opened = 0;
53 char *mca_base_system_default_path = NULL;
54 char *mca_base_user_default_path = NULL;
55 bool mca_base_component_show_load_errors =
56 (bool) OPAL_SHOW_LOAD_ERRORS_DEFAULT;
57 bool mca_base_component_track_load_errors = false;
58 bool mca_base_component_disable_dlopen = false;
59
60 static char *mca_base_verbose = NULL;
61
62
63
64
65 static void set_defaults(opal_output_stream_t *lds);
66 static void parse_verbose(char *e, opal_output_stream_t *lds);
67
68
69
70
71
72 int mca_base_open(void)
73 {
74 char *value;
75 opal_output_stream_t lds;
76 char hostname[OPAL_MAXHOSTNAMELEN];
77 int var_id;
78
79 if (mca_base_opened++) {
80 return OPAL_SUCCESS;
81 }
82
83
84 #if OPAL_WANT_HOME_CONFIG_FILES
85 mca_base_system_default_path = strdup(opal_install_dirs.opallibdir);
86 opal_asprintf(&mca_base_user_default_path, "%s"OPAL_PATH_SEP".openmpi"OPAL_PATH_SEP"components", opal_home_directory());
87 #else
88 opal_asprintf(&mca_base_system_default_path, "%s", opal_install_dirs.opallibdir);
89 #endif
90
91
92 if (NULL == mca_base_user_default_path) {
93 value = strdup(mca_base_system_default_path);
94 } else {
95 opal_asprintf(&value, "%s%c%s", mca_base_system_default_path,
96 OPAL_ENV_SEP, mca_base_user_default_path);
97 }
98
99 mca_base_component_path = value;
100 var_id = mca_base_var_register("opal", "mca", "base", "component_path",
101 "Path where to look for additional components",
102 MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
103 OPAL_INFO_LVL_9,
104 MCA_BASE_VAR_SCOPE_READONLY,
105 &mca_base_component_path);
106 (void) mca_base_var_register_synonym(var_id, "opal", "mca", NULL, "component_path",
107 MCA_BASE_VAR_SYN_FLAG_DEPRECATED);
108 free(value);
109
110 mca_base_component_show_load_errors =
111 (bool) OPAL_SHOW_LOAD_ERRORS_DEFAULT;
112 var_id = mca_base_var_register("opal", "mca", "base", "component_show_load_errors",
113 "Whether to show errors for components that failed to load or not",
114 MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
115 OPAL_INFO_LVL_9,
116 MCA_BASE_VAR_SCOPE_READONLY,
117 &mca_base_component_show_load_errors);
118 (void) mca_base_var_register_synonym(var_id, "opal", "mca", NULL, "component_show_load_errors",
119 MCA_BASE_VAR_SYN_FLAG_DEPRECATED);
120
121 mca_base_component_track_load_errors = false;
122 var_id = mca_base_var_register("opal", "mca", "base", "component_track_load_errors",
123 "Whether to track errors for components that failed to load or not",
124 MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
125 OPAL_INFO_LVL_9,
126 MCA_BASE_VAR_SCOPE_READONLY,
127 &mca_base_component_track_load_errors);
128
129 mca_base_component_disable_dlopen = false;
130 var_id = mca_base_var_register("opal", "mca", "base", "component_disable_dlopen",
131 "Whether to attempt to disable opening dynamic components or not",
132 MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
133 OPAL_INFO_LVL_9,
134 MCA_BASE_VAR_SCOPE_READONLY,
135 &mca_base_component_disable_dlopen);
136 (void) mca_base_var_register_synonym(var_id, "opal", "mca", NULL, "component_disable_dlopen",
137 MCA_BASE_VAR_SYN_FLAG_DEPRECATED);
138
139
140 char *str = getenv("OPAL_OUTPUT_INTERNAL_TO_STDOUT");
141 if (NULL != str && str[0] == '1') {
142 mca_base_verbose = "stdout";
143 }
144 else {
145 mca_base_verbose = "stderr";
146 }
147 var_id = mca_base_var_register("opal", "mca", "base", "verbose",
148 "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)",
149 MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
150 OPAL_INFO_LVL_9,
151 MCA_BASE_VAR_SCOPE_READONLY,
152 &mca_base_verbose);
153 (void) mca_base_var_register_synonym(var_id, "opal", "mca", NULL, "verbose",
154 MCA_BASE_VAR_SYN_FLAG_DEPRECATED);
155
156 memset(&lds, 0, sizeof(lds));
157 if (NULL != mca_base_verbose) {
158 parse_verbose(mca_base_verbose, &lds);
159 } else {
160 set_defaults(&lds);
161 }
162 gethostname(hostname, sizeof(hostname));
163 opal_asprintf(&lds.lds_prefix, "[%s:%05d] ", hostname, getpid());
164 opal_output_reopen(0, &lds);
165 opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, 0, "mca: base: opening components");
166 free(lds.lds_prefix);
167
168
169
170 opal_finalize_register_cleanup (mca_base_close);
171
172 return mca_base_component_repository_init();
173 }
174
175
176
177
178
179 static void set_defaults(opal_output_stream_t *lds)
180 {
181
182
183
184 OBJ_CONSTRUCT(lds, opal_output_stream_t);
185 #if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H)
186 lds->lds_syslog_priority = LOG_INFO;
187 lds->lds_syslog_ident = "ompi";
188 #endif
189 lds->lds_want_stderr = true;
190 }
191
192
193
194
195
196 static void parse_verbose(char *e, opal_output_stream_t *lds)
197 {
198 char *edup;
199 char *ptr, *next;
200 bool have_output = false;
201
202 if (NULL == e) {
203 return;
204 }
205
206 edup = strdup(e);
207 ptr = edup;
208
209
210
211 while (NULL != ptr && strlen(ptr) > 0) {
212 next = strchr(ptr, ',');
213 if (NULL != next) {
214 *next = '\0';
215 }
216
217 if (0 == strcasecmp(ptr, "syslog")) {
218 #if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H)
219 lds->lds_want_syslog = true;
220 have_output = true;
221 #else
222 opal_output(0, "syslog support requested but not available on this system");
223 #endif
224 }
225 else if (strncasecmp(ptr, "syslogpri:", 10) == 0) {
226 #if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H)
227 lds->lds_want_syslog = true;
228 have_output = true;
229 if (strcasecmp(ptr + 10, "notice") == 0)
230 lds->lds_syslog_priority = LOG_NOTICE;
231 else if (strcasecmp(ptr + 10, "INFO") == 0)
232 lds->lds_syslog_priority = LOG_INFO;
233 else if (strcasecmp(ptr + 10, "DEBUG") == 0)
234 lds->lds_syslog_priority = LOG_DEBUG;
235 #else
236 opal_output(0, "syslog support requested but not available on this system");
237 #endif
238 } else if (strncasecmp(ptr, "syslogid:", 9) == 0) {
239 #if defined(HAVE_SYSLOG) && defined(HAVE_SYSLOG_H)
240 lds->lds_want_syslog = true;
241 lds->lds_syslog_ident = ptr + 9;
242 #else
243 opal_output(0, "syslog support requested but not available on this system");
244 #endif
245 }
246
247 else if (strcasecmp(ptr, "stdout") == 0) {
248 lds->lds_want_stdout = true;
249 have_output = true;
250 } else if (strcasecmp(ptr, "stderr") == 0) {
251 lds->lds_want_stderr = true;
252 have_output = true;
253 }
254
255 else if (strcasecmp(ptr, "file") == 0 || strcasecmp(ptr, "file:") == 0) {
256 lds->lds_want_file = true;
257 have_output = true;
258 } else if (strncasecmp(ptr, "file:", 5) == 0) {
259 lds->lds_want_file = true;
260 lds->lds_file_suffix = strdup(ptr + 5);
261 have_output = true;
262 } else if (strcasecmp(ptr, "fileappend") == 0) {
263 lds->lds_want_file = true;
264 lds->lds_want_file_append = 1;
265 have_output = true;
266 }
267
268 else if (strncasecmp(ptr, "level", 5) == 0) {
269 lds->lds_verbose_level = 0;
270 if (ptr[5] == OPAL_ENV_SEP)
271 lds->lds_verbose_level = atoi(ptr + 6);
272 }
273
274 if (NULL == next) {
275 break;
276 }
277 ptr = next + 1;
278 }
279
280
281
282 if (!have_output) {
283 lds->lds_want_stderr = true;
284 }
285
286
287
288 free(edup);
289 }