/* * verify that a node count in arg is of a known form (count or min-max) * OUT min, max specified minimum and maximum node counts * RET true if valid */ bool verify_node_count(const char *arg, int *min_nodes, int *max_nodes) { char *ptr, *min_str, *max_str; char *leftover; /* Does the string contain a "-" character? If so, treat as a range. * otherwise treat as an absolute node count. */ if ((ptr = index(arg, '-')) != NULL) { min_str = xstrndup(arg, ptr-arg); *min_nodes = _str_to_nodes(min_str, &leftover); if (!xstring_is_whitespace(leftover)) { error("\"%s\" is not a valid node count", min_str); xfree(min_str); return false; } xfree(min_str); if (*min_nodes == 0) *min_nodes = 1; max_str = xstrndup(ptr+1, strlen(arg)-((ptr+1)-arg)); *max_nodes = _str_to_nodes(max_str, &leftover); if (!xstring_is_whitespace(leftover)) { error("\"%s\" is not a valid node count", max_str); xfree(max_str); return false; } xfree(max_str); } else { *min_nodes = *max_nodes = _str_to_nodes(arg, &leftover); if (!xstring_is_whitespace(leftover)) { error("\"%s\" is not a valid node count", arg); return false; } if (*min_nodes == 0) { /* whitespace does not a valid node count make */ error("\"%s\" is not a valid node count", arg); return false; } } if ((*max_nodes != 0) && (*max_nodes < *min_nodes)) { error("Maximum node count %d is less than" " minimum node count %d", *max_nodes, *min_nodes); return false; } return true; }
/* Return 1 on success, 0 on failure to find a stepid in the string */ static int _parse_stepid(const char *jobid_str, uint32_t *out_stepid) { char *ptr, *job, *step; long stepid; job = xstrdup(jobid_str); ptr = index(job, '.'); if (ptr == NULL) { /* did not find a period, so no step ID in this string */ xfree(job); return 0; } else { step = ptr + 1; } stepid = strtol(step, &ptr, 10); if (!xstring_is_whitespace(ptr)) { fprintf(stderr, "\"%s\" does not look like a stepid\n", step); xfree(job); return 0; } *out_stepid = (uint32_t) stepid; xfree(job); return 1; }
/* Convert a signal name to it's numeric equivalent. * Return -1 on failure */ int sig_name2num(char *signal_name) { char *sig_name[] = {"HUP", "INT", "QUIT", "KILL", "TERM", "USR1", "USR2", "CONT", NULL}; int sig_num[] = {SIGHUP, SIGINT, SIGQUIT, SIGKILL, SIGTERM, SIGUSR1, SIGUSR2, SIGCONT}; char *ptr; long tmp; int sig; int i; tmp = strtol(signal_name, &ptr, 10); if (ptr != signal_name) { /* found a number */ if (xstring_is_whitespace(ptr)) sig = (int)tmp; else return 0; } else { ptr = (char *)signal_name; while (isspace((int)*ptr)) ptr++; if (strncasecmp(ptr, "SIG", 3) == 0) ptr += 3; for (i = 0; ; i++) { if (sig_name[i] == NULL) return 0; if (strncasecmp(ptr, sig_name[i], strlen(sig_name[i])) == 0) { /* found the signal name */ if (!xstring_is_whitespace(ptr + strlen(sig_name[i]))) return 0; sig = sig_num[i]; break; } } } return sig; }
static void _parse_jobid_stepid(char *jobid_str) { char *ptr, *job, *step; long jobid, stepid; verbose("jobid/stepid string = %s\n", jobid_str); job = xstrdup(jobid_str); ptr = index(job, '.'); if (ptr == NULL) { error("Did not find a period in the step ID string"); _usage(); xfree(job); exit(error_exit); } else { *ptr = '\0'; step = ptr + 1; } jobid = strtol(job, &ptr, 10); if (!xstring_is_whitespace(ptr)) { error("\"%s\" does not look like a jobid", job); _usage(); xfree(job); exit(error_exit); } stepid = strtol(step, &ptr, 10); if (!xstring_is_whitespace(ptr)) { error("\"%s\" does not look like a stepid", step); _usage(); xfree(job); exit(error_exit); } opt.jobid = (uint32_t) jobid; opt.stepid = (uint32_t) stepid; xfree(job); }
/* * Get a POSITIVE decimal integer from arg. * * Returns the integer on success, exits program on failure. * */ static int _get_pos_int(const char *arg, const char *what) { char *p; long int result = strtol(arg, &p, 10); if (p == arg || !xstring_is_whitespace(p) || (result < 0L)) { error ("Invalid numeric value \"%s\" for %s.", arg, what); exit(error_exit); } if (result > INT_MAX) { error ("Numeric argument %ld to big for %s.", result, what); exit(error_exit); } return (int) result; }
/* Return 1 on success, 0 on failure to find a jobid in the string */ static int _parse_jobid(const char *jobid_str, uint32_t *out_jobid) { char *ptr, *job; long jobid; job = xstrdup(jobid_str); ptr = index(job, '.'); if (ptr != NULL) { *ptr = '\0'; } jobid = strtol(job, &ptr, 10); if (!xstring_is_whitespace(ptr)) { fprintf(stderr, "\"%s\" does not look like a jobid\n", job); xfree(job); return 0; } *out_jobid = (uint32_t) jobid; xfree(job); return 1; }
/* * verify that a node count in arg is of a known form (count or min-max) * OUT min, max specified minimum and maximum node counts * RET true if valid */ bool verify_node_count(const char *arg, int *min_nodes, int *max_nodes) { char *ptr, *min_str, *max_str; char *leftover; /* Does the string contain a "-" character? If so, treat as a range. * otherwise treat as an absolute node count. */ if ((ptr = index(arg, '-')) != NULL) { min_str = xstrndup(arg, ptr-arg); *min_nodes = _str_to_nodes(min_str, &leftover); if (!xstring_is_whitespace(leftover)) { error("\"%s\" is not a valid node count", min_str); xfree(min_str); return false; } xfree(min_str); #ifdef HAVE_ALPS_CRAY if (*min_nodes < 0) { #else if (*min_nodes == 0) { #endif *min_nodes = 1; } max_str = xstrndup(ptr+1, strlen(arg)-((ptr+1)-arg)); *max_nodes = _str_to_nodes(max_str, &leftover); if (!xstring_is_whitespace(leftover)) { error("\"%s\" is not a valid node count", max_str); xfree(max_str); return false; } xfree(max_str); } else { *min_nodes = *max_nodes = _str_to_nodes(arg, &leftover); if (!xstring_is_whitespace(leftover)) { error("\"%s\" is not a valid node count", arg); return false; } #ifdef HAVE_ALPS_CRAY if (*min_nodes < 0) { #else if (*min_nodes == 0) { #endif /* whitespace does not a valid node count make */ error("\"%s\" is not a valid node count", arg); return false; } } if ((*max_nodes != 0) && (*max_nodes < *min_nodes)) { error("Maximum node count %d is less than" " minimum node count %d", *max_nodes, *min_nodes); return false; } return true; } /* * If the node list supplied is a file name, translate that into * a list of nodes, we orphan the data pointed to * RET true if the node list is a valid one */ bool verify_node_list(char **node_list_pptr, enum task_dist_states dist, int task_count) { char *nodelist = NULL; xassert (node_list_pptr); xassert (*node_list_pptr); if (strchr(*node_list_pptr, '/') == NULL) return true; /* not a file name */ /* If we are using Arbitrary grab count out of the hostfile using them exactly the way we read it in since we are saying, lay it out this way! */ if ((dist & SLURM_DIST_STATE_BASE) == SLURM_DIST_ARBITRARY) nodelist = slurm_read_hostfile(*node_list_pptr, task_count); else nodelist = slurm_read_hostfile(*node_list_pptr, NO_VAL); if (!nodelist) return false; xfree(*node_list_pptr); *node_list_pptr = xstrdup(nodelist); free(nodelist); return true; }