dynamic_string *get_dynamic_string(int initial_size, const char *str) { dynamic_string *ds = calloc(1, sizeof(dynamic_string)); if (ds == NULL) return(ds); if (initial_size > 0) ds->size = initial_size; else ds->size = DS_INITIAL_SIZE; ds->str = calloc(1, ds->size); if (ds->str == NULL) { free(ds); return(NULL); } /* initialize empty str */ ds->used = 0; /* add the string if it exists */ if (str != NULL) { if (append_dynamic_string(ds,str) != PBSE_NONE) { free_dynamic_string(ds); return(NULL); } } return(ds); }
int is_stat_get( char *node_name, struct tcp_chan *chan) { int rc; char log_buf[LOCAL_LOG_BUF_SIZE]; dynamic_string *status_info; if (LOGLEVEL >= 3) { sprintf(log_buf, "received status from node %s", node_name); log_record(PBSEVENT_SCHED, PBS_EVENTCLASS_REQUEST, __func__, log_buf); } status_info = get_status_info(chan); if (is_reporter_node(node_name)) rc = process_alps_status(node_name, status_info); else rc = process_status_info(node_name, status_info); free_dynamic_string(status_info); return(rc); } /* END is_stat_get() */
int execute_reservation( char *command_str, char **reservation_id) { int rc; FILE *alps_pipe; int fd; dynamic_string *output = NULL; char tmpBuf[MAXLINE]; int bytes_read; int total_bytes_read = 0; if ((alps_pipe = popen(command_str, "r")) == NULL) { snprintf(log_buffer, sizeof(log_buffer), "Unable to open command %s for apbasil", command_str); log_err(errno, __func__, log_buffer); return(WRITING_PIPE_ERROR); } fd = fileno(alps_pipe); /* now read from the pipe */ output = get_dynamic_string(-1, NULL); while ((bytes_read = read(fd, tmpBuf, sizeof(tmpBuf) - 1)) > 0) { total_bytes_read += bytes_read; tmpBuf[bytes_read] = '\0'; append_dynamic_string(output, tmpBuf); } /* perform post-processing */ pclose(alps_pipe); if ((bytes_read == -1) || (total_bytes_read == 0)) rc = READING_PIPE_ERROR; else { rc = parse_reservation_output(output->str, reservation_id); } free_dynamic_string(output); return(rc); } /* END execute_reservation() */
dynamic_string *get_reservation_command( resizable_array *host_req_list, char *username, char *jobid, char *apbasil_path, char *apbasil_protocol) { dynamic_string *command = get_dynamic_string(-1, NULL); dynamic_string *node_list = get_dynamic_string(-1, NULL); char buf[MAXLINE * 2]; unsigned int width = 0; unsigned int nppn = 0; int iter = -1; host_req *hr; /* place the top header */ snprintf(buf, sizeof(buf), APBASIL_RESERVE_REQ, (apbasil_protocol != NULL) ? apbasil_protocol : DEFAULT_APBASIL_PROTOCOL); append_dynamic_string(command, buf); /* place the reserve header */ snprintf(buf, sizeof(buf), APBASIL_RESERVE_ARRAY, username, jobid); append_dynamic_string(command, buf); while ((hr = (host_req *)next_thing(host_req_list, &iter)) != NULL) { width += hr->ppn; nppn = MAX(nppn,hr->ppn); if (node_list->used != 0) append_dynamic_string(node_list, ","); append_dynamic_string(node_list, hr->hostname); free_host_req(hr); } save_current_reserve_param(command, node_list, width, nppn); free_dynamic_string(node_list); /* pipe the output to apbasil */ snprintf(buf, sizeof(buf), "</ReserveParamArray></BasilRequest>\" | %s", (apbasil_path != NULL) ? apbasil_path : DEFAULT_APBASIL_PATH); append_dynamic_string(command, buf); return(command); } /* END get_reservation_command() */
dynamic_string *get_reservation_command( resizable_array *host_req_list, char *username, char *jobid, char *apbasil_path, char *apbasil_protocol, char *multi_req_list, int use_nppn, int nppcu, int mppdepth) { dynamic_string *command = get_dynamic_string(-1, NULL); dynamic_string *node_list = get_dynamic_string(-1, NULL); char buf[MAXLINE * 2]; /* place the top header */ snprintf(buf, sizeof(buf), APBASIL_RESERVE_REQ, (apbasil_protocol != NULL) ? apbasil_protocol : DEFAULT_APBASIL_PROTOCOL); append_dynamic_string(command, buf); /* place the reserve header */ snprintf(buf, sizeof(buf), APBASIL_RESERVE_ARRAY, username, jobid); append_dynamic_string(command, buf); if (multi_req_list == NULL) { create_reserve_params_from_host_req_list(host_req_list, apbasil_protocol, use_nppn, nppcu, mppdepth, command); } else { /* no need to account for use_nppn here, this path always should */ create_reserve_params_from_multi_req_list(multi_req_list, apbasil_protocol, nppcu, mppdepth, command); } free_dynamic_string(node_list); /* pipe the output to apbasil */ snprintf(buf, sizeof(buf), "</ReserveParamArray></BasilRequest>\" | %s", (apbasil_path != NULL) ? apbasil_path : DEFAULT_APBASIL_PATH); append_dynamic_string(command, buf); return(command); } /* END get_reservation_command() */
void account_jobstr( job *pjob) { dynamic_string *ds; /* pack in general information about the job */ if ((ds = get_dynamic_string(-1, NULL)) == NULL) return; acct_job(pjob, ds); account_record(PBS_ACCT_RUN, pjob, ds->str); free_dynamic_string(ds); return; } /* END account_jobstr() */
END_TEST START_TEST(get_reservation_command_test) { resizable_array *hrl = parse_exec_hosts(eh1); dynamic_string *apbasil_command; char *reserve_param; char *reserve_param2; char *nppn; int ppn; apbasil_command = get_reservation_command(hrl, uname, jobids[0], NULL, apbasil_protocol, NULL, 0, 0); snprintf(buf, sizeof(buf), "Username '%s' not found in command '%s'", uname, apbasil_command->str); fail_unless(strstr(apbasil_command->str, uname) != NULL, buf); reserve_param = strstr(apbasil_command->str, "ReserveParam "); fail_unless(reserve_param != NULL, "Couldn't find a ReserveParam element in the request"); reserve_param2 = strstr(reserve_param + 1, "ReserveParam "); snprintf(buf, sizeof(buf), "Found two ReserveParam elements when there should be only one '%s'", apbasil_command->str); fail_unless(reserve_param2 == NULL, buf); free_resizable_array(hrl); free_dynamic_string(apbasil_command); hrl = parse_exec_hosts(eh3); apbasil_command = get_reservation_command(hrl, uname, jobids[1], apbasil_path, apbasil_protocol, NULL, 0, 1); reserve_param = strstr(apbasil_command->str, "ReserveParam "); reserve_param2 = strstr(reserve_param + 1, "ReserveParam "); fail_unless(reserve_param != NULL, "Couldn't find the first ReserveParam element in the request"); nppn = strstr(reserve_param, "nppn"); fail_unless(nppn != NULL, "Couldn't find the nppn specification in the first reservation"); nppn += strlen("nppn='"); ppn = atoi(nppn); snprintf(buf, sizeof(buf), "nppn should be 3 but is %d", ppn); fail_unless(ppn == 3, buf); }
/* * initializes a dynamic string and returns it, or NULL if there is no memory * * @param initial_size - the initial size of the string, use default if -1 * @param str - the initial string to place in the dynamic string if not NULL * @return - the dynamic string object or NULL if no memory */ dynamic_string *get_dynamic_string( int initial_size, /* I (-1 means default) */ const char *str) /* I (optional) */ { dynamic_string *ds = (dynamic_string *)calloc(1, sizeof(dynamic_string)); if (ds == NULL) return(ds); if (initial_size > 0) ds->size = initial_size; else ds->size = DS_INITIAL_SIZE; ds->str = (char *)calloc(1, ds->size); if (ds->str == NULL) { free(ds); return(NULL); } /* initialize empty str */ ds->used = 0; /* add the string if it exists */ if (str != NULL) { if (append_dynamic_string(ds,str) != PBSE_NONE) { free_dynamic_string(ds); return(NULL); } } return(ds); } /* END get_dynamic_string() */
int create_alps_reservation( char *exec_hosts, char *username, char *jobid, char *apbasil_path, char *apbasil_protocol, long long pagg_id_value, int use_nppn, int nppcu, int mppdepth, char **reservation_id, const char *mppnodes) { resizable_array *host_req_list; dynamic_string *command; int rc = 1; int retry_count = 0; char *user = strdup(username); char *aroba; if ((aroba = strchr(user, '@')) != NULL) *aroba = '\0'; if (strchr(exec_hosts, '|') == NULL) { host_req_list = parse_exec_hosts(exec_hosts,mppnodes); if (host_req_list->num == 0) { free(user); free_resizable_array(host_req_list); /* this is a login only job */ return(PBSE_NONE); } command = get_reservation_command(host_req_list, user, jobid, apbasil_path, apbasil_protocol, NULL, use_nppn, nppcu, mppdepth); free_resizable_array(host_req_list); } else { command = get_reservation_command(NULL, user, jobid, apbasil_path, apbasil_protocol, exec_hosts, use_nppn, nppcu, mppdepth); } free(user); /* retry on failure up to */ while ((retry_count++ < APBASIL_RETRIES) && (rc != apbasil_fail_permanent) && (rc != PBSE_NONE)) { rc = execute_reservation(command->str, reservation_id); if (rc != PBSE_NONE) usleep(100); } if (rc == PBSE_NONE) { char confirm_command_buf[MAXLINE * 2]; if (LOGLEVEL >= 3) { snprintf(log_buffer, sizeof(log_buffer), "Successful reservation command is: %s", command->str); log_event(PBSEVENT_JOB | PBSEVENT_SYSLOG, PBS_EVENTCLASS_JOB, __func__, log_buffer); } rc = 1; retry_count = 0; while ((retry_count++ < APBASIL_RETRIES) && (rc != apbasil_fail_permanent) && (rc != PBSE_NONE)) { rc = confirm_reservation(jobid, *reservation_id, pagg_id_value, apbasil_path, apbasil_protocol, confirm_command_buf, sizeof(confirm_command_buf)); if (rc != PBSE_NONE) usleep(100); } if (rc != PBSE_NONE) { snprintf(log_buffer, sizeof(log_buffer), "Failed confirmation command is: %s", confirm_command_buf); log_err(-1, __func__, confirm_command_buf); } else if (LOGLEVEL >= 3) { snprintf(log_buffer, sizeof(log_buffer), "Successful confirmation command is: %s", confirm_command_buf); log_event(PBSEVENT_JOB | PBSEVENT_SYSLOG, PBS_EVENTCLASS_JOB, __func__, log_buffer); } } else { snprintf(log_buffer, sizeof(log_buffer), "Failed reservation command is: %s", command->str); log_err(-1, __func__, log_buffer); } free_dynamic_string(command); return(rc); } /* END create_alps_reservation() */
void account_jobend( job *pjob, char *used) /* job usage information, see req_jobobit() */ { dynamic_string *ds; char local_buf[MAXLINE * 4]; #ifdef USESAVEDRESOURCES pbs_attribute *pattr; long walltime_val = 0; #else time_t time_now = time(NULL); #endif /* pack in general information about the job */ if ((ds = get_dynamic_string(-1, NULL)) == NULL) return; if ((acct_job(pjob, ds)) != PBSE_NONE) { free_dynamic_string(ds); return; } /* session */ sprintf(local_buf, "session=%ld ", pjob->ji_wattr[JOB_ATR_session_id].at_val.at_long); if (append_dynamic_string(ds, local_buf) != PBSE_NONE) { free_dynamic_string(ds); return; } /* Alternate id if present */ if (pjob->ji_wattr[JOB_ATR_altid].at_flags & ATR_VFLAG_SET) { sprintf(local_buf, "alt_id=%s ", pjob->ji_wattr[JOB_ATR_altid].at_val.at_str); if (append_dynamic_string(ds, local_buf) != PBSE_NONE) { free_dynamic_string(ds); return; } } /* add the execution end time */ #ifdef USESAVEDRESOURCES pattr = &pjob->ji_wattr[JOB_ATR_resc_used]; if (pattr->at_flags & ATR_VFLAG_SET) { resource *pres; char *pname; pres = (resource *)GET_NEXT(pattr->at_val.at_list); /* find the walltime resource */ for (;pres != NULL;pres = (resource *)GET_NEXT(pres->rs_link)) { pname = pres->rs_defin->rs_name; if (strcmp(pname, "walltime") == 0) { /* found walltime */ walltime_val = pres->rs_value.at_val.at_long; break; } } } sprintf(local_buf, "end=%ld ", (long)pjob->ji_qs.ji_stime + walltime_val); #else sprintf(local_buf, "end=%ld ", (long)time_now); #endif /* USESAVEDRESOURCES */ if (append_dynamic_string(ds, local_buf) != PBSE_NONE) { free_dynamic_string(ds); return; } /* finally add on resources used from req_jobobit() */ if (append_dynamic_string(ds, used) != PBSE_NONE) { free_dynamic_string(ds); return; } account_record(PBS_ACCT_END, pjob, ds->str); free_dynamic_string(ds); return; } /* END account_jobend() */
int save_attr_xml( struct attribute_def *padef, /* pbs_attribute definition array */ pbs_attribute *pattr, /* ptr to pbs_attribute value array */ int numattr, /* number of attributes in array */ int fds) /* file descriptor where attributes are written */ { int i; int rc; char buf[MAXLINE<<8]; char log_buf[LOCAL_LOG_BUF_SIZE]; dynamic_string *ds = get_dynamic_string(-1, NULL); /* write the opening tag for attributes */ snprintf(buf,sizeof(buf),"<attributes>\n"); if ((rc = write_buffer(buf,strlen(buf),fds)) != 0) return(rc); for (i = 0; i < numattr; i++) { if (pattr[i].at_flags & ATR_VFLAG_SET) { buf[0] = '\0'; clear_dynamic_string(ds); if ((rc = attr_to_str(ds, padef+i, pattr[i], TRUE)) != 0) { if (rc != NO_ATTR_DATA) { /* ERROR */ snprintf(log_buf,sizeof(log_buf), "Not enough space to print pbs_attribute %s", padef[i].at_name); free_dynamic_string(ds); return(rc); } } else { snprintf(buf,sizeof(buf),"<%s>%s</%s>\n", padef[i].at_name, ds->str, padef[i].at_name); if ((rc = write_buffer(buf,strlen(buf),fds)) != 0) { free_dynamic_string(ds); return(rc); } } } } /* END for each pbs_attribute */ free_dynamic_string(ds); /* close the attributes */ snprintf(buf,sizeof(buf),"</attributes>\n"); rc = write_buffer(buf,strlen(buf),fds); /* we can just return this since its the last write */ return(rc); } /* END save_attr_xml() */
int process_gpu_status( struct pbsnode *pnode, char **str_ptr) { char *str = *str_ptr; pbs_attribute temp; int gpu_count = 0; int rc; char buf[MAXLINE * 2]; dynamic_string *gpu_info; memset(&temp, 0, sizeof(temp)); if ((gpu_info = get_dynamic_string(-1, NULL)) == NULL) { *str_ptr = finish_gpu_status(str); return(ENOMEM); } if ((rc = decode_arst(&temp, NULL, NULL, NULL, 0)) != PBSE_NONE) { log_record(PBSEVENT_DEBUG, PBS_EVENTCLASS_NODE, __func__, "cannot initialize attribute"); *str_ptr = finish_gpu_status(str); free_dynamic_string(gpu_info); return(rc); } /* move past the initial gpu status */ str += strlen(str) + 1; for (; str != NULL && *str != '\0'; str += strlen(str) + 1) { if (!strcmp(str, CRAY_GPU_STATUS_END)) break; if (!strncmp(str, "gpu_id=", strlen("gpu_id="))) { snprintf(buf, sizeof(buf), "gpu[%d]=%s;", gpu_count, str); rc = append_dynamic_string(gpu_info, buf); gpu_count++; } else { rc = append_dynamic_string(gpu_info, str); rc = append_char_to_dynamic_string(gpu_info, ';'); } if (rc != PBSE_NONE) { free_dynamic_string(gpu_info); *str_ptr = finish_gpu_status(str); return(rc); } } set_ngpus(pnode, gpu_count); decode_arst(&temp, NULL, NULL, gpu_info->str, 0); node_gpustatus_list(&temp, pnode, ATR_ACTION_ALTER); free_arst(&temp); free_dynamic_string(gpu_info); *str_ptr = str; return(PBSE_NONE); } /* END process_gpu_status() */
int generate_alps_status( dynamic_string *status, const char *apbasil_path, const char *apbasil_protocol) { FILE *alps_pipe; int fd; int rc; int bytes_read; int total_bytes_read = 0; char inventory_command[MAXLINE * 2]; char input_buffer[MAXLINE]; char *ptr; dynamic_string *alps_output; if ((alps_output = get_dynamic_string(-1, NULL)) == NULL) return(ENOMEM); snprintf(inventory_command, sizeof(inventory_command), APBASIL_QUERY, (apbasil_protocol != NULL) ? apbasil_protocol : DEFAULT_APBASIL_PROTOCOL, (apbasil_path != NULL) ? apbasil_path : DEFAULT_APBASIL_PATH); if ((alps_pipe = popen(inventory_command, "r")) == NULL) { snprintf(log_buffer, sizeof(log_buffer), "Unable to open command %s for apbasil", inventory_command); log_err(errno, __func__, log_buffer); return(WRITING_PIPE_ERROR); } fd = fileno(alps_pipe); /* now read from the pipe */ ptr = input_buffer; memset(input_buffer, 0, sizeof(input_buffer)); while ((bytes_read = read(fd, ptr, sizeof(input_buffer) - 1)) > 0) { append_dynamic_string(alps_output, ptr); memset(input_buffer, 0, sizeof(input_buffer)); total_bytes_read += bytes_read; } /* perform post-processing */ pclose(alps_pipe); if ((bytes_read == -1) || (total_bytes_read == 0)) rc = READING_PIPE_ERROR; else { int index = alps_output->used - 1; while (alps_output->str[index] != '>') { alps_output->str[index] = '\0'; index--; } alps_output->used -= 1; rc = parse_alps_output(alps_output, status); } free_dynamic_string(alps_output); return(rc); } /* END generate_alps_status() */
int process_node( dynamic_string *status, xmlNode *node) { char *attr_value; char *role_value; xmlNode *child; xmlNode *segments; xmlNode *segment_child; dynamic_string *features; char buf[MAXLINE]; int num_procs = 0; int avail_procs = 0; unsigned long memory = 0; unsigned long long mem_kb; char *rsv_id = NULL; if ((features = get_dynamic_string(-1, NULL)) == NULL) return(ENOMEM); copy_to_end_of_dynamic_string(status, "node="); attr_value = (char *)xmlGetProp(node, (const xmlChar *)node_id); append_dynamic_string(status, attr_value); free(attr_value); /* check to see if the role is interactive - report these as down */ role_value = (char *)xmlGetProp(node, (const xmlChar *)role); copy_to_end_of_dynamic_string(status, "ARCH="); attr_value = (char *)xmlGetProp(node, (const xmlChar *)architecture); append_dynamic_string(status, attr_value); free(attr_value); copy_to_end_of_dynamic_string(status, "name="); attr_value = (char *)xmlGetProp(node, (const xmlChar *)name); append_dynamic_string(status, attr_value); free(attr_value); /* process the children */ for (child = node->children; child != NULL; child = child->next) { if (!strcmp((const char *)child->name, segment_array)) { for (segments = child->children; segments != NULL; segments = segments->next) { for (segment_child = segments->children; segment_child != NULL; segment_child = segment_child->next) { if (!strcmp((const char *)segment_child->name, processor_array)) process_processor_array(segment_child, &num_procs, &avail_procs, &rsv_id); else if (!strcmp((const char *)segment_child->name, memory_array)) process_memory_array(segment_child, &memory); else if (!strcmp((const char *)segment_child->name, label_array)) process_label_array(features, segment_child); } } } else if (!strcmp((const char *)child->name, processor_array)) { process_processor_array(child, &num_procs, &avail_procs, &rsv_id); } else if (!strcmp((const char *)child->name, memory_array)) { process_memory_array(child, &memory); } else if (!strcmp((const char *)child->name, label_array)) { process_label_array(features, child); } else if (!strcmp((const char *)child->name, accelerator_array)) { process_accelerator_array(status, child); } } /* END the loop for processing the children */ /* once done, add the procs, available procs, memory info, reservation, and features */ snprintf(buf, sizeof(buf), "CPROC=%d", num_procs); copy_to_end_of_dynamic_string(status, buf); snprintf(buf, sizeof(buf), "APROC=%d", avail_procs); copy_to_end_of_dynamic_string(status, buf); snprintf(buf, sizeof(buf), "CMEMORY=%lu", memory); copy_to_end_of_dynamic_string(status, buf); mem_kb = memory * 1024; snprintf(buf, sizeof(buf), "totmem=%llukb", mem_kb); copy_to_end_of_dynamic_string(status, buf); snprintf(buf, sizeof(buf), "physmem=%llukb", mem_kb); copy_to_end_of_dynamic_string(status, buf); if (rsv_id != NULL) { /* don't write the reservation id if we're in interactive mode */ if ((role_value == NULL) || (strcmp(role_value, interactive_caps))) { copy_to_end_of_dynamic_string(status, "reservation_id="); append_dynamic_string(status, rsv_id); } free(rsv_id); /* if there's a reservation on this node, the state is busy */ copy_to_end_of_dynamic_string(status, "state=BUSY"); snprintf(buf, sizeof(buf), "availmem=0kb"); copy_to_end_of_dynamic_string(status, buf); } else { /* no reservation, evaluate the state normally */ copy_to_end_of_dynamic_string(status, "state="); attr_value = (char *)xmlGetProp(node, (const xmlChar *)state); if ((role_value != NULL) && (!strcmp(role_value, interactive_caps))) { append_dynamic_string(status, "DOWN"); snprintf(buf, sizeof(buf), "availmem=0kb"); copy_to_end_of_dynamic_string(status, buf); } else { append_dynamic_string(status, attr_value); snprintf(buf, sizeof(buf), "availmem=%llukb", mem_kb); copy_to_end_of_dynamic_string(status, buf); } free(attr_value); } if (role_value != NULL) free(role_value); if (features->used > 0) { copy_to_end_of_dynamic_string(status, "feature_list="); append_dynamic_string(status, features->str); } free_dynamic_string(features); return(PBSE_NONE); } /* END process_node() */
int svr_save_xml( struct server *ps, int mode) { char *id = "svr_save_xml"; char buf[MAXLINE<<8]; dynamic_string *ds; int fds; int rc; int len; int i; fds = open(path_svrdb, O_WRONLY | O_CREAT | O_Sync | O_TRUNC, 0600); if (fds < 0) { log_err(errno,id,msg_svdbopen); return(-1); } /* write the sv_qs info */ snprintf(buf,sizeof(buf), "<server_db>\n<numjobs>%d</numjobs>\n<numque>%d</numque>\n<nextjobid>%d</nextjobid>\n<savetime>%ld</savetime>\n", ps->sv_qs.sv_numjobs, ps->sv_qs.sv_numque, ps->sv_qs.sv_jobidnumber, time_now); len = strlen(buf); if ((rc = write_buffer(buf,len,fds))) return(rc); /* write the attribute info */ snprintf(buf,sizeof(buf),"<attributes>"); if ((rc = write_buffer(buf,strlen(buf),fds))) return(rc); if ((ds = get_dynamic_string(-1, NULL)) == NULL) { log_err(ENOMEM, id, ""); return(ENOMEM); } i = 0; while (i != SRV_ATR_LAST) { if (ps->sv_attr[i].at_flags & ATR_VFLAG_SET) { buf[0] = '\0'; clear_dynamic_string(ds); if ((rc = attr_to_str(ds, svr_attr_def + i, ps->sv_attr[i], TRUE) != 0)) { if (rc != NO_ATTR_DATA) { /* ERROR */ snprintf(log_buffer,sizeof(log_buffer), "Not enough space to print attribute %s", svr_attr_def[i].at_name); log_err(-1,id,log_buffer); free_dynamic_string(ds); return(rc); } } else { snprintf(buf,sizeof(buf),"<%s>%s</%s>\n", svr_attr_def[i].at_name, ds->str, svr_attr_def[i].at_name); if (buf[0] != '\0') { if ((rc = write_buffer(buf,strlen(buf),fds))) { free_dynamic_string(ds); return(rc); } } } } i++; } free_dynamic_string(ds); snprintf(buf,sizeof(buf),"</attributes>\n"); if ((rc = write_buffer(buf,strlen(buf),fds))) return(rc); /* close the server_db */ snprintf(buf,sizeof(buf),"</server_db>"); if ((rc = write_buffer(buf,strlen(buf),fds))) return(rc); close(fds); return(0); } /* END svr_save_xml */
int create_alps_reservation( char *exec_hosts, char *username, char *jobid, char *apbasil_path, char *apbasil_protocol, long long pagg_id_value, char **reservation_id) { resizable_array *host_req_list; dynamic_string *command; int rc = 1; int retry_count = 0; char *user = strdup(username); char *aroba; host_req_list = parse_exec_hosts(exec_hosts); if (host_req_list->num == 0) { /* this is a login only job */ return(PBSE_NONE); } if ((aroba = strchr(user, '@')) != NULL) *aroba = '\0'; command = get_reservation_command(host_req_list, user, jobid, apbasil_path, apbasil_protocol); free(user); /* retry on failure up to */ while ((retry_count++ < APBASIL_RETRIES) && (rc != apbasil_fail_permanent) && (rc != PBSE_NONE)) { rc = execute_reservation(command->str, reservation_id); if (rc != PBSE_NONE) usleep(100); } free_dynamic_string(command); if (rc == PBSE_NONE) { rc = 1; retry_count = 0; while ((retry_count++ < APBASIL_RETRIES) && (rc != apbasil_fail_permanent) && (rc != PBSE_NONE)) { rc = confirm_reservation(jobid, *reservation_id, pagg_id_value, apbasil_path, apbasil_protocol); if (rc != PBSE_NONE) usleep(100); } } return(rc); } /* END create_alps_reservation() */
int parse_variable_list( memmgr **mm, /* memory manager */ job_data **dest_hash, /* This is the dest hashmap for vars found */ job_data *user_env, /* This is the source hashmap */ int var_type, /* Type for vars not pulled from the source hash */ int op_type, /* Op for vars not pulled from the source hash */ char *the_list) /* name=value,name1=value1,etc to be parsed */ { int alloc_size = 0; dynamic_string *job_env = get_dynamic_string(-1, NULL); char name[JOB_ENV_START_SIZE]; char *s = NULL; char *c = NULL; char *delim = NULL; s = the_list; while (s) { delim = strpbrk(s, "=,"); if (delim == s) { fprintf(stderr, "invalid -v syntax\n"); return(3); } /* If delim is ','or NULL we have no value. Get the environment variable in s */ /* If delim is '=' and delim+1 is ',' or NULL we also need to get the environment variable in s */ if (delim == NULL || *delim == ',' || ((*delim == '=') && (*(delim + 1) == ',')) || ((*delim == '=') && ((delim + 1) == NULL))) { if (delim == NULL) alloc_size = strlen(s); else alloc_size = delim - s; memcpy(name, s, alloc_size); name[alloc_size] = '\0'; c = getenv(name); if (c != NULL) { append_dynamic_string(job_env, name); append_dynamic_string(job_env, "="); append_dynamic_string(job_env, c); if (delim == NULL) s = NULL; else { append_dynamic_string(job_env, ","); s = delim + 1; if (*s == ',') /* This ended in '='. Move one more */ s++; } } else { /* No environment variable set for this name. Pass it on with value "" */ if (delim == NULL) { snprintf(name, sizeof(name), "%s", s); append_dynamic_string(job_env, name); append_dynamic_string(job_env, "="); s = NULL; } else { memcpy(name, s, delim - s); name[delim - s] = '\0'; append_dynamic_string(job_env, name); append_dynamic_string(job_env, "=,"); s = delim + 1; } } } else { /* We have a key value pair */ delim = strchr(s, ','); if (delim == NULL) { alloc_size = strlen(s); /* we are at the end */ append_dynamic_string(job_env, s); s = NULL; } else { /* We have another variable in the list. Take care of the current one */ alloc_size = delim - s; memcpy(name, s, alloc_size); name[alloc_size] = '\0'; append_dynamic_string(job_env, name); append_dynamic_string(job_env, ","); s = delim + 1; } } } hash_add_or_exit(mm, dest_hash, ATTR_v, job_env->str, ENV_DATA); free_dynamic_string(job_env); return(PBSE_NONE); } /* END parse_variable_list() */