/** * @brief * -returns the default server name. * * @return string * @retval dflt srvr name success * @retval NULL error * */ char * __pbs_default() { char dflt_server[PBS_MAXSERVERNAME+1]; struct pbs_client_thread_context *p; /* initialize the thread context data, if not already initialized */ if (pbs_client_thread_init_thread_context() != 0) return NULL; p = pbs_client_thread_get_context_data(); if (pbs_loadconf(0) == 0) return NULL; if (p->th_pbs_defserver[0] == '\0') { /* The check for PBS_DEFAULT is done in pbs_loadconf() */ if (pbs_conf.pbs_primary && pbs_conf.pbs_secondary) { strncpy(dflt_server, pbs_conf.pbs_primary, PBS_MAXSERVERNAME); } else if (pbs_conf.pbs_server_host_name) { strncpy(dflt_server, pbs_conf.pbs_server_host_name, PBS_MAXSERVERNAME); } else if (pbs_conf.pbs_server_name) { strncpy(dflt_server, pbs_conf.pbs_server_name, PBS_MAXSERVERNAME); } else { dflt_server[0] = '\0'; } strcpy(p->th_pbs_defserver, dflt_server); } return (p->th_pbs_defserver); }
/** * @brief * The real verify function called from most IFL API calls * * @par Functionality: * 1. Gets the attr_errlist from the TLS data, deallocates it, if already * allocated and then allocates it again.\n * 2. Clears the connect context values from the TLS\n * 3. Calls verify_attributes to verify the list of attributes passed\n * * @see verify_attributes * * @param[in] connect - Connection Identifier * @param[in] batch_request - Batch Request Type * @param[in] parent_object - Parent Object Type * @param[in] cmd - Command Type * @param[in] attribute_list - list of attributes * * @return int * @retval 0 - No failed attributes * @retval +n - Number of failed attributes (pbs_errno set to last error) * @retval -1 - System error verifying attributes (pbs_errno is set) * * @par Side effects: * Modifies the TLS data for this thread\n * pbs_errno is set on encourtering error * * @par MT-safe: Yes */ static int __pbs_verify_attributes(int connect, int batch_request, int parent_object, int cmd, struct attropl *attribute_list) { struct pbs_client_thread_context *ptr; struct pbs_client_thread_connect_context *con; int rc; /* get error list from TLS */ ptr = (struct pbs_client_thread_context *) pbs_client_thread_get_context_data(); if (ptr == NULL) { /* very unlikely case */ pbs_errno = PBSE_SYSTEM; return -1; } /* since api is going to reuse err_list, free it first */ free_errlist(ptr->th_errlist); ptr->th_errlist = NULL; con = pbs_client_thread_find_connect_context(connect); if (con == NULL) { if ((con = pbs_client_thread_add_connect_context(connect)) == NULL) { pbs_errno = PBSE_SYSTEM; return -1; } } /* clear the TLS error codes */ con->th_ch_errno = 0; if (con->th_ch_errtxt) free(con->th_ch_errtxt); con->th_ch_errtxt = (char *) NULL; if (attribute_list == NULL) return 0; rc = verify_attributes(batch_request, parent_object, cmd, attribute_list, &ptr->th_errlist); if (rc > 0) { /* also set the pbs error code */ pbs_errno = ptr->th_errlist->ecl_attrerr[0].ecl_errcode; /* copy first error code into TLS connection context */ con->th_ch_errno = ptr->th_errlist->ecl_attrerr[0].ecl_errcode; if (ptr->th_errlist->ecl_attrerr[0].ecl_errmsg) { con->th_ch_errtxt = strdup(ptr->th_errlist->ecl_attrerr[0].ecl_errmsg); if (con->th_ch_errtxt == NULL) { pbs_errno = PBSE_SYSTEM; return -1; } } } return rc; }
/** * @brief * -wrapper function for pbs_submit where submission takes credentials. * * @param[in] c - communication handle * @param[in] attrib - pointer to attr list * @param[in] script - script to be submitted * @param[in] destination - host where submission happens * @param[in] extend - extend string for encoding req * @param[in] credtype - credential type * @param[in] credlen - credential length * @param[in] credbuf - buffer to hold cred info * * @return string * @retval jobid success * @retval NULL error * */ char * pbs_submit_with_cred(int c, struct attropl *attrib, char *script, char *destination, char *extend, int credtype, size_t credlen, char *credbuf) { char *ret; struct pbs_client_thread_context *ptr; struct cred_info *cred_info; /* initialize the thread context data, if not already initialized */ if (pbs_client_thread_init_thread_context() != 0) return NULL; /* lock pthread mutex here for this connection */ /* blocking call, waits for mutex release */ if (pbs_client_thread_lock_connection(c) != 0) return NULL; ptr = (struct pbs_client_thread_context *) pbs_client_thread_get_context_data(); if (!ptr) { pbs_errno = PBSE_INTERNAL; (void)pbs_client_thread_unlock_connection(c); return NULL; } if (!ptr->th_cred_info) { cred_info = malloc(sizeof(struct cred_info)); if (!cred_info) { pbs_errno = PBSE_INTERNAL; (void)pbs_client_thread_unlock_connection(c); return NULL; } ptr->th_cred_info = (void *) cred_info; } else cred_info = (struct cred_info *) ptr->th_cred_info; /* copy credentials to static variables */ cred_info->cred_buf = credbuf; cred_info->cred_len = credlen; cred_info->cred_type = credtype; /* pbs_submit takes credentials from static variables */ ret = pbs_submit(c, attrib, script, destination, extend); cred_info->cred_buf = NULL; cred_info->cred_len = 0; cred_info->cred_type = 0; /* unlock the thread lock and update the thread context data */ if (pbs_client_thread_unlock_connection(c) != 0) return NULL; return ret; }
/** * @brief * -The function returns the attributes that failed verification * * @param[in] connect - socket descriptor * * @return structure handle * @retval pointer to ecl_attribute_errors struct success * @retval NULL error * */ struct ecl_attribute_errors * pbs_get_attributes_in_error(int connect) { struct ecl_attribute_errors *err_list = NULL; struct pbs_client_thread_context *ptr = pbs_client_thread_get_context_data(); if (ptr) err_list = ptr->th_errlist; if (err_list && err_list->ecl_numerrors) return err_list; else return NULL; }
int totpool(int con, int update) { struct pbs_client_thread_context *ptr; struct node_pool *np; /* initialize the thread context data, if not already initialized */ if (pbs_client_thread_init_thread_context() != 0) return -1; ptr = (struct pbs_client_thread_context *) pbs_client_thread_get_context_data(); if (!ptr) { pbs_errno = PBSE_INTERNAL; return -1; } if (!ptr->th_node_pool) { np = (struct node_pool *) malloc(sizeof(struct node_pool)); if (!np) { pbs_errno = PBSE_INTERNAL; return -1; } ptr->th_node_pool = (void *) np; if ((np->resc_nodes = strdup("nodes")) == NULL) { free(np); np = NULL; pbs_errno = PBSE_SYSTEM; return -1; } } else np = (struct node_pool *) ptr->th_node_pool; if (update) { if (pbs_rescquery(con, &np->resc_nodes, 1, &np->nodes_avail, &np->nodes_alloc, &np->nodes_resrv, &np->nodes_down) != 0) { return (-1); } } return (np->nodes_avail + np->nodes_alloc + np->nodes_resrv + np->nodes_down); }
/** * @brief * -submit job request * * @param[in] c - communication handle * @param[in] attrib - ponter to attr list * @param[in] script - job script * @param[in] destination - host where job submitted * @param[in] extend - buffer to hold cred info * * @return string * @retval jobid success * @retval NULL error * */ char * __pbs_submit(int c, struct attropl *attrib, char *script, char *destination, char *extend) { struct attropl *pal; char *return_jobid = NULL; int rc; struct pbs_client_thread_context *ptr; struct cred_info *cred_info = NULL; /* initialize the thread context data, if not already initialized */ if (pbs_client_thread_init_thread_context() != 0) return return_jobid; ptr = (struct pbs_client_thread_context *) pbs_client_thread_get_context_data(); if (!ptr) { pbs_errno = PBSE_INTERNAL; return return_jobid; } /* first verify the attributes, if verification is enabled */ rc = pbs_verify_attributes(c, PBS_BATCH_QueueJob, MGR_OBJ_JOB, MGR_CMD_NONE, attrib); if (rc) return return_jobid; /* lock pthread mutex here for this connection */ /* blocking call, waits for mutex release */ if (pbs_client_thread_lock_connection(c) != 0) return return_jobid; /* first be sure that the script is readable if specified ... */ if ((script != NULL) && (*script != '\0')) { if (access(script, R_OK) != 0) { pbs_errno = PBSE_BADSCRIPT; if ((connection[c].ch_errtxt = strdup("cannot access script file")) == NULL) pbs_errno = PBSE_SYSTEM; goto error; } } /* initiate the queueing of the job */ for (pal = attrib; pal; pal = pal->next) pal->op = SET; /* force operator to SET */ /* Queue job with null string for job id */ return_jobid = PBSD_queuejob(c, "", destination, attrib, extend, 0, NULL); if (return_jobid == NULL) goto error; /* send script across */ if ((script != NULL) && (*script != '\0')) { if ((rc = PBSD_jscript(c, script, 0, NULL)) != 0) { if (rc == PBSE_JOBSCRIPTMAXSIZE) pbs_errno = rc; else pbs_errno = PBSE_BADSCRIPT; goto error; } } /* OK, the script got across, apparently, so we are */ /* ready to commit */ cred_info = (struct cred_info *) ptr->th_cred_info; /* opaque information */ if (cred_info && cred_info->cred_len > 0) { if (PBSD_jcred(c, cred_info->cred_type, cred_info->cred_buf, cred_info->cred_len, 0, NULL) != 0) { pbs_errno = PBSE_BADCRED; goto error; } } if (PBSD_commit(c, return_jobid, 0, NULL) != 0) goto error; /* unlock the thread lock and update the thread context data */ if (pbs_client_thread_unlock_connection(c) != 0) return NULL; return return_jobid; error: (void)pbs_client_thread_unlock_connection(c); return NULL; }