/* * _parse_commandline - parse and process any command line arguments * IN argc - number of command line arguments * IN argv - the command line arguments * IN/OUT conf_ptr - pointer to current configuration, update as needed */ static void _parse_commandline(int argc, char *argv[]) { int c = 0; char *tmp_char; opterr = 0; while ((c = getopt(argc, argv, "Dhn:vV")) != -1) switch (c) { case 'D': foreground = 1; break; case 'h': _usage(argv[0]); exit(0); break; case 'n': new_nice = strtol(optarg, &tmp_char, 10); if (tmp_char[0] != '\0') { error("Invalid option for -n option (nice " "value), ignored"); new_nice = 0; } break; case 'v': debug_level++; break; case 'V': print_slurm_version(); exit(0); break; default: _usage(argv[0]); exit(1); } }
/* * parse_command_line, fill in params data structure with data */ void parse_command_line(int argc, char *argv[]) { int opt_char; int option_index; static struct option long_options[] = { {"all", no_argument, 0, 'a'}, {"bgblock", required_argument, 0, 'b'}, {"partition", required_argument, 0, 'p'}, {"remove", no_argument, 0, 'r'}, {"wait", no_argument, 0, 'w'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {"usage", no_argument, 0, 'u'}, {NULL, 0, 0, 0} }; while ((opt_char = getopt_long(argc, argv, "ab:hp:ruVw", long_options, &option_index)) != -1) { switch (opt_char) { case (int) '?': fprintf(stderr, "Try \"sfree --help\" for more information\n"); exit(1); break; case (int) 'a': all_blocks = 1; break; case (int) 'b': case (int) 'p': if (!block_list) block_list = list_create(slurm_destroy_char); slurm_addto_char_list(block_list, optarg); break; case (int) 'h': case (int) OPT_LONG_HELP: _help(); exit(0); case (int) 'r': remove_blocks = 1; break; case (int) 'u': case (int) OPT_LONG_USAGE: _usage(); exit(0); case (int) 'V': print_slurm_version(); exit(0); case (int) 'w': wait_full = true; break; } } }
static void _print_version(void) { print_slurm_version(); if (quiet_flag == -1) { long version = slurm_api_version(); printf("slurm_api_version: %ld, %ld.%ld.%ld\n", version, SLURM_VERSION_MAJOR(version), SLURM_VERSION_MINOR(version), SLURM_VERSION_MICRO(version)); } }
/* * parse_command_line, fill in params data structure with data */ extern void parse_command_line(int argc, char *argv[]) { int opt_char; int option_index; static struct option long_options[] = { {"all", no_argument, 0, 'a'}, {"help", no_argument, 0, 'h'}, {"reset", no_argument, 0, 'r'}, {"sort-by-id", no_argument, 0, 'i'}, {"sort-by-time",no_argument, 0, 't'}, {"sort-by-time2",no_argument, 0, 'T'}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"version", no_argument, 0, 'V'}, {NULL, 0, 0, 0} }; while ((opt_char = getopt_long(argc, argv, "ahirtTV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'a': sdiag_param = STAT_COMMAND_GET; break; case (int)'h': _help(); exit(0); break; case (int)'i': sort_by_id = true; break; case (int)'r': sdiag_param = STAT_COMMAND_RESET; break; case (int)'t': sort_by_time = true; break; case (int)'T': sort_by_time2 = true; break; case (int) 'V': print_slurm_version(); exit(0); break; case (int)OPT_LONG_USAGE: _usage(); exit(0); break; } } }
/* * _parse_commandline - parse and process any command line arguments * IN argc - number of command line arguments * IN argv - the command line arguments * IN/OUT conf_ptr - pointer to current configuration, update as needed */ static void _parse_commandline(int argc, char **argv) { int c = 0; char *tmp_char; opterr = 0; while ((c = getopt(argc, argv, "Dhn:R::vV")) != -1) switch (c) { case 'D': foreground = 1; break; case 'h': _usage(argv[0]); exit(0); break; case 'n': if (!optarg) /* CLANG fix */ break; new_nice = strtol(optarg, &tmp_char, 10); if (tmp_char[0] != '\0') { error("Invalid option for -n option (nice " "value), ignored"); new_nice = 0; } break; case 'R': reset_lft_rgt = 1; if (optarg) { lft_rgt_list = list_create(slurm_destroy_char); slurm_addto_char_list(lft_rgt_list, optarg); } break; case 'v': debug_level++; break; case 'V': print_slurm_version(); exit(0); break; default: _usage(argv[0]); exit(1); } }
void set_options(const int argc, char **argv) { int opt_char, option_index = 0; static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"label", no_argument, 0, 'l'}, {"quiet", no_argument, 0, 'Q'}, {"usage", no_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"layout", no_argument, 0, LONG_OPT_LAYOUT_ONLY}, {"debugger-test",no_argument, 0, LONG_OPT_DEBUGGER_TEST}, {"input-filter", required_argument,0, LONG_OPT_IN_FILTER}, {"output-filter",required_argument,0, LONG_OPT_OUT_FILTER}, {"error-filter", required_argument,0, LONG_OPT_ERR_FILTER}, {"pty", no_argument, 0, LONG_OPT_PTY}, {NULL} }; char *opt_string = "+hlQuvV"; opt.progname = xbasename(argv[0]); optind = 0; while((opt_char = getopt_long(argc, argv, opt_string, long_options, &option_index)) != -1) { switch (opt_char) { case '?': fprintf(stderr, "Try \"sattach --help\" for more " "information\n"); exit(error_exit); break; case 'h': _help(); exit(0); case 'l': opt.labelio = true; break; case 'Q': opt.quiet++; break; case 'u': _usage(); exit(0); case 'v': opt.verbose++; break; case 'V': print_slurm_version(); exit(0); break; case LONG_OPT_IN_FILTER: if (xstrcmp(optarg, "-") != 0) { opt.input_filter = (uint32_t) _get_pos_int(optarg, "input-filter"); } opt.input_filter_set = true; break; case LONG_OPT_OUT_FILTER: if (xstrcmp(optarg, "-") != 0) { opt.output_filter = (uint32_t) _get_pos_int(optarg, "output-filter"); } opt.output_filter_set = true; break; case LONG_OPT_ERR_FILTER: if (xstrcmp(optarg, "-") != 0) { opt.error_filter = (uint32_t) _get_pos_int(optarg, "error-filter"); } opt.error_filter_set = true; break; case LONG_OPT_LAYOUT_ONLY: opt.layout_only = true; break; case LONG_OPT_DEBUGGER_TEST: opt.debugger_test = true; break; case LONG_OPT_PTY: #ifdef HAVE_PTY_H opt.pty = true; #else error("--pty not currently supported on this system " "type"); #endif break; default: error("Unrecognized command line parameter %c", opt_char); exit(error_exit); } } }
/* * 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'}, {"format", required_argument, 0, 'o'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"hide", no_argument, 0, OPT_LONG_HIDE}, {"iterate", required_argument, 0, 'i'}, {"jobs", optional_argument, 0, 'j'}, {"long", no_argument, 0, 'l'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"node", required_argument, 0, 'n'}, {"nodes", required_argument, 0, 'n'}, {"noheader", no_argument, 0, 'h'}, {"partitions", required_argument, 0, 'p'}, {"qos", required_argument, 0, 'q'}, {"reservation",required_argument, 0, 'R'}, {"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} }; if (getenv("SQUEUE_ALL")) params.all_flag = true; if ( ( env_val = getenv("SQUEUE_SORT") ) ) params.sort = xstrdup(env_val); if ( ( env_val = getenv("SLURM_CLUSTERS") ) ) { if (!(params.clusters = slurmdb_get_info_cluster(env_val))) { error("'%s' can't be reached now, " "or it is an invalid entry for " "SLURM_CLUSTERS. Use 'sacctmgr --list " "cluster' to see avaliable clusters.", env_val); exit(1); } working_cluster_rec = list_peek(params.clusters); } while ((opt_char = getopt_long(argc, argv, "A:ahi:j::ln:M:o:p:q:R:s::S:t:u:U:vV", 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) 'M': if (params.clusters) list_destroy(params.clusters); if (!(params.clusters = slurmdb_get_info_cluster(optarg))) { error("'%s' can't be reached now, " "or it is an invalid entry for " "--cluster. Use 'sacctmgr --list " "cluster' to see avaliable clusters.", optarg); exit(1); } working_cluster_rec = list_peek(params.clusters); break; case (int) 'n': if (params.nodes) hostset_destroy(params.nodes); params.nodes = hostset_create(optarg); if (params.nodes == NULL) { error("'%s' invalid entry for --nodes", optarg); exit(1); } break; case (int) 'o': xfree(params.format); params.format = xstrdup(optarg); 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) '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) '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 OPT_LONG_HELP: _help(); exit(0); case OPT_LONG_HIDE: params.all_flag = false; break; case OPT_LONG_START: params.start_flag = true; break; case OPT_LONG_USAGE: _usage(); exit(0); } } if ( override_format_env == false ) { if ( ( env_val = getenv("SQUEUE_FORMAT") ) ) params.format = 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); if (nodenames == NULL) fatal("malloc failure"); while ( hostset_count(params.nodes) > 0 ) { name1 = hostset_pop(params.nodes); /* localhost = use current host name */ if ( strcasecmp("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.nodename with the new one */ hostset_destroy(params.nodes); params.nodes = nodenames; } if ( ( params.accounts == NULL ) && ( env_val = getenv("SQUEUE_ACCOUNT") ) ) { params.accounts = xstrdup(env_val); params.account_list = _build_str_list( params.accounts ); } 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("%.7i %.9P %.8j %.8u %.2t %.19S %.6D %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 ); } } params.max_cpus = _max_cpus_per_node(); if ( params.verbose ) _print_options(); }
/* * parse_command_line, fill in params data structure with data */ extern void parse_command_line(int argc, char *argv[]) { int first = 1; int opt_char; int option_index; uid_t some_uid; long tmp_l; static struct option long_options[] = { {"primary_slurmctld_failure", no_argument, 0, 'a'}, {"primary_slurmctld_resumed_operation", no_argument, 0, 'A'}, {"primary_slurmctld_resumed_control", no_argument, 0, 'b'}, {"backup_slurmctld_failure", no_argument, 0, 'B'}, {"backup_slurmctld_resumed_operation", no_argument, 0, 'c'}, {"backup_slurmctld_assumed_control", no_argument, 0, 'C'}, {"down", no_argument, 0, 'd'}, {"drained", no_argument, 0, 'D'}, {"primary_slurmctld_acct_buffer_full", no_argument, 0, 'e'}, {"fini", no_argument, 0, 'f'}, {"fail", no_argument, 0, 'F'}, {"primary_slurmdbd_failure", no_argument, 0, 'g'}, {"primary_slurmdbd_resumed_operation", no_argument, 0, 'G'}, {"primary_database_failure", no_argument, 0, 'h'}, {"primary_database_resumed_operation", no_argument, 0, 'H'}, {"id", required_argument, 0, 'i'}, {"idle", no_argument, 0, 'I'}, {"jobid", required_argument, 0, 'j'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"node", optional_argument, 0, 'n'}, {"offset", required_argument, 0, 'o'}, {"program", required_argument, 0, 'p'}, {"quiet", no_argument, 0, 'Q'}, {"reconfig", no_argument, 0, 'r'}, {"time", no_argument, 0, 't'}, {"up", no_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"block_err", no_argument, 0, OPT_LONG_BLOCK_ERR}, {"clear", no_argument, 0, OPT_LONG_CLEAR}, {"flags", required_argument, 0, OPT_LONG_FLAGS}, {"front_end", no_argument, 0, OPT_LONG_FRONT_END}, {"get", no_argument, 0, OPT_LONG_GET}, {"help", no_argument, 0, OPT_LONG_HELP}, {"set", no_argument, 0, OPT_LONG_SET}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"user", required_argument, 0, OPT_LONG_USER}, {NULL, 0, 0, 0} }; _init_options(); optind = 0; while ((opt_char = getopt_long(argc, argv, "aAbBcCdDeFfgGhHi:Ij:M:n::o:p:QrtuvV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': if (first) { first = 0; fprintf(stderr, "Try \"strigger --help\" for " "more information\n"); } exit(1); break; case (int)'a': params.pri_ctld_fail = true; break; case (int)'A': params.pri_ctld_res_op = true; break; case (int)'b': params.pri_ctld_res_ctrl = true; break; case (int)'B': params.bu_ctld_fail = true; break; case (int)'c': params.bu_ctld_res_op = true; break; case (int)'C': params.bu_ctld_as_ctrl = true; break; case (int)'d': params.node_down = true; break; case (int)'D': params.node_drained = true; break; case (int)'e': params.pri_ctld_acct_buffer_full = true; break; case (int)'f': params.job_fini = true; break; case (int)'F': params.node_fail = true; break; case (int)'g': params.pri_dbd_fail = true; break; case (int)'G': params.pri_dbd_res_op = true; break; case (int)'h': params.pri_db_fail = true; break; case (int)'H': params.pri_db_res_op = true; break; case (int)'i': params.trigger_id = atoi(optarg); break; case (int)'I': params.node_idle = true; break; case (int)'j': tmp_l = atol(optarg); if (tmp_l <= 0) { error("Invalid jobid %s", optarg); exit(1); } params.job_id = tmp_l; break; case (int) 'M': if (params.clusters) list_destroy(params.clusters); if (!(params.clusters = slurmdb_get_info_cluster(optarg))) { error("'%s' can't be reached now, " "or it is an invalid entry for " "--cluster. Use 'sacctmgr --list " "cluster' to see available clusters.", optarg); exit(1); } working_cluster_rec = list_peek(params.clusters); break; case (int)'n': xfree(params.node_id); if (optarg) params.node_id = xstrdup(optarg); else params.node_id = xstrdup("*"); break; case (int)'o': params.offset = atoi(optarg); break; case (int)'p': xfree(params.program); params.program = xstrdup(optarg); break; case (int)'Q': params.quiet = true; break; case (int)'r': params.reconfig = true; break; case (int)'t': params.time_limit = true; break; case (int)'u': params.node_up = true; break; case (int) 'v': params.verbose++; break; case (int) 'V': print_slurm_version(); exit(0); case (int) OPT_LONG_BLOCK_ERR: params.block_err = true; break; case (int) OPT_LONG_HELP: _help(); exit(0); case (int) OPT_LONG_USAGE: _usage(); exit(0); case (int) OPT_LONG_CLEAR: params.mode_clear = true; break; case (int) OPT_LONG_FLAGS: if (!strncasecmp(optarg, "perm", 4)) params.flags = TRIGGER_FLAG_PERM; else { error("Invalid flags %s", optarg); exit(1); } break; case (int) OPT_LONG_FRONT_END: params.front_end = true; break; case (int) OPT_LONG_GET: params.mode_get = true; break; case (int) OPT_LONG_SET: params.mode_set = true; break; case (int) OPT_LONG_USER: if ( uid_from_string( optarg, &some_uid ) != 0 ) { error("Invalid user %s", optarg); exit(1); } params.user_id = (uint32_t) some_uid; break; } } if (params.verbose) _print_options(); _validate_options(); }
/* * opt_args() : set options via commandline args and getopt_long */ static void _opt_args(int argc, char **argv) { int opt_char; int option_index; static struct option long_options[] = { {"account", required_argument, 0, 'A'}, {"batch", no_argument, 0, 'b'}, {"ctld", no_argument, 0, OPT_LONG_CTLD}, {"help", no_argument, 0, OPT_LONG_HELP}, {"interactive", no_argument, 0, 'i'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"name", required_argument, 0, 'n'}, {"nodelist", required_argument, 0, 'w'}, {"partition", required_argument, 0, 'p'}, {"qos", required_argument, 0, 'q'}, {"quiet", no_argument, 0, 'Q'}, {"reservation", required_argument, 0, 'R'}, {"signal", required_argument, 0, 's'}, {"state", required_argument, 0, 't'}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"user", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"wckey", required_argument, 0, OPT_LONG_WCKEY}, {NULL, 0, 0, 0} }; while ((opt_char = getopt_long(argc, argv, "A:biM:n:p:Qq:R:s:t:u:vVw:", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"scancel --help\" for more " "information\n"); exit(1); break; case (int)'A': opt.account = xstrtolower(xstrdup(optarg)); break; case (int)'b': opt.batch = true; break; case OPT_LONG_CTLD: opt.ctld = true; break; case (int)'i': opt.interactive = true; break; case (int)'M': opt.ctld = true; FREE_NULL_LIST(opt.clusters); opt.clusters = slurmdb_get_info_cluster(optarg); if (!opt.clusters) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(opt.clusters); break; case (int)'n': opt.job_name = xstrdup(optarg); break; case (int)'p': opt.partition = xstrdup(optarg); break; case (int)'Q': opt.verbose = -1; break; case (int)'q': opt.qos = xstrtolower(xstrdup(optarg)); break; case (int)'R': opt.reservation = xstrdup(optarg); break; case (int)'s': opt.signal = _xlate_signal_name(optarg); break; case (int)'t': opt.state = _xlate_state_name(optarg, false); break; case (int)'u': opt.user_name = xstrdup(optarg); break; case (int)'v': opt.verbose++; break; case (int)'V': print_slurm_version (); exit(0); case (int)'w': opt.nodelist = xstrdup(optarg); break; case OPT_LONG_WCKEY: opt.wckey = xstrdup(optarg); break; case OPT_LONG_HELP: _help(); exit(0); case OPT_LONG_USAGE: _usage(); exit(0); } } if (optind < argc) { char **rest = argv + optind; opt.job_list = rest; _xlate_job_step_ids(rest); } if (!_opt_verify()) exit(1); }
/* * parse_command_line, fill in params data structure with data */ extern void parse_command_line(int argc, char *argv[]) { char *env_val = NULL; int opt_char; int option_index; hostlist_t host_list; static struct option long_options[] = { {"all", no_argument, 0, 'a'}, {"bg", no_argument, 0, 'b'}, {"dead", no_argument, 0, 'd'}, {"exact", no_argument, 0, 'e'}, {"noheader", no_argument, 0, 'h'}, {"iterate", required_argument, 0, 'i'}, {"long", no_argument, 0, 'l'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"nodes", required_argument, 0, 'n'}, {"Node", no_argument, 0, 'N'}, {"format", required_argument, 0, 'o'}, {"partition", required_argument, 0, 'p'}, {"responding",no_argument, 0, 'r'}, {"list-reasons", no_argument, 0, 'R'}, {"summarize", no_argument, 0, 's'}, {"sort", required_argument, 0, 'S'}, {"states", required_argument, 0, 't'}, {"reservation",no_argument, 0, 'T'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"hide", no_argument, 0, OPT_LONG_HIDE}, {NULL, 0, 0, 0} }; if (getenv("SINFO_ALL")) params.all_flag = true; if ( ( env_val = getenv("SINFO_PARTITION") ) ) { params.partition = xstrdup(env_val); params.all_flag = true; } if ( ( env_val = getenv("SINFO_SORT") ) ) params.sort = xstrdup(env_val); if ( ( env_val = getenv("SLURM_CLUSTERS") ) ) { if (!(params.clusters = slurmdb_get_info_cluster(env_val))) { error("'%s' can't be reached now, " "or it is an invalid entry for " "SLURM_CLUSTERS. Use 'sacctmgr --list " "cluster' to see available clusters.", env_val); exit(1); } working_cluster_rec = list_peek(params.clusters); } while((opt_char = getopt_long(argc, argv, "abdehi:lM:n:No:p:rRsS:t:TvV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sinfo --help\" for more information\n"); exit(1); break; case (int)'a': params.all_flag = true; break; case (int)'b': params.cluster_flags = slurmdb_setup_cluster_flags(); if (params.cluster_flags & CLUSTER_FLAG_BG) params.bg_flag = true; else { error("Must be on a BG system to use --bg " "option, if using --cluster option " "put the --bg option " "after the --cluster option."); exit(1); } break; case (int)'d': params.dead_nodes = true; break; case (int)'e': params.exact_match = true; break; case (int)'h': params.no_header = true; break; case (int) 'i': params.iterate= atoi(optarg); if (params.iterate <= 0) { error ("Error: invalid entry for " "--iterate=%s", optarg); exit(1); } break; case (int) 'l': params.long_output = true; break; case (int) 'M': if (params.clusters) list_destroy(params.clusters); if (!(params.clusters = slurmdb_get_info_cluster(optarg))) { error("'%s' can't be reached now, " "or it is an invalid entry for " "--cluster. Use 'sacctmgr --list " "cluster' to see available clusters.", optarg); exit(1); } working_cluster_rec = list_peek(params.clusters); break; case (int) 'n': xfree(params.nodes); params.nodes = xstrdup(optarg); /* * confirm valid nodelist entry */ host_list = hostlist_create(params.nodes); if (!host_list) { error("'%s' invalid entry for --nodes", optarg); exit(1); } if (hostlist_count(host_list) == 1) params.node_name_single = true; else params.node_name_single = false; hostlist_destroy(host_list); break; case (int) 'N': params.node_flag = true; break; case (int) 'o': xfree(params.format); params.format = xstrdup(optarg); break; case (int) 'p': xfree(params.partition); params.partition = xstrdup(optarg); params.all_flag = true; break; case (int) 'r': params.responding_nodes = true; break; case (int) 'R': params.list_reasons = true; break; case (int) 's': params.summarize = true; break; case (int) 'S': xfree(params.sort); params.sort = xstrdup(optarg); break; case (int) 't': xfree(params.states); params.states = xstrdup(optarg); if (!(params.state_list = _build_state_list(optarg))) { error ("valid states: %s", _node_state_list ()); exit (1); } break; case (int) 'T': params.reservation_flag = true; break; case (int) 'v': params.verbose++; break; case (int) 'V': print_slurm_version (); exit(0); case (int) OPT_LONG_HELP: _help(); exit(0); case (int) OPT_LONG_USAGE: _usage(); exit(0); case OPT_LONG_HIDE: params.all_flag = false; break; } } params.cluster_flags = slurmdb_setup_cluster_flags(); if ( params.format == NULL ) { if ( params.summarize ) { params.part_field_flag = true; /* compute size later */ if (params.cluster_flags & CLUSTER_FLAG_BG) params.format = "%9P %.5a %.10l %.32F %N"; else params.format = "%9P %.5a %.10l %.16F %N"; } else if ( params.node_flag ) { params.node_field_flag = true; /* compute size later */ params.part_field_flag = true; /* compute size later */ params.format = params.long_output ? "%N %.6D %.9P %.11T %.4c %.8z %.6m %.8d %.6w %.8f %20E" : "%N %.6D %.9P %6t"; } else if (params.list_reasons) { params.format = params.long_output ? "%20E %12U %19H %6t %N" : "%20E %9u %19H %N"; } else if ((env_val = getenv ("SINFO_FORMAT"))) { params.format = xstrdup(env_val); } else { params.part_field_flag = true; /* compute size later */ params.format = params.long_output ? "%9P %.5a %.10l %.10s %.4r %.5h %.10g %.6D %.11T %N" : "%9P %.5a %.10l %.6D %.6t %N"; } } _parse_format( params.format ); if (params.list_reasons && (params.state_list == NULL)) { params.states = xstrdup ("down,drain,error"); if (!(params.state_list = _build_state_list (params.states))) fatal ("Unable to build state list for -R!"); } if (params.dead_nodes || params.nodes || params.partition || params.responding_nodes ||params.state_list) params.filtering = true; if (params.verbose) _print_options(); }
/* * parse_command_line, fill in params data structure with data */ extern void parse_command_line(int argc, char **argv) { char *env_val = NULL; int opt_char; int option_index; hostlist_t host_list; bool long_form = false; bool opt_a_set = false, opt_p_set = false; bool env_a_set = false, env_p_set = false; static struct option long_options[] = { {"all", no_argument, 0, 'a'}, {"bg", no_argument, 0, 'b'}, {"dead", no_argument, 0, 'd'}, {"exact", no_argument, 0, 'e'}, {"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'}, {"local", no_argument, 0, OPT_LONG_LOCAL}, {"long", no_argument, 0, 'l'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"nodes", required_argument, 0, 'n'}, {"noconvert", no_argument, 0, OPT_LONG_NOCONVERT}, {"noheader", no_argument, 0, 'h'}, {"Node", no_argument, 0, 'N'}, {"format", required_argument, 0, 'o'}, {"Format", required_argument, 0, 'O'}, {"partition", required_argument, 0, 'p'}, {"responding",no_argument, 0, 'r'}, {"list-reasons", no_argument, 0, 'R'}, {"summarize", no_argument, 0, 's'}, {"sort", required_argument, 0, 'S'}, {"states", required_argument, 0, 't'}, {"reservation",no_argument, 0, 'T'}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {NULL, 0, 0, 0} }; params.convert_flags = CONVERT_NUM_UNIT_EXACT; if (slurmctld_conf.fed_params && strstr(slurmctld_conf.fed_params, "fed_display")) params.federation_flag = true; if (getenv("SINFO_ALL")) { env_a_set = true; params.all_flag = true; } if (getenv("SINFO_FEDERATION")) params.federation_flag = true; if (getenv("SINFO_LOCAL")) params.local = true; if ( ( env_val = getenv("SINFO_PARTITION") ) ) { env_p_set = true; params.partition = xstrdup(env_val); params.part_list = _build_part_list(env_val); params.all_flag = true; } if (env_a_set && env_p_set) { error("Conflicting options, SINFO_ALL and SINFO_PARTITION, specified. " "Please choose one or the other."); exit(1); } if ( ( env_val = getenv("SINFO_SORT") ) ) params.sort = xstrdup(env_val); 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 = true; } while ((opt_char = getopt_long(argc, argv, "abdehi:lM:n:No:O:p:rRsS:t:TvV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sinfo --help\" for more information\n"); exit(1); break; case (int)'a': opt_a_set = true; xfree(params.partition); FREE_NULL_LIST(params.part_list); params.all_flag = true; break; case (int)'b': params.cluster_flags = slurmdb_setup_cluster_flags(); if (params.cluster_flags & CLUSTER_FLAG_BG) params.bg_flag = true; else { error("Must be on a BG system to use --bg " "option, if using --cluster option " "put the --bg option " "after the --cluster option."); exit(1); } break; case (int)'d': params.dead_nodes = true; break; case (int)'e': params.exact_match = true; break; case (int)'h': params.no_header = true; break; case (int) 'i': params.iterate= atoi(optarg); if (params.iterate <= 0) { error ("Error: invalid entry for " "--iterate=%s", optarg); exit(1); } break; case (int) 'l': params.long_output = true; break; case (int) 'M': 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 = true; break; case OPT_LONG_NOCONVERT: params.convert_flags |= CONVERT_NUM_UNIT_NO; break; case (int) 'n': xfree(params.nodes); params.nodes = xstrdup(optarg); /* * confirm valid nodelist entry */ host_list = hostlist_create(params.nodes); if (!host_list) { error("'%s' invalid entry for --nodes", optarg); exit(1); } if (hostlist_count(host_list) == 1) { params.node_name_single = true; xfree(params.nodes); params.nodes = hostlist_deranged_string_xmalloc(host_list); } else params.node_name_single = false; hostlist_destroy(host_list); break; case (int) 'N': params.node_flag = true; break; case (int) 'o': xfree(params.format); params.format = xstrdup(optarg); break; case (int) 'O': long_form = true; xfree(params.format); params.format = xstrdup(optarg); break; case (int) 'p': opt_p_set = true; xfree(params.partition); FREE_NULL_LIST(params.part_list); params.partition = xstrdup(optarg); params.part_list = _build_part_list(optarg); params.all_flag = true; break; case (int) 'r': params.responding_nodes = true; break; case (int) 'R': params.list_reasons = true; break; case (int) 's': params.summarize = true; break; case (int) 'S': xfree(params.sort); params.sort = xstrdup(optarg); break; case (int) 't': xfree(params.states); params.states = xstrdup(optarg); if (!(params.state_list = _build_state_list(optarg))) { error ("valid states: %s", _node_state_list ()); exit (1); } break; case (int) 'T': params.reservation_flag = true; break; case (int) 'v': params.verbose++; break; case (int) 'V': print_slurm_version (); exit(0); case (int) OPT_LONG_FEDR: params.federation_flag = true; break; case (int) OPT_LONG_HELP: _help(); exit(0); case (int) OPT_LONG_USAGE: _usage(); exit(0); case OPT_LONG_HIDE: params.all_flag = false; break; case OPT_LONG_LOCAL: params.local = true; break; } } if (opt_a_set && opt_p_set) { error("Conflicting options, -a and -p, specified. " "Please choose one or the other."); exit(1); } params.cluster_flags = slurmdb_setup_cluster_flags(); if (params.federation_flag && !params.clusters && !params.local) { void *ptr = NULL; char *cluster_name = slurm_get_cluster_name(); if (slurm_load_federation(&ptr) || !cluster_in_federation(ptr, cluster_name)) { /* Not in federation */ params.local = true; slurm_destroy_federation_rec(ptr); } else { params.fed = (slurmdb_federation_rec_t *) ptr; } xfree(cluster_name); } if ( params.format == NULL ) { if ( params.summarize ) { params.part_field_flag = true; /* compute size later */ if (params.cluster_flags & CLUSTER_FLAG_BG) params.format = "%9P %.5a %.10l %.32F %N"; else params.format = "%9P %.5a %.10l %.16F %N"; } else if ( params.node_flag ) { params.node_field_flag = true; /* compute size later */ params.part_field_flag = true; /* compute size later */ params.format = params.long_output ? "%N %.6D %.9P %.11T %.4c %.8z %.6m %.8d %.6w %.8f %20E" : "%N %.6D %.9P %6t"; } else if (params.list_reasons) { params.format = params.long_output ? "%20E %12U %19H %6t %N" : "%20E %9u %19H %N"; } else if ((env_val = getenv ("SINFO_FORMAT"))) { params.format = xstrdup(env_val); } else if (params.fed) { params.part_field_flag = true; /* compute size later */ params.format = params.long_output ? "%9P %8V %.5a %.10l %.10s %.4r %.8h %.10g %.6D %.11T %N" : "%9P %8V %.5a %.10l %.6D %.6t %N"; } else { params.part_field_flag = true; /* compute size later */ params.format = params.long_output ? "%9P %.5a %.10l %.10s %.4r %.8h %.10g %.6D %.11T %N" : "%9P %.5a %.10l %.6D %.6t %N"; } } if (long_form) _parse_long_format(params.format); else _parse_format(params.format); if (params.list_reasons && (params.state_list == NULL)) { params.states = xstrdup ("down,drain,error"); if (!(params.state_list = _build_state_list (params.states))) fatal ("Unable to build state list for -R!"); } if (params.dead_nodes || params.nodes || params.partition || params.responding_nodes ||params.state_list) params.filtering = true; if (params.verbose) _print_options(); }
/* * parse_command_line */ extern void parse_command_line( int argc, char* *argv ) { int opt_char; int option_index; static struct option long_options[] = { {"noheader", no_argument, 0, 'h'}, {"jobs", optional_argument, 0, 'j'}, {"long", no_argument, 0, 'l'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"norm", no_argument, 0, 'n'}, {"format", required_argument, 0, 'o'}, {"user", required_argument, 0, 'u'}, {"users", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"weights", no_argument, 0, 'w'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {NULL, 0, 0, 0} }; /* get defaults from environment */ _opt_env(); while((opt_char = getopt_long(argc, argv, "hj::lM:no:u:vVw", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sprio --help\" " "for more information\n"); exit(1); case (int)'h': params.no_header = true; 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; break; case (int) 'M': FREE_NULL_LIST(params.clusters); if (!(params.clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } break; case (int) 'n': params.normalized = true; break; case (int) 'o': xfree(params.format); params.format = xstrdup(optarg); 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': params.weights = true; break; case OPT_LONG_HELP: _help(); exit(0); case OPT_LONG_USAGE: _usage(); exit(0); } } if (optind < argc) { if (params.job_flag) { params.jobs = xstrdup(argv[optind++]); params.job_list = _build_job_list(params.jobs); } if (optind < argc) { error("Unrecognized option: %s",argv[optind]); _usage(); exit(1); } } if (params.verbose) _print_options(); if (params.clusters) { if (list_count(params.clusters) > 1) { fatal("Only one cluster can be used at a time with " "sprio"); } working_cluster_rec = list_peek(params.clusters); } }
static void _set_options(const int argc, char **argv) { int option_index = 0, c; log_options_t logopt = LOG_OPTS_STDERR_ONLY; char *next_str = NULL; uid_t uid = -1; static struct option long_options[] = { {"extract", no_argument, 0, 'E'}, {"help", no_argument, 0, 'h'}, {"job", required_argument, 0, 'j'}, {"input", required_argument, 0, 'i'}, {"level", required_argument, 0, 'l'}, {"node", required_argument, 0, 'N'}, {"output", required_argument, 0, 'o'}, {"profiledir", required_argument, 0, 'p'}, {"series", required_argument, 0, 's'}, {"savefiles", no_argument, 0, 'S'}, {"usage", 0, ¶ms.help, 3}, {"user", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {0, 0, 0, 0}}; log_init(xbasename(argv[0]), logopt, 0, NULL); _init_opts(); while (1) { /* now cycle through the command line */ c = getopt_long(argc, argv, "Ehi:j:l:N:o:p:s:Su:vV", long_options, &option_index); if (c == -1) break; switch (c) { case 'E': params.mode = SH5UTIL_MODE_EXTRACT; break; case 'h': params.help = 1; break; case 'i': params.input = xstrdup(optarg); break; case 'j': params.job_id = strtol(optarg, &next_str, 10); if (next_str[0] == '.') params.step_id = strtol(next_str+1, NULL, 10); break; case 'l': params.level = xstrdup(optarg); break; case 'N': params.node = xstrdup(optarg); break; case 'o': params.output = xstrdup(optarg); break; case 'p': params.dir = xstrdup(optarg); break; case 's': params.series = xstrdup(optarg); break; case 'S': params.keepfiles = 1; break; case 'u': if (uid_from_string (optarg, &uid) < 0) { error("--uid=\"%s\" invalid", optarg); exit(1); } break; case (int)'v': params.verbose++; break; case (int)'V': print_slurm_version(); exit(0); break; case ':': case '?': /* getopt() has explained it */ exit(1); } } if (params.help) { switch (params.help) { case 1: case 3: _help_msg(); break; default: fprintf(stderr, "bug: --help=%d\n", params.help); } exit(0); } if (params.job_id == -1) fatal("You need to supply a --jobs value."); if (uid == -1) uid = getuid(); params.user = uid_to_string(uid); if (!params.dir) acct_gather_profile_g_get(ACCT_GATHER_PROFILE_DIR, ¶ms.dir); if (!params.dir) fatal("You need to supply a --profiledir or be on a " "node with a valid acct_gather.conf"); if (params.verbose) { logopt.stderr_level += params.verbose; log_alter(logopt, SYSLOG_FACILITY_USER, NULL); } /* FIXME : For now all these only work for extract. Seems * like it would be easy to add the logic to "merge" as well. */ if (params.input || params.level || params.node || (params.step_id != -1) || params.series) params.mode = SH5UTIL_MODE_EXTRACT; if (params.mode == SH5UTIL_MODE_EXTRACT) { if (!params.level) params.level = xstrdup("Node:Totals"); if (!params.input) params.input = xstrdup_printf( "./job_%d.h5", params.job_id); if (!params.output) params.output = xstrdup_printf( "./extract_%d.csv", params.job_id); } if (!params.output) params.output = xstrdup_printf("./job_%d.h5", params.job_id); }
/* * parse_command_line, fill in params data structure with data */ extern void parse_command_line(int argc, char **argv) { char *sbcast_parameters; char *end_ptr = NULL, *env_val = NULL, *sep, *tmp; int opt_char; int option_index; static struct option long_options[] = { {"compress", optional_argument, 0, 'C'}, {"fanout", required_argument, 0, 'F'}, {"force", no_argument, 0, 'f'}, {"jobid", required_argument, 0, 'j'}, {"preserve", no_argument, 0, 'p'}, {"size", required_argument, 0, 's'}, {"timeout", required_argument, 0, 't'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {NULL, 0, 0, 0} }; if ((sbcast_parameters = slurm_get_sbcast_parameters()) && (tmp = strcasestr(sbcast_parameters, "Compression="))) { tmp += 12; sep = strchr(tmp, ','); if (sep) sep[0] = '\0'; params.compress = parse_compress_type(tmp); if (sep) sep[0] = ','; } if ((env_val = getenv("SBCAST_COMPRESS"))) params.compress = parse_compress_type(env_val); if ( ( env_val = getenv("SBCAST_FANOUT") ) ) params.fanout = atoi(env_val); if (getenv("SBCAST_FORCE")) params.force = true; params.job_id = NO_VAL; params.pack_job_offset = NO_VAL; params.step_id = NO_VAL; if (getenv("SBCAST_PRESERVE")) params.preserve = true; if ( ( env_val = getenv("SBCAST_SIZE") ) ) params.block_size = _map_size(env_val); else params.block_size = 8 * 1024 * 1024; if ( ( env_val = getenv("SBCAST_TIMEOUT") ) ) params.timeout = (atoi(env_val) * 1000); optind = 0; while ((opt_char = getopt_long(argc, argv, "CfF:j:ps:t:vV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sbcast --help\" for more information\n"); exit(1); break; case (int)'C': params.compress = parse_compress_type(optarg); break; case (int)'f': params.force = true; break; case (int)'F': params.fanout = atoi(optarg); break; case (int)'j': params.job_id = strtol(optarg, &end_ptr, 10); if (end_ptr[0] == '+') { params.pack_job_offset = strtol(end_ptr+1, &end_ptr, 10); } if (end_ptr[0] == '.') params.step_id = strtol(end_ptr+1, NULL, 10); break; case (int)'p': params.preserve = true; break; case (int) 's': params.block_size = _map_size(optarg); break; case (int)'t': params.timeout = (atoi(optarg) * 1000); break; case (int) 'v': params.verbose++; break; case (int) 'V': print_slurm_version(); exit(0); case (int) OPT_LONG_HELP: _help(); exit(0); case (int) OPT_LONG_USAGE: _usage(); exit(0); } } if ((argc - optind) != 2) { fprintf(stderr, "Need two file names, have %d names\n", (argc - optind)); fprintf(stderr, "Try \"sbcast --help\" for more information\n"); exit(1); } if (params.job_id == NO_VAL) { if (!(env_val = getenv("SLURM_JOB_ID"))) { error("Need a job id to run this command. " "Run from within a Slurm job or use the " "--jobid option."); exit(1); } params.job_id = strtol(env_val, &end_ptr, 10); if (end_ptr[0] == '.') params.step_id = strtol(end_ptr+1, NULL, 10); } params.src_fname = xstrdup(argv[optind]); if (argv[optind+1][0] == '/') { params.dst_fname = xstrdup(argv[optind+1]); } else if (sbcast_parameters && (tmp = strcasestr(sbcast_parameters, "DestDir="))) { tmp += 8; sep = strchr(tmp, ','); if (sep) sep[0] = '\0'; xstrfmtcat(params.dst_fname, "%s/%s", tmp, argv[optind+1]); if (sep) sep[0] = ','; } else { #ifdef HAVE_GET_CURRENT_DIR_NAME tmp = get_current_dir_name(); #else tmp = malloc(PATH_MAX); tmp = getcwd(tmp, PATH_MAX); #endif xstrfmtcat(params.dst_fname, "%s/%s", tmp, argv[optind+1]); free(tmp); } xfree(sbcast_parameters); if (params.verbose) _print_options(); }
static void _process_cmdline(int ac, char **av) { int c; char *tmp_char; conf->prog = xbasename(av[0]); while ((c = getopt(ac, av, GETOPT_ARGS)) > 0) { switch (c) { case 'c': conf->cleanstart = 1; break; case 'C': _print_config(); exit(0); break; case 'd': conf->stepd_loc = xstrdup(optarg); break; case 'D': conf->daemonize = 0; break; case 'f': conf->conffile = xstrdup(optarg); break; case 'h': _usage(); exit(0); break; case 'L': conf->logfile = xstrdup(optarg); break; case 'M': conf->mlock_pages = 1; break; case 'n': conf->nice = strtol(optarg, &tmp_char, 10); if (tmp_char[0] != '\0') { error("Invalid option for -n option (nice " "value), ignored"); conf->nice = 0; } break; case 'N': conf->node_name = xstrdup(optarg); break; case 'v': conf->debug_level++; conf->debug_level_set = 1; break; case 'V': print_slurm_version(); exit(0); break; default: _usage(); exit(1); break; } } /* * If slurmstepd path wasn't overridden by command line, set * it to the default here: */ if (!conf->stepd_loc) conf->stepd_loc = xstrdup_printf("%s/sbin/slurmstepd", SLURM_PREFIX); }
void parse_command_line(int argc, char **argv) { extern int optind; int c, i, optionIndex = 0; char *end = NULL, *start = NULL, *acct_type = NULL; slurmdb_selected_step_t *selected_step = NULL; ListIterator itr = NULL; struct stat stat_buf; char *dot = NULL; bool brief_output = FALSE, long_output = FALSE; bool all_users = 0; bool all_clusters = 0; slurmdb_job_cond_t *job_cond = params.job_cond; log_options_t opts = LOG_OPTS_STDERR_ONLY ; int verbosity; /* count of -v options */ bool set; static struct option long_options[] = { {"allusers", no_argument, 0, 'a'}, {"accounts", required_argument, 0, 'A'}, {"allocations", no_argument, ¶ms.opt_allocs, OPT_LONG_ALLOCS}, {"brief", no_argument, 0, 'b'}, {"completion", no_argument, ¶ms.opt_completion, 'c'}, {"duplicates", no_argument, ¶ms.opt_dup, OPT_LONG_DUP}, {"helpformat", no_argument, 0, 'e'}, {"help-fields", no_argument, 0, 'e'}, {"endtime", required_argument, 0, 'E'}, {"file", required_argument, 0, 'f'}, {"gid", required_argument, 0, 'g'}, {"group", required_argument, 0, 'g'}, {"help", no_argument, 0, 'h'}, {"helpformat", no_argument, ¶ms.opt_help, OPT_LONG_HELP}, {"name", required_argument, 0, OPT_LONG_NAME}, {"nnodes", required_argument, 0, 'i'}, {"ncpus", required_argument, 0, 'I'}, {"jobs", required_argument, 0, 'j'}, {"timelimit-min", required_argument, 0, 'k'}, {"timelimit-max", required_argument, 0, 'K'}, {"long", no_argument, 0, 'l'}, {"allclusters", no_argument, 0, 'L'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"nodelist", required_argument, 0, 'N'}, {"noheader", no_argument, 0, 'n'}, {"fields", required_argument, 0, 'o'}, {"format", required_argument, 0, 'o'}, {"parsable", no_argument, 0, 'p'}, {"parsable2", no_argument, 0, 'P'}, {"qos", required_argument, 0, 'q'}, {"partition", required_argument, 0, 'r'}, {"state", required_argument, 0, 's'}, {"starttime", required_argument, 0, 'S'}, {"truncate", no_argument, 0, 'T'}, {"uid", required_argument, 0, 'u'}, {"usage", no_argument, ¶ms.opt_help, OPT_LONG_USAGE}, {"user", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"wckeys", required_argument, 0, 'W'}, {"associations", required_argument, 0, 'x'}, {0, 0, 0, 0}}; params.opt_uid = getuid(); params.opt_gid = getgid(); verbosity = 0; log_init("sacct", opts, SYSLOG_FACILITY_DAEMON, NULL); opterr = 1; /* Let getopt report problems to the user */ while (1) { /* now cycle through the command line */ c = getopt_long(argc, argv, "aA:bcC:dDeE:f:g:hi:I:j:k:K:lLM:nN:o:OpPq:r:s:S:Ttu:vVW:x:X", long_options, &optionIndex); if (c == -1) break; switch (c) { case 'a': all_users = 1; break; case 'A': if(!job_cond->acct_list) job_cond->acct_list = list_create(slurm_destroy_char); slurm_addto_char_list(job_cond->acct_list, optarg); break; case 'b': brief_output = true; break; case 'c': params.opt_completion = 1; break; case 'C': /* 'C' is deprecated since 'M' is cluster on everything else. */ case 'M': if(!strcasecmp(optarg, "-1")) { all_clusters = 1; break; } all_clusters=0; if(!job_cond->cluster_list) job_cond->cluster_list = list_create(slurm_destroy_char); slurm_addto_char_list(job_cond->cluster_list, optarg); break; case 'D': params.opt_dup = 1; break; case 'e': params.opt_help = 2; break; case 'E': job_cond->usage_end = parse_time(optarg, 1); if (errno == ESLURM_INVALID_TIME_VALUE) exit(1); break; case 'f': xfree(params.opt_filein); params.opt_filein = xstrdup(optarg); break; case 'g': if(!job_cond->groupid_list) job_cond->groupid_list = list_create(slurm_destroy_char); _addto_id_char_list(job_cond->groupid_list, optarg, 1); break; case 'h': params.opt_help = 1; break; case 'i': set = get_resource_arg_range( optarg, "requested node range", (int *)&job_cond->nodes_min, (int *)&job_cond->nodes_max, true); if (set == false) { error("invalid node range -i '%s'", optarg); exit(1); } break; case 'I': set = get_resource_arg_range( optarg, "requested cpu range", (int *)&job_cond->cpus_min, (int *)&job_cond->cpus_max, true); if (set == false) { error("invalid cpu range -i '%s'", optarg); exit(1); } break; case 'j': if ((strspn(optarg, "0123456789, ") < strlen(optarg)) && (strspn(optarg, ".batch0123456789, ") < strlen(optarg))) { fprintf(stderr, "Invalid jobs list: %s\n", optarg); exit(1); } if(!job_cond->step_list) job_cond->step_list = list_create( slurmdb_destroy_selected_step); _addto_step_list(job_cond->step_list, optarg); break; case 'k': job_cond->timelimit_min = time_str2mins(optarg); if (((int32_t)job_cond->timelimit_min <= 0) && (job_cond->timelimit_min != INFINITE)) fatal("Invalid time limit specification"); break; case 'K': job_cond->timelimit_max = time_str2mins(optarg); if (((int32_t)job_cond->timelimit_max <= 0) && (job_cond->timelimit_max != INFINITE)) fatal("Invalid time limit specification"); break; case 'L': all_clusters = 1; break; case 'l': long_output = true; break; case 'n': print_fields_have_header = 0; break; case 'N': if(job_cond->used_nodes) { error("Aleady asked for nodes '%s'", job_cond->used_nodes); break; } job_cond->used_nodes = xstrdup(optarg); break; case OPT_LONG_NAME: if(!job_cond->jobname_list) job_cond->jobname_list = list_create(slurm_destroy_char); slurm_addto_char_list(job_cond->jobname_list, optarg); break; case 'o': xstrfmtcat(params.opt_field_list, "%s,", optarg); break; case 'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case 'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case 'q': if (!g_qos_list) { slurmdb_qos_cond_t qos_cond; memset(&qos_cond, 0, sizeof(slurmdb_qos_cond_t)); qos_cond.with_deleted = 1; g_qos_list = slurmdb_qos_get( acct_db_conn, &qos_cond); } if(!job_cond->qos_list) job_cond->qos_list = list_create(slurm_destroy_char); if(!slurmdb_addto_qos_char_list(job_cond->qos_list, g_qos_list, optarg, 0)) fatal("problem processing qos list"); break; case 'r': if(!job_cond->partition_list) job_cond->partition_list = list_create(slurm_destroy_char); slurm_addto_char_list(job_cond->partition_list, optarg); break; case 's': if(!job_cond->state_list) job_cond->state_list = list_create(slurm_destroy_char); _addto_state_char_list(job_cond->state_list, optarg); break; case 'S': job_cond->usage_start = parse_time(optarg, 1); if (errno == ESLURM_INVALID_TIME_VALUE) exit(1); break; case 'T': job_cond->without_usage_truncation = 0; break; case 'U': params.opt_help = 3; break; case 'u': if(!strcmp(optarg, "-1")) { all_users = 1; break; } all_users = 0; if(!job_cond->userid_list) job_cond->userid_list = list_create(slurm_destroy_char); _addto_id_char_list(job_cond->userid_list, optarg, 0); break; case 'v': /* Handle -vvv thusly... */ verbosity++; break; case 'W': if(!job_cond->wckey_list) job_cond->wckey_list = list_create(slurm_destroy_char); slurm_addto_char_list(job_cond->wckey_list, optarg); break; case 'V': print_slurm_version(); exit(0); case 'x': if(!job_cond->associd_list) job_cond->associd_list = list_create(slurm_destroy_char); slurm_addto_char_list(job_cond->associd_list, optarg); break; case 't': case 'X': params.opt_allocs = 1; break; case ':': case '?': /* getopt() has explained it */ exit(1); } } if (verbosity) { opts.stderr_level += verbosity; opts.prefix_level = 1; log_alter(opts, 0, NULL); } /* Now set params.opt_dup, unless they've already done so */ if (params.opt_dup < 0) /* not already set explicitly */ params.opt_dup = 0; job_cond->duplicates = params.opt_dup; job_cond->without_steps = params.opt_allocs; if(!job_cond->usage_start && !job_cond->step_list) { struct tm start_tm; job_cond->usage_start = time(NULL); if (!localtime_r(&job_cond->usage_start, &start_tm)) { error("Couldn't get localtime from %ld", (long)job_cond->usage_start); return; } start_tm.tm_sec = 0; start_tm.tm_min = 0; start_tm.tm_hour = 0; start_tm.tm_isdst = -1; job_cond->usage_start = mktime(&start_tm); } if(verbosity > 0) { char *start_char =NULL, *end_char = NULL; start_char = xstrdup(ctime(&job_cond->usage_start)); /* remove the new line */ start_char[strlen(start_char)-1] = '\0'; if(job_cond->usage_end) { end_char = xstrdup(ctime(&job_cond->usage_end)); /* remove the new line */ end_char[strlen(end_char)-1] = '\0'; } else end_char = xstrdup("Now"); info("Jobs eligible from %s - %s", start_char, end_char); xfree(start_char); xfree(end_char); } debug("Options selected:\n" "\topt_completion=%d\n" "\topt_dup=%d\n" "\topt_field_list=%s\n" "\topt_help=%d\n" "\topt_allocs=%d", params.opt_completion, params.opt_dup, params.opt_field_list, params.opt_help, params.opt_allocs); if(params.opt_completion) { g_slurm_jobcomp_init(params.opt_filein); acct_type = slurm_get_jobcomp_type(); if ((strcmp(acct_type, "jobcomp/none") == 0) && (stat(params.opt_filein, &stat_buf) != 0)) { fprintf(stderr, "SLURM job completion is disabled\n"); exit(1); } xfree(acct_type); } else { slurm_acct_storage_init(params.opt_filein); acct_type = slurm_get_accounting_storage_type(); if ((strcmp(acct_type, "accounting_storage/none") == 0) && (stat(params.opt_filein, &stat_buf) != 0)) { fprintf(stderr, "SLURM accounting storage is disabled\n"); exit(1); } xfree(acct_type); acct_db_conn = slurmdb_connection_get(); if(errno != SLURM_SUCCESS) { error("Problem talking to the database: %m"); exit(1); } } /* specific clusters requested? */ if(all_clusters) { if(job_cond->cluster_list && list_count(job_cond->cluster_list)) { list_destroy(job_cond->cluster_list); job_cond->cluster_list = NULL; } debug2("Clusters requested:\tall"); } else if (job_cond->cluster_list && list_count(job_cond->cluster_list)) { debug2( "Clusters requested:"); itr = list_iterator_create(job_cond->cluster_list); while((start = list_next(itr))) debug2("\t: %s", start); list_iterator_destroy(itr); } else if(!job_cond->cluster_list || !list_count(job_cond->cluster_list)) { if(!job_cond->cluster_list) job_cond->cluster_list = list_create(slurm_destroy_char); if((start = slurm_get_cluster_name())) { list_append(job_cond->cluster_list, start); debug2("Clusters requested:\t%s", start); } } /* if any jobs or nodes are specified set to look for all users if none are set */ if(!job_cond->userid_list || !list_count(job_cond->userid_list)) if((job_cond->step_list && list_count(job_cond->step_list)) || job_cond->used_nodes) all_users=1; /* set all_users for user root if not requesting any */ if(!job_cond->userid_list && !params.opt_uid) all_users = 1; if(all_users) { if(job_cond->userid_list && list_count(job_cond->userid_list)) { list_destroy(job_cond->userid_list); job_cond->userid_list = NULL; } debug2("Userids requested:\tall"); } else if (job_cond->userid_list && list_count(job_cond->userid_list)) { debug2("Userids requested:"); itr = list_iterator_create(job_cond->userid_list); while((start = list_next(itr))) debug2("\t: %s", start); list_iterator_destroy(itr); } else if(!job_cond->userid_list || !list_count(job_cond->userid_list)) { if(!job_cond->userid_list) job_cond->userid_list = list_create(slurm_destroy_char); start = xstrdup_printf("%u", params.opt_uid); list_append(job_cond->userid_list, start); debug2("Userid requested\t: %s", start); } if (job_cond->groupid_list && list_count(job_cond->groupid_list)) { debug2("Groupids requested:"); itr = list_iterator_create(job_cond->groupid_list); while((start = list_next(itr))) debug2("\t: %s", start); list_iterator_destroy(itr); } /* specific partitions requested? */ if (job_cond->partition_list && list_count(job_cond->partition_list)) { debug2("Partitions requested:"); itr = list_iterator_create(job_cond->partition_list); while((start = list_next(itr))) debug2("\t: %s", start); list_iterator_destroy(itr); } /* specific qos' requested? */ if (job_cond->qos_list && list_count(job_cond->qos_list)) { start = get_qos_complete_str(g_qos_list, job_cond->qos_list); debug2("QOS requested\t: %s\n", start); xfree(start); } /* specific jobs requested? */ if (job_cond->step_list && list_count(job_cond->step_list)) { debug2("Jobs requested:"); itr = list_iterator_create(job_cond->step_list); while((selected_step = list_next(itr))) { if(selected_step->stepid != NO_VAL) debug2("\t: %d.%d", selected_step->jobid, selected_step->stepid); else debug2("\t: %d", selected_step->jobid); } list_iterator_destroy(itr); } /* specific states (completion state) requested? */ if (job_cond->state_list && list_count(job_cond->state_list)) { debug2("States requested:"); itr = list_iterator_create(job_cond->state_list); while((start = list_next(itr))) { debug2("\t: %s", job_state_string(atoi(start))); } list_iterator_destroy(itr); } if (job_cond->wckey_list && list_count(job_cond->wckey_list)) { debug2("Wckeys requested:"); itr = list_iterator_create(job_cond->wckey_list); while((start = list_next(itr))) debug2("\t: %s\n", start); list_iterator_destroy(itr); } if (job_cond->timelimit_min) { char time_str[128], tmp1[32], tmp2[32]; mins2time_str(job_cond->timelimit_min, tmp1, sizeof(tmp1)); sprintf(time_str, "%s", tmp1); if(job_cond->timelimit_max) { int len = strlen(tmp1); mins2time_str(job_cond->timelimit_max, tmp2, sizeof(tmp2)); sprintf(time_str+len, " - %s", tmp2); } debug2("Timelimit requested\t: %s", time_str); } /* specific jobnames requested? */ if (job_cond->jobname_list && list_count(job_cond->jobname_list)) { debug2("Jobnames requested:"); itr = list_iterator_create(job_cond->jobname_list); while((start = list_next(itr))) { debug2("\t: %s", start); } list_iterator_destroy(itr); } /* select the output fields */ if(brief_output) { if(params.opt_completion) dot = BRIEF_COMP_FIELDS; else dot = BRIEF_FIELDS; xstrfmtcat(params.opt_field_list, "%s,", dot); } if(long_output) { if(params.opt_completion) dot = LONG_COMP_FIELDS; else dot = LONG_FIELDS; xstrfmtcat(params.opt_field_list, "%s,", dot); } if (params.opt_field_list==NULL) { if(params.opt_completion) dot = DEFAULT_COMP_FIELDS; else dot = DEFAULT_FIELDS; xstrfmtcat(params.opt_field_list, "%s,", dot); } start = params.opt_field_list; while ((end = strstr(start, ","))) { char *tmp_char = NULL; int command_len = 0; int newlen = 0; *end = 0; while (isspace(*start)) start++; /* discard whitespace */ if(!(int)*start) continue; if((tmp_char = strstr(start, "\%"))) { newlen = atoi(tmp_char+1); tmp_char[0] = '\0'; } command_len = strlen(start); for (i = 0; fields[i].name; i++) { if (!strncasecmp(fields[i].name, start, command_len)) goto foundfield; } error("Invalid field requested: \"%s\"", start); exit(1); foundfield: if(newlen) fields[i].len = newlen; list_append(print_fields_list, &fields[i]); start = end + 1; }
/* * parse_command_line, fill in params data structure with data */ extern void parse_command_line(int argc, char *argv[]) { int opt_char; int option_index; int tmp = 0; static struct option long_options[] = { {"commandline", no_argument, 0, 'c'}, {"display", required_argument, 0, 'D'}, {"noheader", no_argument, 0, 'h'}, {"iterate", required_argument, 0, 'i'}, {"ionodes", required_argument, 0, 'I'}, {"cluster", required_argument, 0, 'M'}, {"clusters",required_argument, 0, 'M'}, {"nodes", required_argument, 0, 'n'}, {"quiet", no_argument, 0, 'Q'}, {"resolve", required_argument, 0, 'R'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"show_hidden", no_argument, 0, 'H'}, {NULL, 0, 0, 0} }; memset(¶ms, 0, sizeof(params)); while ((opt_char = getopt_long(argc, argv, "cD:hi:I:Hn:M:QR:vV", long_options, &option_index)) != -1) { switch (opt_char) { case '?': fprintf(stderr, "Try \"smap --help\" for more information\n"); exit(1); break; case 'c': params.commandline = TRUE; break; case 'D': if (!strcmp(optarg, "j")) tmp = JOBS; else if (!strcmp(optarg, "s")) tmp = SLURMPART; else if (!strcmp(optarg, "b")) tmp = BGPART; else if (!strcmp(optarg, "c")) tmp = COMMANDS; else if (!strcmp(optarg, "r")) tmp = RESERVATIONS; params.display = tmp; break; case 'h': params.no_header = true; break; case 'H': params.all_flag = true; break; case 'i': params.iterate = atoi(optarg); if (params.iterate <= 0) { error("Error: --iterate=%s", optarg); exit(1); } break; case 'I': /* * confirm valid ionodelist entry (The 128 is * a large number here to avoid having to do a * lot more querying to figure out the correct * pset size. This number should be large enough. */ params.io_bit = bit_alloc(128); if(bit_unfmt(params.io_bit, optarg) == -1) { error("'%s' invalid entry for --ionodes", optarg); exit(1); } break; case 'M': if(params.clusters) list_destroy(params.clusters); if(!(params.clusters = slurmdb_get_info_cluster(optarg))) { error("'%s' invalid entry for --cluster", optarg); exit(1); } working_cluster_rec = list_peek(params.clusters); break; case 'n': /* * confirm valid nodelist entry */ params.hl = hostlist_create(optarg); if (!params.hl) { error("'%s' invalid entry for --nodes", optarg); exit(1); } break; case 'Q': quiet_flag = 1; break; case 'R': params.commandline = TRUE; params.resolve = xstrdup(optarg); break; case 'v': params.verbose++; break; case 'V': print_slurm_version(); exit(0); case OPT_LONG_HELP: _help(); exit(0); case OPT_LONG_USAGE: _usage(); exit(0); } } params.cluster_dims = slurmdb_setup_cluster_dims(); if (params.cluster_dims > 4) fatal("smap is unable to support more than four dimensions"); params.cluster_base = hostlist_get_base(params.cluster_dims); params.cluster_flags = slurmdb_setup_cluster_flags(); }