int load_config( char **ip, int *t_port, int *d_port) { int rc = PBSE_NONE; char *tmp_name = pbs_default(); /* Assume TORQUE_HOME = /var/spool/torque */ /* /var/spool/torque/server_name */ if (tmp_name == NULL) rc = PBSE_BADHOST; else { /* Currently this only display's the port for the trq server * from the lib_ifl.h file or server_name file (The same way * the client utilities determine the pbs_server port) */ printf("hostname: %s\n", tmp_name); *ip = tmp_name; PBS_get_server(tmp_name, (unsigned int *)t_port); if (*t_port == 0) *t_port = PBS_BATCH_SERVICE_PORT; *d_port = TRQ_AUTHD_SERVICE_PORT; } return rc; }
int TShowAbout_exit(void) { char *dserver; char *servervar; char tmpLine[1024]; dserver = pbs_default(); servervar = getenv("PBS_DEFAULT"); strcpy(tmpLine, PBS_DEFAULT_FILE); tmpLine[strlen(tmpLine) - strlen("/pbs_server") - 1] = '\0'; fprintf(stderr, "HomeDir: %s InstallDir: %s Server: %s%s\n", tmpLine, PBS_INSTALL_DIR, dserver, (servervar != NULL) ? " (PBS_DEFAULT is set)" : ""); fprintf(stderr, "BuildDir: %s\n", PBS_SOURCE_DIR); fprintf(stderr, "BuildUser: %s\n", PBS_BUILD_USER); fprintf(stderr, "BuildHost: %s\n", PBS_BUILD_HOST); fprintf(stderr, "BuildDate: %s\n", PBS_BUILD_DATE); fprintf(stderr, "Version: %s\n", PACKAGE_VERSION); exit(0); } /* END TShowAbout_exit() */
void get_port_from_server_name_file(unsigned int *server_name_file_port) { char *the_server = pbs_default(); if (the_server != NULL) { PBS_get_server(the_server, server_name_file_port); } }
char *PBS_get_server( const char *server, /* I (NULL|'\0' for not set,modified) */ unsigned int *port) /* O */ { int i; char *pc; for (i = 0;i < PBS_MAXSERVERNAME + 1;i++) { /* clear global server_name */ server_name[i] = '\0'; } if (dflt_port == 0) { dflt_port = get_svrport( (char *)PBS_BATCH_SERVICE_NAME, (char *)"tcp", PBS_BATCH_SERVICE_PORT); } /* first, get the "net.address[:port]" into 'server_name' */ if ((server == (char *)NULL) || (*server == '\0')) { if (pbs_default() == NULL) { return(NULL); } } else { snprintf(server_name, sizeof(server_name), "%s", server); } /* now parse out the parts from 'server_name' */ if ((pc = strchr(server_name, (int)':'))) { /* got a port number */ *pc++ = '\0'; *port = atoi(pc); } else { *port = dflt_port; } return(server_name); } /* END PBS_get_server() */
/* Get the name of the active pbs_server */ int load_trqauthd_config( char **default_server_name, int *t_port, char **trqauthd_unix_domain_port) { int rc = PBSE_NONE; char *tmp_name = NULL; int unix_domain_len; tmp_name = pbs_default(); if ((tmp_name == NULL) || (tmp_name[0] == '\0')) rc = PBSE_BADHOST; else { /* Currently this only display's the port for the trq server * from the lib_ifl.h file or server_name file (The same way * the client utilities determine the pbs_server port) */ printf("hostname: %s\n", tmp_name); *default_server_name = tmp_name; PBS_get_server(tmp_name, (unsigned int *)t_port); if (*t_port == 0) *t_port = PBS_BATCH_SERVICE_PORT; unix_domain_len = strlen(TRQAUTHD_SOCK_DIR); unix_domain_len += strlen(TRQAUTHD_SOCK_NAME) + 2; /* on for the "/" and one for zero termination*/ *trqauthd_unix_domain_port = (char *)malloc(unix_domain_len); if (*trqauthd_unix_domain_port == NULL) { fprintf(stderr, "could not allocate memory for unix domain port"); return(PBSE_MEM_MALLOC); } strcpy(*trqauthd_unix_domain_port, TRQAUTHD_SOCK_DIR); strcat(*trqauthd_unix_domain_port, "/"); strcat(*trqauthd_unix_domain_port, TRQAUTHD_SOCK_NAME); set_active_pbs_server(tmp_name, *t_port); } return rc; }
/** * @brief * -returns the server name. * * @param[in] server - server name * @param[out] server_name - server name * @param[in] port - port number * * @return string * @retval servr name success * */ static char * PBS_get_server(char *server, char *server_name, unsigned int *port) { int i; char *pc; unsigned int dflt_port = 0; char *p; for (i=0;i<PBS_MAXSERVERNAME+1;i++) server_name[i] = '\0'; if (dflt_port == 0) dflt_port = pbs_conf.batch_service_port; /* first, get the "net.address[:port]" into 'server_name' */ if ((server == NULL) || (*server == '\0')) { if ((p=pbs_default()) == NULL) return NULL; strcpy(server_name, p); } else { strncpy(server_name, server, PBS_MAXSERVERNAME); } /* now parse out the parts from 'server_name' */ if ((pc = strchr(server_name, (int)':')) != NULL) { /* got a port number */ *pc++ = '\0'; *port = atoi(pc); } else { *port = dflt_port; } return server_name; }
int main( int ArgC, /* I */ char **ArgV) /* I */ { const char *OptString = "c:Cd:f:h:lp:q:r:sv"; char HostList[65536]; char *HPtr; int c; int rc = PBSE_NONE; int local_errno = 0; int HostCount; int FailCount; /* initialize */ HostList[0] = '\0'; ConfigBuf[0] = '\0'; if (IamRoot() == 0) { exit(EXIT_FAILURE); } while ((c = getopt(ArgC, ArgV, OptString)) != EOF) { switch (c) { case 'c': /* clear job */ JPtr = optarg; CmdIndex = momClear; break; case 'C': /* force cycle */ CmdIndex = momQuery; Query[QueryI] = strdup("cycle"); QueryI++; break; case 'd': /* diagnose */ /* FORMAT: momctl -d<X> */ CmdIndex = momQuery; if ((Query[QueryI] = (char *)calloc(strlen(DiagPtr) + 3, sizeof(char))) == NULL) { fprintf(stderr,"ERROR: could not calloc %d bytes!\n", (int)strlen(DiagPtr) + 3); exit(EXIT_FAILURE); } if (optarg == NULL) { strncpy(Query[QueryI],DiagPtr,strlen(DiagPtr)); } else { snprintf(Query[QueryI],strlen(DiagPtr) + 2,"%s%s", DiagPtr, optarg); } QueryI++; break; case 'f': { int rc; FILE *fp; long size; if ((fp = fopen(optarg, "r")) == NULL) { fprintf(stderr, "ERROR: cannot open file '%s', errno: %d (%s)\n", optarg, errno, strerror(errno)); exit(EXIT_FAILURE); } rc = fread(HostList, sizeof(HostList), 1, fp); if ((rc == 0) && (!feof(fp))) { fprintf(stderr, "ERROR: cannot read file '%s', errno: %d (%s)\n", optarg, errno, strerror(errno)); exit(EXIT_FAILURE); } if ((size = ftell(fp)) < 0) size = 0; HostList[MIN(size,(long)sizeof(HostList) - 1)] = '\0'; fclose(fp); } /* END BLOCK */ break; case 'h': /* connect to specified host */ snprintf(HostList, sizeof(HostList), "%s", optarg); break; case 'l': CmdIndex = momLayout; break; case 'p': /* port */ if (optarg == NULL) MCShowUsage("port not specified"); MOMPort = (int)strtol(optarg, NULL, 10); if (MOMPort == 0) MCShowUsage("invalid port specified"); break; case 'q': /* query resources */ if (optarg == NULL) { MCShowUsage("query not specified"); Query[QueryI] = strdup(DiagPtr); } else { Query[QueryI] = strdup(optarg); } QueryI++; CmdIndex = momQuery; break; case 'r': /* reconfigure */ { CmdIndex = momReconfig; /* NOTE: specify remote file to load -> 'fname' */ /* specify local file to stage -> 'LOCAL:fname' */ if (optarg == NULL) MCShowUsage("file not specified"); if (!strncmp(optarg, "LOCAL:", strlen("LOCAL:"))) { FILE *fp; int size; int rc; char *ptr; char *cptr; strcpy(ConfigBuf, "CONFIG:"); cptr = ConfigBuf + strlen(ConfigBuf); ptr = optarg + strlen("LOCAL:"); if ((fp = fopen(ptr, "r")) == NULL) { fprintf(stderr, "ERROR: cannot open file '%s', errno: %d (%s)\n", optarg, errno, strerror(errno)); exit(EXIT_FAILURE); } rc = fread(cptr, sizeof(ConfigBuf) - strlen(ConfigBuf), 1, fp); if ((rc == 0) && (!feof(fp))) { fprintf(stderr, "ERROR: cannot read file '%s', errno: %d (%s)\n", optarg, errno, strerror(errno)); exit(EXIT_FAILURE); } size = ftell(fp); ConfigBuf[MIN(size + strlen("CONFIG:"),sizeof(ConfigBuf) - 1)] = '\0'; fclose(fp); } else { snprintf(ConfigBuf, sizeof(ConfigBuf), "%s", optarg); } } /* END (case 'r') */ break; case 's': /* shutdown */ CmdIndex = momShutdown; break; case 'v': /* report verbose logging */ IsVerbose = TRUE; break; } /* END switch (c) */ } /* END while (c = getopt()) */ if (CmdIndex == momNONE) { MCShowUsage("no command specified"); } if (HostList[0] == '\0') snprintf(HostList, sizeof(HostList), "%s", LocalHost); HPtr = strtok(HostList, ", \t\n"); HostCount = 0; FailCount = 0; /* at this point, all args processing and setup is completed ... * ... now we run through each comma-delimited word in HPtr */ while (HPtr != NULL) { if ((*HPtr == ':') && (*(HPtr + 1) != '\0')) { /* finds nodes with this property */ int con; char *def_server, *pserver, *servername; struct batch_status *bstatus, *pbstat; struct attrl *nodeattrs; def_server = pbs_default(); if ((pserver = strchr(HPtr,'@')) != NULL) { *pserver = '\0'; servername = pserver + 1; } else { servername = def_server; } con = pbs_connect(servername); if (con < 0) { fprintf(stderr,"failed to connect to pbs_server:%s\n", servername); exit(EXIT_FAILURE); } /* get a batch_status entry for each node in ":property" */ bstatus = pbs_statnode_err(con,HPtr,NULL,NULL, &local_errno); if (bstatus != NULL) { for (pbstat = bstatus;pbstat != NULL;pbstat = pbstat->next) { /* check state first, only do_mom() if not down */ for (nodeattrs = pbstat->attribs;nodeattrs != NULL; nodeattrs = nodeattrs->next) { if (!strcmp(nodeattrs->name, ATTR_NODE_state)) { if (!strstr(nodeattrs->value, ND_down)) { if ((rc = perform_communications_with_retry(pbstat->name, MOMPort, &FailCount)) == PBSE_NONE) HostCount++; } else { fprintf(stderr,"%12s: skipping down node\n", pbstat->name); } break; } /* END if (attrib name eq state) */ } /* END for (nodeattrs) */ } /* END for (pbstat) */ pbs_statfree(bstatus); } /* END if (bstatus != NULL) */ else { fprintf(stderr,"no nodes found in %s on %s\n", HPtr, servername); } pbs_disconnect(con); if (pserver != NULL) *pserver = '@'; } else { if ((rc = perform_communications_with_retry(HPtr, MOMPort, &FailCount)) == PBSE_NONE) HostCount++; } /* END if (*HPtr == ':') */ HPtr = strtok(NULL, ", \t\n"); } /* END while (HPtr != NULL) */ if (IsVerbose == TRUE) { fprintf(stdout, "Node Summary: %d Successful %d Failed\n", HostCount, FailCount); } /* test success of do_mom before returning success */ if (rc != PBSE_NONE) exit(EXIT_FAILURE); /* SUCCESS */ exit(EXIT_SUCCESS); } /* END main() */
int main( int argc, /* I */ char **argv) /* I */ { struct batch_status *bstatus = NULL; int con; char *specified_server = NULL; int errflg = 0; int i; extern char *optarg; extern int optind; char **pa; struct batch_status *pbstat; int flag = ALLI; char *note = NULL; enum note_flags note_flag = unused; char **nodeargs = NULL; int lindex; enum NStateEnum ListType = tnsNONE; /* get default server, may be changed by -s option */ progname = strdup(argv[0]); while ((i = getopt(argc, argv, "acdlopqrs:x-:N:n")) != EOF) { switch (i) { case 'a': flag = ALLI; break; case 'c': flag = CLEAR; break; case 'd': flag = DIAG; break; case 'l': flag = LIST; break; case 'o': flag = OFFLINE; break; case 'p': flag = PURGE; break; case 'q': quiet = 1; break; case 'r': flag = RESET; break; case 's': specified_server = optarg; break; case 'x': flag = ALLI; DisplayXML = TRUE; break; case 'N': /* preserve any previous option other than the default, * to allow -N to be combined with -o, -c, etc */ if (flag == ALLI) flag = NOTE; note = strdup(optarg); if (note == NULL) { perror("Error: strdup() returned NULL"); exit(1); } note_flag = set; /* -N n is the same as -N "" -- it clears the note */ if (!strcmp(note, "n")) *note = '\0'; if (strlen(note) > MAX_NOTE) { fprintf(stderr, "Warning: note exceeds length limit (%d) - server may reject it...\n", MAX_NOTE); } if (strchr(note, '\n') != NULL) fprintf(stderr, "Warning: note contains a newline - server may reject it...\n"); break; case 'n': note_flag = list; break; case '-': if ((optarg != NULL) && !strcmp(optarg, "version")) { fprintf(stderr, "Version: %s\nRevision: %s\n", PACKAGE_VERSION, SVN_VERSION); exit(0); } else if ((optarg != NULL) && !strcmp(optarg, "about")) { TShowAbout_exit(); } errflg = 1; break; case '?': default: errflg = 1; break; } /* END switch (i) */ } /* END while (i = getopt()) */ if ((note_flag == list) && (flag != LIST)) { fprintf(stderr, "Error: -n requires -l\n"); errflg = 1; } for (pa = argv + optind;*pa;pa++) { if (strlen(*pa) == 0) { errflg = 1; } } if (errflg != 0) { if (!quiet) { fprintf(stderr, "usage:\t%s [-{c|d|l|o|p|r}] [-s server] [-n] [-N \"note\"] [-q] node ...\n", progname); fprintf(stderr, "\t%s [-{a|x}] [-s server] [-q] [node]\n", progname); } exit(1); } con = cnt2server(specified_server); if (con <= 0) { if (!quiet) { fprintf(stderr, "%s: cannot connect to server %s, error=%d (%s)\n", progname, (specified_server) ? specified_server : pbs_default(), con * -1, pbs_strerror(con * -1)); } exit(1); } /* if flag is ALLI, LIST, get status of all nodes */ if ((flag == ALLI) || (flag == LIST) || (flag == DIAG)) { if ((flag == ALLI) || (flag == LIST) || (flag == DIAG)) { if (flag == LIST) { /* allow state specification */ if (argv[optind] != NULL) { for (lindex = 1;lindex < tnsLAST;lindex++) { if (!strcasecmp(NState[lindex], argv[optind])) { ListType = lindex; optind++; break; } } } } /* allow node specification (if none, then create an empty list) */ if (argv[optind] != NULL) { nodeargs = argv + optind; } else { nodeargs = calloc(2, sizeof(char **)); nodeargs[0] = strdup(""); nodeargs[1] = '\0'; } } } if ((note_flag == set) && (note != NULL)) { /* set the note attrib string on specified nodes */ for (pa = argv + optind;*pa;pa++) { set_note(con, *pa, note); } } switch (flag) { case DIAG: /* NYI */ break; case CLEAR: /* clear OFFLINE from specified nodes */ for (pa = argv + optind;*pa;pa++) { marknode(con, *pa, ND_offline, DECR, NULL, DECR); } break; case RESET: /* clear OFFLINE, add DOWN to specified nodes */ for (pa = argv + optind;*pa;pa++) { marknode(con, *pa, ND_offline, DECR, ND_down, INCR); } break; case OFFLINE: /* set OFFLINE on specified nodes */ for (pa = argv + optind;*pa;pa++) { marknode(con, *pa, ND_offline, INCR, NULL, INCR); } break; case PURGE: /* remove node record */ /* NYI */ break; case ALLI: if (DisplayXML == TRUE) { char *tmpBuf = NULL, *tail = NULL; int bufsize; mxml_t *DE; DE = NULL; MXMLCreateE(&DE, "Data"); for (lindex = 0;nodeargs[lindex] != '\0';lindex++) { bstatus = statnode(con, nodeargs[lindex]); for (pbstat = bstatus;pbstat;pbstat = pbstat->next) { addxmlnode(DE, pbstat); } /* END for (pbstat) */ pbs_statfree(pbstat); } MXMLToXString(DE, &tmpBuf, &bufsize, INT_MAX, &tail, TRUE); MXMLDestroyE(&DE); fprintf(stdout, "%s\n", tmpBuf); } else { for (lindex = 0;nodeargs[lindex] != '\0';lindex++) { bstatus = statnode(con, nodeargs[lindex]); for (pbstat = bstatus;pbstat;pbstat = pbstat->next) { printf("%s\n", pbstat->name); prt_node_attr(pbstat, 0); putchar('\n'); } /* END for (bpstat) */ pbs_statfree(pbstat); } } break; case LIST: /* list any node that is DOWN, OFFLINE, or UNKNOWN */ for (lindex = 0;nodeargs[lindex] != '\0';lindex++) { bstatus = statnode(con, nodeargs[lindex]); for (pbstat = bstatus;pbstat != NULL;pbstat = pbstat->next) { char *S; S = get_nstate(pbstat); if (filterbystate(pbstat, ListType, S)) { char *n; if ((note_flag == list) && (n = get_note(pbstat))) { printf("%-20.20s %-26.26s %s\n", pbstat->name, S, n); } else { printf("%-20.20s %s\n", pbstat->name, S); } } } pbs_statfree(pbstat); } break; } /* END switch (flag) */ pbs_disconnect(con); return(0); } /* END main() */
int cnt2server( const char *SpecServer) /* I (optional) */ { int connect; time_t firsttime = 0, thistime = 0; char Server[1024]; if (cnt2server_retry > 0) { firsttime = time(NULL); } memset(Server, 0, sizeof(Server)); if ((SpecServer != NULL) && (SpecServer[0] != '\0')) { snprintf(Server, sizeof(Server)-1, "%s", SpecServer); } /* NOTE: env vars PBS_DEFAULT and PBS_SERVER will be checked and applied w/in pbs_connect() */ start: connect = pbs_connect(Server); if (connect <= 0) { /* PBSE_ * -1 is returned if applicable */ if ((connect * -1) > PBSE_) { switch (connect * -1) { case PBSE_BADHOST: if (Server[0] == '\0') { fprintf(stderr, "Cannot resolve default server host '%s' - check server_name file.\n", pbs_default()); } else { fprintf(stderr, "Cannot resolve specified server host '%s'.\n", Server); } break; case PBSE_NOCONNECTS: if (thistime == 0) fprintf(stderr, "Too many open connections.\n"); if (cnt2server_retry != 0) goto retry; break; case PBSE_NOSERVER: fprintf(stderr, "No default server name - check server_name file.\n"); break; case PBSE_SYSTEM: if (thistime == 0) fprintf(stderr, "System call failure.\n"); if (cnt2server_retry != 0) goto retry; break; case PBSE_PERM: if (thistime == 0) fprintf(stderr, "No Permission.\n"); if (cnt2server_retry != 0) goto retry; break; case PBSE_IFF_NOT_FOUND: fprintf(stderr, "pbs_iff command not found.\n"); break; case PBSE_PROTOCOL: fprintf(stderr, "protocol failure.\n"); break; default: if (thistime == 0) fprintf(stderr, "Communication failure.\n"); if (cnt2server_retry != 0) goto retry; break; } } /* END if (a PBSE_ was reported) */ else /* These represent system errors (errno numbers) */ { if (thistime == 0) { if ((connect *-1) == ECONNREFUSED) { if (Server[0] == '\0') { char *fbserver; fbserver = pbs_fbserver(); if ((fbserver != NULL) && (fbserver[0] != '\0')) { snprintf(Server, sizeof(Server), "%s", fbserver); if (getenv("PBSDEBUG") != NULL) { fprintf(stderr, "attempting fallback server %s\n", fbserver); } goto start; } fprintf(stderr, "Cannot connect to default server host '%s' - check pbs_server daemon and/or trqauthd.\n", pbs_default()); } else { fprintf(stderr, "Cannot connect to specified server host '%s'.\n", Server); } } else { pbs_strerror(connect *-1); } } if (cnt2server_retry != 0) goto retry; } } /* END if (connect <= 0) */ return(connect); retry: if (thistime == 0) { fprintf(stderr, "Retrying for %d seconds\n", (int)cnt2server_retry); } thistime = time(NULL); if (cnt2server_retry > 0) /* negative is infinite */ { if ((thistime - firsttime) > cnt2server_retry) { return(connect); } if (getenv("PBSDEBUG") != NULL) { fprintf(stderr, "seconds remaining: %d\n", (int)(cnt2server_retry - (thistime - firsttime))); } } else { if (getenv("PBSDEBUG") != NULL) fprintf(stderr, "retrying...\n"); } sleep(CNTRETRYDELAY); goto start; } /* END cnt2server() */
int main( int argc, /* I */ char **argv) /* I */ { 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; int local_errno = 0; if (argc != 3) { static char usage[] = "usage: qorder job_identifier job_identifier\n"; fprintf(stderr, "%s", usage); exit(2); } snprintf(job_id1, sizeof(job_id1), "%s", argv[1]); snprintf(job_id2, sizeof(job_id2), "%s", argv[2]); svrtmp[0] = '\0'; if (get_server(job_id1, job_id1_out, sizeof(job_id1_out), svrtmp, sizeof(svrtmp))) { fprintf(stderr, "qorder: illegally formed job identifier: %s\n", job_id1); exit(1); } if (*svrtmp == '\0') { if ((pn = pbs_default())) { 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, NULL) != 0) { fprintf(stderr, "qorder: invalid server name: %s\n", job_id1); exit(1); } svrtmp[0] = '\0'; if (get_server(job_id2, job_id2_out, sizeof(job_id2_out), svrtmp, sizeof(svrtmp))) { fprintf(stderr, "qorder: illegally formed job identifier: %s\n", job_id2); exit(1); } if (*svrtmp == '\0') { if ((pn = pbs_default())) { snprintf(svrtmp, sizeof(svrtmp), "%s", 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, NULL) != 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 != NULL) *pn = ':'; /* restore : if it was present */ connect = cnt2server(svrtmp); if (connect <= 0) { local_errno = -1 * connect; if (svrtmp[0] != 0) fprintf(stderr, "qorder: cannot connect to server %s (errno=%d) %s\n", svrtmp, local_errno, pbs_strerror(local_errno)); else fprintf(stderr, "qorder: cannot connect to server %s (errno=%d) %s\n", pbs_server, local_errno, pbs_strerror(local_errno)); exit(1); } stat = pbs_orderjob_err(connect, job_id1_out, job_id2_out, NULL, &local_errno); if (stat != 0) { prt_job_err("qorder", connect, ""); rc = local_errno; } pbs_disconnect(connect); exit(rc); } /* END main() */
int main( int argc, char **argv) { int c; int errflg = 0; int any_failed = 0; int purge_completed = FALSE; int located = FALSE; 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] = ""; char extend[1024]; #define GETOPT_ARGS "acm:pW:t:" initialize_network_info(); extend[0] = '\0'; while ((c = getopt(argc, argv, GETOPT_ARGS)) != EOF) { switch (c) { case 'a': /* Async job deletion */ if (extend[0] != '\0') { errflg++; break; } strcpy(extend, DELASYNC); break; case 'c': if (extend[0] != '\0') { errflg++; break; } snprintf(extend,sizeof(extend),"%s%ld",PURGECOMP,(long)(time(NULL))); purge_completed = TRUE; break; case 'm': /* add delete message */ if (extend[0] != '\0') { /* extension option already specified */ errflg++; break; } strncpy(extend, optarg, sizeof(extend)); break; case 'p': if (extend[0] != '\0') { errflg++; break; } strcpy(extend, DELPURGE); strcat(extend, "1"); break; case 't': if (extend[0] != '\0') { errflg++; break; } pc = optarg; if (strlen(pc) == 0) { fprintf(stderr, "qdel: illegal -t value (array range cannot be zero length)\n"); errflg++; break; } snprintf(extend,sizeof(extend),"%s%s", ARRAY_RANGE, pc); break; case 'W': if (extend[0] != '\0') { errflg++; break; } pc = optarg; if (strlen(pc) == 0) { fprintf(stderr, "qdel: illegal -W value\n"); errflg++; break; } while (*pc != '\0') { if (!isdigit(*pc)) { fprintf(stderr, "qdel: illegal -W value\n"); errflg++; break; } pc++; } strcpy(extend, DELDELAY); strcat(extend, optarg); break; default: errflg++; break; } } /* END while (c) */ if (purge_completed) { strcpy(server_out,pbs_default()); goto cnt; } if ((errflg != 0) || (optind >= argc)) { static char usage[] = "usage: qdel [{ -a | -c | -p | -t | -W delay | -m message}] [<JOBID>[<JOBID>]|'all'|'ALL']...\n"; fprintf(stderr, "%s", usage); fprintf(stderr, " -a -c, -m, -p, -t, and -W are mutually exclusive\n"); exit(2); } for (;optind < argc;optind++) { int connect; int stat = 0; /* check to see if user specified 'all' to delete all jobs */ snprintf(job_id, sizeof(job_id), "%s", argv[optind]); if (get_server(job_id, job_id_out, sizeof(job_id_out), server_out, sizeof(server_out))) { fprintf(stderr, "qdel: illegally formed job identifier: %s\n", job_id); any_failed = 1; continue; } cnt: connect = cnt2server(server_out); if (connect <= 0) { any_failed = -1 * connect; if(server_out[0] != 0) fprintf(stderr, "qdel: cannot connect to server %s (errno=%d) %s\n", server_out, any_failed, pbs_strerror(any_failed)); else fprintf(stderr, "qdel: cannot connect to server %s (errno=%d) %s\n", pbs_server, any_failed, pbs_strerror(any_failed)); continue; } stat = pbs_deljob_err(connect, job_id_out, extend, &any_failed); if (stat && (any_failed != PBSE_UNKJOBID)) { prt_job_err("qdel", connect, job_id_out); } else if (stat && (any_failed != 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("qdel", connect, job_id_out); } pbs_disconnect(connect); } exit(any_failed); } /* END main() */
/** * Take a job ID string and parse it into * job ID and server name parts. * * @param job_id_in Input string of the form <job number>[.<parent server name>][@<host server url>] * @param job_id_out Output string containing only the job ID part of the input specification. * @param server_out Output string containing nothing or a host url if specified. */ int get_server( char *job_id_in, /* read only */ char *job_id_out, /* write only */ int job_id_out_size, /* sizeof the out buffer */ char *server_out, /* write only */ int server_out_size) /* sizeof the out buffer */ { char *seq_number; char *parent_server; char *current_server; char def_server[PBS_MAXSERVERNAME + 1]; char host_server[PBS_MAXSERVERNAME + 1]; char *c; /* parse the job_id_in into components */ if (!strcasecmp("all",job_id_in)) { snprintf(job_id_out, job_id_out_size, "%s", job_id_in); server_out[0] = '\0'; } else { if (parse_jobid(job_id_in, &seq_number, &parent_server, ¤t_server)) { return(1); } /* Apply the above rules, in order, except for the locate job request. * That request is only sent if the job is not found on the local server. */ if (notNULL(current_server)) { /* @server found */ snprintf(server_out, server_out_size, "%s", current_server); } else if (notNULL(parent_server)) { /* .server found */ snprintf(server_out, server_out_size, "%s", parent_server); } else { /* can't locate a server, so return a NULL to tell pbs_connect to use default */ server_out[0] = '\0'; } /* Make a fully qualified name of the job id. */ if (notNULL(parent_server)) { if (notNULL(current_server)) { snprintf(job_id_out, job_id_out_size, "%s.%s", seq_number, parent_server); /* parent_server might not be resolvable if current_server specified */ } else { if (get_fullhostname(parent_server, host_server, PBS_MAXSERVERNAME, NULL) != 0) { /* FAILURE */ return(1); } snprintf(job_id_out, job_id_out_size, "%s.%s", seq_number, host_server); } if ((c = strchr(parent_server, ':')) != 0) { if (*(c - 1) == '\\') c--; snprintf(job_id_out + strlen(job_id_out), job_id_out_size - strlen(job_id_out), "%s", c); } } else { parent_server = pbs_default(); if ((parent_server == (char *)NULL) || (*parent_server == '\0')) { return(1); } snprintf(def_server, PBS_MAXSERVERNAME, "%s", parent_server); c = def_server; while ((*c != '\n') && (*c != '\0')) c++; *c = '\0'; if (get_fullhostname(def_server, host_server, PBS_MAXSERVERNAME, NULL) != 0) { /* FAILURE */ return(1); } if ((c = strchr(def_server, ':')) != 0) { if (*(c - 1) == '\\') c--; snprintf(job_id_out, job_id_out_size, "%s.%s%s", seq_number, host_server, c); } else snprintf(job_id_out, job_id_out_size, "%s.%s", seq_number, host_server); } /* END else */ } return(PBSE_NONE); } /* END get_server() */
int qdel_main( int argc, char **argv, char **envp) { int c; int errflg = 0; int any_failed = 0; int purge_completed = FALSE; int located = FALSE; char *pc; bool dash_t = false; /* for array submission job handling */ int past_failure = 0; /* for multiple job submission error message tracking */ char job_id[PBS_MAXCLTJOBID]; /* from the command line */ char job_id_out[PBS_MAXCLTJOBID]; char server_out[MAXSERVERNAME] = ""; char rmt_server[MAXSERVERNAME] = ""; char extend[1024]; job_data_container attr; job_data *tmp_data = NULL; int client_retry = 0; #define GETOPT_ARGS "ab:cm:pW:t:" set_env_opts(&attr, envp); process_config_file(&attr); if (hash_find(&attr, "PBS_CLIENTRETRY", &tmp_data)) { client_retry = atoi(tmp_data->value.c_str()); } extend[0] = '\0'; while ((c = getopt(argc, argv, GETOPT_ARGS)) != EOF) { switch (c) { case 'a': /* Async job deletion */ if (extend[0] != '\0') { errflg++; break; } snprintf(extend, sizeof(extend), "%s", DELASYNC); break; case 'b': client_retry = atoi(optarg); break; case 'c': if (extend[0] != '\0') { errflg++; break; } snprintf(extend,sizeof(extend),"%s%ld",PURGECOMP,(long)(time(NULL))); purge_completed = TRUE; break; case 'm': /* add delete message */ if (extend[0] != '\0') { /* extension option already specified */ errflg++; break; } snprintf(extend, sizeof(extend), "%s", optarg); break; case 'p': if (extend[0] != '\0') { errflg++; break; } snprintf(extend, sizeof(extend), "%s1", DELPURGE); break; case 't': dash_t = true; if (extend[0] != '\0') { errflg++; break; } pc = optarg; if (strlen(pc) == 0) { fprintf(stderr, "qdel: illegal -t value (array range cannot be zero length)\n"); errflg++; break; } snprintf(extend,sizeof(extend),"%s%s", ARRAY_RANGE, pc); break; case 'W': if (extend[0] != '\0') { errflg++; break; } pc = optarg; if (strlen(pc) == 0) { fprintf(stderr, "qdel: illegal -W value\n"); errflg++; break; } while (*pc != '\0') { if (!isdigit(*pc)) { fprintf(stderr, "qdel: illegal -W value\n"); errflg++; break; } pc++; } snprintf(extend, sizeof(extend), "%s%s", DELDELAY, optarg); break; default: errflg++; break; } } /* END while (c) */ if (purge_completed) { snprintf(server_out, sizeof(server_out), "%s", pbs_default()); goto cnt; } if ((errflg != 0) || (optind >= argc)) { static char usage[] = "usage: qdel [{ -a | -c | -p | -t | -W delay | -m message}] [-b retry_seconds] [<JOBID>[<JOBID>]|'all'|'ALL']...\n"; fprintf(stderr, "%s", usage); fprintf(stderr, " -a -c, -m, -p, -t, and -W are mutually exclusive\n"); exit(2); } if (client_retry > 0) { cnt2server_conf(client_retry); /* set number of seconds to retry */ } for (;optind < argc;optind++) { int connect; int stat; /* check to see if user specified 'all' to delete all jobs */ snprintf(job_id, sizeof(job_id), "%s", argv[optind]); if ((dash_t == true) && is_array(job_id) == false) { fprintf(stderr, "qdel: Error: job id '%s' isn't a job array but -t was specified.\n", job_id); any_failed = 1; exit(any_failed); } if (get_server(job_id, job_id_out, sizeof(job_id_out), server_out, sizeof(server_out))) { fprintf(stderr, "qdel: illegally formed job identifier: %s\n", job_id); any_failed = 1; exit(any_failed); } cnt: connect = cnt2server(server_out); if (connect <= 0) { any_failed = -1 * connect; if(server_out[0] != 0) fprintf(stderr, "qdel: cannot connect to server %s (errno=%d) %s\n", server_out, any_failed, pbs_strerror(any_failed)); else fprintf(stderr, "qdel: cannot connect to server %s (errno=%d) %s\n", pbs_server, any_failed, pbs_strerror(any_failed)); continue; } int retries = 0; do { stat = pbs_deljob_err(connect, job_id_out, extend, &any_failed); if (any_failed == PBSE_TIMEOUT) { sleep(1); fprintf(stdout, "Connection to server timed out. Trying again"); } } while ((++retries < MAX_RETRIES) && (any_failed == PBSE_TIMEOUT)); if (past_failure == 0) past_failure = any_failed; if (stat && (any_failed != PBSE_UNKJOBID)) { if (!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((char *)"qdel", connect, job_id_out); } if (!located && any_failed != 0) { fprintf(stderr, "qdel: nonexistent job id: %s\n", job_id); } pbs_disconnect(connect); } if ((past_failure != PBSE_NONE) && (any_failed == PBSE_NONE)) any_failed = past_failure; exit(any_failed); } /* END qdel_main() */
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); }