static bool test8(void) { char *a[] = { "aaa", "bbbbbbbb", "cccccccccc", NULL }; int i; char **b; /* bozo case */ if (NULL != opal_argv_copy(NULL)) { return false; } /* dup the a array and compare it (array length, contents, etc.) */ b = opal_argv_copy(a); if (opal_argv_count(a) != opal_argv_count(b)) { return false; } for (i = 0; a[i] != NULL; ++i) { if (0 != strcmp(a[i], b[i])) { return false; } } /* All done */ opal_argv_free(b); return true; }
int opal_paffinity_base_slot_list_set(long rank, char *slot_str) { char **item; char **socket_core; int item_cnt, socket_core_cnt, rc; bool logical_map; if (NULL == slot_str){ return OPAL_ERR_BAD_PARAM; } /* if the slot string is empty, that is an error */ if (0 == strlen(slot_str)) { return OPAL_ERR_BAD_PARAM; } /* check for diag request to avoid repeatedly doing so */ if (4 < opal_output_get_verbosity(opal_paffinity_base_output)) { diag_requested = true; } else { diag_requested = false; } opal_output_verbose(5, opal_paffinity_base_output, "paffinity slot assignment: slot_list == %s", slot_str); if ('P' == slot_str[0] || 'p' == slot_str[0]) { /* user has specified physical mapping */ logical_map = false; item = opal_argv_split (&slot_str[1], ','); } else { logical_map = true; /* default to logical mapping */ item = opal_argv_split (slot_str, ','); } item_cnt = opal_argv_count (item); socket_core = opal_argv_split (item[0], ':'); socket_core_cnt = opal_argv_count(socket_core); opal_argv_free(socket_core); switch (socket_core_cnt) { case 1: /* binding to cpu's */ if (OPAL_SUCCESS != (rc = opal_paffinity_base_socket_to_cpu_set(item, item_cnt, rank, logical_map))) { opal_argv_free(item); return rc; } break; case 2: /* binding to socket/core specification */ if (OPAL_SUCCESS != (rc = opal_paffinity_base_socket_core_to_cpu_set(item, item_cnt, rank, logical_map))) { opal_argv_free(item); return rc; } break; default: opal_argv_free(item); return OPAL_ERROR; } opal_argv_free(item); return OPAL_SUCCESS; }
/* * APP CONTEXT */ int orte_rmgr_base_size_app_context(size_t *size, orte_app_context_t *src, orte_data_type_t type) { int j, rc, count; orte_std_cntr_t i; size_t map_size; /* account for the object itself */ *size = sizeof(orte_app_context_t); /* if src is NULL, then that's all we wanted */ if (NULL == src) return ORTE_SUCCESS; if (NULL != src->app) { *size += strlen(src->app); } count = opal_argv_count(src->argv); if (0 < count) { /* account for array of char* */ *size += count * sizeof(char*); for (j=0; j < count; j++) { *size += strlen(src->argv[j]); } } *size += sizeof(char**); /* account for size of the argv pointer itself */ count = opal_argv_count(src->env); if (0 < count) { /* account for array of char* */ *size += count * sizeof(char*); for (i=0; i < count; i++) { *size += strlen(src->env[i]); } } *size += sizeof(char**); /* account for size of the env pointer itself */ if (NULL != src->cwd) { *size += strlen(src->cwd); /* working directory */ } if (0 < src->num_map) { for (i=0; i < src->num_map; i++) { if (ORTE_SUCCESS != (rc = orte_rmgr_base_size_app_context_map(&map_size, src->map_data[i], ORTE_APP_CONTEXT_MAP))) { ORTE_ERROR_LOG(rc); *size = 0; return rc; } } } if (NULL != src->prefix_dir) { *size += strlen(src->prefix_dir); } return ORTE_SUCCESS; }
int opal_argv_insert(char ***target, int start, char **source) { int i, source_count, target_count; int suffix_count; /* Check for the bozo cases */ if (NULL == target || NULL == *target || start < 0) { return OPAL_ERR_BAD_PARAM; } else if (NULL == source) { return OPAL_SUCCESS; } /* Easy case: appending to the end */ target_count = opal_argv_count(*target); source_count = opal_argv_count(source); if (start > target_count) { for (i = 0; i < source_count; ++i) { opal_argv_append(&target_count, target, source[i]); } } /* Harder: insertting into the middle */ else { /* Alloc out new space */ *target = (char**) realloc(*target, sizeof(char *) * (target_count + source_count + 1)); /* Move suffix items down to the end */ suffix_count = target_count - start; for (i = suffix_count - 1; i >= 0; --i) { (*target)[start + source_count + i] = (*target)[start + i]; } (*target)[start + suffix_count + source_count] = NULL; /* Strdup in the source argv */ for (i = start; i < start + source_count; ++i) { (*target)[i] = strdup(source[i - start]); } } /* All done */ return OPAL_SUCCESS; }
/* * APP CONTEXT */ int orte_dt_print_app_context(char **output, char *prefix, orte_app_context_t *src, opal_data_type_t type) { char *tmp, *tmp2, *pfx2; int i, count; /* set default result */ *output = NULL; /* protect against NULL prefix */ if (NULL == prefix) { asprintf(&pfx2, " "); } else { asprintf(&pfx2, "%s", prefix); } asprintf(&tmp, "\n%sData for app_context: index %lu\tapp: %s\n%s\tNum procs: %lu", pfx2, (unsigned long)src->idx, src->app, pfx2, (unsigned long)src->num_procs); count = opal_argv_count(src->argv); for (i=0; i < count; i++) { asprintf(&tmp2, "%s\n%s\tArgv[%d]: %s", tmp, pfx2, i, src->argv[i]); free(tmp); tmp = tmp2; } count = opal_argv_count(src->env); for (i=0; i < count; i++) { asprintf(&tmp2, "%s\n%s\tEnv[%lu]: %s", tmp, pfx2, (unsigned long)i, src->env[i]); free(tmp); tmp = tmp2; } asprintf(&tmp2, "%s\n%s\tWorking dir: %s (user: %d)\n%s\tHostfile: %s\tAdd-Hostfile: %s", tmp, pfx2, src->cwd, (int) src->user_specified_cwd, pfx2, (NULL == src->hostfile) ? "NULL" : src->hostfile, (NULL == src->add_hostfile) ? "NULL" : src->add_hostfile); free(tmp); tmp = tmp2; count = opal_argv_count(src->dash_host); for (i=0; i < count; i++) { asprintf(&tmp2, "%s\n%s\tDash_host[%lu]: %s", tmp, pfx2, (unsigned long)i, src->dash_host[i]); free(tmp); tmp = tmp2; } /* set the return */ *output = tmp; free(pfx2); return ORTE_SUCCESS; }
/** * ================================ * char **str_array_pt = NULL; char *str1 = "hello"; char *str2 = "haha"; opal_argv_prepend_nosize(&str_array_pt, str1); opal_argv_prepend_nosize(&str_array_pt, str2); while(*str_array_pt) puts(*str_array_pt++); * ===============================- * haha hello * */ int opal_argv_prepend_nosize(char ***argv, const char *arg) { int argc; int i; /* Create new argv. */ if (NULL == *argv) { *argv = (char**) malloc(2 * sizeof(char *)); if (NULL == *argv) { return OPAL_ERR_OUT_OF_RESOURCE; } (*argv)[0] = strdup(arg); (*argv)[1] = NULL; } else { /* count how many entries currently exist */ argc = opal_argv_count(*argv); *argv = (char**) realloc(*argv, (argc + 2) * sizeof(char *)); if (NULL == *argv) { return OPAL_ERR_OUT_OF_RESOURCE; } (*argv)[argc+1] = NULL; /* shift all existing elements down 1 */ for (i=argc; 0 < i; i--) { (*argv)[i] = (*argv)[i-1]; } (*argv)[0] = strdup(arg); } return OPAL_SUCCESS; }
static void check_sanity(char ***if_sanity_list, const char *dev_name, int port) { int i; char tmp[BUFSIZ], **list; const char *compare; if (NULL == if_sanity_list || NULL == *if_sanity_list) { return; } list = *if_sanity_list; /* A match is found if: - "dev_name" is in the list and port == -1, or - "dev_name:port" is in the list If a match is found, remove that entry from the list. */ memset(tmp, 0, sizeof(tmp)); if (port > 0) { snprintf(tmp, sizeof(tmp) - 1, "%s:%d", dev_name, port); compare = tmp; } else { compare = dev_name; } for (i = 0; NULL != list[i]; ++i) { if (0 == strcmp(list[i], compare)) { int count = opal_argv_count(list); opal_argv_delete(&count, &list, i, 1); *if_sanity_list = list; --i; } } }
static char * get_slurm_nodename(int nodeid) { char **names = NULL; char *slurm_nodelist; char *ret; slurm_nodelist = getenv("OMPI_MCA_orte_slurm_nodelist"); if (NULL == slurm_nodelist) { return NULL; } /* split the node list into an argv array */ names = opal_argv_split(slurm_nodelist, ','); if (NULL == names) { /* got an error */ return NULL; } /* check to see if there are enough entries */ if (nodeid > opal_argv_count(names)) { return NULL; } ret = strdup(names[nodeid]); opal_argv_free(names); /* All done */ return ret; }
static char * get_slurm_nodename(int nodeid) { char **names = NULL; char *slurm_nodelist; char *ret; mca_base_param_reg_string_name("orte", "nodelist", "List of nodes in job", true, false, NULL, &slurm_nodelist); if (NULL == slurm_nodelist) { return NULL; } /* split the node list into an argv array */ names = opal_argv_split(slurm_nodelist, ','); if (NULL == names) { /* got an error */ return NULL; } /* check to see if there are enough entries */ if (nodeid > opal_argv_count(names)) { return NULL; } ret = strdup(names[nodeid]); opal_argv_free(names); /* All done */ return ret; }
/* * Make one big string with all the lines. This isn't the most * efficient method in the world, but we're going for clarity here -- * not optimization. :-) */ static int output(bool want_error_header, char **lines, const char *base, const char *topic, va_list arglist) { int i, count; size_t len; char *concat; /* See how much space we need */ len = want_error_header ? 2 * strlen(dash_line) : 0; count = opal_argv_count(lines); for (i = 0; i < count; ++i) { if (NULL == lines[i]) { break; } len += strlen(lines[i]) + 1; } /* Malloc it out */ concat = (char*) malloc(len + 1); if (NULL == concat) { fprintf(stderr, dash_line); fprintf(stderr, "Sorry! You were supposed to get help about:\n %s\nfrom the file:\n %s\n", topic, base); fprintf(stderr, "But memory seems to be exhausted. Sorry!\n"); fprintf(stderr, dash_line); return OPAL_ERR_OUT_OF_RESOURCE; } /* Fill the big string */ *concat = '\0'; if (want_error_header) { strcat(concat, dash_line); } for (i = 0; i < count; ++i) { if (NULL == lines[i]) { break; } strcat(concat, lines[i]); strcat(concat, "\n"); } if (want_error_header) { strcat(concat, dash_line); } /* Apply formatting */ vfprintf( stderr, concat, arglist ); /* All done */ free(concat); return OPAL_SUCCESS; }
static int pretty_print_migration(void) { char **loc_off_nodes = NULL; char **loc_off_procs = NULL; char **loc_onto_nodes = NULL; int loc_off_nodes_cnt = 0; int loc_off_procs_cnt = 0; int loc_onto_cnt = 0; int i; if( NULL != orte_migrate_globals.off_nodes ) { loc_off_nodes = opal_argv_split(orte_migrate_globals.off_nodes, ','); loc_off_nodes_cnt = opal_argv_count(loc_off_nodes); } if( NULL != orte_migrate_globals.off_procs ) { loc_off_procs = opal_argv_split(orte_migrate_globals.off_procs, ','); loc_off_procs_cnt = opal_argv_count(loc_off_procs); } if( NULL != orte_migrate_globals.onto_nodes ) { loc_onto_nodes = opal_argv_split(orte_migrate_globals.onto_nodes, ','); loc_onto_cnt = opal_argv_count(loc_onto_nodes); } printf("Migrate Nodes: (%d nodes)\n", loc_off_nodes_cnt); for(i = 0; i < loc_off_nodes_cnt; ++i) { printf("\t\"%s\"\n", loc_off_nodes[i]); } printf("Migrate Ranks: (%d ranks)\n", loc_off_procs_cnt); for(i = 0; i < loc_off_procs_cnt; ++i) { printf("\t\"%s\"\n", loc_off_procs[i]); } printf("Migrate Onto : (%d nodes)\n", loc_onto_cnt); for(i = 0; i < loc_onto_cnt; ++i) { printf("\t\"%s\"\n", loc_onto_nodes[i]); } return ORTE_SUCCESS; }
static int workflow_add_send_workflow(opal_buffer_t *buf, char **aggregator) { orte_process_name_t wf_agg; orte_rml_recv_cb_t *xfer = NULL; int rc; int node_index; for (node_index = 0; node_index < opal_argv_count(aggregator); node_index++) { xfer = OBJ_NEW(orte_rml_recv_cb_t); if (NULL == xfer) { return ORCM_ERR_OUT_OF_RESOURCE; } workflow_output_setup(xfer); OBJ_RETAIN(buf); if (ORCM_SUCCESS != (rc = orcm_cfgi_base_get_hostname_proc(aggregator[node_index], &wf_agg))) { orcm_octl_error("node-notfound", aggregator[node_index]); orte_rml.recv_cancel(ORTE_NAME_WILDCARD, ORCM_RML_TAG_ANALYTICS); SAFE_RELEASE(xfer); return rc; } rc = workflow_send_buffer(&wf_agg, buf, xfer); if (ORCM_SUCCESS != rc) { orcm_octl_error("connection-fail"); orte_rml.recv_cancel(ORTE_NAME_WILDCARD, ORCM_RML_TAG_ANALYTICS); SAFE_RELEASE(xfer); return rc; } /* unpack workflow id */ ORCM_WAIT_FOR_COMPLETION(xfer->active, ORCM_OCTL_WAIT_TIMEOUT, &rc); if (ORCM_SUCCESS != rc) { orcm_octl_error("connection-fail"); orte_rml.recv_cancel(ORTE_NAME_WILDCARD, ORCM_RML_TAG_ANALYTICS); SAFE_RELEASE(xfer); return rc; } rc = workflow_add_unpack_buffer(xfer); if (ORCM_SUCCESS != rc) { orte_rml.recv_cancel(ORTE_NAME_WILDCARD, ORCM_RML_TAG_ANALYTICS); SAFE_RELEASE(xfer); return rc; } orte_rml.recv_cancel(ORTE_NAME_WILDCARD, ORCM_RML_TAG_ANALYTICS); SAFE_RELEASE(xfer); } return ORCM_SUCCESS; }
static int rte_init(void) { int rc; orte_vpid_t vpid; char *vpid_string; char *nidmap_string; vpid_string = getenv("PTL_MY_RID"); nidmap_string = getenv("PTL_NIDMAP"); if (NULL == vpid_string || NULL == nidmap_string || NULL == getenv("PTL_PIDMAP") || NULL == getenv("PTL_IFACE")) { return ORTE_ERR_NOT_FOUND; } /* Get our process information */ /* Procs in this environment are directly launched. Hence, there * was no mpirun to create a jobid for us, and each app proc is * going to have to fend for itself. For now, we assume that the * jobid is some arbitrary number (say, 1). */ ORTE_PROC_MY_NAME->jobid = 1; /* not 0, since it has special meaning */ /* find our vpid assuming range starts at 0 */ if (ORTE_SUCCESS != (rc = orte_util_convert_string_to_vpid(&vpid, vpid_string))) { ORTE_ERROR_LOG(rc); return(rc); } ORTE_PROC_MY_NAME->vpid = vpid; /* * Get the number of procs in the job. We assume vpids start at 0. We * assume that there are <num : + 1> procs, since the nidmap is a * : seperated list of nids, and the utcp reference implementation * assumes all will be present */ /* split the nidmap string */ nidmap = opal_argv_split(nidmap_string, ':'); orte_process_info.num_procs = (orte_std_cntr_t) opal_argv_count(nidmap); /* MPI_Init needs the grpcomm framework, so we have to init it */ if (ORTE_SUCCESS != (rc = orte_grpcomm_base_open())) { ORTE_ERROR_LOG(rc); return rc; } if (ORTE_SUCCESS != (rc = orte_grpcomm_base_select())) { ORTE_ERROR_LOG(rc); return rc; } /* that's all we need here */ return ORTE_SUCCESS; }
/** orte_plm_poe_component_open - open component and register all parameters @return error number */ int orte_plm_poe_component_open(void) { char *param; mca_base_component_t *c = &mca_plm_poe_component.super.base_version; mca_base_param_reg_int(c, "mp_retry", "specifies the interval (in seconds) to wait before repeating the node request", true, false, 0, &mca_plm_poe_component.mp_retry); mca_base_param_reg_int(c, "mp_retrycount", "specifies the number of times the Partition Manager should make the request before returning", true, false, 0, &mca_plm_poe_component.mp_retrycount); mca_base_param_reg_int(c, "mp_infolevel", "specify the level of messages you want from POE (0-6)", true, false, 0, &mca_plm_poe_component.mp_infolevel); mca_base_param_reg_string(c, "mp_labelio", "Whether or not to label message output with task identifiers (yes or no)", true, false, "no", &mca_plm_poe_component.mp_labelio); mca_base_param_reg_string(c, "mp_stdoutmode", "standard output mode (ordered, unordered or taskID)", true, false, "unordered", &mca_plm_poe_component.mp_stdoutmode); mca_base_param_reg_int(c, "debug", "Whether or not to enable debugging output for the poe plm component (0 or 1)", false, false, 0, &mca_plm_poe_component.debug); mca_base_param_reg_int(c, "priority", "Priority of the poe plm component", false , false, 0, &mca_plm_poe_component.priority); mca_base_param_reg_string(c, "class", "class (interactive or batch)", true, false, "interactive", &mca_plm_poe_component.class); mca_base_param_reg_string(c, "resource_allocation", "resource_allocation mode (hostfile or automatic)", false, false, "hostfile", &mca_plm_poe_component.resource_allocation); mca_base_param_reg_string(c, "progenv", "The command name that setup environment", false, false, "env", &mca_plm_poe_component.env); mca_base_param_reg_string(c, "progpoe", "The POE command", false, false, "poe", ¶m); mca_plm_poe_component.argv = opal_argv_split(param, ' '); mca_plm_poe_component.argc = opal_argv_count(mca_plm_poe_component.argv); if (mca_plm_poe_component.argc > 0) { mca_plm_poe_component.path = strdup(mca_plm_poe_component.argv[0]); return ORTE_SUCCESS; } else { mca_plm_poe_component.path = NULL; return ORTE_ERR_BAD_PARAM; } return ORTE_SUCCESS; }
static int find_options_index(const char *arg) { int i, j; #ifdef HAVE_REGEXEC int args_count; regex_t res; #endif for (i = 0 ; i <= parse_options_idx ; ++i) { if (NULL == options_data[i].compiler_args) { continue; } #ifdef HAVE_REGEXEC args_count = opal_argv_count(options_data[i].compiler_args); for (j = 0 ; j < args_count ; ++j) { if (0 != regcomp(&res, options_data[i].compiler_args[j], REG_NOSUB)) { return -1; } if (0 == regexec(&res, arg, (size_t) 0, NULL, 0)) { regfree(&res); return i; } regfree(&res); } #else for (j = 0 ; j < opal_argv_count(options_data[i].compiler_args) ; ++j) { if (0 == strcmp(arg, options_data[i].compiler_args[j])) { return i; } } #endif } return -1; }
/* * Append a string to the end of a new or existing argv array. * ===================================== * char **str_array_pt = NULL; int argc; char *str1 = "hello"; char *str2 = "haha"; opal_argv_append(&argc, &str_array_pt, str1); opal_argv_append(&argc, &str_array_pt, str2); while(*str_array_pt) puts(*str_array_pt++); printf("argc = %d\n", argc); * ===================================== * hello haha argc = 2 */ int opal_argv_append(int *argc, char ***argv, const char *arg) { int rc; /* add the new element */ if (OPAL_SUCCESS != (rc = opal_argv_append_nosize(argv, arg))) { return rc; } *argc = opal_argv_count(*argv); return OPAL_SUCCESS; }
/** * ==================================== * char **str_array_pt = NULL; int argc; opal_argv_append(&argc, &str_array_pt, "first"); opal_argv_append(&argc, &str_array_pt, "second"); opal_argv_append(&argc, &str_array_pt, "third"); opal_argv_append(&argc, &str_array_pt, "forth"); opal_argv_append(&argc, &str_array_pt, "fifth"); opal_argv_append(&argc, &str_array_pt, "sixth"); opal_argv_append(&argc, &str_array_pt, "seventh"); opal_argv_append(&argc, &str_array_pt, "eighth"); printf("argc = %d\n", argc); int start = 2; int num_to_delete = 2; opal_argv_delete(&argc, &str_array_pt, start, num_to_delete); printf("argc = %d\n", argc); while(*str_array_pt) puts(*str_array_pt++); *===================================== argc = 8 argc = 6 first second fifth sixth seventh eighth *===================================== */ int opal_argv_delete(int *argc, char ***argv, int start, int num_to_delete) { int i; int count; int suffix_count; char **tmp; /* Check for the bozo cases */ if (NULL == argv || NULL == *argv || 0 == num_to_delete) { return OPAL_SUCCESS; } count = opal_argv_count(*argv); if (start > count) { return OPAL_SUCCESS; } else if (start < 0 || num_to_delete < 0) { return OPAL_ERR_BAD_PARAM; } /* Ok, we have some tokens to delete. Calculate the new length of the argv array. */ suffix_count = count - (start + num_to_delete); if (suffix_count < 0) { suffix_count = 0; } /* Free all items that are being deleted */ for (i = start; i < count && i < start + num_to_delete; ++i) { free((*argv)[i]); } /* Copy the suffix over the deleted items */ for (i = start; i < start + suffix_count; ++i) { (*argv)[i] = (*argv)[i + num_to_delete]; } /* Add the trailing NULL */ (*argv)[i] = NULL; /* adjust the argv array */ tmp = (char**)realloc(*argv, sizeof(char**) * (i + 1)); if (NULL != tmp) *argv = tmp; /* adjust the argc */ (*argc) -= num_to_delete; return OPAL_SUCCESS; }
/* * Join all the elements of an argv array from within a * specified range into a single newly-allocated string. * ======================================= * char *str_array[] = {"shanghai", "beijing", "tianjin", "xian", "chongqi", NULL}; * char* range_rt = opal_argv_join_range(str_array, 0, 3, ','); * puts(range_rt); * ======================================= * shanghai,beijing,tianjin */ char *opal_argv_join_range(char **argv, size_t start, size_t end, int delimiter) { char **p; char *pp; char *str; size_t str_len = 0; size_t i; /* Bozo case */ if (NULL == argv || NULL == argv[0] || (int)start > opal_argv_count(argv)) { return strdup(""); } /* Find the total string length in argv including delimiters. The last delimiter is replaced by the NULL character. */ for (p = &argv[start], i=start; *p && i < end; ++p, ++i) { str_len += strlen(*p) + 1; } /* Allocate the string. */ if (NULL == (str = (char*) malloc(str_len))) return NULL; /* Loop filling in the string. */ str[--str_len] = '\0'; p = &argv[start]; pp = *p; for (i = 0; i < str_len; ++i) { if ('\0' == *pp) { /* End of a string, fill in a delimiter and go to the next string. */ str[i] = (char) delimiter; ++p; pp = *p; } else { str[i] = *pp++; } } /* All done */ return str; }
static int workflow_remove_parse_args(char **value, char ***aggregator, char **workflow_name, char **workflow_id) { int rc; rc = opal_argv_count(value); if (5 != opal_argv_count(value)) { orcm_octl_usage("workflow-remove", INVALID_USG); return ORCM_ERR_BAD_PARAM; } rc = orcm_logical_group_parse_array_string(value[2], aggregator); if (ORCM_SUCCESS != rc) { orcm_octl_error("nodelist-extract", value[2]); return rc; } *workflow_name = value[3]; *workflow_id = value[4]; return ORCM_SUCCESS; }
int orcm_octl_session_cancel(char **argv) { orcm_scd_cmd_flag_t command; orcm_alloc_id_t id; opal_buffer_t *buf; orte_rml_recv_cb_t xfer; long session; int rc, n, result; if (3 != opal_argv_count(argv)) { fprintf(stderr, "\n incorrect arguments! \n\n usage: \"session \ cancel <session-id>\"\n"); return ORCM_ERR_BAD_PARAM; }
/* * Free all the strings in the array and destruct the array */ static int destroy_message(char **lines) { int i, count; count = opal_argv_count(lines); for (i = 0; i < count; ++i) { if (NULL == lines[i]) { break; } free(lines[i]); } return OPAL_SUCCESS; }
int opal_crs_base_cleanup_flush(void) { int argc, i; /* * Cleanup files first */ if( NULL != cleanup_file_argv ) { argc = opal_argv_count(cleanup_file_argv); for( i = 0; i < argc; ++i) { opal_output_verbose(15, opal_crs_base_framework.framework_output, "opal:crs: cleanup_flush: Remove File <%s>\n", cleanup_file_argv[i]); unlink(cleanup_file_argv[i]); } opal_argv_free(cleanup_file_argv); cleanup_file_argv = NULL; } /* * Try to cleanup directories next */ if( NULL != cleanup_dir_argv ) { argc = opal_argv_count(cleanup_dir_argv); for( i = 0; i < argc; ++i) { opal_output_verbose(15, opal_crs_base_framework.framework_output, "opal:crs: cleanup_flush: Remove Dir <%s>\n", cleanup_dir_argv[i]); opal_os_dirpath_destroy(cleanup_dir_argv[i], true, NULL); } opal_argv_free(cleanup_dir_argv); cleanup_dir_argv = NULL; } return OPAL_SUCCESS; }
int orcm_octl_power_set(int cmd, char **argv) { orcm_scd_cmd_flag_t command; opal_buffer_t *buf; orte_rml_recv_cb_t xfer; int rc, n, result; int32_t int_param; float float_param; bool bool_param; bool per_session = false; if (4 != opal_argv_count(argv)) { fprintf(stderr, "\n incorrect arguments! \n\n usage: \"power set\ <command> <value>\"\n"); return ORCM_ERR_BAD_PARAM; }
int opal_net_init(void) { char **args, *arg; uint32_t a, b, c, d, bits, addr; int i, count, found_bad = 0; args = opal_argv_split( opal_net_private_ipv4, ';' ); if( NULL != args ) { count = opal_argv_count(args); private_ipv4 = (private_ipv4_t*)malloc( (count + 1) * sizeof(private_ipv4_t)); if( NULL == private_ipv4 ) { opal_output(0, "Unable to allocate memory for the private addresses array" ); opal_argv_free(args); goto do_local_init; } for( i = 0; i < count; i++ ) { arg = args[i]; (void)sscanf( arg, "%u.%u.%u.%u/%u", &a, &b, &c, &d, &bits ); if( (a > 255) || (b > 255) || (c > 255) || (d > 255) || (bits > 32) ) { if (0 == found_bad) { opal_show_help("help-opal-util.txt", "malformed net_private_ipv4", true, args[i]); found_bad = 1; } continue; } addr = (a << 24) | (b << 16) | (c << 8) | d; private_ipv4[i].addr = htonl(addr); private_ipv4[i].netmask_bits = bits; } private_ipv4[i].addr = 0; private_ipv4[i].netmask_bits = 0; opal_argv_free(args); } do_local_init: #if OPAL_ENABLE_IPV6 return opal_tsd_key_create(&hostname_tsd_key, hostname_cleanup); #else return OPAL_SUCCESS; #endif }
static int workflow_list_parse_args(char **value, char ***aggregator) { int rc; if (3 != opal_argv_count(value)) { orcm_octl_usage("workflow-list", INVALID_USG); return ORCM_ERR_BAD_PARAM; } rc = orcm_logical_group_parse_array_string(value[2], aggregator); if (ORCM_SUCCESS != rc) { orcm_octl_error("nodelist-notfound", value[2]); return rc; } return ORCM_SUCCESS; }
int orcm_octl_diag_cpu(char **argv) { orcm_diag_cmd_flag_t command = ORCM_DIAG_START_COMMAND; char *comp; opal_buffer_t *buf = NULL; int rc = ORCM_SUCCESS, cnt, i, result; bool want_result = false; int numopts = 0; orte_process_name_t tgt; orte_rml_recv_cb_t *xfer = NULL; char **nodelist = NULL; if (3 != opal_argv_count(argv)) { fprintf(stderr, "\n incorrect arguments! \n\n usage:\"diag \ cpu <node-list>\"\n"); return ORCM_ERR_BAD_PARAM; }
int orte_session_setup_base(orte_process_name_t *proc) { int rc; /* Ensure that system info is set */ orte_proc_info(); /* setup job and proc session directories */ if( ORTE_SUCCESS != (rc = _setup_job_session_dir(proc)) ){ return rc; } if( ORTE_SUCCESS != (rc = _setup_proc_session_dir(proc)) ){ return rc; } /* BEFORE doing anything else, check to see if this prefix is * allowed by the system */ if (NULL != orte_prohibited_session_dirs || NULL != orte_process_info.tmpdir_base ) { char **list; int i, len; /* break the string into tokens - it should be * separated by ',' */ list = opal_argv_split(orte_prohibited_session_dirs, ','); len = opal_argv_count(list); /* cycle through the list */ for (i=0; i < len; i++) { /* check if prefix matches */ if (0 == strncmp(orte_process_info.tmpdir_base, list[i], strlen(list[i]))) { /* this is a prohibited location */ orte_show_help("help-orte-runtime.txt", "orte:session:dir:prohibited", true, orte_process_info.tmpdir_base, orte_prohibited_session_dirs); opal_argv_free(list); return ORTE_ERR_FATAL; } } opal_argv_free(list); /* done with this */ } return ORTE_SUCCESS; }
/* get key/value from line */ static opal_value_t *oflow_parse_next_line(FILE *fp) { char *ret, *ptr; char **tokens = NULL; char input[ORCM_MAX_LINE_LENGTH]; size_t i; opal_value_t *tokenized; int array_length; ret = fgets(input, ORCM_MAX_LINE_LENGTH, fp); if (NULL != ret) { /* remove newline */ input[strlen(input)-1] = '\0'; /* strip leading spaces */ ptr = input; for (i=0; i < strlen(input)-1; i++) { if (' ' != input[i]) { ptr = &input[i]; break; } } tokens = opal_argv_split(ptr, ':'); array_length = opal_argv_count(tokens); if (2 == array_length) { tokenized = (opal_value_t *)malloc(sizeof(opal_value_t)); if (!tokenized) { opal_argv_free(tokens); return NULL; } tokenized->type = OPAL_STRING; tokenized->key = tokens[0]; tokenized->data.string = tokens[1]; opal_argv_free(tokens); return tokenized; } opal_argv_free(tokens); } return NULL; }
static int workflow_add_parse_args(char **value, char **file, char **aggregator) { if (3 > opal_argv_count(value)) { orcm_octl_usage("workflow-add", INVALID_USG); return ORCM_ERR_BAD_PARAM; } if (NULL != value[2]) { *file = value[2]; } else { orcm_octl_error("workflow-notfound"); return ORCM_ERR_BAD_PARAM; } if (NULL != value[3]) { *aggregator = value[3]; } return ORCM_SUCCESS; }
static void add_extra_includes(const char *includes, const char* includedir) { int i; char **values = opal_argv_split(includes, ' '); for (i = 0 ; i < opal_argv_count(values) ; ++i) { char *line, *include_directory; include_directory = opal_os_path(false, includedir, values[i], NULL); #if defined(__WINDOWS__) asprintf(&line, OPAL_INCLUDE_FLAG"\"%s\"", include_directory); #else asprintf(&line, OPAL_INCLUDE_FLAG"%s", include_directory); #endif /* defined(__WINDOWS__) */ opal_argv_append_nosize(&options_data[parse_options_idx].preproc_flags, line); free(include_directory); free(line); } }