/* * msg_queue_remove_uid() * * usuwa wiadomo¶æ z kolejki wiadomo¶ci dla danego * u¿ytkownika. * * - uin. * * 0 je¶li usuniêto, -1 je¶li nie ma takiej wiadomo¶ci. */ int msg_queue_remove_uid(const char *uid) { msg_queue_t *m; int res = -1; for (m = msgs_queue; m; m = m->next) { if (!xstrcasecmp(m->rcpts, uid)) { m = msgs_queue_removei(m); res = 0; } } return res; }
/*****************************************************************************\ * process and respond to a request \*****************************************************************************/ static void _proc_msg(int new_fd, char *msg) { char send_buf[SIZE]; uint16_t nodes = 0, slots = 0; info("AAA: received from client: %s", msg); if (new_fd < 0) return; if (!msg) { strcpy(send_buf, "NULL request, failure"); info("BBB: send to client: %s", send_buf); send_reply(new_fd, send_buf); } else { //identify the cmd if (0 == xstrcasecmp(msg, "get total nodes and slots")) { get_total_nodes_slots(&nodes, &slots); sprintf(send_buf, "total_nodes=%d total_slots=%d", nodes, slots); info("BBB: send to client: %s", send_buf); send_reply(new_fd, send_buf); } else if (0 == xstrcasecmp(msg, "get available nodes and slots")) { get_free_nodes_slots(&nodes, &slots); sprintf(send_buf, "avail_nodes=%d avail_slots=%d", nodes, slots); info("BBB: send to client: %s", send_buf); send_reply(new_fd, send_buf); } else if (0 == strncasecmp(msg, "allocate", 8)) { allocate_job_op(new_fd, msg); } else if (0 == strncasecmp(msg, "deallocate", 10)) { deallocate(msg); } } return; }
/* kind = 0 for sent, 1 for toobig */ static void xmsg_unlink_dotfiles(session_t *s, const char *varname) { if (session_int_get(s, varname)) { const int kind = !xstrcasecmp(varname, "unlink_sent"); const int maxfs = session_int_get(s, "max_filesize"); const char *dfsuffix = session_get(s, "dotfile_suffix"); const char *dir = xmsg_dirfix(session_uid_get(s)+XMSG_UID_DIROFFSET); DIR *d; struct dirent *de; struct stat st, std; char *df, *dfd, *dp, *dpd; if (!dir || !(d = opendir(dir))) { xdebug("unable to open specified directory"); return; } df = xmalloc(xstrlen(dir) + NAME_MAX + 2); dfd = xmalloc(xstrlen(dir) + NAME_MAX + 3 + xstrlen(dfsuffix)); xstrcpy(df, dir); dp = df + xstrlen(df); *(dp++) = '/'; xstrcpy(dfd, df); dpd = dfd + xstrlen(dfd); *(dpd++) = '.'; while ((de = readdir(d))) { if (de->d_name[0] == '.') continue; if (xstrlen(de->d_name) > NAME_MAX) { xdebug2(DEBUG_ERROR, "Filename longer than NAME_MAX (%s), skipping.", de->d_name); continue; } xstrcpy(dp, de->d_name); xstrcpy(dpd, de->d_name); xstrcat(dpd, dfsuffix); if (!stat(df, &st) && !stat(dfd, &std) && ((!maxfs || (st.st_size < maxfs)) == kind)) { xdebug("removing %s", de->d_name); unlink(df); unlink(dfd); } } closedir(d); xfree(df); xfree(dfd); } }
int s_p_handle_uint32(uint32_t* data, const char* key, const char* value) { char *endptr; unsigned long num; errno = 0; num = strtoul(value, &endptr, 0); if ((endptr[0] == 'k') || (endptr[0] == 'K')) { num *= 1024; endptr++; } if ((num == 0 && errno == EINVAL) || (*endptr != '\0')) { if ((xstrcasecmp(value, "UNLIMITED") == 0) || (xstrcasecmp(value, "INFINITE") == 0)) { num = (uint32_t) INFINITE; } else { error("%s value (%s) is not a valid number", key, value); return SLURM_ERROR; } } else if (errno == ERANGE) { error("%s value (%s) is out of range", key, value); return SLURM_ERROR; } else if (value[0] == '-') { error("%s value (%s) is less than zero", key, value); return SLURM_ERROR; } else if (num > 0xffffffff) { error("%s value (%s) is greater than 4294967295", key, value); return SLURM_ERROR; } *data = (uint32_t)num; return SLURM_SUCCESS; }
extern bool client_req_get_bool(client_req_t *req, const char *key, bool *pval) { char *val; val = _client_req_get_val(req, key); if (val == NULL) return false; if (!xstrcasecmp(val, TRUE_VAL)) *pval = true; else *pval = false; return true; }
int s_p_handle_double(double* data, const char* key, const char* value) { char *endptr; double num; errno = 0; num = strtod(value, &endptr); if ((num == 0 && errno == EINVAL) || (*endptr != '\0')) { if ((xstrcasecmp(value, "UNLIMITED") == 0) || (xstrcasecmp(value, "INFINITE") == 0)) { num = HUGE_VAL; } else { error("%s value (%s) is not a valid number", key, value); return SLURM_ERROR; } } else if (errno == ERANGE) { error("%s value (%s) is out of range", key, value); return SLURM_ERROR; } *data = num; return SLURM_SUCCESS; }
/* * ncurses_binding_delete() * * usuwa akcjê z danego klawisza. */ void ncurses_binding_delete(const char *key, int quiet) { struct binding *b; if (!key) return; for (b = bindings; b; b = b->next) { int i; if (!b->key || xstrcasecmp(key, b->key)) continue; if (b->internal) { printq("bind_seq_incorrect", key); return; } xfree(b->action); xfree(b->arg); if (b->default_action) { b->action = xstrdup(b->default_action); b->arg = xstrdup(b->default_arg); b->function = b->default_function; b->internal = 1; } else { xfree(b->key); for (i = 0; i < KEY_MAX + 1; i++) { if (ncurses_binding_map[i] == b) ncurses_binding_map[i] = NULL; if (ncurses_binding_map_meta[i] == b) ncurses_binding_map_meta[i] = NULL; } LIST_REMOVE2(&bindings, b, NULL); } config_changed = 1; printq("bind_seq_remove", key); return; } printq("bind_seq_incorrect", key); }
/* print_db_notok() - Print an error message about slurmdbd * is unreachable or wrong cluster name. * IN cname - char * cluster name * IN isenv - bool cluster name from env or from command line option. */ void print_db_notok(const char *cname, bool isenv) { if (errno) error("There is a problem talking to the database: %m. " "Only local cluster communication is available, remove " "%s or contact your admin to resolve the problem.", isenv ? "SLURM_CLUSTERS from your environment" : "--cluster from your command line"); else if (!xstrcasecmp("all", cname)) error("No clusters can be reached now. " "Contact your admin to resolve the problem."); else error("'%s' can't be reached now, " "or it is an invalid entry for %s. " "Use 'sacctmgr list clusters' to see available clusters.", cname, isenv ? "SLURM_CLUSTERS" : "--cluster"); }
/* * variable_find() * * znajduje strukturê variable_t opisuj±c± zmienn± o podanej nazwie. * * - name. */ variable_t *variable_find(const char *name) { GSList *vl; int hash; if (!name) return NULL; hash = variable_hash(name); for (vl = variables; vl; vl = vl->next) { variable_t *v = vl->data; if (v->name_hash == hash && !xstrcasecmp(v->name, name)) return v; } return NULL; }
/* * msg_queue_remove_seq() * * usuwa wiadomo¶æ z kolejki wiadomo¶æ o podanym numerze sekwencyjnym. * * - seq * * 0/-1 */ int msg_queue_remove_seq(const char *seq) { int res = -1; msg_queue_t *m; if (!seq) return -1; for (m = msgs_queue; m; m = m->next) { if (!xstrcasecmp(m->seq, seq)) { m = msgs_queue_removei(m); res = 0; } } return res; }
/* khem, var jest gg:*.... byl kod ktory nie dzialal... tak? */ void gg_changed_dcc(const char *var) { if (!xstrcmp(var, ("gg:dcc"))) { if (!gg_config_dcc) { gg_dcc_socket_close(); gg_dcc_ip = 0; gg_dcc_port = 0; } if (gg_config_dcc) { if (gg_dcc_socket_open(gg_config_dcc_port) == -1) print("dcc_create_error", strerror(errno)); } } else if (!xstrcmp(var, ("gg:dcc_ip"))) { if (gg_config_dcc_ip) { if (!xstrcasecmp(gg_config_dcc_ip, "auto")) { gg_dcc_ip = inet_addr("255.255.255.255"); } else { if (inet_addr(gg_config_dcc_ip) != INADDR_NONE) gg_dcc_ip = inet_addr(gg_config_dcc_ip); else { print("dcc_invalid_ip"); gg_config_dcc_ip = NULL; gg_dcc_ip = 0; } } } else gg_dcc_ip = 0; } else if (!xstrcmp(var, ("gg:dcc_port"))) { if (gg_config_dcc && gg_config_dcc_port) { gg_dcc_socket_close(); gg_dcc_ip = 0; gg_dcc_port = 0; if (gg_dcc_socket_open(gg_config_dcc_port) == -1) print("dcc_create_error", strerror(errno)); } } else if (!xstrcmp(var, ("gg:audio"))) { gg_config_audio = 0; debug("[gg_config_audio] gg:audio not supported.\n"); } if (!in_autoexec) print("config_must_reconnect"); }
static int on_off(const char *value) { if (!value) return -1; if (!xstrcasecmp(value, "on") || !xstrcasecmp(value, "true") || !xstrcasecmp(value, "yes") || !xstrcasecmp(value, "tak") || !xstrcmp(value, "1")) return 1; if (!xstrcasecmp(value, "off") || !xstrcasecmp(value, "false") || !xstrcasecmp(value, "no") || !xstrcasecmp(value, "nie") || !xstrcmp(value, "0")) return 0; return -1; }
extern bool is_user_coord(slurmdb_user_rec_t *user, char *account) { ListIterator itr; slurmdb_coord_rec_t *coord; xassert(user); xassert(account); if (!user->coord_accts || !list_count(user->coord_accts)) return 0; itr = list_iterator_create(user->coord_accts); while((coord = list_next(itr))) { if (!xstrcasecmp(coord->name, account)) break; } list_iterator_destroy(itr); return coord ? 1 : 0; }
static void _build_user_env(void) { char *tmp_env, *tok, *save_ptr = NULL, *eq_ptr, *value; tmp_env = xstrdup(opt.export_env); tok = strtok_r(tmp_env, ",", &save_ptr); while (tok) { if (!xstrcasecmp(tok, "NONE")) break; eq_ptr = strchr(tok, '='); if (eq_ptr) { eq_ptr[0] = '\0'; value = eq_ptr + 1; setenv(tok, value, 1); } tok = strtok_r(NULL, ",", &save_ptr); } xfree(tmp_env); }
static int validate_sorted_tokens(char *toks[]) { /* Determines whether the NULL-terminated array of strings (toks) is sorted. * Returns 0 if the array is sorted; o/w, returns -1. */ char **pp; char *p, *q; if (!toks) { return(-1); } if ((pp = toks) && *pp) { for (p=*pp++, q=*pp++; q; p=q, q=*pp++) { if (xstrcasecmp(p, q) > 0) return(-1); } } return(0); }
/* * variable_remove() * * usuwa zmienn±. */ int variable_remove(plugin_t *plugin, const char *name) { int hash; GSList *vl; if (!name) return -1; hash = ekg_hash(name); for (vl = variables; vl; vl = vl->next) { variable_t *v = vl->data; if (!v->name) continue; if (hash == v->name_hash && plugin == v->plugin && !xstrcasecmp(name, v->name)) { variables_remove(v); return 0; } } return -1; }
int s_p_handle_boolean(bool* data, const char* key, const char* value) { bool flag; if (!xstrcasecmp(value, "yes") || !xstrcasecmp(value, "up") || !xstrcasecmp(value, "true") || !xstrcasecmp(value, "1")) { flag = true; } else if (!xstrcasecmp(value, "no") || !xstrcasecmp(value, "down") || !xstrcasecmp(value, "false") || !xstrcasecmp(value, "0")) { flag = false; } else { error("\"%s\" is not a valid option for \"%s\"", value, key); return SLURM_ERROR; } *data = flag; return SLURM_SUCCESS; }
static List _build_tres_list(char *tres_str) { List tres_list = NULL; ListIterator iter; slurmdb_tres_rec_t *tres; slurmdb_tres_cond_t cond; char *tres_tmp = NULL, *tres_tmp2 = NULL, *save_ptr = NULL, *tok; memset(&cond, 0, sizeof(slurmdb_tres_cond_t)); tres_list = acct_storage_g_get_tres(db_conn, my_uid, &cond); if (!tres_list) { fatal("Problem getting TRES data: %m"); exit(1); } iter = list_iterator_create(tres_list); while ((tres = list_next(iter))) { if (tres_str) { tres_tmp = xstrdup(tres_str); xstrfmtcat(tres_tmp2, "%s%s%s", tres->type, tres->name ? "/" : "", tres->name ? tres->name : ""); tok = strtok_r(tres_tmp, ",", &save_ptr); while (tok) { if (!xstrcasecmp(tres_tmp2, tok)) break; tok = strtok_r(NULL, ",", &save_ptr); } if (!tok) /* Not found */ tres->id = NO_VAL; /* Skip this TRES */ xfree(tres_tmp2); xfree(tres_tmp); } else if (tres->id != TRES_CPU) { tres->id = NO_VAL; /* Skip this TRES */ } } list_iterator_destroy(iter); return tres_list; }
static int isMemberInEntry(Header h, const char *name, rpmTag tag) /*@globals internalState @*/ /*@modifies internalState @*/ { HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); int rc = -1; int xx; he->tag = tag; xx = headerGet(h, he, 0); if (!xx) return rc; rc = 0; while (he->c) { he->c--; if (xstrcasecmp(he->p.argv[he->c], name)) continue; rc = 1; break; } he->p.ptr = _free(he->p.ptr); return rc; }
static char * _get_node_state(struct node_record *node_ptr) { static bool got_select_type = false; static bool node_allocations; if (!got_select_type) { char * select_type = slurm_get_select_type(); if (select_type && (xstrcasecmp(select_type, "select/linear") == 0)) node_allocations = true; else node_allocations = false; xfree(select_type); got_select_type = true; } if (IS_NODE_DRAIN(node_ptr) || IS_NODE_FAIL(node_ptr)) { return "Drained"; return "Draining"; } if (IS_NODE_COMPLETING(node_ptr)) return "Busy"; if (IS_NODE_DOWN(node_ptr)) return "Down"; if (IS_NODE_ALLOCATED(node_ptr)) { if (node_allocations) return "Busy"; else return "Running"; } if (IS_NODE_IDLE(node_ptr)) return "Idle"; return "Unknown"; }
int main (int argc, char *argv[]) { char *prio_type = NULL; int error_code = SLURM_SUCCESS; priority_factors_request_msg_t req_msg; priority_factors_response_msg_t *resp_msg = NULL; log_options_t opts = LOG_OPTS_STDERR_ONLY ; slurm_conf_init(NULL); log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_USER, NULL); parse_command_line( argc, argv ); if (params.verbose) { opts.stderr_level += params.verbose; log_alter(opts, SYSLOG_FACILITY_USER, NULL); } if (working_cluster_rec) { slurm_ctl_conf_info_msg_t *slurm_ctl_conf_ptr; error_code = slurm_load_ctl_conf((time_t) NULL, &slurm_ctl_conf_ptr); if (error_code) { slurm_perror ("slurm_load_ctl_conf error"); exit(error_code); } weight_age = slurm_ctl_conf_ptr->priority_weight_age; weight_fs = slurm_ctl_conf_ptr->priority_weight_fs; weight_js = slurm_ctl_conf_ptr->priority_weight_js; weight_part = slurm_ctl_conf_ptr->priority_weight_part; weight_qos = slurm_ctl_conf_ptr->priority_weight_qos; weight_tres = slurm_ctl_conf_ptr->priority_weight_tres; prio_type = xstrdup(slurm_ctl_conf_ptr->priority_type); slurm_free_ctl_conf(slurm_ctl_conf_ptr); } else { weight_age = slurm_get_priority_weight_age(); weight_fs = slurm_get_priority_weight_fairshare(); weight_js = slurm_get_priority_weight_job_size(); weight_part = slurm_get_priority_weight_partition(); weight_qos = slurm_get_priority_weight_qos(); weight_tres = slurm_get_priority_weight_tres(); prio_type = slurm_get_priority_type(); } /* Check to see if we are running a supported accounting plugin */ if (xstrcasecmp(prio_type, "priority/basic") == 0) { fprintf (stderr, "You are not running a supported " "priority plugin\n(%s).\n" "Only 'priority/multifactor' is supported.\n", prio_type); exit(1); } xfree(prio_type); memset(&req_msg, 0, sizeof(priority_factors_request_msg_t)); if (params.jobs) req_msg.job_id_list = params.job_list; else req_msg.job_id_list = NULL; if (params.users) req_msg.uid_list = params.user_list; else req_msg.uid_list = NULL; error_code = _get_info(&req_msg, &resp_msg); if (error_code) { slurm_perror("Couldn't get priority factors from controller"); exit(error_code); } if (params.format == NULL) { if (params.normalized) { if (params.long_list) params.format = "%.15i %.8u %10y %10a %10f " "%10j %10p %10q %20t"; else{ params.format = xstrdup("%.15i"); if (params.users) xstrcat(params.format, " %.8u"); xstrcat(params.format, " %10y"); if (weight_age) xstrcat(params.format, " %10a"); if (weight_fs) xstrcat(params.format, " %10f"); if (weight_js) xstrcat(params.format, " %10j"); if (weight_part) xstrcat(params.format, " %10p"); if (weight_qos) xstrcat(params.format, " %10q"); if (weight_tres) xstrcat(params.format, " %20t"); } } else { if (params.long_list) params.format = "%.15i %.8u %.10Y %.10A %.10F " "%.10J %.10P %.10Q %.6N %.20T"; else{ params.format = xstrdup("%.15i"); if (params.users) xstrcat(params.format, " %.8u"); xstrcat(params.format, " %.10Y"); if (weight_age) xstrcat(params.format, " %.10A"); if (weight_fs) xstrcat(params.format, " %.10F"); if (weight_js) xstrcat(params.format, " %.10J"); if (weight_part) xstrcat(params.format, " %.10P"); if (weight_qos) xstrcat(params.format, " %.10Q"); if (weight_tres) xstrcat(params.format, " %.20T"); } } } /* create the format list from the format */ parse_format(params.format); if (params.jobs && (!resp_msg || !resp_msg->priority_factors_list || !list_count(resp_msg->priority_factors_list))) { printf("Unable to find jobs matching user/id(s) specified\n"); } else if (resp_msg) { print_jobs_array(resp_msg->priority_factors_list, params.format_list); } #if 0 /* Free storage here if we want to verify that logic. * Since we exit next, this is not important */ FREE_NULL_LIST(params.format_list); slurm_free_priority_factors_response_msg(resp_msg); #endif exit (error_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; slurm_conf_init(NULL); 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 (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); 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; } } /* readline library writes \n when echoes the input string, it does * not when it sees the EOF, so in that case we have to print it to * align the terminal prompt. */ if (exit_flag == 2) putchar('\n'); if (local_exit_code) exit_code = local_exit_code; acct_storage_g_close_connection(&db_conn); slurm_acct_storage_fini(); FREE_NULL_LIST(g_qos_list); FREE_NULL_LIST(g_res_list); FREE_NULL_LIST(g_tres_list); exit(exit_code); }
extern int sacctmgr_add_cluster(int argc, char **argv) { int rc = SLURM_SUCCESS; int i = 0; slurmdb_cluster_rec_t *cluster = NULL; slurmdb_cluster_rec_t *start_cluster = xmalloc(sizeof(slurmdb_cluster_rec_t)); List name_list = list_create(slurm_destroy_char); List cluster_list = NULL; slurmdb_assoc_rec_t start_assoc; int limit_set = 0; ListIterator itr = NULL, itr_c = NULL; char *name = NULL; slurmdb_init_assoc_rec(&start_assoc, 0); slurmdb_init_cluster_rec(start_cluster, 0); for (i=0; i<argc; i++) { int command_len = strlen(argv[i]); if (!strncasecmp(argv[i], "Where", MAX(command_len, 5)) || !strncasecmp(argv[i], "Set", MAX(command_len, 3))) i++; limit_set += _set_rec(&i, argc, argv, name_list, &start_assoc, start_cluster); } if (exit_code) { FREE_NULL_LIST(name_list); slurmdb_destroy_cluster_rec(start_cluster); return SLURM_ERROR; } else if (!list_count(name_list)) { FREE_NULL_LIST(name_list); slurmdb_destroy_cluster_rec(start_cluster); exit_code=1; fprintf(stderr, " Need name of cluster to add.\n"); return SLURM_ERROR; } else { List temp_list = NULL; slurmdb_cluster_cond_t cluster_cond; slurmdb_init_cluster_cond(&cluster_cond, 0); cluster_cond.cluster_list = name_list; cluster_cond.classification = start_cluster->classification; temp_list = acct_storage_g_get_clusters(db_conn, my_uid, &cluster_cond); if (!temp_list) { exit_code=1; fprintf(stderr, " Problem getting clusters from database. " "Contact your admin.\n"); slurmdb_destroy_cluster_rec(start_cluster); return SLURM_ERROR; } itr_c = list_iterator_create(name_list); itr = list_iterator_create(temp_list); while((name = list_next(itr_c))) { slurmdb_cluster_rec_t *cluster_rec = NULL; list_iterator_reset(itr); while((cluster_rec = list_next(itr))) { if (!xstrcasecmp(cluster_rec->name, name)) break; } if (cluster_rec) { printf(" This cluster %s already exists. " "Not adding.\n", name); list_delete_item(itr_c); } } list_iterator_destroy(itr); list_iterator_destroy(itr_c); FREE_NULL_LIST(temp_list); if (!list_count(name_list)) { FREE_NULL_LIST(name_list); slurmdb_destroy_cluster_rec(start_cluster); return SLURM_ERROR; } } if (start_cluster->fed.name) { int rc; List fed_list = list_create(slurm_destroy_char); list_append(fed_list, xstrdup(start_cluster->fed.name)); rc = verify_federations_exist(fed_list); FREE_NULL_LIST(fed_list); if (rc) { slurmdb_destroy_cluster_rec(start_cluster); FREE_NULL_LIST(name_list); return SLURM_ERROR; } } printf(" Adding Cluster(s)\n"); cluster_list = list_create(slurmdb_destroy_cluster_rec); itr = list_iterator_create(name_list); while((name = list_next(itr))) { if (!name[0]) { exit_code=1; fprintf(stderr, " No blank names are " "allowed when adding.\n"); rc = SLURM_ERROR; continue; } cluster = xmalloc(sizeof(slurmdb_cluster_rec_t)); slurmdb_init_cluster_rec(cluster, 0); list_append(cluster_list, cluster); slurmdb_copy_cluster_rec(cluster, start_cluster); cluster->name = xstrdup(name); printf(" Name = %s\n", cluster->name); cluster->root_assoc = xmalloc(sizeof(slurmdb_assoc_rec_t)); slurmdb_init_assoc_rec(cluster->root_assoc, 0); cluster->root_assoc->def_qos_id = start_assoc.def_qos_id; cluster->root_assoc->shares_raw = start_assoc.shares_raw; slurmdb_copy_assoc_rec_limits( cluster->root_assoc, &start_assoc); } list_iterator_destroy(itr); FREE_NULL_LIST(name_list); if (limit_set) printf(" Setting\n"); if (limit_set & CLUS_REC_SET) sacctmgr_print_cluster(start_cluster); if (limit_set & CLUS_ASSOC_SET) { printf(" Default Limits:\n"); sacctmgr_print_assoc_limits(&start_assoc); FREE_NULL_LIST(start_assoc.qos_list); } slurmdb_destroy_cluster_rec(start_cluster); if (!list_count(cluster_list)) { printf(" Nothing new added.\n"); rc = SLURM_ERROR; goto end_it; } /* Since we are creating tables with add cluster that can't be rolled back. So we ask before hand if they are serious about it so we can rollback if needed. */ if (commit_check("Would you like to commit changes?")) { notice_thread_init(); rc = acct_storage_g_add_clusters(db_conn, my_uid, cluster_list); notice_thread_fini(); if (rc == SLURM_SUCCESS) { acct_storage_g_commit(db_conn, 1); } else { exit_code=1; fprintf(stderr, " Problem adding clusters: %s\n", slurm_strerror(rc)); /* this isn't really needed, but just to be safe */ acct_storage_g_commit(db_conn, 0); } } else { printf(" Changes Discarded\n"); /* this isn't really needed, but just to be safe */ acct_storage_g_commit(db_conn, 0); } end_it: FREE_NULL_LIST(cluster_list); return rc; }
extern int jobacct_gather_init(void) { char *plugin_type = "jobacct_gather"; char *type = NULL; int retval=SLURM_SUCCESS; if (slurmdbd_conf || (_init_run_test() && g_context)) return retval; slurm_mutex_lock(&g_context_lock); if (g_context) goto done; type = slurm_get_jobacct_gather_type(); g_context = plugin_context_create( plugin_type, type, (void **)&ops, syms, sizeof(syms)); if (!g_context) { error("cannot create %s context for %s", plugin_type, type); retval = SLURM_ERROR; goto done; } if (!xstrcasecmp(type, "jobacct_gather/none")) { plugin_polling = false; goto done; } slurm_mutex_lock(&init_run_mutex); init_run = true; slurm_mutex_unlock(&init_run_mutex); /* only print the WARNING messages if in the slurmctld */ if (!run_in_daemon("slurmctld")) goto done; plugin_type = type; type = slurm_get_proctrack_type(); if (!xstrcasecmp(type, "proctrack/pgid")) { info("WARNING: We will use a much slower algorithm with " "proctrack/pgid, use Proctracktype=proctrack/linuxproc " "or some other proctrack when using %s", plugin_type); pgid_plugin = true; } xfree(type); xfree(plugin_type); type = slurm_get_accounting_storage_type(); if (!xstrcasecmp(type, ACCOUNTING_STORAGE_TYPE_NONE)) { error("WARNING: Even though we are collecting accounting " "information you have asked for it not to be stored " "(%s) if this is not what you have in mind you will " "need to change it.", ACCOUNTING_STORAGE_TYPE_NONE); } done: slurm_mutex_unlock(&g_context_lock); xfree(type); return(retval); }
/* * verify mem_bind arguments * * we support different memory binding names * we also allow a verbose setting to be specified * --mem_bind=v * --mem_bind=rank,v * --mem_bind=rank * --mem_bind={MAP_MEM|MASK_MEM}:0,1,2,3,4 * * returns -1 on error, 0 otherwise */ int slurm_verify_mem_bind(const char *arg, char **mem_bind, mem_bind_type_t *flags) { char *buf, *p, *tok; int bind_bits = MEM_BIND_NONE|MEM_BIND_RANK|MEM_BIND_LOCAL| MEM_BIND_MAP|MEM_BIND_MASK; if (arg == NULL) { return 0; } buf = xstrdup(arg); p = buf; /* change all ',' delimiters not followed by a digit to ';' */ /* simplifies parsing tokens while keeping map/mask together */ while (p[0] != '\0') { if ((p[0] == ',') && (!_isvalue(&(p[1])))) p[0] = ';'; p++; } p = buf; while ((tok = strsep(&p, ";"))) { if (xstrcasecmp(tok, "help") == 0) { slurm_print_mem_bind_help(); return 1; } else if ((xstrcasecmp(tok, "q") == 0) || (xstrcasecmp(tok, "quiet") == 0)) { *flags &= ~MEM_BIND_VERBOSE; } else if ((xstrcasecmp(tok, "v") == 0) || (xstrcasecmp(tok, "verbose") == 0)) { *flags |= MEM_BIND_VERBOSE; } else if ((xstrcasecmp(tok, "no") == 0) || (xstrcasecmp(tok, "none") == 0)) { _clear_then_set((int *)flags, bind_bits, MEM_BIND_NONE); xfree(*mem_bind); } else if (xstrcasecmp(tok, "rank") == 0) { _clear_then_set((int *)flags, bind_bits, MEM_BIND_RANK); xfree(*mem_bind); } else if (xstrcasecmp(tok, "local") == 0) { _clear_then_set((int *)flags, bind_bits,MEM_BIND_LOCAL); xfree(*mem_bind); } else if ((strncasecmp(tok, "map_mem", 7) == 0) || (strncasecmp(tok, "mapmem", 6) == 0)) { char *list; (void) strsep(&tok, ":="); list = strsep(&tok, ":="); /* THIS IS NOT REDUNDANT */ _clear_then_set((int *)flags, bind_bits, MEM_BIND_MAP); xfree(*mem_bind); if (list && *list) { *mem_bind = xstrdup(list); } else { error("missing list for \"--mem_bind=map_mem:<list>\""); xfree(buf); return 1; } } else if ((strncasecmp(tok, "mask_mem", 8) == 0) || (strncasecmp(tok, "maskmem", 7) == 0)) { char *list; (void) strsep(&tok, ":="); list = strsep(&tok, ":="); /* THIS IS NOT REDUNDANT */ _clear_then_set((int *)flags, bind_bits, MEM_BIND_MASK); xfree(*mem_bind); if (list && *list) { *mem_bind = xstrdup(list); } else { error("missing list for \"--mem_bind=mask_mem:<list>\""); xfree(buf); return 1; } } else { error("unrecognized --mem_bind argument \"%s\"", tok); xfree(buf); return 1; } } xfree(buf); return 0; }
/* * verify cpu_bind arguments * * we support different launch policy names * we also allow a verbose setting to be specified * --cpu_bind=threads * --cpu_bind=cores * --cpu_bind=sockets * --cpu_bind=v * --cpu_bind=rank,v * --cpu_bind=rank * --cpu_bind={MAP_CPU|MASK_CPU}:0,1,2,3,4 * * * returns -1 on error, 0 otherwise */ int slurm_verify_cpu_bind(const char *arg, char **cpu_bind, cpu_bind_type_t *flags) { char *buf, *p, *tok; int bind_bits = CPU_BIND_NONE|CPU_BIND_RANK|CPU_BIND_MAP|CPU_BIND_MASK; int bind_to_bits = CPU_BIND_TO_SOCKETS|CPU_BIND_TO_CORES|CPU_BIND_TO_THREADS; uint32_t task_plugin_param = slurm_get_task_plugin_param(); bool have_binding = _have_task_affinity(); bool log_binding = true; bind_bits |= CPU_BIND_LDRANK|CPU_BIND_LDMAP|CPU_BIND_LDMASK; bind_to_bits |= CPU_BIND_TO_LDOMS|CPU_BIND_TO_BOARDS; if (arg == NULL) { if ((*flags != 0) || /* already set values */ (task_plugin_param == 0)) /* no system defaults */ return 0; /* set system defaults */ xfree(*cpu_bind); if (task_plugin_param & CPU_BIND_NONE) *flags = CPU_BIND_NONE; else if (task_plugin_param & CPU_BIND_TO_SOCKETS) *flags = CPU_BIND_TO_SOCKETS; else if (task_plugin_param & CPU_BIND_TO_CORES) *flags = CPU_BIND_TO_CORES; else if (task_plugin_param & CPU_BIND_TO_THREADS) *flags |= CPU_BIND_TO_THREADS; else if (task_plugin_param & CPU_BIND_TO_LDOMS) *flags |= CPU_BIND_TO_LDOMS; else if (task_plugin_param & CPU_BIND_TO_BOARDS) *flags |= CPU_BIND_TO_BOARDS; if (task_plugin_param & CPU_BIND_VERBOSE) *flags |= CPU_BIND_VERBOSE; return 0; } /* Start with system default verbose flag (if set) */ if (task_plugin_param & CPU_BIND_VERBOSE) *flags |= CPU_BIND_VERBOSE; buf = xstrdup(arg); p = buf; /* change all ',' delimiters not followed by a digit to ';' */ /* simplifies parsing tokens while keeping map/mask together */ while (p[0] != '\0') { if ((p[0] == ',') && (!_isvalue(&(p[1])))) p[0] = ';'; p++; } p = buf; while ((tok = strsep(&p, ";"))) { if (xstrcasecmp(tok, "help") == 0) { slurm_print_cpu_bind_help(); return 1; } if (!have_binding && log_binding) { info("cluster configuration lacks support for cpu " "binding"); log_binding = false; } if ((xstrcasecmp(tok, "q") == 0) || (xstrcasecmp(tok, "quiet") == 0)) { *flags &= ~CPU_BIND_VERBOSE; } else if ((xstrcasecmp(tok, "v") == 0) || (xstrcasecmp(tok, "verbose") == 0)) { *flags |= CPU_BIND_VERBOSE; } else if ((xstrcasecmp(tok, "one_thread") == 0)) { *flags |= CPU_BIND_ONE_THREAD_PER_CORE; } else if ((xstrcasecmp(tok, "no") == 0) || (xstrcasecmp(tok, "none") == 0)) { _clear_then_set((int *)flags, bind_bits, CPU_BIND_NONE); xfree(*cpu_bind); } else if (xstrcasecmp(tok, "rank") == 0) { _clear_then_set((int *)flags, bind_bits, CPU_BIND_RANK); xfree(*cpu_bind); } else if ((strncasecmp(tok, "map_cpu", 7) == 0) || (strncasecmp(tok, "mapcpu", 6) == 0)) { char *list; (void) strsep(&tok, ":="); list = strsep(&tok, ":="); /* THIS IS NOT REDUNDANT */ _clear_then_set((int *)flags, bind_bits, CPU_BIND_MAP); xfree(*cpu_bind); if (list && *list) { *cpu_bind = xstrdup(list); } else { error("missing list for \"--cpu_bind=" "map_cpu:<list>\""); xfree(buf); return 1; } } else if ((strncasecmp(tok, "mask_cpu", 8) == 0) || (strncasecmp(tok, "maskcpu", 7) == 0)) { char *list; (void) strsep(&tok, ":="); list = strsep(&tok, ":="); /* THIS IS NOT REDUNDANT */ _clear_then_set((int *)flags, bind_bits, CPU_BIND_MASK); xfree(*cpu_bind); if (list && *list) { *cpu_bind = xstrdup(list); } else { error("missing list for \"--cpu_bind=" "mask_cpu:<list>\""); xfree(buf); return -1; } } else if (xstrcasecmp(tok, "rank_ldom") == 0) { _clear_then_set((int *)flags, bind_bits, CPU_BIND_LDRANK); xfree(*cpu_bind); } else if ((strncasecmp(tok, "map_ldom", 8) == 0) || (strncasecmp(tok, "mapldom", 7) == 0)) { char *list; (void) strsep(&tok, ":="); list = strsep(&tok, ":="); /* THIS IS NOT REDUNDANT */ _clear_then_set((int *)flags, bind_bits, CPU_BIND_LDMAP); xfree(*cpu_bind); if (list && *list) { *cpu_bind = xstrdup(list); } else { error("missing list for \"--cpu_bind=" "map_ldom:<list>\""); xfree(buf); return 1; } } else if ((strncasecmp(tok, "mask_ldom", 9) == 0) || (strncasecmp(tok, "maskldom", 8) == 0)) { char *list; (void) strsep(&tok, ":="); list = strsep(&tok, ":="); /* THIS IS NOT REDUNDANT */ _clear_then_set((int *)flags, bind_bits, CPU_BIND_LDMASK); xfree(*cpu_bind); if (list && *list) { *cpu_bind = xstrdup(list); } else { error("missing list for \"--cpu_bind=" "mask_ldom:<list>\""); xfree(buf); return -1; } } else if ((xstrcasecmp(tok, "socket") == 0) || (xstrcasecmp(tok, "sockets") == 0)) { if (task_plugin_param & (CPU_BIND_NONE | CPU_BIND_TO_CORES | CPU_BIND_TO_THREADS | CPU_BIND_TO_LDOMS | CPU_BIND_TO_BOARDS)) { debug("--cpu_bind=sockets incompatible with " "TaskPluginParam configuration " "parameter"); } _clear_then_set((int *)flags, bind_to_bits, CPU_BIND_TO_SOCKETS); } else if ((xstrcasecmp(tok, "core") == 0) || (xstrcasecmp(tok, "cores") == 0)) { if (task_plugin_param & (CPU_BIND_NONE | CPU_BIND_TO_SOCKETS | CPU_BIND_TO_THREADS | CPU_BIND_TO_LDOMS | CPU_BIND_TO_BOARDS)) { debug("--cpu_bind=cores incompatible with " "TaskPluginParam configuration " "parameter"); } _clear_then_set((int *)flags, bind_to_bits, CPU_BIND_TO_CORES); } else if ((xstrcasecmp(tok, "thread") == 0) || (xstrcasecmp(tok, "threads") == 0)) { if (task_plugin_param & (CPU_BIND_NONE | CPU_BIND_TO_SOCKETS | CPU_BIND_TO_CORES | CPU_BIND_TO_LDOMS | CPU_BIND_TO_BOARDS)) { debug("--cpu_bind=threads incompatible with " "TaskPluginParam configuration " "parameter"); } _clear_then_set((int *)flags, bind_to_bits, CPU_BIND_TO_THREADS); } else if ((xstrcasecmp(tok, "ldom") == 0) || (xstrcasecmp(tok, "ldoms") == 0)) { if (task_plugin_param & (CPU_BIND_NONE | CPU_BIND_TO_SOCKETS | CPU_BIND_TO_CORES | CPU_BIND_TO_THREADS | CPU_BIND_TO_BOARDS)) { debug("--cpu_bind=threads incompatible with " "TaskPluginParam configuration " "parameter"); } _clear_then_set((int *)flags, bind_to_bits, CPU_BIND_TO_LDOMS); } else if ((xstrcasecmp(tok, "board") == 0) || (xstrcasecmp(tok, "boards") == 0)) { if (task_plugin_param & (CPU_BIND_NONE | CPU_BIND_TO_SOCKETS | CPU_BIND_TO_CORES | CPU_BIND_TO_THREADS | CPU_BIND_TO_LDOMS)) { debug("--cpu_bind=threads incompatible with " "TaskPluginParam configuration " "parameter"); } _clear_then_set((int *)flags, bind_to_bits, CPU_BIND_TO_BOARDS); } else { error("unrecognized --cpu_bind argument \"%s\"", tok); xfree(buf); return -1; } } xfree(buf); /* Set system default CPU binding as needed */ if ((*flags & (~CPU_BIND_VERBOSE)) == 0) { if (task_plugin_param & CPU_BIND_NONE) *flags = CPU_BIND_NONE; else if (task_plugin_param & CPU_BIND_TO_SOCKETS) *flags = CPU_BIND_TO_SOCKETS; else if (task_plugin_param & CPU_BIND_TO_CORES) *flags = CPU_BIND_TO_CORES; else if (task_plugin_param & CPU_BIND_TO_THREADS) *flags |= CPU_BIND_TO_THREADS; else if (task_plugin_param & CPU_BIND_TO_LDOMS) *flags |= CPU_BIND_TO_LDOMS; else if (task_plugin_param & CPU_BIND_TO_BOARDS) *flags |= CPU_BIND_TO_BOARDS; } return 0; }
/* * Parse a comma separated list of SelectType Parameters * * Return SLURM_SUCCESS on success, or SLURM_ERROR otherwise */ int parse_select_type_param(char *select_type_parameters, uint16_t *param) { int rc = SLURM_SUCCESS; char *str_parameters, *st_str = NULL; int param_cnt = 0; *param = 0; st_str = xstrdup(select_type_parameters); str_parameters = strtok(st_str,","); while (str_parameters) { if (!xstrcasecmp(str_parameters, "CR_Socket")) { *param |= CR_SOCKET; param_cnt++; } else if (!xstrcasecmp(str_parameters, "CR_Socket_Memory")) { *param |= CR_SOCKET; *param |= CR_MEMORY; param_cnt++; } else if (!xstrcasecmp(str_parameters, "CR_Core")) { *param |= CR_CORE; param_cnt++; } else if (!xstrcasecmp(str_parameters, "CR_Core_Memory")) { *param |= CR_CORE; *param |= CR_MEMORY; param_cnt++; } else if (!xstrcasecmp(str_parameters, "CR_Memory")) { *param |= CR_MEMORY; param_cnt++; } else if (!xstrcasecmp(str_parameters, "CR_CPU")) { *param |= CR_CPU; param_cnt++; } else if (!xstrcasecmp(str_parameters, "CR_CPU_Memory")) { *param |= CR_CPU; *param |= CR_MEMORY; param_cnt++; } else if (!xstrcasecmp(str_parameters, "other_cons_res")) { *param |= CR_OTHER_CONS_RES; } else if (!xstrcasecmp(str_parameters, "CR_ALLOCATE_FULL_SOCKET")) { verbose("CR_ALLOCATE_FULL_SOCKET is deprecated. " "It is now the default for CR_SOCKET*. " "It is safe to remove it " "from your slurm.conf"); } else if (!xstrcasecmp(str_parameters, "CR_ONE_TASK_PER_CORE")) { *param |= CR_ONE_TASK_PER_CORE; } else if (!xstrcasecmp(str_parameters, "CR_CORE_DEFAULT_DIST_BLOCK")) { *param |= CR_CORE_DEFAULT_DIST_BLOCK; } else if (!xstrcasecmp(str_parameters, "CR_LLN")) { *param |= CR_LLN; } else if (!xstrcasecmp(str_parameters, "NHC_No")) { *param |= CR_NHC_STEP_NO; *param |= CR_NHC_NO; } else if (!xstrcasecmp(str_parameters, "NHC_No_Steps")) { *param |= CR_NHC_STEP_NO; } else if (!xstrcasecmp(str_parameters, "CR_PACK_NODES")) { *param |= CR_PACK_NODES; } else { error("Bad SelectTypeParameter: %s", str_parameters); rc = SLURM_ERROR; xfree(st_str); return rc; } str_parameters = strtok(NULL,","); } xfree(st_str); if (param_cnt > 1) rc = SLURM_ERROR; return rc; }
/* Take the user's format specification and use it to build build the * format specifications (internalize it to print.c data structures) */ static int _parse_format( char* format ) { int field_size; bool right_justify; char *prefix = NULL, *suffix = NULL, *token = NULL; char *tmp_char = NULL, *tmp_format = NULL; char field[1]; bool format_all = false; int i; if (format == NULL) { fprintf( stderr, "Format option lacks specification\n" ); exit( 1 ); } params.format_list = list_create( NULL ); if ((prefix = _get_prefix(format))) format_add_prefix( params.format_list, 0, 0, prefix); if (!xstrcasecmp(format, "%all")) { xstrfmtcat(tmp_format, "%c%c", '%', 'a'); for (i = 'b'; i <= 'z'; i++) xstrfmtcat(tmp_format, "|%c%c", '%', (char) i); for (i = 'A'; i <= 'Z'; i++) xstrfmtcat(tmp_format, "|%c%c ", '%', (char) i); format_all = true; } else { tmp_format = xstrdup(format); } token = strtok_r( tmp_format, "%", &tmp_char); if (token && (format[0] != '%')) /* toss header */ token = strtok_r( NULL, "%", &tmp_char ); while (token) { _parse_token( token, field, &field_size, &right_justify, &suffix); if (field[0] == 'a') { params.match_flags.avail_flag = true; format_add_avail( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'A') { format_add_nodes_ai( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'b') { params.match_flags.features_act_flag = true; format_add_features_act( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'B') { params.match_flags.max_cpus_per_node_flag = true; format_add_max_cpus_per_node( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'c') { params.match_flags.cpus_flag = true; format_add_cpus( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'C') { params.match_flags.cpus_flag = true; format_add_cpus_aiot( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'd') { params.match_flags.disk_flag = true; format_add_disk( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'D') { format_add_nodes( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'e') { params.match_flags.free_mem_flag = true; format_add_free_mem( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'E') { params.match_flags.reason_flag = true; format_add_reason( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'f') { params.match_flags.features_flag = true; format_add_features( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'F') { format_add_nodes_aiot( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'g') { params.match_flags.groups_flag = true; format_add_groups( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'G') { params.match_flags.gres_flag = true; format_add_gres( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'h') { params.match_flags.oversubscribe_flag = true; format_add_oversubscribe( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'H') { params.match_flags.reason_timestamp_flag = true; format_add_timestamp( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'I') { params.match_flags.priority_job_factor_flag = true; format_add_priority_job_factor(params.format_list, field_size, right_justify, suffix); } else if (field[0] == 'l') { params.match_flags.max_time_flag = true; format_add_time( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'L') { params.match_flags.default_time_flag = true; format_add_default_time( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'm') { params.match_flags.memory_flag = true; format_add_memory( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'M') { params.match_flags.preempt_mode_flag = true; format_add_preempt_mode( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'n') { params.match_flags.hostnames_flag = true; format_add_node_hostnames( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'N') { format_add_node_list( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'o') { params.match_flags.node_addr_flag = true; format_add_node_address( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'O') { params.match_flags.cpu_load_flag = true; format_add_cpu_load( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'p') { params.match_flags.priority_tier_flag = true; format_add_priority_tier(params.format_list, field_size, right_justify, suffix); } else if (field[0] == 'P') { params.match_flags.partition_flag = true; format_add_partition( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'r') { params.match_flags.root_flag = true; format_add_root( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'R') { params.match_flags.partition_flag = true; format_add_partition_name( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 's') { params.match_flags.job_size_flag = true; format_add_size( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'S') { format_add_alloc_nodes( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 't') { params.match_flags.state_flag = true; format_add_state_compact( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'T') { params.match_flags.state_flag = true; format_add_state_long( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'u') { params.match_flags.reason_user_flag = true; format_add_user( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'U') { params.match_flags.reason_user_flag = true; format_add_user_long( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'v') { params.match_flags.version_flag = true; format_add_version( params.format_list, field_size, right_justify, suffix); } else if (field[0] == 'V') { format_add_cluster_name(params.format_list, field_size, right_justify, suffix); } else if (field[0] == 'w') { params.match_flags.weight_flag = true; format_add_weight( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'X') { params.match_flags.sockets_flag = true; format_add_sockets( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'Y') { params.match_flags.cores_flag = true; format_add_cores( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'Z') { params.match_flags.threads_flag = true; format_add_threads( params.format_list, field_size, right_justify, suffix ); } else if (field[0] == 'z') { params.match_flags.sct_flag = true; format_add_sct( params.format_list, field_size, right_justify, suffix ); } else if (format_all) { ; /* ignore */ } else { prefix = xstrdup("%"); xstrcat(prefix, token); xfree(suffix); suffix = prefix; format_add_invalid( params.format_list, field_size, right_justify, suffix ); fprintf(stderr, "Invalid node format specification: %c\n", field[0] ); } token = strtok_r( NULL, "%", &tmp_char); } xfree( tmp_format ); return SLURM_SUCCESS; }
static int _parse_long_format (char* format_long) { int field_size; bool right_justify, format_all = false; char *tmp_format = NULL, *token = NULL, *str_tmp = NULL; char *sep = NULL; char* suffix = NULL; if (format_long == NULL) { error("Format long option lacks specification"); exit( 1 ); } params.format_list = list_create(NULL); tmp_format = xstrdup(format_long); token = strtok_r(tmp_format, ",",&str_tmp); while (token) { _parse_long_token( token, sep, &field_size, &right_justify, &suffix); if (!xstrcasecmp(token, "all")) { _parse_format ("%all"); } else if (!xstrcasecmp(token, "allocmem")) { params.match_flags.alloc_mem_flag = true; format_add_alloc_mem( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "allocnodes")) { format_add_alloc_nodes( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "available")) { params.match_flags.avail_flag = true; format_add_avail( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "cluster")) { format_add_cluster_name(params.format_list, field_size, right_justify, suffix); } else if (!xstrcasecmp(token, "cpus")) { params.match_flags.cpus_flag = true; format_add_cpus( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "cpusload")) { params.match_flags.cpu_load_flag = true; format_add_cpu_load( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "freemem")) { params.match_flags.free_mem_flag = true; format_add_free_mem( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "cpusstate")) { params.match_flags.cpus_flag = true; format_add_cpus_aiot( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "cores")) { params.match_flags.cores_flag = true; format_add_cores( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "defaulttime")) { params.match_flags.default_time_flag = true; format_add_default_time( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "disk")) { params.match_flags.disk_flag = true; format_add_disk( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "features")) { params.match_flags.features_flag = true; format_add_features( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "features_act")) { params.match_flags.features_act_flag = true; format_add_features_act( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "groups")) { params.match_flags.groups_flag = true; format_add_groups( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "gres")) { params.match_flags.gres_flag = true; format_add_gres( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "maxcpuspernode")) { params.match_flags.max_cpus_per_node_flag = true; format_add_max_cpus_per_node( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "memory")) { params.match_flags.memory_flag = true; format_add_memory( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "nodes")) { format_add_nodes( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "nodeaddr")) { params.match_flags.node_addr_flag = true; format_add_node_address( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "nodeai")) { format_add_nodes_ai( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "nodeaiot")) { format_add_nodes_aiot( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "nodehost")) { params.match_flags.hostnames_flag = true; format_add_node_hostnames( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "nodelist")) { format_add_node_list( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "partition")) { params.match_flags.partition_flag = true; format_add_partition( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "partitionname")) { params.match_flags.partition_flag = true; format_add_partition_name( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "port")) { params.match_flags.port_flag = true; format_add_port( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "preemptmode")) { params.match_flags.preempt_mode_flag = true; format_add_preempt_mode( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "priorityjobfactor")) { params.match_flags.priority_job_factor_flag = true; format_add_priority_job_factor(params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "prioritytier")) { params.match_flags.priority_tier_flag = true; format_add_priority_tier(params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "reason")) { params.match_flags.reason_flag = true; format_add_reason( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "root")) { params.match_flags.root_flag = true; format_add_root( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "oversubscribe") || !xstrcasecmp(token, "share")) { params.match_flags.oversubscribe_flag = true; format_add_oversubscribe( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "size")) { params.match_flags.job_size_flag = true; format_add_size( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "statecompact")) { params.match_flags.state_flag = true; format_add_state_compact( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "statelong")) { params.match_flags.state_flag = true; format_add_state_long( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "sockets")) { params.match_flags.sockets_flag = true; format_add_sockets( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "socketcorethread")) { params.match_flags.sct_flag = true; format_add_sct( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "time")) { params.match_flags.max_time_flag = true; format_add_time( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "timestamp")) { params.match_flags.reason_timestamp_flag = true; format_add_timestamp( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "threads")) { params.match_flags.threads_flag = true; format_add_threads( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "user")) { params.match_flags.reason_user_flag = true; format_add_user( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "userlong")) { params.match_flags.reason_user_flag = true; format_add_user_long( params.format_list, field_size, right_justify, suffix ); } else if (!xstrcasecmp(token, "version")) { params.match_flags.version_flag = true; format_add_version( params.format_list, field_size, right_justify, suffix); } else if (!xstrcasecmp(token, "weight")) { params.match_flags.weight_flag = true; format_add_weight( params.format_list, field_size, right_justify, suffix ); } else if (format_all) { /* ignore */ } else { format_add_invalid( params.format_list, field_size, right_justify, suffix ); error( "Invalid job format specification: %s", token ); } token = strtok_r(NULL, ",", &str_tmp); } xfree(tmp_format); return SLURM_SUCCESS; }
static int PerformActions(int vb,int no) { static int disable_sysfunc=0; /* Recursion lock */ int d=BitFlags&(1<<DARKBIT); int ct=0; int fl; int doagain=0; if(vb==1 && no == -1 ) { Output("Give me a direction too."); return(0); } if(vb==1 && no>=1 && no<=6) { int nl; if(Items[LIGHT_SOURCE].Location==MyLoc || Items[LIGHT_SOURCE].Location==CARRIED) d=0; if(d) Output("Dangerous to move in the dark! "); nl=Rooms[MyLoc].Exits[no-1]; if(nl!=0) { MyLoc=nl; return(0); } if(d) { if(Options&YOUARE) Output("You fell down and broke your neck. "); else Output("I fell down and broke my neck. "); glk_exit(); } if(Options&YOUARE) Output("You can't go in that direction. "); else Output("I can't go in that direction. "); return(0); } fl= -1; while(ct<=GameHeader.NumActions) { int vv,nv; vv=Actions[ct].Vocab; /* Think this is now right. If a line we run has an action73 run all following lines with vocab of 0,0 */ if(vb!=0 && (doagain&&vv!=0)) break; /* Oops.. added this minor cockup fix 1.11 */ if(vb!=0 && !doagain && fl== 0) break; nv=vv%150; vv/=150; if((vv==vb)||(doagain&&Actions[ct].Vocab==0)) { if((vv==0 && RandomPercent(nv))||doagain|| (vv!=0 && (nv==no||nv==0))) { int f2; if(fl== -1) fl= -2; if((f2=PerformLine(ct))>0) { /* ahah finally figured it out ! */ fl=0; if(f2==2) doagain=1; if(vb!=0 && doagain==0) return(0); } } } ct++; /* Previously this did not check ct against * GameHeader.NumActions and would read past the end of * Actions. I don't know what should happen on the last * action, but doing nothing is better than reading one * past the end. * --Chris */ if(ct <= GameHeader.NumActions && Actions[ct].Vocab!=0) doagain=0; } if(fl!=0 && disable_sysfunc==0) { int item; if(Items[LIGHT_SOURCE].Location==MyLoc || Items[LIGHT_SOURCE].Location==CARRIED) d=0; if(vb==10 || vb==18) { /* Yes they really _are_ hardcoded values */ if(vb==10) { if(xstrcasecmp(NounText,"ALL")==0) { int i=0; int f=0; if(d) { Output("It is dark.\n"); return 0; } while(i<=GameHeader.NumItems) { if(Items[i].Location==MyLoc && Items[i].AutoGet!=NULL && Items[i].AutoGet[0]!='*') { no=WhichWord(Items[i].AutoGet,Nouns); disable_sysfunc=1; /* Don't recurse into auto get ! */ PerformActions(vb,no); /* Recursively check each items table code */ disable_sysfunc=0; if(CountCarried()==GameHeader.MaxCarry) { if(Options&YOUARE) Output("You are carrying too much. "); else Output("I've too much to carry. "); return(0); } Items[i].Location= CARRIED; Output(Items[i].Text); Output(": O.K.\n"); f=1; } i++; } if(f==0) Output("Nothing taken."); return(0); } if(no==-1) { Output("What ? "); return(0); } if(CountCarried()==GameHeader.MaxCarry) { if(Options&YOUARE) Output("You are carrying too much. "); else Output("I've too much to carry. "); return(0); } item=MatchUpItem(NounText,MyLoc); if(item==-1) { if(Options&YOUARE) Output("It is beyond your power to do that. "); else Output("It's beyond my power to do that. "); return(0); } Items[item].Location= CARRIED; Output("O.K. "); return(0); } if(vb==18) { if(xstrcasecmp(NounText,"ALL")==0) { int i=0; int f=0; while(i<=GameHeader.NumItems) { if(Items[i].Location==CARRIED && Items[i].AutoGet && Items[i].AutoGet[0]!='*') { no=WhichWord(Items[i].AutoGet,Nouns); disable_sysfunc=1; PerformActions(vb,no); disable_sysfunc=0; Items[i].Location=MyLoc; Output(Items[i].Text); Output(": O.K.\n"); f=1; } i++; } if(f==0) Output("Nothing dropped.\n"); return(0); } if(no==-1) { Output("What ? "); return(0); } item=MatchUpItem(NounText,CARRIED); if(item==-1) { if(Options&YOUARE) Output("It's beyond your power to do that.\n"); else Output("It's beyond my power to do that.\n"); return(0); } Items[item].Location=MyLoc; Output("O.K. "); return(0); } } } return(fl); }