void process_config_file( job_data_container *attr) { char torque_cfg_buf[MAX_LINE_LEN]; /* Buffer holds config file */ char *param_val; if (load_config(torque_cfg_buf, sizeof(torque_cfg_buf)) == 0) { if ((param_val = get_trq_param("CLIENTRETRY", torque_cfg_buf)) != NULL) { hash_add_or_exit(attr, "PBS_CLIENTRETRY", param_val, CONFIG_DATA); } } } /* END process_config_file */
int add_verify_resources( job_data_container *res_attr, /* M */ char *resources, /* I */ int p_type) /* I */ { char *r; char *eq; char *v; char *e = NULL; char *str; char *name; char *value = NULL; int gpugres; int len; int vlen; char *qptr = NULL; int braces = 0; r = resources; while (*r != '\0') { /* skip leading whitespace */ while (isspace((int)*r)) r++; /* get resource name */ eq = r; while ((*eq != '=') && (*eq != ',') && (*eq != '\0')) eq++; /* make sure there is a resource name */ if (r == eq) { /* FAILURE */ return(1); } /* * Count the number of non-space characters that make up the * resource name. Count only up to the last character before the * separator ('\0', ',' or '='). */ for (str = r, len = 0;(str < eq) && !isspace((int)*str);str++) len++; /* if separated by an equal sign, get the value */ if (*eq == '=') { char *ptr; v = eq + 1; while (isspace((int)*v)) v++; /* FORMAT: <ATTR>=[{'"}]<VAL>,<VAL>[{'"}][,<ATTR>=...]... */ ptr = strchr(v, ','); if (((qptr = strchr(v, '\'')) != NULL) && ((ptr == NULL) || ((ptr != NULL) && (qptr < ptr)))) { /* skip quote if before ',' or at the end of the string */ v = qptr + 1; } else if (((qptr = strchr(v, '\"')) != NULL) && ((ptr == NULL) || ((ptr != NULL) && (qptr < ptr)))) { /* skip quote if before ',' or at the end of the string */ v = qptr + 1; } else { qptr = NULL; } e = v; while (*e != '\0') { /* FORMAT: <ATTR>=[{'"}]<VAL>,<VAL>[{'"}][,<ATTR>=...]... */ /* NOTE already tokenized by getopt() which will support quoted whitespace, do not fail on spaces */ if (*e=='[' && qptr == NULL) { braces = 1; } if (braces && (*e == ']')) { braces=0; } if (qptr != NULL) { /* value contains quote - only terminate with quote */ if ((*e == '\'') || (*e == '\"')) break; } else { if (*e == ',' && braces==0) break; } #ifdef TNOT if (isspace((int)*e)) { /* FAILURE */ return(1); } #endif /* TNOT */ e++; } /* END while (*e != '\0') */ } /* END if (*eq == '=') */ else { /* no attr=value pair found */ fprintf(stderr, "Cannot find an attr=value pair in comma separated value '%s'\n", r); exit(1); } /* This code in combination with the backend server code ends up with * the logic of last added element remains. All others are dropped off. * Instead of posponing all of this logic, it will now occur here. */ gpugres = !strncmp(r,"gpus",strlen("gpus")); if (gpugres) { len = 5; /* + 6 = 1 for null terminator and 5 for 'gpus:' */ vlen = (e - v) + 6; name = (char *)calloc(1, len); value = (char *)calloc(1, vlen); } else { len++; vlen = (e - v) + 1; name = (char *)calloc(1, len); value = (char *)calloc(1, vlen); } if ((name != NULL) && (value != NULL)) { if (gpugres) snprintf(name, len, "gres"); else snprintf(name, len, "%s", r); if (gpugres) { char *gpu_eq = strchr(r, '='); if(gpu_eq == NULL) { fprintf(stderr,"Error with resource strings.\n"); exit(1); } *gpu_eq = ':'; snprintf(value, vlen, "%s", r); *gpu_eq = '='; } else snprintf(value, vlen, "%s", v); hash_add_or_exit(res_attr, name, value, p_type); } else { fprintf(stderr, "Error allocating memory for add_verify_resources\n"); exit(1); } /* Get ready for next resource/value pair */ if (qptr != NULL) { /* skip quotes looking for ',' */ while ((*e == '\'') || (*e == '\"')) e++; } if (v != NULL) r = e; else r = eq; if (*r == ',') { r++; if (*r == '\0') { return(1); } } } /* END while (*r != '\0') */ /* SUCCESS */ return(0); } /* END add_verify_resources() */
int parse_variable_list( job_data_container *dest_hash, /* This is the dest hashmap for vars found */ job_data_container * UNUSED(user_env), /* This is the source hashmap */ int UNUSED(var_type), /* Type for vars not pulled from the source hash */ int UNUSED(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; std::string job_env = ""; 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) { job_env += name; job_env += "="; add_env_value_to_string(job_env, c); if (delim == NULL) s = NULL; else { 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); job_env += "name"; job_env += "="; s = NULL; } else { memcpy(name, s, delim - s); name[delim - s] = '\0'; job_env += name; job_env += "=,"; s = delim + 1; } } } else { /* We have a key value pair */ delim = strchr(s, ','); if (delim == NULL) { /* we are at the end */ 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'; job_env += name; job_env += ","; s = delim + 1; } } } hash_add_or_exit(dest_hash, ATTR_v, job_env.c_str(), ENV_DATA); return(PBSE_NONE); } /* END parse_variable_list() */
/* This takes comma delimited list of name=value pairs. * If value is empty (i.e. name=,name1=...) the the value is pulled from the * env * return 1 on success, 0 on failure */ void 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; char *s = NULL; char *e = NULL; char *delim = NULL; char *name = NULL; char *tmp_name = NULL; char *val = NULL; job_data *hash_var = NULL; s = the_list; while (s) { delim = strpbrk(s, "=,"); /* There is no = or , in the following string */ /* The string is improperly formatted (, found when = should have been) */ /* The start character is a , or = */ if ((delim == NULL) || (*delim == ',') || (delim == s)) break; e = strchr(delim+1, ','); /* This is last value */ if (!e) e = strchr(delim+1, '\0'); /* Get the variable from the src hash */ /* Set the variable from the incoming data */ alloc_size = delim - s; /* the +8 is for prepending the value of pbs_var_ to the value * This is used and removed in build_var_list later */ calloc_or_fail(mm, &name, alloc_size+8, "parse_variable_list name"); memcpy(name, "pbs_var_", 8); memcpy(name+8, s, alloc_size); if ((e - delim) == 1) { calloc_or_fail(mm, &tmp_name, alloc_size, "parse_variable_list name"); memcpy(tmp_name, s, alloc_size); if (hash_find(user_env, tmp_name, &hash_var)) { hash_add_or_exit(mm, dest_hash, name, hash_var->value, hash_var->var_type); } else { hash_add_or_exit(mm, dest_hash, name, "", CMDLINE_DATA); } } else { delim++; /* Move past the = */ alloc_size = e - delim; calloc_or_fail(mm, &val, alloc_size, "parse_variable_list val"); strncpy(val, delim, alloc_size); hash_add_or_exit(mm, dest_hash, name, val, var_type); } if (*e == '\0') s = NULL; /* End of string previously found */ else s = e + 1; /* Set the start to one char beyond the , */ } } /* END parse_variable_list() */