/* * Look for and handle any -mca options on the command line */ int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd, char ***context_env, char ***global_env) { int i, num_insts; char **params; char **values; /* If no relevant parameters were given, just return */ if (!opal_cmd_line_is_taken(cmd, "mca") && !opal_cmd_line_is_taken(cmd, "gmca")) { return OPAL_SUCCESS; } /* Handle app context-specific parameters */ num_insts = opal_cmd_line_get_ninsts(cmd, "mca"); params = values = NULL; for (i = 0; i < num_insts; ++i) { process_arg(opal_cmd_line_get_param(cmd, "mca", i, 0), opal_cmd_line_get_param(cmd, "mca", i, 1), ¶ms, &values); } if (NULL != params) { add_to_env(params, values, context_env); opal_argv_free(params); opal_argv_free(values); } /* Handle global parameters */ num_insts = opal_cmd_line_get_ninsts(cmd, "gmca"); params = values = NULL; for (i = 0; i < num_insts; ++i) { process_arg(opal_cmd_line_get_param(cmd, "gmca", i, 0), opal_cmd_line_get_param(cmd, "gmca", i, 1), ¶ms, &values); } if (NULL != params) { add_to_env(params, values, global_env); opal_argv_free(params); opal_argv_free(values); } /* All done */ return OPAL_SUCCESS; }
void orte_info_do_params(bool want_all_in, bool want_internal) { int count; char *type, *component, *str; bool found; int i; bool want_all = false; orte_info_components_open(); if (want_all_in) { want_all = true; } else { /* See if the special param "all" was givin to --param; that * superceeds any individual type */ count = opal_cmd_line_get_ninsts(orte_info_cmd_line, "param"); for (i = 0; i < count; ++i) { type = opal_cmd_line_get_param(orte_info_cmd_line, "param", (int)i, 0); if (0 == strcmp(orte_info_type_all, type)) { want_all = true; break; } } } /* Show the params */ if (want_all) { for (i = 0; i < mca_types.size; ++i) { if (NULL == (type = (char *)opal_pointer_array_get_item(&mca_types, i))) { continue; } orte_info_show_mca_params(type, orte_info_component_all, want_internal); } } else { for (i = 0; i < count; ++i) { type = opal_cmd_line_get_param(orte_info_cmd_line, "param", (int)i, 0); component = opal_cmd_line_get_param(orte_info_cmd_line, "param", (int)i, 1); for (found = false, i = 0; i < mca_types.size; ++i) { if (NULL == (str = (char *)opal_pointer_array_get_item(&mca_types, i))) { continue; } if (0 == strcmp(str, type)) { found = true; break; } } if (!found) { char *usage = opal_cmd_line_get_usage_msg(orte_info_cmd_line); orte_show_help("help-orte-info.txt", "not-found", true, type); free(usage); exit(1); } orte_info_show_mca_params(type, component, want_internal); } } }
/* * do_version * * Determines the version information related to the ompi components * being used. * Accepts: * - want_all: True if all components' info is required. * - cmd_line: The constructed command line argument */ void ompi_info_do_version(bool want_all, opal_cmd_line_t *cmd_line) { unsigned int count; size_t i; char *arg1, *scope, *type, *component; char *pos; int j; ompi_info_open_components(); if (want_all) { ompi_info_show_ompi_version(ompi_info_ver_full); for (j = 0; j < mca_types.size; ++j) { if (NULL == (pos = (char*)opal_pointer_array_get_item(&mca_types, j))) { continue; } ompi_info_show_component_version(pos, ompi_info_component_all, ompi_info_ver_full, ompi_info_type_all); } } else { count = opal_cmd_line_get_ninsts(cmd_line, "version"); for (i = 0; i < count; ++i) { arg1 = opal_cmd_line_get_param(cmd_line, "version", (int)i, 0); scope = opal_cmd_line_get_param(cmd_line, "version", (int)i, 1); /* Version of Open MPI */ if (0 == strcmp(ompi_info_type_ompi, arg1)) { ompi_info_show_ompi_version(scope); } /* Specific type and component */ else if (NULL != (pos = strchr(arg1, ':'))) { *pos = '\0'; type = arg1; pos++; component = pos; ompi_info_show_component_version(type, component, scope, ompi_info_ver_all); } /* All components of a specific type */ else { ompi_info_show_component_version(arg1, ompi_info_component_all, scope, ompi_info_ver_all); } } } }
void ompi_info_do_path(bool want_all, opal_cmd_line_t *cmd_line) { int i, count; char *scope; /* Check bozo case */ count = opal_cmd_line_get_ninsts(cmd_line, "path"); for (i = 0; i < count; ++i) { scope = opal_cmd_line_get_param(cmd_line, "path", i, 0); if (0 == strcmp("all", scope)) { want_all = true; break; } } if (want_all) { ompi_info_show_path(ompi_info_path_prefix, opal_install_dirs.prefix); ompi_info_show_path(ompi_info_path_exec_prefix, opal_install_dirs.exec_prefix); ompi_info_show_path(ompi_info_path_bindir, opal_install_dirs.bindir); ompi_info_show_path(ompi_info_path_sbindir, opal_install_dirs.sbindir); ompi_info_show_path(ompi_info_path_libdir, opal_install_dirs.libdir); ompi_info_show_path(ompi_info_path_incdir, opal_install_dirs.includedir); ompi_info_show_path(ompi_info_path_mandir, opal_install_dirs.mandir); ompi_info_show_path(ompi_info_path_pkglibdir, opal_install_dirs.pkglibdir); ompi_info_show_path(ompi_info_path_libexecdir, opal_install_dirs.libexecdir); ompi_info_show_path(ompi_info_path_datarootdir, opal_install_dirs.datarootdir); ompi_info_show_path(ompi_info_path_datadir, opal_install_dirs.datadir); ompi_info_show_path(ompi_info_path_sysconfdir, opal_install_dirs.sysconfdir); ompi_info_show_path(ompi_info_path_sharedstatedir, opal_install_dirs.sharedstatedir); ompi_info_show_path(ompi_info_path_localstatedir, opal_install_dirs.localstatedir); ompi_info_show_path(ompi_info_path_infodir, opal_install_dirs.infodir); ompi_info_show_path(ompi_info_path_pkgdatadir, opal_install_dirs.pkgdatadir); ompi_info_show_path(ompi_info_path_pkglibdir, opal_install_dirs.pkglibdir); ompi_info_show_path(ompi_info_path_pkgincludedir, opal_install_dirs.pkgincludedir); } else { count = opal_cmd_line_get_ninsts(cmd_line, "path"); for (i = 0; i < count; ++i) { scope = opal_cmd_line_get_param(cmd_line, "path", i, 0); if (0 == strcmp(ompi_info_path_prefix, scope)) { ompi_info_show_path(ompi_info_path_prefix, opal_install_dirs.prefix); } else if (0 == strcmp(ompi_info_path_bindir, scope)) { ompi_info_show_path(ompi_info_path_bindir, opal_install_dirs.bindir); } else if (0 == strcmp(ompi_info_path_libdir, scope)) { ompi_info_show_path(ompi_info_path_libdir, opal_install_dirs.libdir); } else if (0 == strcmp(ompi_info_path_incdir, scope)) { ompi_info_show_path(ompi_info_path_incdir, opal_install_dirs.includedir); } else if (0 == strcmp(ompi_info_path_mandir, scope)) { ompi_info_show_path(ompi_info_path_mandir, opal_install_dirs.mandir); } else if (0 == strcmp(ompi_info_path_pkglibdir, scope)) { ompi_info_show_path(ompi_info_path_pkglibdir, opal_install_dirs.pkglibdir); } else if (0 == strcmp(ompi_info_path_sysconfdir, scope)) { ompi_info_show_path(ompi_info_path_sysconfdir, opal_install_dirs.sysconfdir); } else if (0 == strcmp(ompi_info_path_exec_prefix, scope)) { ompi_info_show_path(ompi_info_path_exec_prefix, opal_install_dirs.exec_prefix); } else if (0 == strcmp(ompi_info_path_sbindir, scope)) { ompi_info_show_path(ompi_info_path_sbindir, opal_install_dirs.sbindir); } else if (0 == strcmp(ompi_info_path_libexecdir, scope)) { ompi_info_show_path(ompi_info_path_libexecdir, opal_install_dirs.libexecdir); } else if (0 == strcmp(ompi_info_path_datarootdir, scope)) { ompi_info_show_path(ompi_info_path_datarootdir, opal_install_dirs.datarootdir); } else if (0 == strcmp(ompi_info_path_datadir, scope)) { ompi_info_show_path(ompi_info_path_datadir, opal_install_dirs.datadir); } else if (0 == strcmp(ompi_info_path_sharedstatedir, scope)) { ompi_info_show_path(ompi_info_path_sharedstatedir, opal_install_dirs.sharedstatedir); } else if (0 == strcmp(ompi_info_path_localstatedir, scope)) { ompi_info_show_path(ompi_info_path_localstatedir, opal_install_dirs.localstatedir); } else if (0 == strcmp(ompi_info_path_infodir, scope)) { ompi_info_show_path(ompi_info_path_infodir, opal_install_dirs.infodir); } else if (0 == strcmp(ompi_info_path_pkgdatadir, scope)) { ompi_info_show_path(ompi_info_path_pkgdatadir, opal_install_dirs.pkgdatadir); } else if (0 == strcmp(ompi_info_path_pkgincludedir, scope)) { ompi_info_show_path(ompi_info_path_pkgincludedir, opal_install_dirs.pkgincludedir); } else { char *usage = opal_cmd_line_get_usage_msg(cmd_line); orte_show_help("help-ompi_info.txt", "usage", true, usage); free(usage); exit(1); } } } }
static int parse_env(char **personality, char *path, opal_cmd_line_t *cmd_line, char **srcenv, char ***dstenv) { int i, j; char *param; char *value; char *env_set_flag; char **vars; bool takeus = false; /* see if we are included */ for (i=0; NULL != personality[i]; i++) { if (0 == strcmp(personality[i], "ompi")) { takeus = true; break; } } if (!takeus) { return ORTE_ERR_TAKE_NEXT_OPTION; } for (i = 0; NULL != srcenv[i]; ++i) { if (0 == strncmp("OMPI_", srcenv[i], 5)) { /* check for duplicate in app->env - this * would have been placed there by the * cmd line processor. By convention, we * always let the cmd line override the * environment */ param = strdup(srcenv[i]); value = strchr(param, '='); *value = '\0'; value++; opal_setenv(param, value, false, dstenv); free(param); } } /* set necessary env variables for external usage from tune conf file*/ int set_from_file = 0; vars = NULL; if (OPAL_SUCCESS == mca_base_var_process_env_list_from_file(&vars) && NULL != vars) { for (i=0; NULL != vars[i]; i++) { value = strchr(vars[i], '='); /* terminate the name of the param */ *value = '\0'; /* step over the equals */ value++; /* overwrite any prior entry */ opal_setenv(vars[i], value, true, dstenv); /* save it for any comm_spawn'd apps */ opal_setenv(vars[i], value, true, &orte_forwarded_envars); } set_from_file = 1; opal_argv_free(vars); } /* Did the user request to export any environment variables on the cmd line? */ env_set_flag = getenv("OMPI_MCA_mca_base_env_list"); if (opal_cmd_line_is_taken(cmd_line, "x")) { if (NULL != env_set_flag) { orte_show_help("help-orterun.txt", "orterun:conflict-env-set", false); return ORTE_ERR_FATAL; } j = opal_cmd_line_get_ninsts(cmd_line, "x"); for (i = 0; i < j; ++i) { param = opal_cmd_line_get_param(cmd_line, "x", i, 0); if (NULL != (value = strchr(param, '='))) { /* terminate the name of the param */ *value = '\0'; /* step over the equals */ value++; /* overwrite any prior entry */ opal_setenv(param, value, true, dstenv); /* save it for any comm_spawn'd apps */ opal_setenv(param, value, true, &orte_forwarded_envars); } else { value = getenv(param); if (NULL != value) { /* overwrite any prior entry */ opal_setenv(param, value, true, dstenv); /* save it for any comm_spawn'd apps */ opal_setenv(param, value, true, &orte_forwarded_envars); } else { opal_output(0, "Warning: could not find environment variable \"%s\"\n", param); } } } } else if (NULL != env_set_flag) { /* if mca_base_env_list was set, check if some of env vars were set via -x from a conf file. * If this is the case, error out. */ if (!set_from_file) { /* set necessary env variables for external usage */ vars = NULL; if (OPAL_SUCCESS == mca_base_var_process_env_list(&vars) && NULL != vars) { for (i=0; NULL != vars[i]; i++) { value = strchr(vars[i], '='); /* terminate the name of the param */ *value = '\0'; /* step over the equals */ value++; /* overwrite any prior entry */ opal_setenv(vars[i], value, true, dstenv); /* save it for any comm_spawn'd apps */ opal_setenv(vars[i], value, true, &orte_forwarded_envars); } opal_argv_free(vars); } } else { orte_show_help("help-orterun.txt", "orterun:conflict-env-set", false); return ORTE_ERR_FATAL; } } /* If the user specified --path, store it in the user's app environment via the OMPI_exec_path variable. */ if (NULL != path) { asprintf(&value, "OMPI_exec_path=%s", path); opal_argv_append_nosize(dstenv, value); /* save it for any comm_spawn'd apps */ opal_argv_append_nosize(&orte_forwarded_envars, value); free(value); } return ORTE_SUCCESS; }
int main(int argc, char *argv[]) { int rc, i, j; opal_cmd_line_t cmd_line; char *param, *value; orte_job_t *jdata=NULL; orte_app_context_t *app; char *uri, *ptr; /* Setup and parse the command line */ memset(&myglobals, 0, sizeof(myglobals)); /* find our basename (the name of the executable) so that we can use it in pretty-print error messages */ myglobals.basename = opal_basename(argv[0]); opal_cmd_line_create(&cmd_line, cmd_line_init); mca_base_cmd_line_setup(&cmd_line); if (OPAL_SUCCESS != (rc = opal_cmd_line_parse(&cmd_line, true, argc, argv)) ) { if (OPAL_ERR_SILENT != rc) { fprintf(stderr, "%s: command line error (%s)\n", argv[0], opal_strerror(rc)); } return rc; } /* print version if requested. Do this before check for help so that --version --help works as one might expect. */ if (myglobals.version) { char *str; str = opal_info_make_version_str("all", OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, OPAL_GREEK_VERSION, OPAL_REPO_REV); if (NULL != str) { fprintf(stdout, "%s %s\n\nReport bugs to %s\n", myglobals.basename, str, PACKAGE_BUGREPORT); free(str); } exit(0); } /* check if we are running as root - if we are, then only allow * us to proceed if the allow-run-as-root flag was given. Otherwise, * exit with a giant warning flag */ if (0 == geteuid() && !myglobals.run_as_root) { fprintf(stderr, "--------------------------------------------------------------------------\n"); if (myglobals.help) { fprintf(stderr, "%s cannot provide the help message when run as root\n", myglobals.basename); } else { /* show_help is not yet available, so print an error manually */ fprintf(stderr, "%s has detected an attempt to run as root.\n", myglobals.basename); } fprintf(stderr, " This is *strongly* discouraged as any mistake (e.g., in defining TMPDIR) or bug can\n"); fprintf(stderr, "result in catastrophic damage to the OS file system, leaving\n"); fprintf(stderr, "your system in an unusable state.\n\n"); fprintf(stderr, "You can override this protection by adding the --allow-run-as-root\n"); fprintf(stderr, "option to your cmd line. However, we reiterate our strong advice\n"); fprintf(stderr, "against doing so - please do so at your own risk.\n"); fprintf(stderr, "--------------------------------------------------------------------------\n"); exit(1); } /* * Since this process can now handle MCA/GMCA parameters, make sure to * process them. * NOTE: It is "safe" to call mca_base_cmd_line_process_args() before * opal_init_util() since mca_base_cmd_line_process_args() does *not* * depend upon opal_init_util() functionality. */ if (OPAL_SUCCESS != mca_base_cmd_line_process_args(&cmd_line, &environ, &environ)) { exit(1); } /* Need to initialize OPAL so that install_dirs are filled in */ if (OPAL_SUCCESS != opal_init(&argc, &argv)) { exit(1); } /* Check for help request */ if (myglobals.help) { char *str, *args = NULL; char *project_name = NULL; if (0 == strcmp(myglobals.basename, "mpirun")) { project_name = "Open MPI"; } else { project_name = "OpenRTE"; } args = opal_cmd_line_get_usage_msg(&cmd_line); str = opal_show_help_string("help-orterun.txt", "orterun:usage", false, myglobals.basename, project_name, OPAL_VERSION, myglobals.basename, args, PACKAGE_BUGREPORT); if (NULL != str) { printf("%s", str); free(str); } free(args); /* If someone asks for help, that should be all we do */ exit(0); } /* flag that I am the HNP */ orte_process_info.proc_type = ORTE_PROC_HNP; /* Setup MCA params */ orte_register_params(); /* specify the DVM state machine */ opal_setenv("OMPI_MCA_state", "dvm", true, &environ); /* Intialize our Open RTE environment */ if (ORTE_SUCCESS != (rc = orte_init(&argc, &argv, ORTE_PROC_HNP))) { /* cannot call ORTE_ERROR_LOG as it could be the errmgr * never got loaded! */ return rc; } /* finalize OPAL. As it was opened again from orte_init->opal_init * we continue to have a reference count on it. So we have to finalize it twice... */ opal_finalize(); /* check for request to report uri */ uri = orte_rml.get_contact_info(); if (NULL != myglobals.report_uri) { FILE *fp; if (0 == strcmp(myglobals.report_uri, "-")) { /* if '-', then output to stdout */ printf("VMURI: %s\n", uri); } else if (0 == strcmp(myglobals.report_uri, "+")) { /* if '+', output to stderr */ fprintf(stderr, "VMURI: %s\n", uri); } else if (0 == strncasecmp(myglobals.report_uri, "file:", strlen("file:"))) { ptr = strchr(myglobals.report_uri, ':'); ++ptr; fp = fopen(ptr, "w"); if (NULL == fp) { orte_show_help("help-orterun.txt", "orterun:write_file", false, myglobals.basename, "pid", ptr); exit(0); } fprintf(fp, "%s\n", uri); fclose(fp); } else { fp = fopen(myglobals.report_uri, "w"); if (NULL == fp) { orte_show_help("help-orterun.txt", "orterun:write_file", false, myglobals.basename, "pid", myglobals.report_uri); exit(0); } fprintf(fp, "%s\n", uri); fclose(fp); } free(uri); } else { printf("VMURI: %s\n", uri); } /* get the daemon job object - was created by ess/hnp component */ if (NULL == (jdata = orte_get_job_data_object(ORTE_PROC_MY_NAME->jobid))) { orte_show_help("help-orterun.txt", "bad-job-object", true, myglobals.basename); exit(0); } /* also should have created a daemon "app" */ if (NULL == (app = (orte_app_context_t*)opal_pointer_array_get_item(jdata->apps, 0))) { orte_show_help("help-orterun.txt", "bad-app-object", true, myglobals.basename); exit(0); } /* Did the user specify a prefix, or want prefix by default? */ if (opal_cmd_line_is_taken(&cmd_line, "prefix") || want_prefix_by_default) { size_t param_len; /* if both the prefix was given and we have a prefix * given above, check to see if they match */ if (opal_cmd_line_is_taken(&cmd_line, "prefix") && NULL != myglobals.prefix) { /* if they don't match, then that merits a warning */ param = strdup(opal_cmd_line_get_param(&cmd_line, "prefix", 0, 0)); /* ensure we strip any trailing '/' */ if (0 == strcmp(OPAL_PATH_SEP, &(param[strlen(param)-1]))) { param[strlen(param)-1] = '\0'; } value = strdup(myglobals.prefix); if (0 == strcmp(OPAL_PATH_SEP, &(value[strlen(value)-1]))) { value[strlen(value)-1] = '\0'; } if (0 != strcmp(param, value)) { orte_show_help("help-orterun.txt", "orterun:app-prefix-conflict", true, myglobals.basename, value, param); /* let the global-level prefix take precedence since we * know that one is being used */ free(param); param = strdup(myglobals.prefix); } free(value); } else if (NULL != myglobals.prefix) { param = myglobals.prefix; } else if (opal_cmd_line_is_taken(&cmd_line, "prefix")){ /* must be --prefix alone */ param = strdup(opal_cmd_line_get_param(&cmd_line, "prefix", 0, 0)); } else { /* --enable-orterun-prefix-default was given to orterun */ param = strdup(opal_install_dirs.prefix); } if (NULL != param) { /* "Parse" the param, aka remove superfluous path_sep. */ param_len = strlen(param); while (0 == strcmp (OPAL_PATH_SEP, &(param[param_len-1]))) { param[param_len-1] = '\0'; param_len--; if (0 == param_len) { orte_show_help("help-orterun.txt", "orterun:empty-prefix", true, myglobals.basename, myglobals.basename); return ORTE_ERR_FATAL; } } orte_set_attribute(&app->attributes, ORTE_APP_PREFIX_DIR, ORTE_ATTR_GLOBAL, param, OPAL_STRING); free(param); } } /* Did the user specify a hostfile. Need to check for both * hostfile and machine file. * We can only deal with one hostfile per app context, otherwise give an error. */ if (0 < (j = opal_cmd_line_get_ninsts(&cmd_line, "hostfile"))) { if(1 < j) { orte_show_help("help-orterun.txt", "orterun:multiple-hostfiles", true, myglobals.basename, NULL); return ORTE_ERR_FATAL; } else { value = opal_cmd_line_get_param(&cmd_line, "hostfile", 0, 0); orte_set_attribute(&app->attributes, ORTE_APP_HOSTFILE, ORTE_ATTR_LOCAL, value, OPAL_STRING); } } if (0 < (j = opal_cmd_line_get_ninsts(&cmd_line, "machinefile"))) { if(1 < j || orte_get_attribute(&app->attributes, ORTE_APP_HOSTFILE, NULL, OPAL_STRING)) { orte_show_help("help-orterun.txt", "orterun:multiple-hostfiles", true, myglobals.basename, NULL); return ORTE_ERR_FATAL; } else { value = opal_cmd_line_get_param(&cmd_line, "machinefile", 0, 0); orte_set_attribute(&app->attributes, ORTE_APP_HOSTFILE, ORTE_ATTR_LOCAL, value, OPAL_STRING); } } /* Did the user specify any hosts? */ if (0 < (j = opal_cmd_line_get_ninsts(&cmd_line, "host"))) { char **targ=NULL, *tval; for (i = 0; i < j; ++i) { value = opal_cmd_line_get_param(&cmd_line, "host", i, 0); opal_argv_append_nosize(&targ, value); } tval = opal_argv_join(targ, ','); orte_set_attribute(&app->attributes, ORTE_APP_DASH_HOST, ORTE_ATTR_LOCAL, tval, OPAL_STRING); opal_argv_free(targ); free(tval); } OBJ_DESTRUCT(&cmd_line); /* setup to listen for commands sent specifically to me, even though I would probably * be the one sending them! Unfortunately, since I am a participating daemon, * there are times I need to send a command to "all daemons", and that means *I* have * to receive it too */ orte_rml.recv_buffer_nb(ORTE_NAME_WILDCARD, ORTE_RML_TAG_DAEMON, ORTE_RML_PERSISTENT, orte_daemon_recv, NULL); /* override the notify_completed state so we can send a message * back to anyone who submits a job to us telling them the job * completed */ if (ORTE_SUCCESS != (rc = orte_state.set_job_state_callback(ORTE_JOB_STATE_NOTIFY_COMPLETED, notify_requestor))) { ORTE_ERROR_LOG(rc); ORTE_UPDATE_EXIT_STATUS(rc); exit(orte_exit_status); } /* spawn the DVM - we skip the initial steps as this * isn't a user-level application */ ORTE_ACTIVATE_JOB_STATE(jdata, ORTE_JOB_STATE_ALLOCATE); /* loop the event lib until an exit event is detected */ while (orte_event_base_active) { opal_event_loop(orte_event_base, OPAL_EVLOOP_ONCE); } /* cleanup and leave */ orte_finalize(); if (orte_debug_flag) { fprintf(stderr, "exiting with status %d\n", orte_exit_status); } exit(orte_exit_status); }