static int cleanupMigJob(struct jobCard *jp) { static char fname[] = "cleanupMigJob()"; int pid; unlockHosts (jp, jp->jobSpecs.numToHosts); if (!jp->jobSpecs.postCmd || jp->jobSpecs.postCmd[0] == '\0') return 0; if ((pid = fork()) < 0) { ls_syslog(LOG_ERR, I18N_JOB_FAIL_S_M, fname, lsb_jobid2str(jp->jobSpecs.jobId), "fork"); lsb_merr2(_i18n_msg_get(ls_catd , NL_SETN, 700, "Unable to fork a child to run the queue's post-exec command for job <%s>. Please run <%s> manually if necessary.\n"), /* catgets 700 */ lsb_jobid2str(jp->jobSpecs.jobId), jp->jobSpecs.postCmd); return (pid); } if (pid) return (pid); closeBatchSocket(); putEnv(LS_EXEC_T, "END"); if (postJobSetup(jp) == -1) { ls_syslog(LOG_ERR, I18N_JOB_FAIL_S, fname, lsb_jobid2str(jp->jobSpecs.jobId), "postJobSetup"); lsb_merr2(_i18n_msg_get(ls_catd , NL_SETN, 701, "Unable to setup the environment for job <%s> to run the queue's post exec. Please run <%s> manually if necessary.\n"), /* catgets 701 */ lsb_jobid2str(jp->jobSpecs.jobId), jp->jobSpecs.postCmd); exit(-1); } runQPost(jp); exit(0); }
void do_newjob(XDR *xdrs, int chfd, struct LSFHeader *reqHdr) { static char fname[] = "do_newjob()"; char reply_buf[MSGSIZE]; XDR xdrs2; struct jobSpecs jobSpecs; struct jobReply jobReply; struct jobCard *jp; sbdReplyType reply; struct LSFHeader replyHdr; char *replyStruct; struct lsfAuth *auth = NULL; memset(&jobReply, 0, sizeof(struct jobReply)); if (!xdr_jobSpecs(xdrs, &jobSpecs, reqHdr)) { reply = ERR_BAD_REQ; ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "xdr_jobSpecs"); goto sendReply; } for (jp = jobQueHead->forw; (jp != jobQueHead); jp = jp->forw) { if (jp->jobSpecs.jobId == jobSpecs.jobId) { jobReply.jobId = jp->jobSpecs.jobId; jobReply.jobPid = jp->jobSpecs.jobPid; jobReply.jobPGid = jp->jobSpecs.jobPGid; jobReply.jStatus = jp->jobSpecs.jStatus; reply = ERR_NO_ERROR; goto sendReply; } } jp = calloc(1, sizeof(struct jobCard)); if (jp == NULL) { ls_syslog(LOG_ERR, I18N_JOB_FAIL_S_M, fname, lsb_jobid2str(jobSpecs.jobId), "calloc"); reply = ERR_MEM; goto sendReply; } memcpy((char *) &jp->jobSpecs, (char *) &jobSpecs, sizeof(struct jobSpecs)); jp->jobSpecs.jStatus &= ~JOB_STAT_MIG; jp->jobSpecs.startTime = now; jp->jobSpecs.reasons = 0; jp->jobSpecs.subreasons = 0; /* Initialize the core number */ jp->core_num = -1; if (jp->jobSpecs.jAttrib & Q_ATTRIB_EXCLUSIVE) { if (lockHosts (jp) < 0) { ls_syslog(LOG_ERR, I18N_JOB_FAIL_S, fname, lsb_jobid2str(jp->jobSpecs.jobId), "lockHosts"); unlockHosts (jp, jp->jobSpecs.numToHosts); reply = ERR_LOCK_FAIL; freeWeek(jp->week); FREEUP(jp); goto sendReply; } } jp->runTime = 0; if (initJobCard(jp, &jobSpecs, (int *)&reply) < 0) { if (jp->jobSpecs.jAttrib & Q_ATTRIB_EXCLUSIVE) { unlockHosts (jp, jp->jobSpecs.numToHosts); } FREEUP(jp); goto sendReply; } jp->execJobFlag = 0; if (jp->runTime < 0) { jp->runTime = 0; } jp->execGid = 0; jp->execUsername[0] = '\0'; jp->jobSpecs.execUid = -1; jp->jobSpecs.execUsername[0] = '\0'; if (jp->jobSpecs.jobSpoolDir[0] != '\0') { char *tmp; if ((tmp = getUnixSpoolDir (jp->jobSpecs.jobSpoolDir)) == NULL) { jp->jobSpecs.jobSpoolDir[0] = '\0'; } } if ((logclass & LC_TRACE) && jp->jobSpecs.jobSpoolDir[0] != 0) { ls_syslog(LOG_DEBUG, "%s: the SpoolDir for job <%s> is %s \n", fname, lsb_jobid2str(jp->jobSpecs.jobId), jp->jobSpecs.jobSpoolDir); } if (jp->jobSpecs.options & SUB_PRE_EXEC) SBD_SET_STATE(jp, (JOB_STAT_RUN | JOB_STAT_PRE_EXEC)) else SBD_SET_STATE(jp, JOB_STAT_RUN); reply = job_exec(jp, chfd); if (reply != ERR_NO_ERROR) { ls_syslog(LOG_ERR, I18N_JOB_FAIL_S, fname, lsb_jobid2str(jp->jobSpecs.jobId), "job_exec"); if (jp->jobSpecs.jAttrib & Q_ATTRIB_EXCLUSIVE) { unlockHosts (jp, jp->jobSpecs.numToHosts); } deallocJobCard(jp); } else { jobReply.jobId = jp->jobSpecs.jobId; jobReply.jobPid = jp->jobSpecs.jobPid; jobReply.jobPGid = jp->jobSpecs.jobPGid; jobReply.jStatus = jp->jobSpecs.jStatus; } sendReply: xdr_lsffree(xdr_jobSpecs, (char *)&jobSpecs, reqHdr); xdrmem_create(&xdrs2, reply_buf, MSGSIZE, XDR_ENCODE); initLSFHeader_(&replyHdr); replyHdr.opCode = reply; replyStruct = (reply == ERR_NO_ERROR) ? (char *) &jobReply : (char *) NULL; if (!xdr_encodeMsg(&xdrs2, replyStruct, &replyHdr, xdr_jobReply, 0, auth)) { ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "xdr_jobReply"); lsb_merr(_i18n_msg_get(ls_catd , NL_SETN, 5804, "Fatal error: xdr_jobReply() failed; sbatchd relifing")); /* catgets 5804 */ relife(); } if (chanWrite_(chfd, reply_buf, XDR_GETPOS(&xdrs2)) <= 0) { ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5805, "%s: Sending jobReply (len=%d) to master failed: %m"), /* catgets 5805 */ fname, XDR_GETPOS(&xdrs2)); } xdr_destroy(&xdrs2); if (reply == ERR_NO_ERROR && !daemonParams[LSB_BSUBI_OLD].paramValue && PURE_INTERACTIVE(&jp->jobSpecs)) { if (status_job (BATCH_STATUS_JOB, jp, jp->jobSpecs.jStatus, ERR_NO_ERROR) < 0) { jp->notReported++; } } }