static void displayShareRes(int argc, char **argv, int index) { struct lsbSharedResourceInfo *lsbResourceInfo; int numRes = 0; char **resourceNames = NULL, **resources = NULL; char fname[]="displayShareRes"; if (argc > index) { if ((resourceNames = (char **) malloc ((argc - index) * sizeof (char *))) == NULL) { char i18nBuf[100]; sprintf ( i18nBuf,I18N_FUNC_FAIL,fname,"malloc"); perror( i18nBuf ); exit (-1); } numRes = getResourceNames (argc, argv, index, resourceNames); } if (numRes > 0) resources = resourceNames; TIMEIT(0, (lsbResourceInfo = lsb_sharedresourceinfo (resources, &numRes, NULL, 0)), "lsb_sharedresourceinfo"); if (lsbResourceInfo == NULL) { if (lsberrno == LSBE_BAD_RESOURCE && resources) lsb_perror(NULL); else lsb_perror("lsb_sharedresourceinfo"); exit(-1); } prtResourcesShort(numRes, lsbResourceInfo); FREEUP(resourceNames); }
int bqc (int argc, char *argv[], int opCode) { struct queueInfoEnt *queueInfo; char **queueList=NULL, **queues ; int numQueues, all = FALSE; int i; queues = NULL; if (argc == optind) numQueues =1; else { numQueues = getNames (argc, argv, optind, &queueList, &all, "queueC"); if (!all) queues = queueList; } if ((queueInfo = lsb_queueinfo(queues, &numQueues, NULL, NULL, 0)) == NULL) { if (lsberrno == LSBE_BAD_QUEUE && queues && queues[numQueues]) lsb_perror(queues[numQueues]); else lsb_perror(NULL); return (-1); } for (i = 0; i < numQueues; i++) { ctrlQueue (queueInfo[i].queue, opCode); } return (exitrc); }
int main(int argc, char **argv) { int cc; char *msg; LS_LONG_INT *jobIDs; if (lsb_init(argv[0]) < 0) { lsb_perror("lsb_init"); return -1; } while ((cc = getopt(argc, argv, "Vhd:")) != EOF) { switch (cc) { case 'V': fputs(_LS_VERSION_, stderr); return -1; case 'h': usage(); return -1; case 'd': msg = optarg; break; default: usage(); return -1; } } if (strlen(msg) > LSB_MAX_MSGSIZE) { fprintf(stderr, "bpost: message bigger than %d\n", LSB_MAX_MSGSIZE); return -1; } getJobIds(argc, argv, NULL, NULL, NULL, NULL, &jobIDs, 0); cc = lsb_postjobmsg(jobIDs[0], msg); if (cc < 0) { lsb_perror("lsb_jobmsg()"); return -1; } printf("Message to job %s posted all right.\n", lsb_jobid2str(jobIDs[0])); return 0; }
int main(int argc, char* argv[]) { int options = PEND_JOB | RUN_JOB | UGRP_INFO; char *user = ALL_USERS; /* match jobs for all users */ struct jobInfoEnt *job; FILE* fp; int more; if (lsb_init(argv[0]) < 0) { lsb_perror("lsb_init"); exit(-1); } if (lsb_openjobinfo(0, NULL, user, NULL, NULL, options) < 0) { lsb_perror("lsb_openjobinfo"); exit(-1); } #if 0 printf("All pending/running jobs submitted by all users:\n"); printf(" JOBID USER STAT QUEUE FROM_HOST EXEC_HOST USER_GROUP JOB_NAME SUBMIT_TIME\n"); #endif fp = fopen("/tmp/group_info.txt", "w"); if (fp == NULL) { perror("Error while opening the file.\n"); exit(EXIT_FAILURE); } for (;;) { job = lsb_readjobinfo(&more); if (job == NULL) { lsb_perror("lsb_readjobinfo"); exit(-1); } if ((job->submit.options & SUB_USER_GROUP)) { /* display job information */ char *host = ""; if (job->status == 4) host = job->exHosts[0]; fprintf(fp, "%ld %s %d %s\n", job->jobId, job->user, job->status, job->submit.userGroup); } if (! more) break; } fclose(fp); lsb_closejobinfo(); exit(0); }
static void ctrlHost(char *host, int hStatus, int opCode, char *message) { if (lsb_hostcontrol(host, opCode, message) < 0) { char i18nBuf[100]; sprintf(i18nBuf,I18N_FUNC_FAILED,"Host control"); lsb_perror (i18nBuf ); exitrc = -1; return; } if (opCode == HOST_OPEN) { if (hStatus & (HOST_STAT_BUSY | HOST_STAT_WIND | HOST_STAT_LOCKED_MASTER | HOST_STAT_LOCKED | HOST_STAT_FULL)) { fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,910, "done : host remains closed due to "))); /* catgets 910 */ if (hStatus & HOST_STAT_LOCKED) fprintf (stderr, (_i18n_msg_get(ls_catd,NL_SETN,911, "being locked; "))); /* catgets 911 */ else if (hStatus & HOST_STAT_LOCKED_MASTER) fprintf(stderr, (I18N(917, "being locked by master LIM;"))); /* catgets 917 */ else if (hStatus & HOST_STAT_WIND) fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,912, "dispatch window; "))); /* catgets 912 */ else if (hStatus & HOST_STAT_FULL) fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,913, "job limit; "))); /* catgets 913 */ else if (hStatus & HOST_STAT_BUSY) fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,914, "load threshold; "))); /* catgets 914 */ fprintf(stderr, " \n"); return; } } fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,915, "done\n"))); /* catgets 915 */ }
int main (int argc, char **argv) { int cc; struct parameterInfo *paramInfo; int longFormat; if (lsb_init(argv[0]) < 0) { lsb_perror("lsb_init"); return -1; } longFormat = FALSE; while ((cc = getopt(argc, argv, "Vhl")) != EOF) { switch (cc) { case 'l': longFormat = TRUE; break; case 'V': fputs(_LS_VERSION_, stderr); return 0; case 'h': usage(argv[0]); return 0; default : usage(argv[0]); return -1; } } if (!(paramInfo = lsb_parameterinfo(NULL, NULL, 0))) { lsb_perror(NULL); return -1; } if (longFormat) printLong(paramInfo); else printShort(paramInfo); return 0; }
static int signalJobs (LS_LONG_INT *jobIds, int numJobs) { int failsignal = FALSE, signaled = FALSE; int i, cc; char msg[80]; for (i = 0; i < numJobs; i++) { if (sigValue == SIGCHK) cc = lsb_chkpntjob(jobIds[i], chkPeriod, chkOptions); else if (sigValue == SIGDEL) cc = lsb_deletejob(jobIds[i], runCount, 0); else if (sigValue == SIGFORCE) cc = lsb_forcekilljob(jobIds[i]); else cc = lsb_signaljob(jobIds[i], sigValue); if (cc < 0) { if (sigValue == SIGCHK && lsberrno == LSBE_NOT_STARTED && chkPeriod != LSB_CHKPERIOD_NOCHNG) { if (chkPeriod) printf((_i18n_msg_get(ls_catd,NL_SETN,470, "Job <%s>: Checkpoint period is now %d min.\n")), /* catgets 470 */ lsb_jobid2str(jobIds[i]), (int) (chkPeriod / 60)); else printf((_i18n_msg_get(ls_catd,NL_SETN,471, "Job <%s>: Periodic checkpointing is disabled\n")), /* catgets 471 */ lsb_jobid2str(jobIds[i])); signaled = TRUE; } else { failsignal = TRUE; sprintf (msg, "%s <%s>", I18N_Job, lsb_jobid2str(jobIds[i])); lsb_perror (msg); } } else { signaled = TRUE; prtSignaled (sigValue, jobIds[i]); } } return (signaled ? !failsignal : FALSE); }
int main(int argc, char **argv) { int cc; struct job_group jg; if (lsb_init(argv[0]) < 0) { lsb_perror("lsb_init"); return -1; } while ((cc = getopt(argc, argv, "hV")) != EOF) { switch (cc) { case 'V': fputs(_LS_VERSION_, stderr); return 0; case 'h': usage(); exit(-1); } } if (argc <= optind) { usage(); return -1; } jg.group_name = argv[argc - 1]; cc = lsb_deljgrp(&jg); if (cc != LSBE_NO_ERROR) { fprintf(stderr, "bgdel: %s.\n", lsb_sysmsg()); return -1; } printf("Group %s removed successfully.\n", jg.group_name); return 0; }
static int ctrlQueue (char *queue, int opCode) { if (lsb_queuecontrol(queue, opCode) < 0) { exitrc = -1; switch (lsberrno) { case LSBE_BAD_QUEUE: case LSBE_QUEUE_WINDOW: case LSBE_PERMISSION: case LSBE_BAD_USER: case LSBE_PROTOCOL: case LSBE_MBATCHD: default: lsb_perror (queue); return (-1); } } switch (opCode) { case QUEUE_OPEN: printf((_i18n_msg_get(ls_catd,NL_SETN,951, "Queue <%s> is opened\n")), queue); /* catgets 951 */ break; case QUEUE_CLOSED: printf((_i18n_msg_get(ls_catd,NL_SETN,952, "Queue <%s> is closed\n")), queue); /* catgets 952 */ break; case QUEUE_ACTIVATE: printf((_i18n_msg_get(ls_catd,NL_SETN,953, "Queue <%s> is activated\n")), queue); /* catgets 953 */ break; case QUEUE_INACTIVATE: printf((_i18n_msg_get(ls_catd,NL_SETN,954, "Queue <%s> is inactivated\n")), queue); /* catgets 954 */ break; default: fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,955, "Command internal error: corrupt opCode\n"))); /* catgets 955 */ return (-1); } return (0); }
int bsignal(int argc, char **argv) { int numJobs; LS_LONG_INT *jobIds; int signalValue; if (lsb_init(argv[0]) < 0) { lsb_perror("lsb_init"); exit(-1); } if (strstr (argv[0], "bkill")) signalValue = SIGKILL; else if (strstr (argv[0], "bstop")) signalValue = SIGSTOP; else if (strstr (argv[0], "bresume")) signalValue = SIGCONT; else if (strstr (argv[0], "bchkpnt")) signalValue = SIGCHK; else if (strstr (argv[0], "bdel")) signalValue = SIGDEL; else { fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,468, "%s: Illegal operation\n")), argv[0]); /* catgets 468 */ exit (-1); } numJobs = do_options (argc, argv, &jobIds, signalValue); if ((signalValue == SIGKILL) && (sigValue != SIGFORCE) && (sigValue >= LSF_NSIG || sigValue < 1) ) { fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,469, "%d: Illegal signal value\n")), sigValue); /* catgets 469 */ exit(-1); } return (signalJobs (jobIds, numJobs)); }
int main(int argc, char** argv) { char* hosts = NULL; struct runJobRequest runJobRequest; int cc; int c; bool_t fFlag = FALSE; bool_t bFlag = FALSE; int rc; rc = _i18n_init ( I18N_CAT_MIN ); if (lsb_init(argv[0]) < 0) { lsb_perror("lsb_init"); exit (-1); } while((c = getopt(argc, argv, "m:fbhV")) != EOF) { switch(c) { case 'm': hosts = putstr_(optarg); if (hosts == NULL) { perror("putstr_"); exit(-1); } break; case 'f': fFlag = TRUE; break; case 'b': bFlag = TRUE; break; case 'V': fputs(_LS_VERSION_, stderr); return (0); case 'h': usage(argv[0]); exit(-1); } } if (argc <= optind) { usage(argv[0]); exit(-1); } memset((struct runJobRequest* )&runJobRequest, 0, sizeof(struct runJobRequest)); if (getOneJobId (argv[argc - 1], &(runJobRequest.jobId), 0)) { usage(argv[0]); exit(-1); } runJobRequest.numHosts = countHosts(hosts); if (runJobRequest.numHosts > 1) { int i; runJobRequest.hostname = (char **)calloc(runJobRequest.numHosts, sizeof(char *)); if (runJobRequest.hostname == NULL) { perror("calloc"); exit(-1); } for (i = 0; i < runJobRequest.numHosts; i++) { while (isspace(*hosts)) hosts++; runJobRequest.hostname[i] = hosts; hosts += strlen(hosts) + 1; } } else runJobRequest.hostname = &hosts; runJobRequest.options = (fFlag == TRUE) ? RUNJOB_OPT_NOSTOP : RUNJOB_OPT_NORMAL; if (bFlag) { runJobRequest.options |= RUNJOB_OPT_FROM_BEGIN; } cc = lsb_runjob(&runJobRequest); if (cc < 0) { lsb_perror((_i18n_msg_get(ls_catd,NL_SETN,2755, "Failed to run the job"))); /* catgets 2755 */ exit(-1); } printf((_i18n_msg_get(ls_catd,NL_SETN,2756, "Job <%s> is being forced to run.\n")), /* catgets 2756 */ lsb_jobid2str(runJobRequest.jobId)); _i18n_end ( ls_catd ); return (0); }
int main(int argc, char *argv[]) { /* The current event file is /lsf/work/lsf-odyssey/logdir/lsb.acct" * * John Brunelle has all previous (mostly) event files in /n/RC_Team/lsf_logs.sorted/acct */ FILE *fp; char *eventFile = argv[1]; int lineNum = 0; struct eventRec *record; struct jobFinishLog *finishJob; if (argc != 2) { printf("Usage: %s lsb.acct\n", argv[0]); exit(-1); } if (lsb_init(argv[0]) < 0) { lsb_perror("lsb_init"); exit(-1); } fp = fopen(eventFile, "r"); if (fp == NULL) { perror(eventFile); exit(-1); } struct jobFinishLog *finishJob; for (;;) { record = lsb_geteventrec(fp, &lineNum); if (record == NULL) { if (lsberrno == LSBE_EOF) exit(0); lsb_perror("lsb_geteventrec"); exit(-1); } if (record->type == EVENT_JOB_FINISH) { finishJob = &(record->eventLog.jobFinishLog); int jobId = finishJob->jobId; int userId = finishJob->userId; char *userName = finishJob->userName; int options = finishJob->options; int numProcessors = finishJob->numProcessors; int jStatus = finishJob->jStatus; time_t submitTime = finishJob->submitTime; time_t startTime = finishJob->startTime; time_t endTime = finishJob->endTime; char *queue = finishJob->queue; char *subtime = ctime(&submitTime); char *starttime = ctime(&startTime); char *endtime = ctime(&endTime); subtime[24] = '\0'; starttime[24] = '\0'; endtime[24] = '\0'; printf("\"\\N\",\"%d\",\"%d\",\"%s\",\"%d\",\"%d\",\"%d\",\"%ld\",\"%ld\",\"%ld\",\"%s\",", jobId, userId, userName, options, numProcessors, jStatus, submitTime, startTime, endTime, queue); char *resReq = finishJob->resReq; char *fromHost = finishJob->fromHost; char *cwd = finishJob->cwd; char *inFile = finishJob->inFile; char *outFile = finishJob->outFile; char *errFile = finishJob->errFile; char *inFileSpool = finishJob->inFileSpool; printf("\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",", resReq, fromHost, cwd, inFile, outFile, errFile, inFileSpool); char *commandSpool = finishJob->commandSpool; char *jobFile = finishJob->jobFile; int numAskedHosts = finishJob->numAskedHosts; char **askedHosts = finishJob->askedHosts; float hostFactor = finishJob->hostFactor; int numExHosts = finishJob->numExHosts; char **execHosts = finishJob->execHosts; float cpuTime = finishJob->cpuTime; char *jobName = finishJob->jobName; char *command = finishJob->command; char *askedHostsString = join_string(askedHosts,numAskedHosts,","); char *execHostsString = join_string(execHosts,numExHosts,","); printf("\"%s\",\"%s\",\"%d\",\"%s\",\"%f\",\"%d\",\"%s\",\"%f\",\"%s\",",commandSpool,jobFile,numAskedHosts,askedHostsString,hostFactor,numExHosts,execHostsString,cpuTime,jobName); /*struct lsfRuage *lsfRusage = finishJob->lsfRusage;*/ char *dependCond = finishJob->dependCond; char *timeEvent = finishJob->timeEvent; char *preExecCmd = finishJob->preExecCmd; char *mailUser = finishJob->mailUser; char *projectName = finishJob->projectName; int exitStatus = finishJob->exitStatus; int maxNumProcessors = finishJob->maxNumProcessors; printf("\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%d\",\"%d\",",dependCond,timeEvent,preExecCmd,mailUser,projectName,exitStatus,maxNumProcessors); char *loginShell = finishJob->loginShell; int idx = finishJob->idx; int maxRMem = finishJob->maxRMem; int maxRSwap = finishJob->maxRSwap; char *rsvId = finishJob->rsvId; char *sla = finishJob->sla; int exceptMask = finishJob->exceptMask; char *additionalInfo = finishJob->additionalInfo; printf("\"%s\",\"%d\",\"%d\",\"%d\",\"%s\",\"%s\",\"%d\",\"%s\",",loginShell,idx,maxRMem,maxRSwap,rsvId,sla,exceptMask,additionalInfo); int exitInfo = finishJob->exitInfo; int warningTimePeriod = finishJob->warningTimePeriod; char *warningAction = finishJob->warningAction; char *chargedSAAP = finishJob->chargedSAAP; char *licenseProject = finishJob->licenseProject; char *app = finishJob->app; char *postExecCmd = finishJob->postExecCmd; int runtimeEstimation = finishJob->runtimeEstimation; char *jgroup = finishJob->jgroup; int options2 = finishJob->options2; char *requeueEValues = finishJob->requeueEValues; char *notifyCmd = finishJob->notifyCmd; time_t lastResizeTime = finishJob->lastResizeTime; char *jobDescription = finishJob->jobDescription; /* struct submit_ext *submitExt = finishJob->submitExt;*/ char *tmpstr = ctime(&lastResizeTime); tmpstr[24] = '\0'; printf("\"%d\",\"%d\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%d\",\"%s\",\"%d\",\"%s\",\"%s\",\"%ld\",\"%s\",\"%s;\n", exitInfo, warningTimePeriod, warningAction, chargedSAAP, licenseProject, app, postExecCmd, runtimeEstimation, jgroup, options2, requeueEValues, notifyCmd, lastResizeTime, jobDescription, command); } } }
int bhc(int argc, char *argv[], int opCode) { struct hostInfoEnt *hostInfo ; char **hostPoint ; char **hosts=NULL; char *optName; char message[MAXLINELEN]; int i; int fFlag = FALSE; int all = FALSE, numHosts = 0; int inquerFlag = FALSE; while ((optName = myGetOpt(argc, argv, "C:f|")) != NULL) { switch (optName[0]) { case 'f': fFlag = TRUE; break; case 'C': if (strlen(optarg) > MAXLINELEN-1) { printf("Message too long, truncated to %d char.\n", MAXLINELEN-1); strncpy(message, optarg, MAXLINELEN-1); message[MAXLINELEN-1]='\0'; } else strcpy(message, optarg); break; default: return -2; } } switch (opCode) { case HOST_OPEN : opStr = (_i18n_msg_get(ls_catd,NL_SETN,901, "Open")); /* catgets 901 */ break; case HOST_CLOSE : opStr = (_i18n_msg_get(ls_catd,NL_SETN,902, "Close")); /* catgets 902 */ break; case HOST_REBOOT : opStr = (_i18n_msg_get(ls_catd,NL_SETN,903, "Restart slave batch daemon on")); /* catgets 903 */ break; case HOST_SHUTDOWN : opStr = (_i18n_msg_get(ls_catd,NL_SETN,904, "Shut down slave batch daemon on")); /* catgets 904 */ break; default : fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,905, "Unknown operation code\n"))); /* catgets 905 */ exit(-1); } exitrc = 0; numHosts = getNames (argc, argv, optind, &hosts, &all, "hostC"); hostPoint = NULL; if (!numHosts && !all) numHosts = 1; else if (numHosts) hostPoint = hosts; if ((opCode == HOST_REBOOT || opCode == HOST_SHUTDOWN) && !(numHosts == 0 && all)) { if ((hostInfo = getHostList(&numHosts, hostPoint)) == NULL) return -1; } else { if ((hostInfo = lsb_hostinfo (hostPoint, &numHosts)) == NULL) { lsb_perror(NULL); return -1; } } if (!fFlag && all && (opCode == HOST_REBOOT || opCode == HOST_SHUTDOWN)) inquerFlag = !doConfirm (opCode, NULL); for (i = 0; i < numHosts; i++) { if (strcmp(hostInfo[i].host, "lost_and_found") == 0 && (opCode == HOST_REBOOT || opCode == HOST_SHUTDOWN)) { if (!all) fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,906, "<lost_and_found> is not a real host, ignored\n"))); /* catgets 906 */ continue; } if (inquerFlag && !(doConfirm (opCode, hostInfo[i].host))) continue; fprintf(stderr, "%s <%s> ...... ", opStr, hostInfo[i].host); fflush(stderr); ctrlHost (hostInfo[i].host, hostInfo[i].hStatus, opCode, message); } return exitrc; }
/* Prints out information about the jobs running that fit the defined parameters */ struct numq print_section( int options, char *inp_queue, char *user, char *inp_hosts, int numcoresq, int numnodesq) { /* variables for simulating bjobs command */ struct jobInfoEnt *job; /* detailed job info */ struct queueInfoEnt *que; /* detailed queue info */ struct numq nq; /* information about the queue being polled by the user that we wish to pass on to other routines */ int tot_jobs; /* total jobs */ int more; /* number of remaining jobs unread */ int nodenum; /* Node number counter */ int i,j; /* counter*/ int alreadycounted; /* Logical flag used to figure out if the quantity in question has already been counted*/ int numQueues = 1; /* number of Queues to poll queue info about */ int t; /* Time remaining */ int tdays; /* Time remaining in days */ int thrs; /* Time remaining in hours */ int tmin; /* Time remaining in minutes */ int tsec; /* Time remaining in seconds */ char *targetqueue; /* array for the queue names to poll queue info about */ char startstr[14]; /* string of date when job started */ char submitstr[14]; /* string of data when job was submitted */ char statstr[5]; /* string of status */ char exclus; /* exclusive flag */ char nodelistcheck[10000][20]; /* a list of node names that we will compare against to test uniqueness*/ /* Initialize struct values */ nq.cores=numcoresq; nq.nodes=numnodesq; /* gets the total number of jobs. Exits if failure */ tot_jobs = lsb_openjobinfo(0, NULL, user, inp_queue, inp_hosts, options); /* Sanity Checks */ if (tot_jobs < 0) { printf("No matching jobs found\n"); return nq; } if (tot_jobs<0){ lsb_perror("lsb_openjobinfo"); exit(-1); } /* Print header for section */ printf("%-12s %-8.8s %-6.6s %-7.7s %-4s %-14s %-14s %-14s\n", \ "JOBID", "USER", "STAT", "QUEUE", "CORES/NODES", "TIME REMAINING", \ "SUBMIT TIME", "START TIME"); /* Loop over jobs until complete */ for (;;) { job = lsb_readjobinfo(&more); /* get the job details */ /* Sanity Check */ if (job == NULL) { lsb_perror("lsb_readjobinfo"); exit(-1); } /* Store our current target queue */ targetqueue=job->submit.queue; /* Grab information about that queue */ que = lsb_queueinfo(&targetqueue,&numQueues,NULL,NULL,0); /* Sanity check */ if (que == NULL){ lsb_perror("lsb_queueinfo"); exit(-1); } /* Detects if the job is running in exclusive mode */ exclus=' '; if (job->submit.options & SUB_EXCLUSIVE) { exclus='X'; } /* Counts the Number of nodes */ nodenum=1; if (job->numExHosts > 0) { for(i=0;i < job->numExHosts-1; i++) { if(strcmp(job->exHosts[i],job->exHosts[i+1]) != 0){ nodenum++; } } } /* Finds the jobs status */ if (job->status == JOB_STAT_RUN){ strcpy(statstr,"RUN"); } else if(job->status == JOB_STAT_PEND){ strcpy(statstr,"PEND"); } else if(job->status == JOB_STAT_PSUSP){ strcpy(statstr,"PSUSP"); } else if(job->status == JOB_STAT_SSUSP){ strcpy(statstr,"SSUSP"); } /* Test if there is a queue that the user is interested in */ if (inp_queue != NULL) { /* Stores the number of processors and nodes used by this queue for later use */ if (job->status == JOB_STAT_RUN && strcmp(inp_queue,targetqueue) == 0) { numcoresq=job->submit.numProcessors+numcoresq; /* Count the number of unique nodes are used by this queue */ for (i=0;i < job->numExHosts;i++){ /* We need to check that we aren't double counting nodes */ alreadycounted=0; for(j=0;j<numnodesq;j++){ if (strcmp(job->exHosts[i],nodelistcheck[j]) == 0) { alreadycounted=1; break; } } /* If we've already been counted break out of this loop if not counted then store that data */ if (alreadycounted == 0) { strcpy(nodelistcheck[numnodesq],job->exHosts[i]); numnodesq++; } } } } /* Figures out what time the job was submitted at and when it started running*/ strftime(submitstr,14,"%b %d %R",&(*localtime(&job->submitTime))); strftime(startstr,14,"%b %d %R",&(*localtime(&job->startTime))); /* Calculates Time Remaining */ t=que->rLimits[LSF_RLIMIT_RUN]-job->runTime; /* Checks to see if ther termination time is other than the queue limit */ if (job->submit.rLimits[LSF_RLIMIT_RUN] > 0) { t=job->submit.rLimits[LSF_RLIMIT_RUN]-job->runTime; } /* Calculates the Time remaining in Days, Hours, Minutes and Seconds */ tdays=t/24/60/60; thrs=t/60/60-24*tdays; tmin=t/60-24*60*tdays-60*thrs; tsec=t-24*60*60*tdays-60*60*thrs-60*tmin; /* Prints out job data */ printf("%-12s %-8.8s %-6.6s %-8.8s %4i%1s%2i%1c %2i%1s%-2.2i%1s%2.2i%1s%2.2i %-14s", \ lsb_jobid2str(job->jobId), job->user, statstr, job->submit.queue, \ job->submit.numProcessors, "/",nodenum,exclus, tdays,":", thrs,":",tmin,":",tsec ,submitstr); /* Prints out start time if the job is not pending */ if (options != PEND_JOB) { printf("%-14s",startstr); } printf ("\n"); /* Checks to see if there are more jobs to do. */ if (!more) break; } /* Prints the total number of jobs in the section */ printf("%-i total jobs\n",tot_jobs); /* Store number of cores and nodes used by the queue. These will have nonzero values if the queue is the one being polled by the user. */ nq.cores=numcoresq; nq.nodes=numnodesq; /* Transmit that data out of the function */ return nq; }
int main (int argc, char **argv, char **environ) { char *queue = NULL, *host = NULL, *jobName = NULL, *user = NULL; LS_LONG_INT jobId; int options; struct jobInfoEnt *jInfo; char *outFile; char fflag = FALSE; int cc; int rc; rc = _i18n_init (I18N_CAT_MIN); if (lsb_init (argv[0]) < 0) { lsb_perror ("lsb_init"); exit (-1); } while ((cc = getopt (argc, argv, "Vhfq:m:J:")) != EOF) { switch (cc) { case 'q': if (queue || host || jobName) oneOf (argv[0]); queue = optarg; break; case 'm': if (queue || host || jobName) oneOf (argv[0]); host = optarg; break; case 'J': if (queue || host || jobName) oneOf (argv[0]); jobName = optarg; break; case 'V': fputs (_LS_VERSION_, stderr); exit (0); case 'f': fflag = TRUE; break; case 'h': default: usage (argv[0]); } } jobId = 0; options = LAST_JOB; if (argc >= optind + 1) { if (queue || host || jobName) { oneOf (argv[0]); } else if ((argc > 2 && !fflag) || (argc > 3 && fflag)) usage (argv[0]); if (getOneJobId (argv[optind], &jobId, 0)) { usage (argv[0]); } options = 0; } if (lsb_openjobinfo (jobId, jobName, NULL, queue, host, options) < 0 || (jInfo = lsb_readjobinfo (NULL)) == NULL) { if (jobId != 0 || jobName != NULL) { user = ALL_USERS; if (lsb_openjobinfo (jobId, jobName, user, queue, host, options) < 0 || (jInfo = lsb_readjobinfo (NULL)) == NULL) { jobInfoErr (jobId, jobName, NULL, queue, host, options); exit (-1); } } else { jobInfoErr (jobId, jobName, NULL, queue, host, options); exit (-1); } } lsb_closejobinfo (); if (jobId && jInfo->jobId != jobId) { lsberrno = LSBE_JOB_ARRAY; lsb_perror ("bpeek"); exit (-1); } if ((jInfo->submit.options & SUB_INTERACTIVE) && !(jInfo->submit.options & (SUB_OUT_FILE | SUB_ERR_FILE))) { fprintf (stderr, _i18n_msg_get (ls_catd, NL_SETN, 2456, "Job <%s> : Cannot bpeek an interactive job.\n"), /* catgets 2456 */ lsb_jobid2str (jInfo->jobId)); exit (-1); } if (IS_PEND (jInfo->status) || jInfo->execUsername[0] == '\0') { fprintf (stderr, _i18n_msg_get (ls_catd, NL_SETN, 2454, "Job <%s> : Not yet started.\n"), /* catgets 2454 */ lsb_jobid2str (jInfo->jobId)); exit (-1); } if (IS_FINISH (jInfo->status)) { fprintf (stderr, _i18n_msg_get (ls_catd, NL_SETN, 2455, "Job <%s> : Already finished.\n"), /* catgets 2455 */ lsb_jobid2str (jInfo->jobId)); exit (-1); } if ((outFile = lsb_peekjob (jInfo->jobId)) == NULL) { char msg[50]; sprintf (msg, "%s <%s>", I18N_Job, lsb_jobid2str (jInfo->jobId)); lsb_perror (msg); exit (-1); } displayOutput (outFile, jInfo, fflag, environ); _i18n_end (ls_catd); exit (0); }
void bmove (int argc, char **argv, int opCode) { int position, reqPos; LS_LONG_INT jobId = 0; int achar; if (lsb_init(argv[0]) < 0) { lsb_perror("lsb_init"); exit(-1); } opterr = 0; while((achar = getopt(argc, argv, "hV")) != EOF) { switch(achar) { case 'V': fputs(_LS_VERSION_, stderr); exit(0); case 'h': default: usage(argv[0]); } } if (argc == optind) { fprintf(stderr, "%s.\n", (_i18n_msg_get(ls_catd,NL_SETN,852, "Job ID must be specified"))); /* catgets 852 */ usage(argv[0]); } if (optind < argc-2) { fprintf(stderr, "%s.\n", (_i18n_msg_get(ls_catd,NL_SETN,853, "Command syntax error: too many arguments"))); /* catgets 853 */ usage(argv[0]); } if (getOneJobId (argv[optind], &jobId, 0)) { usage(argv[0]); } position = 1; if (optind == argc - 2) { if (!isint_(argv[++optind]) || atoi(argv[optind]) <= 0) { fprintf(stderr, "%s: %s.\n", argv[optind], I18N(854, "Position value must be a positive integer")); /* catgets854*/ usage(argv[0]); } position = atoi(argv[optind]); } reqPos = position; if (lsb_movejob(jobId, &position, opCode) <0) { lsb_perror(lsb_jobid2str (jobId)); exit(-1); } if (position != reqPos) fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,855, "Warning: position value <%d> is beyond movable range.\n")), /* catgets 855 */ reqPos); if (opCode == TO_TOP) fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,856, "Job <%s> has been moved to position %d from top.\n")), /* catgets 856 */ lsb_jobid2str (jobId), position); else fprintf(stderr, (_i18n_msg_get(ls_catd,NL_SETN,857, "Job <%s> has been moved to position %d from bottom.\n")), /* catgets 857 */ lsb_jobid2str (jobId), position); exit(0); }
/* Main routine. */ int main(int argc, char **argv) { struct numq nq; /* Struct for passing information between routines */ int c; /* Used for holding information passed in from the command line */ char *user = "******", *queue=NULL, *hosts=NULL; /* Pointers to the information we are querying */ int i, def; /* counters */ /* Initialize Default Flag and structs*/ def=1; nq.cores=0; nq.nodes=0; /* Read in and interpret command line options */ while (1) { static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument,0, 'h'}, {"q", required_argument, 0, 'q'}, {"u", required_argument, 0, 'u'}, {"n", required_argument, 0, 'n'}, {0, 0, 0, 0} }; /* Get information from command line */ int option_index = 0; c = getopt_long (argc, argv, "u:q:n:help",long_options, &option_index); /* Detect the end of the options. */ if (c == -1) break; /* Check what options we are using */ /* Default Flag set to false, we are actually passing options so the default is not used */ def=0; switch (c) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options[option_index].flag != 0) break; printf ("option %s", long_options[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case 'q': queue = optarg; break; case 'u': user = optarg; break; case 'n': hosts = optarg; break; case '?': /* This section handles when getopt_long is confused about what you are passing it */ /* getopt_long already printed an error message. */ exit(-1); case 'h': /* Displays this help page then exits */ printf("Welcome to the Help Section.\n"); printf("Showq provides an overview of the cluster and LSF queues in a similar way to showq in PBS.Torque.\n"); printf("By default showq will show you your running, pending and suspended jobs plus an overview of the cluster.\n"); printf("Depending on cluster activity this command could take a few minutes to complete.\n"); printf("Each job has several fields which are listed below.\n"); printf("\n"); printf("JOBID The LSF job id.\n"); printf("\n"); printf("USER The name of the user.\n"); printf("\n"); printf("STAT The current job state. RUN if it is running, PEND if it is pending,\n"); printf(" PSUSP if suspended by the owner or admin,\n"); printf(" SSUSP if suspended due to host being overloaded or queue run window closure.\n"); printf("\n"); printf("QUEUE The LSF queue the job was submitted from.\n"); printf("\n"); printf("CORES/NODES This lists the number of cores used by the process followed by the number of nodes after the /.\n"); printf(" Additionally if the job is running in Exclusive mode a X appears next to the node count.\n"); printf("\n"); printf("TIME REMAINING The amount of time remaining on this run. This is based off of the queue run time limit\n"); printf(" or if the user defines a run time using BSUB -W it will use that. Jobs that overrun\n"); printf(" the a time limit show up with negative time equal to the amount they have overrun.\n"); printf(" Jobs from queues with no time limit and no user defined limit show up as negative as well.\n"); printf(" The value in that case is just the negative value of the time the job has run for.\n"); printf("\n"); printf("SUBMIT TIME The time at which the job was submitted to the queue.\n"); printf("\n"); printf("START TIME The time at which the job started running.\n"); printf("\n"); printf("Additional Usage options are as below.\n"); printf("\n"); printf("-help Gets you to this convenient help page.\n"); printf("\n"); printf("-q queue_name Shows you what is going on in that queue currently.\n"); printf("\n"); printf("-u user_name Shows the jobs current associated with that user.\n"); printf(" By default this is set to all if -n or -q is used other wise it is set to the current user.\n"); printf(" If -u is used in tandem with -q it will show only the jobs running on that queue for that user.\n"); printf("\n"); printf("-n host_name Shows what is going on for this host or group of hosts. Does not show pending jobs for these hosts.\n"); exit(-1); default: abort (); } } /* Sets what will happen when the default flag is set */ /* In this case it will simply return what jobs belong to the user and the node summary */ if (def) user = NULL; /* initialize LSBLIB and get the configuration environment */ if (lsb_init(argv[0]) < 0) { lsb_perror("simbjobs: lsb_init() failed"); exit(-1); } /* Query about the following information */ printf("ACTIVE JOBS-------------\n"); nq = print_section(RUN_JOB, queue, user, hosts, nq.cores, nq.nodes); printf("\nSUSPENDED JOBS-------------\n"); nq = print_section(SUSP_JOB, queue, user, hosts, nq.cores, nq.nodes); printf("\n"); print_summary(queue, user, hosts, nq.cores, nq.nodes); printf("\n"); printf("PENDING JOBS-------------\n"); nq = print_section(PEND_JOB, queue, user, hosts, nq.cores, nq.nodes); /* when finished to display the job info, close the connection to the mbatchd */ lsb_closejobinfo(); exit(0); }
static void prtLoad (struct hostInfoEnt *hPtrs, struct lsInfo *lsInfo) { static char fname[] = "prtLoad"; char **nlp = NULL; int i, nf; char **loadval; char **loadval1; int start = 0; int end; int last; if (!fmt) { if(!(fmt=(struct indexFmt *) malloc((lsInfo->numIndx+2)*sizeof (struct indexFmt)))) { lsberrno=LSBE_NO_MEM; lsb_perror("print_long"); exit(-1); } for (i=0; i<NBUILTINDEX+2; i++) fmt[i]=fmt1[i]; } if ((nlp = formLINamesList (lsInfo)) == NULL) { fprintf (stderr, "%s\n", _i18n_msg_get(ls_catd,NL_SETN,1629, "Bad load index name specified")); /* catgets 1629 */ exit (-1); } if ((loadval=(char **) malloc((lsInfo->numIndx+1) * sizeof(char *))) == NULL) { lserrno=LSE_MALLOC; lsb_perror(fname); exit(-1); } if ((loadval1=(char **) malloc((lsInfo->numIndx+1) * sizeof(char *))) == NULL) { lserrno=LSE_MALLOC; lsb_perror(fname); exit(-1); } last = hPtrs->nIdx; for (i=0; i < last; i++) { loadval[i] = malloc(MAXFIELDSIZE); loadval1[i] = malloc(MAXFIELDSIZE); if (loadval[i] == NULL || loadval[i] == NULL) { lserrno=LSE_MALLOC; lsb_perror(fname); exit(-1); } } nf = makeFields(hPtrs, loadval, nlp, TRUE); nf = makeFields(hPtrs, loadval1, nlp, FALSE); while ((end = getDispLastItem(nlp, start, last)) > start && start < last) { printf(" %11s", " "); printf("%s\n", formatHeader(nlp, start, end)); printf( " %-11.11s", _i18n_msg_get(ls_catd,NL_SETN,1630, "Total")); /* catgets 1630 */ for (i=start; i < end; i++) printf("%s", loadval[i]); putchar('\n'); printf( " %-11.11s", _i18n_msg_get(ls_catd,NL_SETN,1631, "Reserved")); /* catgets 1631 */ for (i=start; i < end; i++) printf("%s", loadval1[i]); putchar('\n'); putchar('\n'); start = end; } putchar('\n'); for (i=0; i < last; i++) { FREEUP(loadval[i]); FREEUP(loadval1[i]); } FREEUP(loadval); FREEUP(loadval1); }
int main(int argc, char **argv) { int numQueues; char **queueNames=NULL, **queues = NULL; struct queueInfoEnt *queueInfo; char lflag = FALSE; int cc, defaultQ = FALSE; char *host = NULL, *user = NULL; int rc; numQueues = 0; rc = _i18n_init ( I18N_CAT_MIN ); if (lsb_init(argv[0]) < 0) { lsb_perror("lsb_init"); exit(-1); } while ((cc = getopt(argc, argv, "Vhlwm:u:")) != EOF) { switch (cc) { case 'l': lflag = TRUE; if (wflag) usage(argv[0]); break; case 'w': wflag = TRUE; if (lflag) usage(argv[0]); break; case 'm': if (host != NULL || *optarg == '\0') usage(argv[0]); host = optarg; break; case 'u': if (user != NULL || *optarg == '\0') usage(argv[0]); user = optarg; break; case 'V': fputs(_LS_VERSION_, stderr); exit(0); case 'h': default: usage(argv[0]); } } numQueues = getNames(argc, argv, optind, &queueNames, &defaultQ, "queue"); if (!defaultQ && numQueues != 0) queues = queueNames; else queues = NULL; TIMEIT(0, (queueInfo = lsb_queueinfo(queues, &numQueues, host, user, 0)), "lsb_queueinfo"); if (!queueInfo) { if (lsberrno == LSBE_BAD_QUEUE && queues) lsb_perror(queues[numQueues]); else { switch (lsberrno) { case LSBE_BAD_HOST : case LSBE_QUEUE_HOST : lsb_perror (host); break; case LSBE_BAD_USER : case LSBE_QUEUE_USE : lsb_perror (user); break; default : lsb_perror (NULL); } } return -1; } if (lflag) prtQueuesLong(numQueues, queueInfo); else prtQueuesShort(numQueues, queueInfo); return 0; }
int main(int argc, char** argv) { // Initialise our connection to LSF if (lsb_init(argv[0]) < 0) { lsb_perror("lsb_init() failed"); return -1; } // If queue argument isn't defined then just show data from normal job queue char* queues; if (argc < 2) { queues = strdup("normal"); } else { queues = argv[1]; } // Query LSF int num_queues = 1; struct queueInfoEnt *info = lsb_queueinfo(&queues, &num_queues, NULL, NULL, 0); // For each queue in output (should only be one) process data for (int i = 0; i < num_queues; i++) { struct queueInfoEnt *curr_info = &info[i]; std::map<std::string, float> parent_map; std::list<ShareAcct*> accounts; // SKUNKWORKS SOLUTION for (int j = 1; j < curr_info->numOfSAccts; j++) { struct shareAcctInfoEnt *curr_share = &curr_info->shareAccts[j]; ShareAcct* acct = new ShareAcct( curr_share ); std::string parent = std::string(acct->getParent()); // If the parent is already in the map, sum the shares. Otherwise, add it in with the shares of the first child. if (parent_map.count(parent) > 0) { parent_map[parent] += acct->getShares(); } else { parent_map[parent] = acct->getShares(); } accounts.push_back(acct); } // Now walk back through the accounts (reverse order) and first normalise shares, // then multiply that by the value we calculated for the parents. We do this recursively until // we hit the bottom. std::map<std::string, float> share_map; // Try doing the same for priority. std::map<std::string, float> priority_map; for (auto it = accounts.begin(); it != accounts.end(); it++) { ShareAcct* a = *it; if (parent_map.count(a->getParent()) > 0) { if (share_map.count(a->getParent()) > 0) { share_map[a->getGroup()] = ((a->getShares() / parent_map[a->getParent()]) * share_map[a->getParent()]); priority_map[a->getGroup()] = (a->getPriority() * priority_map[a->getParent()]); } else { share_map[a->getGroup()] = (a->getShares() / parent_map[a->getParent()]); priority_map[a->getGroup()] = a->getPriority(); } } else { share_map[a->getGroup()] = 1; } a->setProportion(share_map[a->getGroup()]); a->setPriority(priority_map[a->getGroup()]); } // /SKUNKWORKS SOLUTION std::string root = accounts.front()->getParent(); // If there are actually any share accounts defined for this queue write result // It's done this way because JSON doesn't support commas at the end of the last list item if (curr_info->numOfSAccts > 0) { printf("[\n"); ShareAcct::print_structure(); // Write the root node printf("\n,\n['%s','' , 1, 1]", root.c_str()); // Write elements for (auto it = accounts.begin(); it != accounts.end(); it++) { printf(",\n"); (*it)->print(parent_map.count((*it)->getGroup()) > 0); } printf("]\n"); } } return 0; }
int breconfig (int argc, char **argv, int configFlag) { char *optName; int vFlag = 0; int fFlag = 0; int checkReply; int stdoutsave; int fd; FILE *fp; char *linep; char tmpfile[256]; char *tmpname = "tmpXXXXXX"; while ((optName = myGetOpt (argc, argv, "f|v|")) != NULL) { switch (optName[0]) { case 'v': vFlag = 1; break; case 'f': fFlag = 1; break; default: return (-2); } } if (optind < argc) { return (-2); } if (!vFlag && !fFlag) { fprintf (stderr, "\nChecking configuration files ...\n\n"); stdoutsave = dup (1); sprintf (tmpfile, "/tmp/%s", tmpname); mktemp (tmpfile); fd = open (tmpfile, O_RDWR | O_CREAT | O_TRUNC, 0666); if (fd > 0) { dup2 (fd, 1); dup2 (fd, 2); checkReply = checkConf (1, 2); fflush (stderr); close (fd); dup2 (stdoutsave, 1); dup2 (stdoutsave, 2); fp = fopen (tmpfile, "r"); if (fp != 0) { if (checkReply == EXIT_FATAL_ERROR || checkReply == EXIT_WARNING_ERROR) { if (checkReply == EXIT_FATAL_ERROR) fprintf (stderr, "There are fatal errors.\n\n"); else fprintf (stderr, "There are warning errors.\n\n"); fflush (stderr); if (getConfirm ((_i18n_msg_get (ls_catd, NL_SETN, 2563, "Do you want to see detailed messages? [y/n] ")))) /* catgets 2563 */ while ((linep = getNextLine_ (fp, 0))) fprintf (stderr, "%s\n", linep); } else fprintf (stderr, I18N (2586, "No errors found.\n\n")); /* catgets 2586 */ fflush (stderr); } fclose (fp); unlink (tmpfile); } else checkReply = checkConf (0, 2); } else checkReply = checkConf (vFlag, 2); if (configFlag == MBD_CKCONFIG) { return (0); } switch (checkReply) { case EXIT_FATAL_ERROR: return -1; case EXIT_WARNING_ERROR: if (fFlag) break; if (configFlag == MBD_RECONFIG) { if (!getConfirm ((_i18n_msg_get (ls_catd, NL_SETN, 2564, "\nDo you want to reconfigure? [y/n] ")))) { /* catgets 2564 */ fprintf (stderr, (_i18n_msg_get (ls_catd, NL_SETN, 2565, "Reconfiguration aborted.\n"))); /* catgets 2565 */ return (-1); } } else { if (!getConfirm (I18N (2570, "\nDo you want to restart MBD? [y/n] "))) { /* catgets 2570 */ fprintf (stderr, (I18N (2571, "MBD restart aborted.\n"))); /* catgets 2571 */ return (-1); } } default: ; } if (lsb_reconfig (configFlag) < 0) { lsb_perror ((_i18n_msg_get (ls_catd, NL_SETN, 2566, "Failed"))); /* catgets 2566 */ return (-1); } if (configFlag == MBD_RECONFIG) { printf ("%s\n", _i18n_msg_get (ls_catd, NL_SETN, 2567, "Reconfiguration initiated")); /* catgets 2567 */ } else { printf ("%s\n", I18N (2569, "MBD restart initiated")); /* catgets 2569 */ } return (0); }
int main(int argc, char **argv) { int numQueues; char **queues; struct queueInfoEnt *queueInfo; char lflag = FALSE; int cc; char *host; char *user; numQueues = 0; user = host = NULL; if (lsb_init(argv[0]) < 0) { lsb_perror("lsb_init"); return -1; } while ((cc = getopt(argc, argv, "Vhlwm:u:")) != EOF) { switch (cc) { case 'l': lflag = TRUE; if (wflag) { usage(argv[0]); return -1; } break; case 'w': wflag = TRUE; if (lflag) { usage(argv[0]); return -1; } break; case 'm': if (host != NULL || *optarg == '\0') usage(argv[0]); host = optarg; break; case 'u': if (user != NULL || *optarg == '\0') usage(argv[0]); user = optarg; break; case 'V': fputs(_LS_VERSION_, stderr); return 0; case 'h': default: usage(argv[0]); return -1; } } queues = NULL; numQueues = 0; if (optind < argc) { numQueues = argc - optind; queues = calloc(argc - optind, sizeof(char *)); for (cc = 0; cc < argc - optind; cc++) queues[cc] = argv[optind + cc]; } TIMEIT(0, (queueInfo = lsb_queueinfo(queues, &numQueues, host, user, 0)), "lsb_queueinfo"); if (!queueInfo) { if (lsberrno == LSBE_BAD_QUEUE && queues) lsb_perror(queues[numQueues]); else { switch (lsberrno) { case LSBE_BAD_HOST : case LSBE_QUEUE_HOST : lsb_perror(host); break; case LSBE_BAD_USER : case LSBE_QUEUE_USE : lsb_perror(user); break; default : lsb_perror(NULL); } } _free_(queues); return -1; } if (lflag) prtQueuesLong(numQueues, queueInfo); else prtQueuesShort(numQueues, queueInfo); _free_(queues); return 0; }
int main (int argc, char **argv) { int cc, myIndex; const char prompt[] = "badmin> "; static char line[MAXLINELEN]; int rc; rc = _i18n_init (I18N_CAT_MIN); if (lsb_init (argv[0]) < 0) { lsb_perror ("lsb_init"); _i18n_end (ls_catd); exit (-1); } while ((cc = getopt (argc, argv, "Vh")) != EOF) { switch (cc) { case 'V': fputs (_LS_VERSION_, stderr); exit (0); case 'h': default: cmdsUsage ("badmin", cmdList, _i18n_msgArray_get (ls_catd, NL_SETN, cmdInfo_ID, cmdInfo)); } } if (argc > optind) { int rc; if ((myIndex = adminCmdIndex (argv[optind], cmdList)) == -1) { fprintf (stderr, (_i18n_msg_get (ls_catd, NL_SETN, 2552, "Invalid command <%s> \n")), argv[optind]); /* catgets 2552 */ cmdsUsage ("badmin", cmdList, _i18n_msgArray_get (ls_catd, NL_SETN, cmdInfo_ID, cmdInfo)); } optind++; rc = doBatchCmd (argc, argv); _i18n_end (ls_catd); exit (rc); } for (;;) { printf ("%s", prompt); fflush (stdout); if (fgets (line, MAXLINELEN, stdin) == NULL) { printf ("\n"); _i18n_end (ls_catd); exit (-1); } parseAndDo (line, doBatchCmd); } return (0); }
static int badminDebug (int nargc, char *nargv[], int opCode) { struct hostInfoEnt *hostInfo; char opt[10]; char **hostPoint; char *word; char **hosts = NULL; int i, c; int send; int retCode = 0; int all = FALSE, numHosts = 0; struct debugReq debug; debug.opCode = opCode; debug.logClass = 0; debug.level = 0; debug.hostName = NULL; debug.logFileName[0] = '\0'; debug.options = 0; if (opCode == MBD_DEBUG || opCode == SBD_DEBUG) strcpy (opt, "oc:l:f:"); else if (opCode == MBD_TIMING || opCode == SBD_TIMING) strcpy (opt, "ol:f:"); else return (-2); linux_optind = 1; linux_opterr = 1; if (strstr (nargv[0], "badmin")) { linux_optind++; } while ((c = getopt (nargc, nargv, opt)) != EOF) { switch (c) { case 'c': while (optarg != NULL && (word = getNextWord_ (&optarg))) { if (strcmp (word, "LC_SCHED") == 0) debug.logClass |= LC_SCHED; if (strcmp (word, "LC_EXEC") == 0) debug.logClass |= LC_EXEC; if (strcmp (word, "LC_TRACE") == 0) debug.logClass |= LC_TRACE; if (strcmp (word, "LC_COMM") == 0) debug.logClass |= LC_COMM; if (strcmp (word, "LC_XDR") == 0) debug.logClass |= LC_XDR; if (strcmp (word, "LC_CHKPNT") == 0) debug.logClass |= LC_CHKPNT; if (strcmp (word, "LC_FILE") == 0) debug.logClass |= LC_FILE; if (strcmp (word, "LC_AUTH") == 0) debug.logClass |= LC_AUTH; if (strcmp (word, "LC_HANG") == 0) debug.logClass |= LC_HANG; if (strcmp (word, "LC_SIGNAL") == 0) debug.logClass |= LC_SIGNAL; if (strcmp (word, "LC_PIM") == 0) debug.logClass |= LC_PIM; if (strcmp (word, "LC_SYS") == 0) debug.logClass |= LC_SYS; if (strcmp (word, "LC_JLIMIT") == 0) debug.logClass |= LC_JLIMIT; if (strcmp (word, "LC_PEND") == 0) debug.logClass |= LC_PEND; if (strcmp (word, "LC_LOADINDX") == 0) debug.logClass |= LC_LOADINDX; if (strcmp (word, "LC_M_LOG") == 0) { debug.logClass |= LC_M_LOG; } if (strcmp (word, "LC_PERFM") == 0) { debug.logClass |= LC_PERFM; } if (strcmp (word, "LC_MPI") == 0) { debug.logClass |= LC_MPI; } if (strcmp (word, "LC_JGRP") == 0) { debug.logClass |= LC_JGRP; } } if (debug.logClass == 0) { fprintf (stderr, I18N (2572, "Command denied.Invalid class name\n")); /* catgets 2572 */ return (-1); } break; case 'l': for (i = 0; i < strlen (optarg); i++) { if (!isdigit (optarg[i])) { fprintf (stderr, I18N (2573, "Command denied. Invalid level value\n")); /* catgets 2573 */ return (-1); } } debug.level = atoi (optarg); if (opCode == MBD_DEBUG || opCode == SBD_DEBUG) { if (debug.level < 0 || debug.level > 3) { fprintf (stderr, I18N (2574, "Command denied. Valid debug level is [0-3] \n")); /* catgets 2574 */ return (-1); } } else if (debug.level < 1 || debug.level > 5) { fprintf (stderr, I18N (2575, "Command denied. Valid timing level is [1-5]\n")); /* catgets 2575 */ return (-1); } break; case 'f': if (strstr (optarg, "/") && strstr (optarg, "\\")) { fprintf (stderr, I18N (2576, "Command denied. Invalid file name\n")); /* catgets 2576 */ return (-1); } memset (debug.logFileName, 0, sizeof (debug.logFileName)); ls_strcat (debug.logFileName, sizeof (debug.logFileName), optarg); if (debug.logFileName[strlen (debug.logFileName) - 1] == '/' || debug.logFileName[strlen (debug.logFileName) - 1] == '\\') { fprintf (stderr, I18N (2577, "Command denied. File name is needed after the path\n")); /* catgets 2577 */ return (-1); } break; case 'o': debug.options = 1; break; default: return (-2); } } if (opCode == SBD_DEBUG || opCode == SBD_TIMING) { numHosts = getNames (nargc, nargv, optind, &hosts, &all, "hostC"); hostPoint = NULL; if (!numHosts && !all) numHosts = 1; else if (numHosts) hostPoint = hosts; if ((hostInfo = lsb_hostinfo (hostPoint, &numHosts)) == NULL) { lsb_perror (NULL); return (-1); } for (i = 0; i < numHosts; i++) { if (strcmp (hostInfo[i].host, "lost_and_found") == 0) { if (!all) fprintf (stderr, "%s.\n", _i18n_msg_get (ls_catd, NL_SETN, 2568, "<lost_and_found> is not a real host, ignored")); /* catgets 2568 */ continue; } fflush (stderr); if (hostInfo[i].hStatus & (HOST_STAT_UNAVAIL | HOST_STAT_UNREACH)) { if (hostInfo[i].hStatus & HOST_STAT_UNAVAIL) fprintf (stderr, I18N (2578, "failed : LSF daemon (LIM) is unavailable on host %s\n"), /* catgets 2578 */ hostInfo[i].host); else fprintf (stderr, I18N (2579, "failed : Slave batch daemon (sbatchd) is unreachable now on host %s\n"), /* catgets 2579 */ hostInfo[i].host); continue; } if ((send = lsb_debugReq (&debug, hostInfo[i].host)) < 0) { char msg[100]; sprintf (msg, I18N (2580, "Operation denied by SBD on <%s>"), /* catgets 2580 */ hostInfo[i].host); lsb_perror (msg); retCode = -1; } } return (retCode); } else { numHosts = getNames (nargc, nargv, optind, &hosts, &all, "hostC"); if (numHosts > 0) { fprintf (stderr, I18N (2581, "Host name does not need to be specified, set debug to the host which runs MBD\n")); /* catgets 2581 */ } if ((send = lsb_debugReq (&debug, NULL)) < 0) { char msg[100]; sprintf (msg, I18N (2582, "Operation denied by MBD")); /* catgets 2582 */ lsb_perror (msg); return (-1); } } return (0); }
int main (int argc, char **argv) { int i, cc, local = FALSE; struct hostInfoEnt *hInfo; char **hosts=NULL, **hostPoint, *resReq = NULL; char lflag = FALSE, sOption = FALSE, otherOption = FALSE; int numHosts; int rc; _lsb_recvtimeout = 30; rc = _i18n_init ( I18N_CAT_MIN ); if (lsb_init(argv[0]) < 0) { lsb_perror("lsb_init"); _i18n_end ( ls_catd ); exit(-1); } for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-h") == 0) { usage(argv[0]); _i18n_end ( ls_catd ); exit (0); } else if (strcmp(argv[i], "-V") == 0) { fputs(_LS_VERSION_, stderr); _i18n_end ( ls_catd ); exit(0); } else if (strcmp(argv[i], "-s") == 0) { if (otherOption == TRUE) { usage(argv[0]); _i18n_end ( ls_catd ); exit(-1); } sOption = TRUE; optind = i + 1; } else if (strcmp(argv[i], "-R") == 0 || strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "-w") == 0) { otherOption = TRUE; if (sOption == TRUE) { usage(argv[0]); _i18n_end ( ls_catd ); exit(-1); } } } if (sOption) { displayShareRes(argc, argv, optind); return (0); } while ((cc = getopt(argc, argv, "lwR:")) != EOF) { switch (cc) { case 'l': lflag = TRUE; if (wflag) usage(argv[0]); break; case 'w': wflag = TRUE; if (lflag) usage(argv[0]); break; case 'R': resReq = optarg; break; default: usage(argv[0]); } } numHosts = getNames (argc, argv, optind, &hosts, &local, "host"); if ((local && numHosts == 1) || !numHosts) hostPoint = NULL; else hostPoint = hosts; TIMEIT(0, (hInfo = lsb_hostinfo_ex(hostPoint, &numHosts, resReq, 0)), "lsb_hostinfo"); if (!hInfo) { if (lsberrno == LSBE_BAD_HOST && hostPoint) lsb_perror (hosts[numHosts]); else lsb_perror (NULL); exit (-1); } if (numHosts > 1 && resReq == NULL) sort_host (numHosts, hInfo); if ( lflag ) prtHostsLong(numHosts, hInfo); else prtHostsShort(numHosts, hInfo); _i18n_end ( ls_catd ); exit(0); }
int main(int argc, char **argv) { int cc; int numGroups = 0; int enumGrp = 0; char **groups=NULL; char **groupPoint; struct groupInfoEnt *grpInfo = NULL; int options = GRP_ALL; int all; int slots; if (lsb_init(argv[0]) < 0) { lsb_perror("lsb_init"); return -1; } slots = 0; while ((cc = getopt(argc, argv, "Vhs")) != EOF) { switch (cc) { case 'r': options |= GRP_RECURSIVE; break; case 'V': fputs(_LS_VERSION_, stderr); return -1; break; case 's': ++slots; break; case 'h': default: usage(argv[0]); return -1; } } if (slots) { if (strstr(argv[0], "bugroup")) { fprintf(stderr, "bugroup: -s option applies only to bmgroup\n"); return -1; } } numGroups = getNames(argc, argv, optind, &groups, &all, "group"); enumGrp = numGroups; if (numGroups) { options &= ~GRP_ALL; groupPoint = groups; } else groupPoint = NULL; if (strstr(argv[0], "bugroup") != NULL) { options |= USER_GRP; grpInfo = lsb_usergrpinfo(groupPoint, &enumGrp, options); } else if (strstr(argv[0], "bmgroup") != NULL) { options |= HOST_GRP; grpInfo = lsb_hostgrpinfo(groupPoint, &enumGrp, options); } if (grpInfo == NULL) { if (lsberrno == LSBE_NO_USER_GROUP || lsberrno == LSBE_NO_HOST_GROUP ) { if (options & HOST_GRP) lsb_perror("host group"); else lsb_perror("user group"); FREEUP(groups); return -1; } if (lsberrno == LSBE_BAD_GROUP && groups) lsb_perror (groups[enumGrp]); else lsb_perror(NULL); FREEUP (groups); return -1; } if (numGroups != enumGrp && numGroups != 0 && lsberrno == LSBE_BAD_GROUP) { if (groups) lsb_perror (groups[enumGrp]); else lsb_perror(NULL); FREEUP(groups); return -1; } FREEUP(groups); if (slots == 0) prtGroups(grpInfo, enumGrp, options); else print_groups(grpInfo, enumGrp); return 0; }