/** * @brief * handles attribute errors and prints appropriate errmsg * * @param[in] err_list - list of possible attribute errors * * @return - Void * */ static void handle_attribute_errors(struct ecl_attribute_errors *err_list) { struct attropl *attribute; char * opt; int i; for (i=0; i<err_list->ecl_numerrors; i++) { attribute = err_list->ecl_attrerr[i].ecl_attribute; if (strcmp(attribute->name, ATTR_resv_end) == 0) opt="E"; else if (strcmp(attribute->name, ATTR_g)==0) opt="g"; else if (strcmp(attribute->name, ATTR_auth_g)==0) opt="G"; else if (strcmp(attribute->name, ATTR_auth_h)==0) opt="H"; else if (strcmp(attribute->name, ATTR_inter) == 0) opt="I"; else if (strcmp(attribute->name, ATTR_l) == 0) opt="l"; else if (strcmp(attribute->name, ATTR_m) == 0) opt="m"; else if (strcmp(attribute->name, ATTR_M) == 0) opt="M"; else if (strcmp(attribute->name, ATTR_resv_name)==0) opt="N"; else if (strcmp(attribute->name, ATTR_resv_start)==0) opt="R"; else if (strcmp(attribute->name, ATTR_resv_rrule)==0) opt="r"; else if (strcmp(attribute->name, ATTR_u)==0) opt="u"; else if (strcmp(attribute->name, ATTR_auth_u)==0) opt="U"; else if (strcmp(attribute->name, ATTR_convert)==0) opt="W"; else return ; CS_close_app(); if (*opt == 'l') { fprintf(stderr, "pbs_rsub: %s\n", err_list->ecl_attrerr[i].ecl_errmsg); exit(err_list->ecl_attrerr[i].ecl_errcode); } else if (err_list->ecl_attrerr->ecl_errcode == PBSE_JOBNBIG) { fprintf(stderr, "pbs_rsub: Reservation %s \n", err_list->ecl_attrerr->ecl_errmsg); exit(2); } else { fprintf(stderr, "pbs_rsub: illegal -%s value\n", opt); print_usage(); exit(2); } } }
int main(int argc, char **argv) { /* * This routine sends a Manage request to the batch server specified by * the destination. The STARTED queue attribute is set to {False}. If the * batch request is accepted, the server will stop scheduling or routing * requests for the specified queue. */ int dest; /* Index into the destination array (argv) */ char *queue; /* Queue name part of destination */ char *server; /* Server name part of destination */ /*test for real deal or just version and exit*/ PRINT_VERSION_AND_EXIT(argc, argv); #ifdef WIN32 if (winsock_init()) { return 1; } #endif if (argc == 1) { fprintf(stderr, "Usage: qstop [queue][@server] ...\n"); fprintf(stderr, " qstop --version\n"); exit(1); } /*perform needed security library initializations (including none)*/ if (CS_client_init() != CS_SUCCESS) { fprintf(stderr, "qstop: unable to initialize security library.\n"); exit(1); } for (dest=1; dest<argc; dest++) if (parse_destination_id(argv[dest], &queue, &server) == 0) execute(queue, server); else { fprintf(stderr, "qstop: illegally formed destination: %s\n", argv[dest]); exitstatus = 1; } /*cleanup security library initializations before exiting*/ CS_close_app(); exit(exitstatus); }
/** * @brief * handles attribute errors and prints appropriate errmsg * * @param[in] connect - value indicating server connection * @param[in] err_list - list of possible attribute errors * * @return - Void * */ static void handle_attribute_errors(int connect, struct ecl_attribute_errors *err_list) { struct attropl *attribute; char * opt; int i; for (i=0; i<err_list->ecl_numerrors; i++) { attribute = err_list->ecl_attrerr[i].ecl_attribute; if (strcmp(attribute->name, ATTR_h) == 0) opt="h"; else return; fprintf(stderr, "qhold: illegal -%s value\n", opt); print_usage(); pbs_disconnect(connect); /*cleanup security library initializations before exiting*/ CS_close_app(); exit(2); } }
int main(int argc, char **argv, char **envp) /* qrls */ { int c; int errflg=0; int any_failed=0; int u_cnt, o_cnt, s_cnt, n_cnt, p_cnt; char *pc; char job_id[PBS_MAXCLTJOBID]; /* from the command line */ char job_id_out[PBS_MAXCLTJOBID]; char server_out[MAXSERVERNAME]; char rmt_server[MAXSERVERNAME]; #define MAX_HOLD_TYPE_LEN 32 char hold_type[MAX_HOLD_TYPE_LEN+1]; #define GETOPT_ARGS "h:" /*test for real deal or just version and exit*/ execution_mode(argc, argv); #ifdef WIN32 winsock_init(); #endif hold_type[0]='\0'; while ((c = getopt(argc, argv, GETOPT_ARGS)) != EOF) switch (c) { case 'h': while (isspace((int)*optarg)) optarg++; if (strlen(optarg) == 0) { fprintf(stderr, "qrls: illegal -h value\n"); errflg++; break; } pc = optarg; u_cnt = o_cnt = s_cnt = n_cnt = p_cnt = 0; while (*pc) { if (*pc == 'u') u_cnt++; else if (*pc == 'o') o_cnt++; else if (*pc == 's') s_cnt++; else if (*pc == 'p') p_cnt++; else if (*pc == 'n') n_cnt++; else { fprintf(stderr, "qrls: illegal -h value\n"); errflg++; break; } pc++; } if (n_cnt && (u_cnt + o_cnt + s_cnt + p_cnt)) { fprintf(stderr, "qrls: illegal -h value\n"); errflg++; break; } strcpy(hold_type, optarg); break; default : errflg++; } if (errflg || optind >= argc) { static char usage[]="usage: qrls [-h hold_list] job_identifier...\n"; static char usag2[]=" qrls --version\n"; fprintf(stderr, "%s", usage); fprintf(stderr, "%s", usag2); exit(2); } /*perform needed security library initializations (including none)*/ if (CS_client_init() != CS_SUCCESS) { fprintf(stderr, "qrls: unable to initialize security library.\n"); exit(1); } for (; optind < argc; optind++) { int connect; int stat=0; int located = FALSE; strcpy(job_id, argv[optind]); if (get_server(job_id, job_id_out, server_out)) { fprintf(stderr, "qrls: illegally formed job identifier: %s\n", job_id); any_failed = 1; continue; } cnt: connect = cnt2server(server_out); if (connect <= 0) { fprintf(stderr, "qrls: cannot connect to server %s (errno=%d)\n", pbs_server, pbs_errno); any_failed = pbs_errno; continue; } stat = pbs_rlsjob(connect, job_id_out, hold_type, NULL); if (stat && (pbs_errno != PBSE_UNKJOBID)) { prt_job_err("qrls", connect, job_id_out); any_failed = pbs_errno; } else if (stat && (pbs_errno == PBSE_UNKJOBID) && !located) { located = TRUE; if (locate_job(job_id_out, server_out, rmt_server)) { pbs_disconnect(connect); strcpy(server_out, rmt_server); goto cnt; } prt_job_err("qrls", connect, job_id_out); any_failed = pbs_errno; } pbs_disconnect(connect); } /*cleanup security library initializations before exiting*/ CS_close_app(); exit(any_failed); }
int main(int argc, char **argv) { /* * This routine sends a Run Job request to the batch server. If the * batch request is accepted, the server will have started the execution * of the job. */ char job[PBS_MAXCLTJOBID]; /* Job Id */ char server[MAXSERVERNAME]; /* Server name */ char *location = NULL; /* Where to run the job */ static char opts[] = "H:a"; /* See man getopt */ static char *usage = "Usage: qrun [-a] [-H vnode_specification ] job_identifier_list\n" " qrun [-a] [-H - ] job_identifier_list\n" " qrun --version\n"; int s; int errflg = 0; /*test for real deal or just version and exit*/ execution_mode(argc, argv); #ifdef WIN32 winsock_init(); #endif /* Command line options */ while ((s = getopt(argc, argv, opts)) != EOF) switch (s) { case 'H': if (strlen(optarg) == 0) { fprintf(stderr, "qrun: illegal -H value\n"); errflg++; break; } location = optarg; break; case 'a': async = 1; break; case '?': default: errflg++; break; } if (errflg || (optind >= argc)) { fprintf(stderr, usage); exit(1); } /*perform needed security library initializations (including none)*/ if (CS_client_init() != CS_SUCCESS) { fprintf(stderr, "qrun: unable to initialize security library.\n"); exit(2); } for (; optind < argc; optind++) { if (get_server(argv[optind], job, server)) { fprintf(stderr, "qrun: illegally formed job identifier: %s\n", argv[optind]); exitstatus = 1; continue; } execute(job, server, location); } /*cleanup security library initializations before exiting*/ CS_close_app(); exit(exitstatus); }
int main(int argc, char **argv, char **envp) /* qhold */ { int c; int errflg=0; int any_failed=0; char job_id[PBS_MAXCLTJOBID]; /* from the command line */ char job_id_out[PBS_MAXCLTJOBID]; char server_out[MAXSERVERNAME]; char rmt_server[MAXSERVERNAME]; struct ecl_attribute_errors *err_list; #define MAX_HOLD_TYPE_LEN 32 char hold_type[MAX_HOLD_TYPE_LEN+1]; #define GETOPT_ARGS "h:-:" /*test for real deal or just version and exit*/ execution_mode(argc, argv); #ifdef WIN32 winsock_init(); #endif hold_type[0]='\0'; while ((c = getopt(argc, argv, GETOPT_ARGS)) != EOF) switch (c) { case 'h': while (isspace((int)*optarg)) optarg++; if (optarg[0] == '\0') { fprintf(stderr, "qhold: illegal -h value\n"); errflg++; } else strcpy(hold_type, optarg); break; default : errflg++; } if (errflg || optind >= argc) { print_usage(); exit(2); } /*perform needed security library initializations (including none)*/ if (CS_client_init() != CS_SUCCESS) { fprintf(stderr, "qhold: unable to initialize security library.\n"); exit(2); } for (; optind < argc; optind++) { int connect; int stat=0; int located = FALSE; strcpy(job_id, argv[optind]); if (get_server(job_id, job_id_out, server_out)) { fprintf(stderr, "qhold: illegally formed job identifier: %s\n", job_id); any_failed = 1; continue; } cnt: connect = cnt2server(server_out); if (connect <= 0) { fprintf(stderr, "qhold: cannot connect to server %s (errno=%d)\n", pbs_server, pbs_errno); any_failed = pbs_errno; continue; } stat = pbs_holdjob(connect, job_id_out, hold_type, NULL); if (stat && (err_list = pbs_get_attributes_in_error(connect))) handle_attribute_errors(connect, err_list); if (stat && (pbs_errno != PBSE_UNKJOBID)) { prt_job_err("qhold", connect, job_id_out); any_failed = pbs_errno; } else if (stat && (pbs_errno == PBSE_UNKJOBID) && !located) { located = TRUE; if (locate_job(job_id_out, server_out, rmt_server)) { pbs_disconnect(connect); strcpy(server_out, rmt_server); goto cnt; } prt_job_err("qhold", connect, job_id_out); any_failed = pbs_errno; } pbs_disconnect(connect); } /*cleanup security library initializations before exiting*/ CS_close_app(); exit(any_failed); }
int main(int argc, char **argv, char **envp) /* pbs_release_nodes */ { int c; int errflg=0; int any_failed=0; char job_id[PBS_MAXCLTJOBID]; /* from the command line */ char job_id_out[PBS_MAXCLTJOBID]; char server_out[MAXSERVERNAME]; char rmt_server[MAXSERVERNAME]; int len; char *node_list = NULL; int connect; int stat=0; int k; int all_opt = 0; #define GETOPT_ARGS "j:a" /*test for real deal or just version and exit*/ execution_mode(argc, argv); #ifdef WIN32 winsock_init(); #endif job_id[0] = '\0'; while ((c = getopt(argc, argv, GETOPT_ARGS)) != EOF) { switch (c) { case 'j': strncpy(job_id, optarg, PBS_MAXCLTJOBID); job_id[PBS_MAXCLTJOBID-1] = '\0'; break; case 'a': all_opt = 1; break; default : errflg++; } } if (job_id[0] == '\0') { char *jid; jid = getenv("PBS_JOBID"); strncpy(job_id, jid?jid:"", PBS_MAXCLTJOBID); job_id[PBS_MAXCLTJOBID-1] = '\0'; } if (errflg || ((optind == argc) && !all_opt) || ((optind != argc) && all_opt) ) { fprintf(stderr, USAGE); fprintf(stderr, USAGE2); fprintf(stderr, USAGE3); exit(2); } if (job_id[0] == '\0') { fprintf(stderr, "pbs_release_nodes: No jobid given\n"); exit(2); } /*perform needed security library initializations (including none)*/ if (CS_client_init() != CS_SUCCESS) { fprintf(stderr, "pbs_release_nodes: unable to initialize security library.\n"); exit(2); } len = 0; for (k = optind; k < argc; k++) { len += (strlen(argv[k]) + 1); /* +1 for space */ } node_list = (char *)malloc(len + 1); if (node_list == NULL) { fprintf(stderr, "failed to malloc to store data (error %d)", errno); exit(2); } node_list[0] = '\0'; for (k = optind; k < argc; k++) { if (k != optind) strcat(node_list, "+"); strcat(node_list, argv[k]); } if (get_server(job_id, job_id_out, server_out)) { fprintf(stderr, "pbs_release_nodes: illegally formed job identifier: %s\n", job_id); free(node_list); exit(2); } pbs_errno = 0; stat = 0; while(1) { connect = cnt2server(server_out); if (connect <= 0) { fprintf(stderr, "pbs_release_nodes: cannot connect to server %s (errno=%d)\n", pbs_server, pbs_errno); break; } stat = pbs_relnodesjob(connect, job_id_out, node_list, NULL); if (stat && (pbs_errno == PBSE_UNKJOBID)) { if (locate_job(job_id_out, server_out, rmt_server)) { /* * job located at a different server * retry connect on the new server */ pbs_disconnect(connect); strcpy(server_out, rmt_server); } else { prt_job_err("pbs_release_nodes", connect, job_id_out); break; } } else { char *info_msg; if (stat && (pbs_errno != PBSE_UNKJOBID)) { prt_job_err("pbs_release_nodes", connect, ""); } else if ((info_msg = pbs_geterrmsg(connect)) != NULL) { /* print potential warning message */ printf("pbs_release_nodes: %s\n", info_msg); } break; } } any_failed = pbs_errno; pbs_disconnect(connect); /*cleanup security library initializations before exiting*/ CS_close_app(); exit(any_failed); }
int main(int argc, char **argv, char **envp) /* qselect */ { int c; int errflg=0; char *errmsg; #define MAX_OPTARG_LEN 256 #define MAX_RESOURCE_NAME_LEN 256 char optargout[MAX_OPTARG_LEN+1]; char resource_name[MAX_RESOURCE_NAME_LEN+1]; enum batch_op op; enum batch_op *pop = &op; struct attropl *select_list = 0; static char destination[PBS_MAXQUEUENAME+1] = ""; char server_out[MAXSERVERNAME] = ""; char *queue_name_out; char *server_name_out; int connect; char **selectjob_list; char *res_pos; char *pc; time_t after; char a_value[80]; char extendopts[4] = ""; char *attr_time = NULL; struct ecl_attribute_errors *err_list; char *resc_time = NULL; #define GETOPT_ARGS "a:A:c:h:HJl:N:p:q:r:s:t:Tu:xP:" /*test for real deal or just version and exit*/ execution_mode(argc, argv); #ifdef WIN32 winsock_init(); #endif while ((c = getopt(argc, argv, GETOPT_ARGS)) != EOF) switch (c) { case 'a': check_op(optarg, pop, optargout); if ((after = cvtdate(optargout)) < 0) { fprintf(stderr, "qselect: illegal -a value\n"); errflg++; break; } sprintf(a_value, "%ld", (long)after); set_attrop(&select_list, ATTR_a, NULL, a_value, op); break; case 'c': check_op(optarg, pop, optargout); pc = optargout; while (isspace((int)*pc)) pc++; if (strlen(pc) == 0) { fprintf(stderr, "qselect: illegal -c value\n"); errflg++; break; } set_attrop(&select_list, ATTR_c, NULL, optargout, op); break; case 'h': check_op(optarg, pop, optargout); pc = optargout; while (isspace((int)*pc)) pc++; set_attrop(&select_list, ATTR_h, NULL, optargout, op); break; case 'J': op = EQ; set_attrop(&select_list, ATTR_array, NULL, "True", op); break; case 'l': res_pos = optarg; while (*res_pos != '\0') { if (check_res_op(res_pos, resource_name, pop, optargout, &res_pos) != 0) { errflg++; break; } set_attrop(&select_list, ATTR_l, resource_name, optargout, op); } break; case 'p': check_op(optarg, pop, optargout); set_attrop(&select_list, ATTR_p, NULL, optargout, op); break; case 'q': strcpy(destination, optarg); check_op(optarg, pop, optargout); set_attrop(&select_list, ATTR_q, NULL, optargout, op); break; case 'r': op = EQ; pc = optarg; while (isspace((int)(*pc))) pc++; if (*pc != 'y' && *pc != 'n') { /* qselect specific check - stays */ fprintf(stderr, "qselect: illegal -r value\n"); errflg++; break; } set_attrop(&select_list, ATTR_r, NULL, pc, op); break; case 's': check_op(optarg, pop, optargout); pc = optargout; while (isspace((int)(*pc))) pc++; set_attrop(&select_list, ATTR_state, NULL, optargout, op); break; case 't': if (get_tsubopt(*optarg, &attr_time, &resc_time)) { fprintf(stderr, "qselect: illegal -t value\n"); errflg++; break; } /* 1st character possess the subopt, so send optarg++ */ optarg ++; check_op(optarg, pop, optargout); if ((after = cvtdate(optargout)) < 0) { fprintf(stderr, "qselect: illegal -t value\n"); errflg++; break; } sprintf(a_value, "%ld", (long)after); set_attrop(&select_list, attr_time, resc_time, a_value, op); break; case 'T': if (strchr(extendopts, (int)'T') == NULL) (void)strcat(extendopts, "T"); break; case 'x': if (strchr(extendopts, (int)'x') == NULL) (void)strcat(extendopts, "x"); break; case 'H': op = EQ; if (strchr(extendopts, (int)'x') == NULL) (void)strcat(extendopts, "x"); set_attrop(&select_list, ATTR_state, NULL, "FM", op); break; case 'u': op = EQ; set_attrop(&select_list, ATTR_u, NULL, optarg, op); break; case 'A': op = EQ; set_attrop(&select_list, ATTR_A, NULL, optarg, op); break; case 'P': op = EQ; set_attrop(&select_list, ATTR_project, NULL, optarg, op); break; case 'N': op = EQ; set_attrop(&select_list, ATTR_N, NULL, optarg, op); break; default : errflg++; } if (errflg || (optind < argc)) { print_usage(); exit(2); } if (notNULL(destination)) { if (parse_destination_id(destination, &queue_name_out, &server_name_out)) { fprintf(stderr, "qselect: illegally formed destination: %s\n", destination); exit(2); } else { if (notNULL(server_name_out)) { strcpy(server_out, server_name_out); } } } /*perform needed security library initializations (including none)*/ if (CS_client_init() != CS_SUCCESS) { fprintf(stderr, "qselect: unable to initialize security library.\n"); exit(2); } connect = cnt2server(server_out); if (connect <= 0) { fprintf(stderr, "qselect: cannot connect to server %s (errno=%d)\n", pbs_server, pbs_errno); /*cleanup security library initializations before exiting*/ CS_close_app(); exit(pbs_errno); } if (extendopts[0] == '\0') selectjob_list = pbs_selectjob(connect, select_list, NULL); else selectjob_list = pbs_selectjob(connect, select_list, extendopts); if (selectjob_list == NULL) { if ((err_list = pbs_get_attributes_in_error(connect))) handle_attribute_errors(err_list); if (pbs_errno != PBSE_NONE) { errmsg = pbs_geterrmsg(connect); if (errmsg != NULL) { fprintf(stderr, "qselect: %s\n", errmsg); } else { fprintf(stderr, "qselect: Error (%d) selecting jobs\n", pbs_errno); } /* * If the server is not configured for history jobs i.e. * job_history_enable svr attr is unset/set to FALSE, qselect * command with -x/-H option is being used, then pbs_selectjob() * will return PBSE_JOBHISTNOTSET error code. But command will * exit with exit code '0'after printing the corresponding error * message. i.e. "job_history_enable is set to false" */ if (pbs_errno == PBSE_JOBHISTNOTSET) pbs_errno = 0; /*cleanup security library initializations before exiting*/ CS_close_app(); exit(pbs_errno); } } else { /* got some jobs ids */ int i = 0; while (selectjob_list[i] != NULL) { printf("%s\n", selectjob_list[i++]); } free(selectjob_list); } pbs_disconnect(connect); /*cleanup security library initializations before exiting*/ CS_close_app(); exit(0); }
/** * @brief * handles attribute errors and prints appropriate errmsg * * @param[in] err_list - list of possible attribute errors * * @return - Void * */ static void handle_attribute_errors(struct ecl_attribute_errors *err_list) { struct attropl *attribute; char * opt; int i; for (i = 0; i < err_list->ecl_numerrors; i++) { attribute = err_list->ecl_attrerr[i].ecl_attribute; if (strcmp(attribute->name, ATTR_a) == 0) opt = "a"; else if (strcmp(attribute->name, ATTR_project) == 0) opt = "P"; else if (strcmp(attribute->name, ATTR_A) == 0) opt = "A"; else if (strcmp(attribute->name, ATTR_c) == 0) opt = "c"; else if (strcmp(attribute->name, ATTR_h) == 0) opt = "h"; else if (strcmp(attribute->name, ATTR_array) == 0) opt = "J"; else if (strcmp(attribute->name, ATTR_l) == 0) { opt = "l"; fprintf(stderr, "qselect: %s\n", err_list->ecl_attrerr[i].ecl_errmsg); exit(err_list->ecl_attrerr[i].ecl_errcode); } else if (strcmp(attribute->name, ATTR_N) == 0) opt = "N"; else if (strcmp(attribute->name, ATTR_p) == 0) { opt = "p"; fprintf(stderr, "qselect: %s\n", err_list->ecl_attrerr[i].ecl_errmsg); exit(err_list->ecl_attrerr[i].ecl_errcode); } else if (strcmp(attribute->name, ATTR_q) == 0) opt = "q"; else if (strcmp(attribute->name, ATTR_r) == 0) opt = "r"; else if (strcmp(attribute->name, ATTR_state) == 0) opt = "s"; else if (strcmp(attribute->name, ATTR_ctime) == 0) opt = "t"; else if (strcmp(attribute->name, ATTR_etime) == 0) opt = "t"; else if (strcmp(attribute->name, ATTR_eligible_time) == 0) opt = "t"; else if (strcmp(attribute->name, ATTR_mtime) == 0) opt = "t"; else if (strcmp(attribute->name, ATTR_qtime) == 0) opt = "t"; else if (strcmp(attribute->name, ATTR_stime) == 0) opt = "t"; else if (strcmp(attribute->name, ATTR_u) == 0) opt = "u"; else return; fprintf(stderr, "qselect: illegal -%s value\n", opt); print_usage(); /*cleanup security library initializations before exiting*/ CS_close_app(); exit(2); } }
/** * @brief * handles attribute errors and prints appropriate errmsg * * @param[in] connect - value indicating server connection * @param[in] err_list - list of possible attribute errors * @param[in] id - corresponding id(string) for attribute error * * @return - Void * */ static void handle_attribute_errors(int connect, struct ecl_attribute_errors *err_list, char *id) { struct attropl *attribute; char * opt; int i; for (i=0; i<err_list->ecl_numerrors; i++) { attribute = err_list->ecl_attrerr[i].ecl_attribute; if (strcmp(attribute->name, ATTR_a) == 0) opt="a"; else if (strcmp(attribute->name, ATTR_A) == 0) opt="A"; else if (strcmp(attribute->name, ATTR_project) == 0) opt = "P"; else if (strcmp(attribute->name, ATTR_c) == 0) opt="c"; else if (strcmp(attribute->name, ATTR_e) == 0) opt="e"; else if (strcmp(attribute->name, ATTR_h) == 0) opt="h"; else if (strcmp(attribute->name, ATTR_j)==0) opt="j"; else if (strcmp(attribute->name, ATTR_k)==0) opt="k"; else if (strcmp(attribute->name, ATTR_l)==0) { opt="l"; fprintf(stderr, "qalter: %s %s\n", err_list->ecl_attrerr[i].ecl_errmsg, id); exit(err_list->ecl_attrerr[i].ecl_errcode); } else if (strcmp(attribute->name, ATTR_m)==0) opt="m"; else if (strcmp(attribute->name, ATTR_M)==0) opt="M"; else if (strcmp(attribute->name, ATTR_N)==0) opt="N"; else if (strcmp(attribute->name, ATTR_o)==0) opt="o"; else if (strcmp(attribute->name, ATTR_p)==0) opt="p"; else if (strcmp(attribute->name, ATTR_r)==0) opt="r"; else if (strcmp(attribute->name, ATTR_R)==0) opt="R"; else if (strcmp(attribute->name, ATTR_S)==0) opt="S"; else if (strcmp(attribute->name, ATTR_u)==0) opt="u"; else if ((strcmp(attribute->name, ATTR_depend)==0) || (strcmp(attribute->name, ATTR_stagein)==0) || (strcmp(attribute->name, ATTR_stageout)==0) || (strcmp(attribute->name, ATTR_sandbox)==0) || (strcmp(attribute->name, ATTR_umask) == 0) || (strcmp(attribute->name, ATTR_runcount) == 0) || (strcmp(attribute->name, ATTR_g)==0)) opt="W"; else return; pbs_disconnect(connect); CS_close_app(); if (err_list->ecl_attrerr->ecl_errcode == PBSE_JOBNBIG) fprintf(stderr, "qalter: Job %s \n", err_list->ecl_attrerr->ecl_errmsg); else { fprintf(stderr, "qalter: illegal -%s value\n", opt); print_usage(); } exit(2); } }
int main(int argc, char **argv, char **envp) /* qalter */ { int c; int errflg=0; int any_failed=0; char *pc; int i; struct attrl *attrib = NULL; char *keyword; char *valuewd; char *erplace; time_t after; char a_value[80]; char job_id[PBS_MAXCLTJOBID]; char job_id_out[PBS_MAXCLTJOBID]; char server_out[MAXSERVERNAME]; char rmt_server[MAXSERVERNAME]; struct ecl_attribute_errors *err_list; #ifdef WIN32 struct attrl *ap = NULL; short int nSizeofHostName = 0; char* orig_apvalue = NULL; char* temp_apvalue = NULL; #endif #define GETOPT_ARGS "a:A:c:e:h:j:k:l:m:M:N:o:p:r:R:S:u:W:P:" /*test for real deal or just version and exit*/ execution_mode(argc, argv); #ifdef WIN32 winsock_init(); #endif while ((c = getopt(argc, argv, GETOPT_ARGS)) != EOF) switch (c) { case 'a': if ((after = cvtdate(optarg)) < 0) { fprintf(stderr, "qalter: illegal -a value\n"); errflg++; break; } sprintf(a_value, "%ld", (long)after); set_attr(&attrib, ATTR_a, a_value); break; case 'A': set_attr(&attrib, ATTR_A, optarg); break; case 'P': set_attr(&attrib, ATTR_project, optarg); break; case 'c': while (isspace((int)*optarg)) optarg++; pc = optarg; if ((pc[0] == 'u') && (pc[1] == '\0')) { fprintf(stderr, "qalter: illegal -c value\n"); errflg++; break; } set_attr(&attrib, ATTR_c, optarg); break; case 'e': set_attr(&attrib, ATTR_e, optarg); break; case 'h': while (isspace((int)*optarg)) optarg++; set_attr(&attrib, ATTR_h, optarg); break; case 'j': set_attr(&attrib, ATTR_j, optarg); break; case 'k': set_attr(&attrib, ATTR_k, optarg); break; case 'l': if ((i = set_resources(&attrib, optarg, TRUE, &erplace)) != 0) { if (i > 1) { pbs_prt_parse_err("qalter: illegal -l value\n", optarg, erplace-optarg, i); } else fprintf(stderr, "qalter: illegal -l value\n"); errflg++; } break; case 'm': while (isspace((int)*optarg)) optarg++; set_attr(&attrib, ATTR_m, optarg); break; case 'M': set_attr(&attrib, ATTR_M, optarg); break; case 'N': set_attr(&attrib, ATTR_N, optarg); break; case 'o': set_attr(&attrib, ATTR_o, optarg); break; case 'p': while (isspace((int)*optarg)) optarg++; set_attr(&attrib, ATTR_p, optarg); break; case 'r': if (strlen(optarg) != 1) { fprintf(stderr, "qalter: illegal -r value\n"); errflg++; break; } if (*optarg != 'y' && *optarg != 'n') { fprintf(stderr, "qalter: illegal -r value\n"); errflg++; break; } set_attr(&attrib, ATTR_r, optarg); break; case 'R': set_attr(&attrib, ATTR_R, optarg); break; case 'S': set_attr(&attrib, ATTR_S, optarg); break; case 'u': set_attr(&attrib, ATTR_u, optarg); break; case 'W': while (isspace((int)*optarg)) optarg++; if (strlen(optarg) == 0) { fprintf(stderr, "qalter: illegal -W value\n"); errflg++; break; } #ifdef WIN32 back2forward_slash2(optarg); #endif i = parse_equal_string(optarg, &keyword, &valuewd); while (i == 1) { set_attr(&attrib, keyword, valuewd); i = parse_equal_string(NULL, &keyword, &valuewd); } if (i == -1) { fprintf(stderr, "qalter: illegal -W value\n"); errflg++; } break; case '?': default : errflg++; break; } if (errflg || optind == argc) { print_usage(); exit(2); } /*perform needed security library initializations (including none)*/ if (CS_client_init() != CS_SUCCESS) { fprintf(stderr, "qalter: unable to initialize security library.\n"); exit(1); } for (; optind < argc; optind++) { int connect; int stat=0; int located = FALSE; strcpy(job_id, argv[optind]); if (get_server(job_id, job_id_out, server_out)) { fprintf(stderr, "qalter: illegally formed job identifier: %s\n", job_id); any_failed = 1; continue; } cnt: connect = cnt2server(server_out); if (connect <= 0) { fprintf(stderr, "qalter: cannot connect to server %s (errno=%d)\n", pbs_server, pbs_errno); any_failed = pbs_errno; continue; } stat = pbs_alterjob(connect, job_id_out, attrib, NULL); if (stat && (pbs_errno != PBSE_UNKJOBID)) { if ((err_list = pbs_get_attributes_in_error(connect))) handle_attribute_errors(connect, err_list, job_id_out); prt_job_err("qalter", connect, job_id_out); any_failed = pbs_errno; } else if (stat && (pbs_errno == PBSE_UNKJOBID) && !located) { located = TRUE; if (locate_job(job_id_out, server_out, rmt_server)) { pbs_disconnect(connect); strcpy(server_out, rmt_server); goto cnt; } prt_job_err("qalter", connect, job_id_out); any_failed = pbs_errno; } pbs_disconnect(connect); } CS_close_app(); exit(any_failed); }
/** * @brief * The main function in C - entry point * * @param[in] argc - argument count * @param[in] argv - pointer to argument array * @param[in] envp - pointer to environment values * * @return int * @retval 0 - success * @retval !0 - error */ int main(int argc, char *argv[], char *envp[]) { int errflg; /* command line option error */ int connect; /* return from pbs_connect */ char *errmsg; /* return from pbs_geterrmsg */ char destbuf[256]; /* buffer for option server */ struct attrl *attrib; /* the attrib list */ char *new_resvname; /* the name returned from pbs_submit_resv */ struct ecl_attribute_errors *err_list; char *interactive = NULL; /*test for real deal or just version and exit*/ execution_mode(argc, argv); #ifdef WIN32 winsock_init(); #endif destbuf[0] = '\0'; errflg = process_opts(argc, argv, &attrib, destbuf); /* get cmdline options */ if (errflg || ((optind+1) < argc) || argc == 1) { print_usage(); exit(2); } /* Get any required environment variables needing to be sent. */ if (! set_resv_env(envp)) { fprintf(stderr, "pbs_rsub: can't send environment with the reservation\n"); exit(3); } /*perform needed security library initializations (including none)*/ if (CS_client_init() != CS_SUCCESS) { fprintf(stderr, "pbs_rsub: unable to initialize security library.\n"); exit(1); } /* Connect to the server */ connect = cnt2server(destbuf); if (connect <= 0) { fprintf(stderr, "pbs_rsub: cannot connect to server %s (errno=%d)\n", pbs_server, pbs_errno); CS_close_app(); exit(pbs_errno); } if (qmoveflg == TRUE) { qmoveflg = FALSE; interactive = get_attr(attrib, ATTR_inter, NULL); if (interactive == NULL) { set_attr(&attrib, ATTR_inter, DEFAULT_INTERACTIVE); } else { if (atoi(interactive) > -1) { fprintf(stderr, "pbs_rsub: -I <timeout> value must be negative when used with -Wqmove option.\n"); CS_close_app(); exit(2); } } errflg = cnvrt_proc_attrib(connect, &attrib, destbuf); if (errflg) { fprintf(stderr, "pbs_rsub: can't make a reservation with the qmove option\n"); CS_close_app(); exit(2); } } pbs_errno = 0; new_resvname = pbs_submit_resv(connect, (struct attropl *)attrib, NULL); if (new_resvname == NULL) { if ((err_list = pbs_get_attributes_in_error(connect))) handle_attribute_errors(err_list); errmsg = pbs_geterrmsg(connect); if (errmsg != NULL) { fprintf(stderr, "pbs_rsub: %s\n", errmsg); } else fprintf(stderr, "pbs_rsub: Error (%d) submitting reservation\n", pbs_errno); CS_close_app(); exit(pbs_errno); } else { printf("%s\n", new_resvname); free(new_resvname); } /* Disconnet from the server. */ pbs_disconnect(connect); CS_close_app(); exit(0); }
int main(int argc, char **argv, char **envp) /* qmsg */ { int c; int to_file; int errflg=0; int any_failed=0; char job_id[PBS_MAXCLTJOBID]; /* from the command line */ char job_id_out[PBS_MAXCLTJOBID]; char server_out[MAXSERVERNAME]; char rmt_server[MAXSERVERNAME]; #define MAX_MSG_STRING_LEN 256 char msg_string[MAX_MSG_STRING_LEN+1]; #define GETOPT_ARGS "EO" /*test for real deal or just version and exit*/ execution_mode(argc, argv); #ifdef WIN32 winsock_init(); #endif msg_string[0]='\0'; to_file = 0; while ((c = getopt(argc, argv, GETOPT_ARGS)) != EOF) switch (c) { case 'E': to_file |= MSG_ERR; break; case 'O': to_file |= MSG_OUT; break; default : errflg++; } if (to_file == 0) to_file = MSG_ERR; /* default */ if (errflg || ((optind+1) >= argc)) { static char usage[]= "usage: qmsg [-O] [-E] msg_string job_identifier...\n"; static char usag2[]= " qmsg --version\n"; fprintf(stderr, "%s", usage); fprintf(stderr, "%s", usag2); exit(2); } strcpy(msg_string, argv[optind]); /*perform needed security library initializations (including none)*/ if (CS_client_init() != CS_SUCCESS) { fprintf(stderr, "qmsg: unable to initialize security library.\n"); exit(2); } for (optind++; optind < argc; optind++) { int connect; int stat=0; int located = FALSE; strcpy(job_id, argv[optind]); if (get_server(job_id, job_id_out, server_out)) { fprintf(stderr, "qmsg: illegally formed job identifier: %s\n", job_id); any_failed = 1; continue; } cnt: connect = cnt2server(server_out); if (connect <= 0) { fprintf(stderr, "qmsg: cannot connect to server %s (errno=%d)\n", pbs_server, pbs_errno); any_failed = pbs_errno; continue; } stat = pbs_msgjob(connect, job_id_out, to_file, msg_string, NULL); if (stat && (pbs_errno != PBSE_UNKJOBID)) { prt_job_err("qmsg", connect, job_id_out); any_failed = pbs_errno; } else if (stat && (pbs_errno == PBSE_UNKJOBID) && !located) { located = TRUE; if (locate_job(job_id_out, server_out, rmt_server)) { pbs_disconnect(connect); strcpy(server_out, rmt_server); goto cnt; } prt_job_err("qmsg", connect, job_id_out); any_failed = pbs_errno; } pbs_disconnect(connect); } /*cleanup security library initializations before exiting*/ CS_close_app(); exit(any_failed); }
int main(int argc, char **argv, char **envp) { char job_id1[PBS_MAXCLTJOBID+1]; /* from the command line */ char job_id2[PBS_MAXCLTJOBID+1]; /* from the command line */ char job_id1_out[PBS_MAXCLTJOBID+1]; char job_id2_out[PBS_MAXCLTJOBID+1]; char *pn; int port1 = 0; int port2 = 0; char server_out1[MAXSERVERNAME+1]; char server_out2[MAXSERVERNAME+1]; char svrtmp[MAXSERVERNAME+1]; int connect; int stat=0; int rc = 0; extern char *PBS_get_server(); /*test for real deal or just version and exit*/ PRINT_VERSION_AND_EXIT(argc, argv); #ifdef WIN32 if (winsock_init()) { return 1; } #endif if (argc != 3) { static char usage[]="usage: qorder job_identifier job_identifier\n"; static char usag2[]=" qorder --version\n"; fprintf(stderr, "%s", usage); fprintf(stderr, "%s", usag2); exit(2); } strcpy(job_id1, argv[1]); strcpy(job_id2, argv[2]); svrtmp[0] = '\0'; if (get_server(job_id1, job_id1_out, svrtmp)) { fprintf(stderr, "qorder: illegally formed job identifier: %s\n", job_id1); exit(1); } if (*svrtmp == '\0') { if ((pn = pbs_default()) != NULL) { (void)strcpy(svrtmp, pn); } else { fprintf(stderr, "qorder: could not get default server: %s\n", job_id1); exit(1); } } if ((pn = strchr(svrtmp, (int)':')) != 0) { *pn = '\0'; port1 = atoi(pn+1); } if (get_fullhostname(svrtmp, server_out1, MAXSERVERNAME) != 0) { fprintf(stderr, "qorder: invalid server name: %s\n", job_id1); exit(1); } svrtmp[0] = '\0'; if (get_server(job_id2, job_id2_out, svrtmp)) { fprintf(stderr, "qorder: illegally formed job identifier: %s\n", job_id2); exit(1); } if (*svrtmp == '\0') { if ((pn = pbs_default()) != NULL) { (void)strcpy(svrtmp, pn); } else { fprintf(stderr, "qorder: could not get default server: %s\n", job_id1); exit(1); } } if ((pn = strchr(svrtmp, (int)':')) != 0) { *pn = '\0'; port2 = atoi(pn+1); } if (get_fullhostname(svrtmp, server_out2, MAXSERVERNAME) != 0) { fprintf(stderr, "qorder: invalid server name: %s\n", job_id2); exit(1); } if ((strcmp(server_out1, server_out2) != 0) || (port1 != port2)) { fprintf(stderr, "qorder: both jobs ids must specify the same server\n"); exit(1); } if (pn) *pn = ':'; /* restore : if it was present */ /*perform needed security library initializations (including none)*/ if (CS_client_init() != CS_SUCCESS) { fprintf(stderr, "qorder: unable to initialize security library.\n"); exit(1); } connect = cnt2server(svrtmp); if (connect <= 0) { fprintf(stderr, "qorder: cannot connect to server %s (errno=%d)\n", pbs_server, pbs_errno); exit(1);; } stat = pbs_orderjob(connect, job_id1_out, job_id2_out, NULL); if (stat) { char job_id_both[PBS_MAXCLTJOBID + PBS_MAXCLTJOBID + 3]; strcpy(job_id_both, job_id1_out); strcat(job_id_both, " or "); strcat(job_id_both, job_id2_out); prt_job_err("qorder", connect, job_id_both); rc = pbs_errno; } pbs_disconnect(connect); /*cleanup security library initializations before exiting*/ CS_close_app(); exit(rc); }
int main(int argc, char **argv, char **envp) /* qmove */ { int any_failed=0; char job_id[PBS_MAXCLTJOBID]; /* from the command line */ char destination[PBS_MAXSERVERNAME]; /* from the command line */ char *q_n_out, *s_n_out; char job_id_out[PBS_MAXCLTJOBID]; char server_out[MAXSERVERNAME]; char rmt_server[MAXSERVERNAME]; /*test for real deal or just version and exit*/ execution_mode(argc, argv); #ifdef WIN32 winsock_init(); #endif if (argc < 3) { static char usage[]="usage: qmove destination job_identifier...\n"; static char usag2[]=" qmove --version\n"; fprintf(stderr, usage); fprintf(stderr, usag2); exit(2); } strcpy(destination, argv[1]); if (parse_destination_id(destination, &q_n_out, &s_n_out)) { fprintf(stderr, "qmove: illegally formed destination: %s\n", destination); exit(2); } /*perform needed security library initializations (including none)*/ if (CS_client_init() != CS_SUCCESS) { fprintf(stderr, "qmove: unable to initialize security library.\n"); exit(2); } for (optind = 2; optind < argc; optind++) { int connect; int stat=0; int located = FALSE; strcpy(job_id, argv[optind]); if (get_server(job_id, job_id_out, server_out)) { fprintf(stderr, "qmove: illegally formed job identifier: %s\n", job_id); any_failed = 1; continue; } cnt: connect = cnt2server(server_out); if (connect <= 0) { fprintf(stderr, "qmove: cannot connect to server %s (errno=%d)\n", pbs_server, pbs_errno); any_failed = pbs_errno; continue; } stat = pbs_movejob(connect, job_id_out, destination, NULL); if (stat && (pbs_errno != PBSE_UNKJOBID)) { if (stat != PBSE_NEEDQUET) { prt_job_err("qmove", connect, job_id_out); any_failed = pbs_errno; } else { fprintf(stderr, "qmove: Queue type not set for queue \'%s\'\n", destination); } } else if (stat && (pbs_errno == PBSE_UNKJOBID) && !located) { located = TRUE; if (locate_job(job_id_out, server_out, rmt_server)) { pbs_disconnect(connect); strcpy(server_out, rmt_server); goto cnt; } prt_job_err("qmove", connect, job_id_out); any_failed = pbs_errno; } pbs_disconnect(connect); } /*cleanup security library initializations before exiting*/ CS_close_app(); exit(any_failed); }