/****************************************************************************\ * opts.c - squeue command line option parsing ***************************************************************************** * Copyright (C) 2002-2007 The Regents of the University of California. * Copyright (C) 2008-2010 Lawrence Livermore National Security. * Copyright (C) 2010-2013 SchedMD LLC. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). * Written by Joey Ekstrom , Morris Jette * CODE-OCEC-09-009. All rights reserved. * * This file is part of Slurm, a resource management program. * For details, see . * Please also read the included file: DISCLAIMER. * * Slurm is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * In addition, as a special exception, the copyright holders give permission * to link the code of portions of this program with the OpenSSL library under * certain conditions as described in each individual source file, and * distribute linked combinations including the two. You must obey the GNU * General Public License in all respects for all of the code used other than * OpenSSL. If you modify file(s) with this exception, you may extend this * exception to your version of the file(s), but you are not obligated to do * so. If you do not wish to do so, delete this exception statement from your * version. If you delete this exception statement from all source files in * the program, then also delete it here. * * Slurm is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along * with Slurm; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. \*****************************************************************************/ #define _GNU_SOURCE #include #include #include #include #include #include #include "src/common/read_config.h" #include "src/common/xstring.h" #include "src/common/proc_args.h" #include "src/common/uid.h" #include "src/squeue/squeue.h" /* getopt_long options, integers but not characters */ #define OPT_LONG_HELP 0x100 #define OPT_LONG_USAGE 0x101 #define OPT_LONG_HIDE 0x102 #define OPT_LONG_START 0x103 #define OPT_LONG_NOCONVERT 0x104 #define OPT_LONG_ARRAY_UNIQUE 0x105 #define OPT_LONG_LOCAL 0x106 #define OPT_LONG_SIBLING 0x107 #define OPT_LONG_FEDR 0x108 #define OPT_LONG_ME 0x109 /* FUNCTIONS */ static List _build_job_list( char* str ); static List _build_str_list( char* str ); static List _build_state_list( char* str ); static List _build_all_states_list( void ); static List _build_step_list( char* str ); static List _build_user_list( char* str ); static char *_get_prefix(char *token); static void _help( void ); static int _parse_state( char* str, uint32_t* states ); static void _parse_token( char *token, char *field, int *field_size, bool *right_justify, char **suffix); static void _parse_long_token( char *token, char *sep, int *field_size, bool *right_justify, char **suffix); static void _print_options( void ); static void _usage( void ); static bool _check_node_names(hostset_t); static bool _find_a_host(char *, node_info_msg_t *); /* * parse_command_line */ extern void parse_command_line( int argc, char* *argv ) { char *env_val = NULL; bool override_format_env = false; int opt_char; int option_index; static struct option long_options[] = { {"accounts", required_argument, 0, 'A'}, {"all", no_argument, 0, 'a'}, {"array", no_argument, 0, 'r'}, {"array-unique",no_argument, 0, OPT_LONG_ARRAY_UNIQUE}, {"Format", required_argument, 0, 'O'}, {"format", required_argument, 0, 'o'}, {"federation", no_argument, 0, OPT_LONG_FEDR}, {"help", no_argument, 0, OPT_LONG_HELP}, {"hide", no_argument, 0, OPT_LONG_HIDE}, {"iterate", required_argument, 0, 'i'}, {"jobs", optional_argument, 0, 'j'}, {"local", no_argument, 0, OPT_LONG_LOCAL}, {"long", no_argument, 0, 'l'}, {"licenses", required_argument, 0, 'L'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"me", no_argument, 0, OPT_LONG_ME}, {"name", required_argument, 0, 'n'}, {"noconvert", no_argument, 0, OPT_LONG_NOCONVERT}, {"node", required_argument, 0, 'w'}, {"nodes", required_argument, 0, 'w'}, {"nodelist", required_argument, 0, 'w'}, {"noheader", no_argument, 0, 'h'}, {"partitions", required_argument, 0, 'p'}, {"priority", no_argument, 0, 'P'}, {"qos", required_argument, 0, 'q'}, {"reservation",required_argument, 0, 'R'}, {"sib", no_argument, 0, OPT_LONG_SIBLING}, {"sibling", no_argument, 0, OPT_LONG_SIBLING}, {"sort", required_argument, 0, 'S'}, {"start", no_argument, 0, OPT_LONG_START}, {"steps", optional_argument, 0, 's'}, {"states", required_argument, 0, 't'}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"user", required_argument, 0, 'u'}, {"users", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {NULL, 0, 0, 0} }; params.convert_flags = CONVERT_NUM_UNIT_EXACT; if (xstrstr(slurm_conf.fed_params, "fed_display")) params.federation_flag = true; if (getenv("SQUEUE_ALL")) params.all_flag = true; if (getenv("SQUEUE_ARRAY")) params.array_flag = true; if ( ( env_val = getenv("SQUEUE_SORT") ) ) params.sort = xstrdup(env_val); if (getenv("SQUEUE_ARRAY_UNIQUE")) params.array_unique_flag = true; if ( ( env_val = getenv("SLURM_CLUSTERS") ) ) { if (!(params.clusters = slurmdb_get_info_cluster(env_val))) { print_db_notok(env_val, 1); exit(1); } working_cluster_rec = list_peek(params.clusters); params.local_flag = true; } if (getenv("SQUEUE_FEDERATION")) params.federation_flag = true; if (getenv("SQUEUE_LOCAL")) params.local_flag = true; if (getenv("SQUEUE_PRIORITY")) params.priority_flag = true; if (getenv("SQUEUE_SIB") || getenv("SQUEUE_SIBLING")) params.sibling_flag = true; while ((opt_char = getopt_long(argc, argv, "A:ahi:j::lL:n:M:O:o:p:Pq:R:rs::S:t:u:U:vVw:", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"squeue --help\" " "for more information\n"); exit(1); case (int) 'A': case (int) 'U': /* backwards compatibility */ xfree(params.accounts); params.accounts = xstrdup(optarg); params.account_list = _build_str_list( params.accounts ); break; case (int)'a': params.all_flag = true; break; case (int)'h': params.no_header = true; break; case (int) 'i': params.iterate= atoi(optarg); if (params.iterate <= 0) { error ("--iterate=%s\n", optarg); exit(1); } break; case (int) 'j': if (optarg) { params.jobs = xstrdup(optarg); params.job_list = _build_job_list(params.jobs); } params.job_flag = true; break; case (int) 'l': params.long_list = true; override_format_env = true; break; case (int) 'L': xfree(params.licenses); params.licenses = xstrdup(optarg); params.licenses_list = _build_str_list(params.licenses); break; case (int) 'M': if (params.clusters) FREE_NULL_LIST(params.clusters); if (!(params.clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(params.clusters); params.local_flag = true; break; case (int) 'n': xfree(params.names); params.names = xstrdup(optarg); params.name_list = _build_str_list( params.names ); break; case (int) 'O': xfree(params.format_long); if (params.format == NULL) { params.format_long = xstrdup(optarg); } else { error ("-O (--Format) is incompatible with -o " "(--format)"); exit(1); } override_format_env = true; break; case (int) 'o': xfree(params.format); if (params.format_long == NULL) { params.format = xstrdup(optarg); } else { error ("-o (--format) is incompatible with -O " "(--Format)"); exit(1); } override_format_env = true; break; case (int) 'p': xfree(params.partitions); params.partitions = xstrdup(optarg); params.part_list = _build_str_list( params.partitions ); params.all_flag = true; break; case (int) 'P': params.priority_flag = true; break; case (int) 'q': xfree(params.qoss); params.qoss = xstrdup(optarg); params.qos_list = _build_str_list( params.qoss ); break; case (int) 'R': xfree(params.reservation); params.reservation = xstrdup(optarg); break; case (int)'r': params.array_flag = true; setenv("SLURM_BITSTR_LEN", "0", 1); break; case (int) 's': if (optarg) { params.steps = xstrdup(optarg); params.step_list = _build_step_list(params.steps); } params.step_flag = true; override_format_env = true; break; case (int) 'S': xfree(params.sort); params.sort = xstrdup(optarg); break; case (int) 't': xfree(params.states); params.states = xstrdup(optarg); params.state_list = _build_state_list( params.states ); break; case (int) 'u': xfree(params.users); params.users = xstrdup(optarg); params.user_list = _build_user_list( params.users ); break; case (int) 'v': params.verbose++; break; case (int) 'V': print_slurm_version(); exit(0); case (int) 'w': if (params.nodes) hostset_destroy(params.nodes); params.nodes = hostset_create(optarg); if (params.nodes == NULL) { error("'%s' invalid entry for --nodelist", optarg); exit(1); } break; case OPT_LONG_ARRAY_UNIQUE: params.array_unique_flag = true; break; case OPT_LONG_HELP: _help(); exit(0); case OPT_LONG_FEDR: params.federation_flag = true; break; case OPT_LONG_HIDE: params.all_flag = false; break; case OPT_LONG_LOCAL: params.local_flag = true; break; case OPT_LONG_ME: xfree(params.users); xstrfmtcat(params.users, "%u", geteuid()); params.user_list = _build_user_list(params.users); break; case OPT_LONG_SIBLING: params.sibling_flag = true; break; case OPT_LONG_START: params.start_flag = true; override_format_env = true; break; case OPT_LONG_NOCONVERT: params.convert_flags |= CONVERT_NUM_UNIT_NO; break; case OPT_LONG_USAGE: _usage(); exit(0); } } if (params.long_list && params.format) fatal("Options -o(--format) and -l(--long) are mutually exclusive. Please remove one and retry."); if (!override_format_env) { if ((env_val = getenv("SQUEUE_FORMAT"))) params.format = xstrdup(env_val); else if ((env_val = getenv("SQUEUE_FORMAT2"))) params.format_long = xstrdup(env_val); } params.cluster_flags = slurmdb_setup_cluster_flags(); if (optind < argc) { if (params.job_flag) { params.jobs = xstrdup(argv[optind++]); params.job_list = _build_job_list(params.jobs); } else if (params.step_flag) { params.steps = xstrdup(argv[optind++]); params.step_list = _build_step_list(params.steps); } if (optind < argc) { error("Unrecognized option: %s",argv[optind]); _usage(); exit(1); } } if ( params.job_flag && params.step_flag) { if (params.job_list) { verbose("Printing job steps with job filter"); params.job_flag = false; } else { error("Incompatible options --jobs and --steps"); exit(1); } } if ( params.nodes ) { char *name1 = NULL; char *name2 = NULL; hostset_t nodenames = hostset_create(NULL); while ( hostset_count(params.nodes) > 0 ) { name1 = hostset_pop(params.nodes); /* localhost = use current host name */ if ( xstrcasecmp("localhost", name1) == 0 ) { name2 = xmalloc(128); gethostname_short(name2, 128); } else { /* translate NodeHostName to NodeName */ name2 = slurm_conf_get_nodename(name1); /* use NodeName if translation failed */ if ( name2 == NULL ) name2 = xstrdup(name1); } hostset_insert(nodenames, name2); free(name1); xfree(name2); } /* Replace params.nodes with the new one */ hostset_destroy(params.nodes); params.nodes = nodenames; /* Check if all node names specified * with -w are known to the controller. */ if (!_check_node_names(params.nodes)) { exit(1); } } if ( ( params.accounts == NULL ) && ( env_val = getenv("SQUEUE_ACCOUNT") ) ) { params.accounts = xstrdup(env_val); params.account_list = _build_str_list( params.accounts ); } if ( ( params.names == NULL ) && ( env_val = getenv("SQUEUE_NAMES") ) ) { params.names = xstrdup(env_val); params.name_list = _build_str_list( params.names ); } if ( ( params.partitions == NULL ) && ( env_val = getenv("SQUEUE_LICENSES") ) ) { params.licenses = xstrdup(env_val); params.licenses_list = _build_str_list( params.licenses ); } if ( ( params.partitions == NULL ) && ( env_val = getenv("SQUEUE_PARTITION") ) ) { params.partitions = xstrdup(env_val); params.part_list = _build_str_list( params.partitions ); params.all_flag = true; } if ( ( params.qoss == NULL ) && ( env_val = getenv("SQUEUE_QOS") ) ) { params.qoss = xstrdup(env_val); params.qos_list = _build_str_list( params.qoss ); } if ( ( params.states == NULL ) && ( env_val = getenv("SQUEUE_STATES") ) ) { params.states = xstrdup(env_val); params.state_list = _build_state_list( params.states ); } if ( ( params.users == NULL ) && ( env_val = getenv("SQUEUE_USERS") ) ) { params.users = xstrdup(env_val); params.user_list = _build_user_list( params.users ); } if ( params.start_flag && !params.step_flag ) { /* Set more defaults */ if (params.format == NULL) params.format = xstrdup("%.18i %.9P %.8j %.8u %.2t %.19S %.6D %20Y %R"); if (params.sort == NULL) params.sort = xstrdup("S"); if (params.states == NULL) { params.states = xstrdup("PD"); params.state_list = _build_state_list( params.states ); } } if (params.job_list && (list_count(params.job_list) == 1)) { squeue_job_step_t *job_step_ptr = list_peek(params.job_list); params.job_id = job_step_ptr->step_id.job_id; } if (params.user_list && (list_count(params.user_list) == 1)) { ListIterator iterator; uint32_t *uid_ptr; iterator = list_iterator_create(params.user_list); while ((uid_ptr = list_next(iterator))) { params.user_id = *uid_ptr; break; } list_iterator_destroy(iterator); } if ( params.verbose ) _print_options(); } /* * _parse_state - convert job state name string to numeric value * IN str - state name * OUT states - enum job_states value corresponding to str * RET 0 or error code */ static int _parse_state( char* str, uint32_t* states ) { uint32_t i; char *state_names; if ((i = job_state_num(str)) != NO_VAL) { *states = i; return SLURM_SUCCESS; } error("Invalid job state specified: %s", str); state_names = xstrdup(job_state_string(0)); for (i=1; i= '0') && (token[i] <= '9')) *field_size = (*field_size * 10) + (token[i++] - '0'); field[0] = token[i++]; *suffix = xstrdup(&token[i]); } static void _parse_long_token( char *token, char *sep, int *field_size, bool *right_justify, char **suffix) { char *end_ptr = NULL, *ptr; *suffix = NULL; xassert(token); ptr = strchr(token, ':'); if (ptr) { ptr[0] = '\0'; if (ptr[1] == '.') { *right_justify = true; ptr++; } else { *right_justify = false; } *field_size = strtol(ptr + 1, &end_ptr, 10); if (end_ptr[0] != '\0') *suffix = xstrdup(end_ptr); } else { *right_justify = false; *field_size = 20; } } /* print the parameters specified */ static void _print_options(void) { ListIterator iterator; int i; char *license, *name, *part; uint32_t *user; uint32_t *state_id; squeue_job_step_t *job_step_id; char hostlist[8192]; if (params.nodes) { hostset_ranged_string(params.nodes, sizeof(hostlist)-1, hostlist); } else hostlist[0] = '\0'; printf( "-----------------------------\n" ); printf( "all = %s\n", params.all_flag ? "true" : "false"); printf( "array = %s\n", params.array_flag ? "true" : "false"); printf( "federation = %s\n", params.federation_flag ? "true":"false"); printf( "format = %s\n", params.format ); printf( "iterate = %d\n", params.iterate ); printf( "job_flag = %d\n", params.job_flag ); printf( "jobs = %s\n", params.jobs ); printf( "licenses = %s\n", params.licenses ); printf( "local = %s\n", params.local_flag ? "true" : "false"); printf( "names = %s\n", params.names ); printf( "nodes = %s\n", hostlist ) ; printf( "partitions = %s\n", params.partitions ) ; printf( "priority = %s\n", params.priority_flag ? "true" : "false"); printf( "reservation = %s\n", params.reservation ) ; printf( "sibling = %s\n", params.sibling_flag ? "true" : "false"); printf( "sort = %s\n", params.sort ) ; printf( "start_flag = %d\n", params.start_flag ); printf( "states = %s\n", params.states ) ; printf( "step_flag = %d\n", params.step_flag ); printf( "steps = %s\n", params.steps ); printf( "users = %s\n", params.users ); printf( "verbose = %d\n", params.verbose ); if ((params.verbose > 1) && params.job_list) { i = 0; iterator = list_iterator_create( params.job_list ); while ( (job_step_id = list_next( iterator )) ) { if (job_step_id->array_id == NO_VAL) { printf( "job_list[%d] = %u\n", i++, job_step_id->step_id.job_id ); } else { printf( "job_list[%d] = %u_%u\n", i++, job_step_id->step_id.job_id, job_step_id->array_id ); } } list_iterator_destroy( iterator ); } if ((params.verbose > 1) && params.name_list) { i = 0; iterator = list_iterator_create( params.name_list ); while ( (name = list_next( iterator )) ) { printf( "name_list[%d] = %u\n", i++, *name); } list_iterator_destroy( iterator ); } if ((params.verbose > 1) && params.licenses_list) { i = 0; iterator = list_iterator_create( params.licenses_list ); while ( (license = list_next( iterator )) ) { printf( "licenses_list[%d] = %s\n", i++, license); } list_iterator_destroy( iterator ); } if ((params.verbose > 1) && params.part_list) { i = 0; iterator = list_iterator_create( params.part_list ); while ( (part = list_next( iterator )) ) { printf( "part_list[%d] = %s\n", i++, part); } list_iterator_destroy( iterator ); } if ((params.verbose > 1) && params.state_list) { i = 0; iterator = list_iterator_create( params.state_list ); while ( (state_id = list_next( iterator )) ) { printf( "state_list[%d] = %s\n", i++, job_state_string( *state_id )); } list_iterator_destroy( iterator ); } if ((params.verbose > 1) && params.step_list) { char tmp_char[34]; i = 0; iterator = list_iterator_create( params.step_list ); while ( (job_step_id = list_next( iterator )) ) { if (job_step_id->array_id == NO_VAL) { log_build_step_id_str(&job_step_id->step_id, tmp_char, sizeof(tmp_char), STEP_ID_FLAG_NO_PREFIX); printf( "step_list[%d] = %s\n", i++, tmp_char); } else { log_build_step_id_str(&job_step_id->step_id, tmp_char, sizeof(tmp_char), (STEP_ID_FLAG_NO_PREFIX | STEP_ID_FLAG_NO_JOB)); printf( "step_list[%d] = %u_%u.%s\n", i++, job_step_id->step_id.job_id, job_step_id->array_id, tmp_char); } } list_iterator_destroy( iterator ); } if ((params.verbose > 1) && params.user_list) { i = 0; iterator = list_iterator_create( params.user_list ); while ( (user = list_next( iterator )) ) { printf( "user_list[%d] = %u\n", i++, *user); } list_iterator_destroy( iterator ); } printf( "-----------------------------\n\n\n" ); } ; /* * _build_job_list- build a list of job_ids * IN str - comma separated list of job_ids * RET List of job_ids (uint32_t) */ static List _build_job_list( char* str ) { List my_list; char *end_ptr = NULL, *job = NULL, *tmp_char = NULL; char *my_job_list = NULL; int job_id, array_id; squeue_job_step_t *job_step_id; if ( str == NULL ) return NULL; my_list = list_create( NULL ); my_job_list = xstrdup( str ); job = strtok_r( my_job_list, ",", &tmp_char ); while (job) { job_id = strtol( job, &end_ptr, 10 ); if (end_ptr[0] == '_') array_id = strtol( end_ptr + 1, &end_ptr, 10 ); else array_id = NO_VAL; if (job_id <= 0) { error( "Invalid job id: %s", job ); exit( 1 ); } job_step_id = xmalloc( sizeof( squeue_job_step_t ) ); job_step_id->step_id.job_id = job_id; job_step_id->array_id = array_id; list_append( my_list, job_step_id ); job = strtok_r (NULL, ",", &tmp_char); } xfree(my_job_list); return my_list; } /* * _build_str_list - convert a string of comma-separated elements * into a list of strings * IN str - comma separated list of strings * RET List of strings */ static List _build_str_list(char* str) { List my_list; char *elem, *tok = NULL, *tmp_char = NULL, *my_str = NULL; if (str == NULL) return NULL; my_list = list_create(NULL); my_str = xstrdup(str); tok = strtok_r(my_str, ",", &tmp_char); while (tok) { elem = xstrdup(tok); list_append(my_list, elem); tok = strtok_r(NULL, ",", &tmp_char); } xfree(my_str); return my_list; } /* * _build_state_list - build a list of job states * IN str - comma separated list of job states * RET List of enum job_states values */ static List _build_state_list( char* str ) { List my_list; char *state = NULL, *tmp_char = NULL, *my_state_list = NULL; uint32_t *state_id = NULL; if (str == NULL) return NULL; if (xstrcasecmp( str, "all") == 0) return _build_all_states_list (); my_list = list_create(NULL); my_state_list = xstrdup(str); state = strtok_r( my_state_list, ",", &tmp_char ); while (state) { state_id = xmalloc(sizeof(uint32_t)); if (_parse_state(state, state_id) != SLURM_SUCCESS) exit(1); list_append(my_list, state_id); state = strtok_r(NULL, ",", &tmp_char); } xfree(my_state_list); return my_list; } static void _append_state_list(List my_list, uint32_t state_id) { uint32_t *state_rec; state_rec = xmalloc(sizeof(uint32_t)); *state_rec = state_id; list_append(my_list, state_rec); } /* * _build_all_states_list - build a list containing all possible job states * RET List of uint16_t values */ static List _build_all_states_list( void ) { List my_list; uint32_t i; my_list = list_create( NULL ); for (i = 0; i < JOB_END; i++) _append_state_list(my_list, i); _append_state_list(my_list, JOB_COMPLETING); _append_state_list(my_list, JOB_CONFIGURING); _append_state_list(my_list, JOB_REVOKED); _append_state_list(my_list, JOB_SPECIAL_EXIT); return my_list; } /* * _build_step_list- build a list of job/step_ids * IN str - comma separated list of job_id[array_id].step_id values * RET List of job/step_ids (structure of uint32_t's) */ static List _build_step_list( char* str ) { List my_list; char *end_ptr = NULL, *step = NULL, *tmp_char = NULL, *tmps_char = NULL; char *job_name = NULL, *step_name = NULL, *my_step_list = NULL; int job_id, array_id, step_id; squeue_job_step_t *job_step_id = NULL; if (str == NULL) return NULL; my_list = list_create(NULL); my_step_list = xstrdup(str); step = strtok_r(my_step_list, ",", &tmp_char); while (step) { job_name = strtok_r(step, ".", &tmps_char); if (job_name == NULL) break; step_name = strtok_r(NULL, ".", &tmps_char); job_id = strtol(job_name, &end_ptr, 10); if (end_ptr[0] == '_') array_id = strtol(end_ptr + 1, &end_ptr, 10); else array_id = NO_VAL; if (step_name == NULL) { error("Invalid job_step id: %s.??", job_name); exit(1); } step_id = strtol( step_name, &end_ptr, 10 ); if ((job_id <= 0) || (step_id < 0)) { error("Invalid job_step id: %s.%s", job_name, step_name); exit(1); } job_step_id = xmalloc(sizeof(squeue_job_step_t)); job_step_id->step_id.job_id = job_id; job_step_id->array_id = array_id; job_step_id->step_id.step_id = step_id; list_append(my_list, job_step_id); step = strtok_r(NULL, ",", &tmp_char); } xfree(my_step_list); return my_list; } /* * _build_user_list- build a list of UIDs * IN str - comma separated list of user names * RET List of UIDs (uint32_t) */ static List _build_user_list( char* str ) { List my_list; char *user = NULL; char *tmp_char = NULL, *my_user_list = NULL; if (str == NULL) return NULL; my_list = list_create(NULL); my_user_list = xstrdup(str); user = strtok_r(my_user_list, ",", &tmp_char); while (user) { uid_t some_uid; if (uid_from_string(user, &some_uid) == 0) { uint32_t *user_id = NULL; user_id = xmalloc(sizeof(uint32_t)); *user_id = (uint32_t) some_uid; list_append(my_list, user_id); } else { error("Invalid user: %s\n", user); } user = strtok_r(NULL, ",", &tmp_char); } xfree(my_user_list); return my_list; } static void _usage(void) { printf("\ Usage: squeue [-A account] [--clusters names] [-i seconds] [--job jobid]\n\ [-n name] [-o format] [-p partitions] [--qos qos]\n\ [--reservation reservation] [--sort fields] [--start]\n\ [--step step_id] [-t states] [-u user_name] [--usage]\n\ [-L licenses] [-w nodes] [--federation] [--local] [--sibling]\n\ [-ahjlrsv]\n"); } static void _help(void) { printf("\ Usage: squeue [OPTIONS]\n\ -A, --account=account(s) comma separated list of accounts\n\ to view, default is all accounts\n\ -a, --all display jobs in hidden partitions\n\ --array-unique display one unique pending job array\n\ element per line\n\ --federation Report federated information if a member\n\ of one\n\ -h, --noheader no headers on output\n\ --hide do not display jobs in hidden partitions\n\ -i, --iterate=seconds specify an interation period\n\ -j, --job=job(s) comma separated list of jobs IDs\n\ to view, default is all\n\ --local Report information only about jobs on the\n\ local cluster. Overrides --federation.\n\ -l, --long long report\n\ -L, --licenses=(license names) comma separated list of license names to view\n\ -M, --clusters=cluster_name cluster to issue commands to. Default is\n\ current cluster. cluster with no name will\n\ reset to default. Implies --local.\n\ -n, --name=job_name(s) comma separated list of job names to view\n\ --noconvert don't convert units from their original type\n\ (e.g. 2048M won't be converted to 2G).\n\ -o, --format=format format specification\n\ -O, --Format=format format specification\n\ -p, --partition=partition(s) comma separated list of partitions\n\ to view, default is all partitions\n\ -q, --qos=qos(s) comma separated list of qos's\n\ to view, default is all qos's\n\ -R, --reservation=name reservation to view, default is all\n\ -r, --array display one job array element per line\n\ --sibling Report information about all sibling jobs\n\ on a federated cluster. Implies --federation.\n\ -s, --step=step(s) comma separated list of job steps\n\ to view, default is all\n\ -S, --sort=fields comma separated list of fields to sort on\n\ --start print expected start times of pending jobs\n\ -t, --states=states comma separated list of states to view,\n\ default is pending and running,\n\ '--states=all' reports all states\n\ -u, --user=user_name(s) comma separated list of users to view\n\ --name=job_name(s) comma separated list of job names to view\n\ -v, --verbose verbosity level\n\ -V, --version output version information and exit\n\ -w, --nodelist=hostlist list of nodes to view, default is \n\ all nodes\n\ \nHelp options:\n\ --help show this help message\n\ --usage display a brief summary of squeue options\n"); } /* _check_node_names() */ static bool _check_node_names(hostset_t names) { int cc; node_info_msg_t *node_info; char *host; hostlist_iterator_t itr; if (names == NULL) return true; cc = slurm_load_node(0, &node_info, SHOW_ALL); if (cc != 0) { slurm_perror ("slurm_load_node error"); return false; } itr = hostset_iterator_create(names); while ((host = hostlist_next(itr))) { if (!_find_a_host(host, node_info)) { error("Invalid node name %s", host); free(host); hostlist_iterator_destroy(itr); return false; } free(host); } hostlist_iterator_destroy(itr); return true; } /* _find_a_host() */ static bool _find_a_host(char *host, node_info_msg_t *node) { int cc; for (cc = 0; cc < node->record_count; cc++) { /* This can happen if the host is removed * fron DNS but still in slurm.conf */ if (node->node_array[cc].name == NULL) continue; if (xstrcmp(host, node->node_array[cc].name) == 0) return true; } return false; }