This source file includes following definitions.
- pmix_mca_base_cmd_line_setup
- pmix_mca_base_cmd_line_process_args
- process_arg
- add_to_env
- pmix_mca_base_cmd_line_wrap_args
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include "pmix_config.h"
22
23 #include <stdio.h>
24 #include <string.h>
25
26 #include "src/util/cmd_line.h"
27 #include "src/util/argv.h"
28 #include "src/util/pmix_environ.h"
29 #include "src/util/show_help.h"
30 #include "src/mca/base/base.h"
31 #include "pmix_common.h"
32
33
34
35
36
37
38
39
40
41 static int process_arg(const char *param, const char *value,
42 char ***params, char ***values);
43 static void add_to_env(char **params, char **values, char ***env);
44
45
46
47
48
49 int pmix_mca_base_cmd_line_setup(pmix_cmd_line_t *cmd)
50 {
51 int ret = PMIX_SUCCESS;
52
53 ret = pmix_cmd_line_make_opt3(cmd, '\0', PMIX_MCA_CMD_LINE_ID, PMIX_MCA_CMD_LINE_ID, 2,
54 "Pass context-specific MCA parameters; they are considered global if --g"PMIX_MCA_CMD_LINE_ID" is not used and only one context is specified (arg0 is the parameter name; arg1 is the parameter value)");
55 if (PMIX_SUCCESS != ret) {
56 return ret;
57 }
58
59 ret = pmix_cmd_line_make_opt3(cmd, '\0', "g"PMIX_MCA_CMD_LINE_ID, "g"PMIX_MCA_CMD_LINE_ID, 2,
60 "Pass global MCA parameters that are applicable to all contexts (arg0 is the parameter name; arg1 is the parameter value)");
61
62 if (PMIX_SUCCESS != ret) {
63 return ret;
64 }
65
66 {
67 pmix_cmd_line_init_t entry =
68 {"mca_base_param_file_prefix", '\0', "am", NULL, 1,
69 NULL, PMIX_CMD_LINE_TYPE_STRING,
70 "Aggregate MCA parameter set file list",
71 PMIX_CMD_LINE_OTYPE_LAUNCH
72 };
73 ret = pmix_cmd_line_make_opt_mca(cmd, entry);
74 if (PMIX_SUCCESS != ret) {
75 return ret;
76 }
77 }
78
79 {
80 pmix_cmd_line_init_t entry =
81 {"mca_base_envar_file_prefix", '\0', "tune", NULL, 1,
82 NULL, PMIX_CMD_LINE_TYPE_STRING,
83 "Application profile options file list",
84 PMIX_CMD_LINE_OTYPE_DEBUG
85 };
86 ret = pmix_cmd_line_make_opt_mca(cmd, entry);
87 if (PMIX_SUCCESS != ret) {
88 return ret;
89 }
90 }
91
92 return ret;
93 }
94
95
96
97
98
99 int pmix_mca_base_cmd_line_process_args(pmix_cmd_line_t *cmd,
100 char ***context_env, char ***global_env)
101 {
102 int i, num_insts, rc;
103 char **params;
104 char **values;
105
106
107
108 if (!pmix_cmd_line_is_taken(cmd, PMIX_MCA_CMD_LINE_ID) &&
109 !pmix_cmd_line_is_taken(cmd, "g"PMIX_MCA_CMD_LINE_ID)) {
110 return PMIX_SUCCESS;
111 }
112
113
114
115 num_insts = pmix_cmd_line_get_ninsts(cmd, PMIX_MCA_CMD_LINE_ID);
116 params = values = NULL;
117 for (i = 0; i < num_insts; ++i) {
118 if (PMIX_SUCCESS != (rc = process_arg(pmix_cmd_line_get_param(cmd, PMIX_MCA_CMD_LINE_ID, i, 0),
119 pmix_cmd_line_get_param(cmd, PMIX_MCA_CMD_LINE_ID, i, 1),
120 ¶ms, &values))) {
121 return rc;
122 }
123 }
124 if (NULL != params) {
125 add_to_env(params, values, context_env);
126 pmix_argv_free(params);
127 pmix_argv_free(values);
128 }
129
130
131
132 num_insts = pmix_cmd_line_get_ninsts(cmd, "g"PMIX_MCA_CMD_LINE_ID);
133 params = values = NULL;
134 for (i = 0; i < num_insts; ++i) {
135 if (PMIX_SUCCESS != (rc = process_arg(pmix_cmd_line_get_param(cmd, "g"PMIX_MCA_CMD_LINE_ID, i, 0),
136 pmix_cmd_line_get_param(cmd, "g"PMIX_MCA_CMD_LINE_ID, i, 1),
137 ¶ms, &values))) {
138 return rc;
139 }
140 }
141 if (NULL != params) {
142 add_to_env(params, values, global_env);
143 pmix_argv_free(params);
144 pmix_argv_free(values);
145 }
146
147
148
149 return PMIX_SUCCESS;
150 }
151
152
153
154
155
156
157 static int process_arg(const char *param, const char *value,
158 char ***params, char ***values)
159 {
160 int i;
161 char *p1;
162
163
164 if ('\"' == value[0] && '\"' == value[strlen(value)-1]) {
165 p1 = strdup(&value[1]);
166 p1[strlen(p1)-1] = '\0';
167 } else {
168 p1 = strdup(value);
169 }
170
171
172
173
174
175 for (i = 0; NULL != *params && NULL != (*params)[i]; ++i) {
176 if (0 == strcmp(param, (*params)[i])) {
177
178
179 fprintf(stderr,
180 "---------------------------------------------------------------------------\n"
181 "The following MCA parameter has been listed multiple times on the\n"
182 "command line:\n\n"
183 " MCA param: %s\n\n"
184 "MCA parameters can only be listed once on a command line to ensure there\n"
185 "is no ambiguity as to its value. Please correct the situation and\n"
186 "try again.\n"
187 "---------------------------------------------------------------------------\n",
188 param);
189 free(p1);
190 return PMIX_ERROR;
191 }
192 }
193
194
195
196 pmix_argv_append_nosize(params, param);
197 pmix_argv_append_nosize(values, p1);
198 free(p1);
199
200 return PMIX_SUCCESS;
201 }
202
203
204 static void add_to_env(char **params, char **values, char ***env)
205 {
206 int i;
207 char *name;
208
209
210
211
212 for (i = 0; NULL != params && NULL != params[i]; ++i) {
213 (void) pmix_mca_base_var_env_name (params[i], &name);
214 pmix_setenv(name, values[i], true, env);
215 free(name);
216 }
217 }
218
219 void pmix_mca_base_cmd_line_wrap_args(char **args)
220 {
221 int i;
222 char *tstr;
223
224 for (i=0; NULL != args && NULL != args[i]; i++) {
225 if (0 == strcmp(args[i], "-"PMIX_MCA_CMD_LINE_ID) ||
226 0 == strcmp(args[i], "--"PMIX_MCA_CMD_LINE_ID)) {
227 if (NULL == args[i+1] || NULL == args[i+2]) {
228
229
230
231 return;
232 }
233 i += 2;
234 if (0 > asprintf(&tstr, "\"%s\"", args[i])) {
235 return;
236 }
237 free(args[i]);
238 args[i] = tstr;
239 }
240 }
241 }