int main (int argc, char **argv) { int error_code = SLURM_SUCCESS, i, opt_char, input_field_count; char **input_fields; log_options_t opts = LOG_OPTS_STDERR_ONLY ; char *temp = NULL; int option_index; uint16_t persist_conn_flags = 0; static struct option long_options[] = { {"all_clusters", 0, 0, 'a'}, {"cluster", 1, 0, 'M'}, {"federation", no_argument, 0, OPT_LONG_FEDR}, {"help", 0, 0, 'h'}, {"immediate",0, 0, 'i'}, {"local", no_argument, 0, OPT_LONG_LOCAL}, {"noheader", 0, 0, 'n'}, {"parsable", 0, 0, 'p'}, {"parsable2",0, 0, 'P'}, {"quiet", 0, 0, 'Q'}, {"sort", 0, 0, 's'}, {"tres", 1, 0, 'T'}, {"usage", 0, 0, 'h'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {NULL, 0, 0, 0} }; command_name = argv[0]; exit_code = 0; exit_flag = 0; federation_flag = false; input_field_count = 0; local_flag = false; quiet_flag = 0; slurm_conf_init(NULL); log_init("sreport", opts, SYSLOG_FACILITY_DAEMON, NULL); /* Check to see if we are running a supported accounting plugin */ temp = slurm_get_accounting_storage_type(); if (xstrcasecmp(temp, "accounting_storage/slurmdbd") && xstrcasecmp(temp, "accounting_storage/mysql")) { fprintf (stderr, "You are not running a supported " "accounting_storage plugin\n(%s).\n" "Only 'accounting_storage/slurmdbd' " "and 'accounting_storage/mysql' are supported.\n", temp); xfree(temp); exit(1); } xfree(temp); if (slurmctld_conf.fed_params && strstr(slurmctld_conf.fed_params, "fed_display")) federation_flag = true; if (getenv("SREPORT_CLUSTER")) { cluster_flag = xstrdup(optarg); local_flag = true; } if (getenv("SREPORT_FEDERATION")) federation_flag = true; if (getenv("SREPORT_LOCAL")) local_flag = true; temp = getenv("SREPORT_TRES"); if (temp) tres_str = xstrdup(temp); while ((opt_char = getopt_long(argc, argv, "aM:hnpPQs:t:T:vV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sreport --help\" " "for more information\n"); exit(1); break; case (int)'h': _usage (); exit(exit_code); break; case (int)'a': all_clusters_flag = 1; break; case OPT_LONG_FEDR: federation_flag = true; break; case OPT_LONG_LOCAL: local_flag = true; break; case (int) 'M': cluster_flag = xstrdup(optarg); federation_flag = true; break; case (int)'n': print_fields_have_header = 0; break; case (int)'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case (int)'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case (int)'Q': quiet_flag = 1; break; case (int)'s': _set_sort(optarg); break; case (int)'t': _set_time_format(optarg); break; case (int)'T': xfree(tres_str); tres_str = xstrdup(optarg); break; case (int)'v': quiet_flag = -1; break; case (int)'V': _print_version(); exit(exit_code); break; default: fprintf(stderr, "getopt error, returned %c\n", opt_char); exit(1); } } i = 0; if (all_clusters_flag) i++; if (cluster_flag) i++; if (local_flag) i++; if (i > 1) { fprintf(stderr, "Only one cluster option can be used (--all_clusters OR --cluster OR --local)\n"), exit(1); } if (argc > MAX_INPUT_FIELDS) /* bogus input, but continue anyway */ input_words = argc; else input_words = 128; input_fields = (char **) xmalloc (sizeof (char *) * input_words); if (optind < argc) { for (i = optind; i < argc; i++) { input_fields[input_field_count++] = argv[i]; } } if (federation_flag && !all_clusters_flag && !cluster_flag && !local_flag) cluster_flag = _build_cluster_string(); db_conn = slurmdb_connection_get2(&persist_conn_flags); if (errno) { fatal("Problem connecting to the database: %m"); exit(1); } if (persist_conn_flags & PERSIST_FLAG_P_USER_CASE) user_case_norm = false; _build_tres_list(); if (input_field_count) exit_flag = 1; else error_code = _get_command (&input_field_count, input_fields); while (error_code == SLURM_SUCCESS) { error_code = _process_command (input_field_count, input_fields); if (error_code || exit_flag) break; error_code = _get_command (&input_field_count, input_fields); } if (exit_flag == 2) putchar('\n'); /* Free the cluster grabbed from the -M option */ xfree(cluster_flag); slurmdb_connection_close(&db_conn); slurm_acct_storage_fini(); exit(exit_code); }
int main (int argc, char *argv[]) { int error_code = SLURM_SUCCESS, i, opt_char, input_field_count; char **input_fields; log_options_t opts = LOG_OPTS_STDERR_ONLY ; int local_exit_code = 0; char *temp = NULL; int option_index; static struct option long_options[] = { {"help", 0, 0, 'h'}, {"usage", 0, 0, 'h'}, {"immediate",0, 0, 'i'}, {"noheader",0, 0, 'n'}, {"oneliner", 0, 0, 'o'}, {"parsable", 0, 0, 'p'}, {"parsable2", 0, 0, 'P'}, {"quiet", 0, 0, 'Q'}, {"readonly", 0, 0, 'r'}, {"associations", 0, 0, 's'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {NULL, 0, 0, 0} }; command_name = argv[0]; rollback_flag = 1; exit_code = 0; exit_flag = 0; input_field_count = 0; quiet_flag = 0; readonly_flag = 0; verbosity = 0; log_init("sacctmgr", opts, SYSLOG_FACILITY_DAEMON, NULL); while((opt_char = getopt_long(argc, argv, "hionpPQrsvV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sacctmgr --help\" " "for more information\n"); exit(1); break; case (int)'h': _usage (); exit(exit_code); break; case (int)'i': rollback_flag = 0; break; case (int)'o': one_liner = 1; break; case (int)'n': print_fields_have_header = 0; break; case (int)'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case (int)'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case (int)'Q': quiet_flag = 1; break; case (int)'r': readonly_flag = 1; break; case (int)'s': with_assoc_flag = 1; break; case (int)'v': quiet_flag = -1; verbosity++; break; case (int)'V': _print_version(); exit(exit_code); break; default: exit_code = 1; fprintf(stderr, "getopt error, returned %c\n", opt_char); exit(exit_code); } } if (argc > MAX_INPUT_FIELDS) /* bogus input, but continue anyway */ input_words = argc; else input_words = 128; input_fields = (char **) xmalloc (sizeof (char *) * input_words); if (optind < argc) { for (i = optind; i < argc; i++) { input_fields[input_field_count++] = argv[i]; } } if (verbosity) { opts.stderr_level += verbosity; opts.prefix_level = 1; log_alter(opts, 0, NULL); } /* Check to see if we are running a supported accounting plugin */ temp = slurm_get_accounting_storage_type(); if(strcasecmp(temp, "accounting_storage/slurmdbd") && strcasecmp(temp, "accounting_storage/mysql")) { fprintf (stderr, "You are not running a supported " "accounting_storage plugin\n(%s).\n" "Only 'accounting_storage/slurmdbd' " "and 'accounting_storage/mysql' are supported.\n", temp); xfree(temp); exit(1); } xfree(temp); errno = 0; db_conn = slurmdb_connection_get(); if(errno != SLURM_SUCCESS) { int tmp_errno = errno; if((input_field_count == 2) && (!strncasecmp(argv[2], "Configuration", strlen(argv[1]))) && ((!strncasecmp(argv[1], "list", strlen(argv[0]))) || (!strncasecmp(argv[1], "show", strlen(argv[0]))))) { if(tmp_errno == ESLURM_DB_CONNECTION) { tmp_errno = 0; sacctmgr_list_config(true); } else sacctmgr_list_config(false); } errno = tmp_errno; if(errno) error("Problem talking to the database: %m"); exit(1); } my_uid = getuid(); if (input_field_count) exit_flag = 1; else error_code = _get_command (&input_field_count, input_fields); while (error_code == SLURM_SUCCESS) { error_code = _process_command (input_field_count, input_fields); if (error_code || exit_flag) break; error_code = _get_command (&input_field_count, input_fields); /* This is here so if someone made a mistake we allow * them to fix it and let the process happen since there * are checks for global exit_code we need to reset it. */ if(exit_code) { local_exit_code = exit_code; exit_code = 0; } } if(local_exit_code) exit_code = local_exit_code; acct_storage_g_close_connection(&db_conn); slurm_acct_storage_fini(); if(g_qos_list) list_destroy(g_qos_list); exit(exit_code); }
int main (int argc, char *argv[]) { int error_code = SLURM_SUCCESS, i, opt_char, input_field_count; char **input_fields; log_options_t opts = LOG_OPTS_STDERR_ONLY ; char *temp = NULL; int option_index; static struct option long_options[] = { {"all_clusters", 0, 0, 'a'}, {"help", 0, 0, 'h'}, {"immediate",0, 0, 'i'}, {"noheader", 0, 0, 'n'}, {"parsable", 0, 0, 'p'}, {"parsable2",0, 0, 'P'}, {"quiet", 0, 0, 'Q'}, {"sort", 0, 0, 's'}, {"usage", 0, 0, 'h'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {NULL, 0, 0, 0} }; command_name = argv[0]; exit_code = 0; exit_flag = 0; input_field_count = 0; quiet_flag = 0; log_init("sreport", opts, SYSLOG_FACILITY_DAEMON, NULL); /* Check to see if we are running a supported accounting plugin */ temp = slurm_get_accounting_storage_type(); if (strcasecmp(temp, "accounting_storage/slurmdbd") && strcasecmp(temp, "accounting_storage/mysql")) { fprintf (stderr, "You are not running a supported " "accounting_storage plugin\n(%s).\n" "Only 'accounting_storage/slurmdbd' " "and 'accounting_storage/mysql' are supported.\n", temp); xfree(temp); exit(1); } xfree(temp); while((opt_char = getopt_long(argc, argv, "ahnpPQs:t:vV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sreport --help\" " "for more information\n"); exit(1); break; case (int)'h': _usage (); exit(exit_code); break; case (int)'a': all_clusters_flag = 1; break; case (int)'n': print_fields_have_header = 0; break; case (int)'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case (int)'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case (int)'Q': quiet_flag = 1; break; case (int)'s': _set_sort(optarg); break; case (int)'t': _set_time_format(optarg); break; case (int)'v': quiet_flag = -1; break; case (int)'V': _print_version(); exit(exit_code); break; default: exit_code = 1; fprintf(stderr, "getopt error, returned %c\n", opt_char); exit(exit_code); } } if (argc > MAX_INPUT_FIELDS) /* bogus input, but continue anyway */ input_words = argc; else input_words = 128; input_fields = (char **) xmalloc (sizeof (char *) * input_words); if (optind < argc) { for (i = optind; i < argc; i++) { input_fields[input_field_count++] = argv[i]; } } db_conn = slurmdb_connection_get(); if (errno) { error("Problem talking to the database: %m"); exit(1); } my_uid = getuid(); if (input_field_count) exit_flag = 1; else error_code = _get_command (&input_field_count, input_fields); while (error_code == SLURM_SUCCESS) { error_code = _process_command (input_field_count, input_fields); if (error_code || exit_flag) break; error_code = _get_command (&input_field_count, input_fields); } if (exit_flag == 2) putchar('\n'); slurmdb_connection_close(&db_conn); slurm_acct_storage_fini(); exit(exit_code); }