Exemplo n.º 1
0
static int
rmJobBufFilesPid(struct jobCard *jp)
{
    static char fname[] = "rmJobBufFilesPid()";
    int pid;

    if ((pid = fork()) < 0) {
	ls_syslog(LOG_ERR, I18N_JOB_FAIL_S_M, fname,
	    lsb_jobid2str(jp->jobSpecs.jobId), "fork");
	return (pid);
    }

    if (pid)
	return (pid);



    closeBatchSocket();
    putEnv(LS_EXEC_T, "END");

    if (postJobSetup(jp) < 0) {
	ls_syslog(LOG_ERR, I18N_JOB_FAIL_S,
	    fname,
	    lsb_jobid2str(jp->jobSpecs.jobId),
	    "postSetupUser");
	exit(-1);
    }

    rmJobBufFiles(jp);
    exit(0);
}
Exemplo n.º 2
0
void 
doSkipSection_conf(struct lsConf *conf, int *LineNum, char *lsfile, char *sectionName)
{
    char *word;
    char *cp;
    
    if (conf == NULL)
	return;

    while ((cp = getNextLineC_conf(conf, LineNum, TRUE)) != NULL) {
	word = getNextWord_(&cp);      
	if (strcasecmp(word, "end") == 0) {
	    word = getNextWord_(&cp);
	    if (! word) {
		ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5419,
	"%s(%d): Section ended without section name, ignored"), lsfile, *LineNum); /* catgets 5419 */
	    } else {
		if (strcasecmp(word, sectionName) != 0)
		    ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5420,
	"%s(%d): Section %s ended with wrong section name: %s, ignored"), lsfile, *LineNum, sectionName, word); /* catgets 5420 */
	    }	
	    return;
	}
    }
    
    ls_syslog(LOG_ERR, I18N_PREMATURE_EOF, 
		"doSkipSection_conf", lsfile, *LineNum, sectionName);

} 
Exemplo n.º 3
0
static int
replyHdrWithRC(int rc, int chfd, int jobId)
{
    XDR                     xdrs2;
    char                    reply_buf[MSGSIZE];
    static char             fname[] = "replyHdrWithRC";
    struct LSFHeader        replyHdr;

    xdrmem_create(&xdrs2, reply_buf, MSGSIZE, XDR_ENCODE);
    replyHdr.opCode = rc;
    replyHdr.length = 0;

    if (!xdr_LSFHeader(&xdrs2, &replyHdr)) {
	ls_syslog(LOG_ERR, "%s: xdr_LSFHeader() failed for job <%d>", fname,
		  jobId);
	xdr_destroy(&xdrs2);
	return -1;
    }

    if (chanWrite_(chfd, reply_buf, XDR_GETPOS(&xdrs2)) <= 0) {
        ls_syslog(LOG_ERR, "%s: chanWrite_(%d) failed for job <%d>: %m",
		  fname, XDR_GETPOS(&xdrs2), jobId);
	xdr_destroy(&xdrs2);
	return -1;
    }
    xdr_destroy(&xdrs2);
    return 0;
}				/* replyHdrWithRC */
Exemplo n.º 4
0
static char *
readPIMBuf(char *pfile)
{
	char *fname="readPIMBuf";
	struct stat bstat;
	FILE *fp;

	FREEUP(pimInfoBuf);
	pimInfoLen = 0;

	if (stat(pfile,&bstat) < 0) {
		ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL_M, fname, "stat", pfile);  
		return(NULL);
	}
	pimInfoLen = bstat.st_size;
	if ((pimInfoBuf = (char *)malloc(pimInfoLen+1)) == NULL) {
		ls_syslog(LOG_ERR, I18N_FUNC_FAIL_M,  fname, "malloc"); 
		return(NULL);
	}
        if ((fp = openPIMFile(pfile)) == NULL) {
	    ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL_M, fname, "openPIMFile", pfile); 
   	    return (FALSE);
        }
	if (fread(pimInfoBuf,sizeof(char),pimInfoLen,fp) <= 0) {
		ls_syslog(LOG_ERR, I18N_FUNC_FAIL_M, fname, "fread");
		FREEUP(pimInfoBuf);
		return(NULL);
	}

	fclose(fp);

	pimInfoBuf[pimInfoLen] = '\0';
	return(pimInfoBuf);
}
Exemplo n.º 5
0
static void
initConn2NIOS (void)
{
  static char fname[] = "initConn2NIOS";


  conn2NIOS.task_duped =
    (int *) calloc (sysconf (_SC_OPEN_MAX), sizeof (int));
  if (!conn2NIOS.task_duped)
    {
      ls_syslog (LOG_ERR, I18N_FUNC_FAIL_M, fname, "calloc");
      resExit_ (-1);
    }
  conn2NIOS.sock.rbuf = (RelayBuf *) malloc (sizeof (RelayBuf));
  if (!conn2NIOS.sock.rbuf)
    {
      ls_syslog (LOG_ERR, I18N_FUNC_FAIL_M, fname, "calloc");
      resExit_ (-1);
    }
  conn2NIOS.sock.wbuf = (RelayLineBuf *) malloc (sizeof (RelayLineBuf));
  if (!conn2NIOS.sock.wbuf)
    {
      ls_syslog (LOG_ERR, I18N_FUNC_FAIL_M, fname, "calloc");
      resExit_ (-1);
    }
  conn2NIOS.sock.fd = -1;
  conn2NIOS.wtag = conn2NIOS.rtag = -1;
  conn2NIOS.num_duped = 0;
  conn2NIOS.sock.rcount = conn2NIOS.sock.wcount = 0;
  conn2NIOS.sock.rbuf->bcount = conn2NIOS.sock.wbuf->bcount = 0;
}
Exemplo n.º 6
0
void
pingReq(XDR *xdrs, struct sockaddr_in *from, struct LSFHeader *reqHdr)
{
    static char fname[] = "pingReq()";
    char buf[MSGSIZE/4];
    XDR  xdrs2;
    enum limReplyCode limReplyCode;
    struct LSFHeader replyHdr;

    limReplyCode = LIME_NO_ERR;
    replyHdr.opCode  = (short) limReplyCode;
    replyHdr.refCode = reqHdr->refCode;
    xdrmem_create(&xdrs2, buf, MSGSIZE/4, XDR_ENCODE);
    if (!xdr_LSFHeader(&xdrs2, &replyHdr) ||
        !xdr_string(&xdrs2, &myHostPtr->hostName, MAXHOSTNAMELEN)) {
        ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "xdr_string");
        xdr_destroy(&xdrs2);
        return;
    }

    if (chanSendDgram_(limSock, buf, XDR_GETPOS(&xdrs2), from) < 0) {
        ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL_M, fname, "chanSendDgram_",
                  sockAdd2Str_(from));
        xdr_destroy(&xdrs2);
        return;
    }
    xdr_destroy(&xdrs2);
    return;

}
Exemplo n.º 7
0
static char *
getLSFAdmin(void)
{
    static char admin[MAXLSFNAMELEN];
    static char fname[] = "getLSFAdmin";
    char *mycluster;
    struct clusterInfo *clusterInfo;
    struct passwd *pw;
    char *lsfUserName;

    if (admin[0] != '\0')
        return admin;

    if ((mycluster = ls_getclustername()) == NULL) {
        ls_syslog(LOG_ERR, I18N_FUNC_FAIL_MM, fname, "ls_getclustername");
        return NULL;
    }
    if ((clusterInfo = ls_clusterinfo(NULL, NULL, NULL, 0, 0)) == NULL) {
        ls_syslog(LOG_ERR, I18N_FUNC_FAIL_MM, fname, "ls_clusterinfo");
        return NULL;
    }

    lsfUserName = (clusterInfo->nAdmins == 0 ? clusterInfo->managerName :
                   clusterInfo->admins[0]);

    if ((pw = getpwnam(lsfUserName)) == NULL) {
        ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL_M,
                  fname, "getpwnam", lsfUserName);
        return NULL;
    }

    strcpy(admin, lsfUserName);

    return admin;
}
Exemplo n.º 8
0
static int
readPIMFile(char *pfile)
{
	char *fname = "readPIMFile";
	struct lsPidInfo *tmp;
	char *buffer,*tmpbuf;
	char pimString[MAXLINELEN];

	if ((buffer=readPIMBuf(pfile))==NULL) {
	    ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "readPIMBuf"); 
	    return(FALSE);
	}

	FREEUP(pinfoList);
	npinfoList = 0;
	pinfoList = (struct lsPidInfo *)malloc(sizeof(struct lsPidInfo) * MAX_NUM_PID);
	if (pinfoList == NULL) {
		ls_syslog(LOG_ERR, I18N_FUNC_D_FAIL_M, fname,  "malloc", 
				sizeof(struct lsPidInfo) * MAX_NUM_PID); 
		return(FALSE);
	}
        
	tmpbuf = getNextString(buffer,pimString);
	if (tmpbuf == NULL) {
		ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5908,
	"%s format error"), "pim.info"); /* catgets 5908 */
		return(FALSE);
	}
	buffer = tmpbuf;
    
        while ((tmpbuf = getNextString(buffer,pimString))!=NULL) {
	    buffer = tmpbuf;
            if (logclass & LC_PIM)
	        ls_syslog(LOG_DEBUG3,"pim info string is %s",pimString);
	    sscanf(pimString, "%d %d %d %d %d %d %d %d %d %d %d %d",
		  &pinfoList[npinfoList].pid, &pinfoList[npinfoList].ppid,
		  &pinfoList[npinfoList].pgid, &pinfoList[npinfoList].jobid,
		  &pinfoList[npinfoList].utime, &pinfoList[npinfoList].stime,
		  &pinfoList[npinfoList].cutime, &pinfoList[npinfoList].cstime,
		  &pinfoList[npinfoList].proc_size, &pinfoList[npinfoList].resident_size,
		  &pinfoList[npinfoList].stack_size,
		  (int *)&pinfoList[npinfoList].status); 

		npinfoList ++;
		if (npinfoList % MAX_NUM_PID == 0) {
			tmp = (struct lsPidInfo *)realloc(pinfoList,
			       sizeof(struct lsPidInfo) * (npinfoList + MAX_NUM_PID));
			if (tmp == NULL) {
				ls_syslog(LOG_ERR, I18N_FUNC_D_FAIL_M, fname, "realloc",
					  sizeof(struct lsPidInfo)
					  * (npinfoList + MAX_NUM_PID));
				return(FALSE);
			}
			pinfoList = tmp;
		}
	}

	return(TRUE);
}
Exemplo n.º 9
0
int
equivalentXferFile(lsRcpXfer *lsXfer, char *szLocalFile, char *szRemoteFile,
                    struct stat *psLstat, struct stat *psRstat, char *szRhost)
{
    char *pszH;
    char szHost1[MAXHOSTNAMELEN], szHost2[MAXHOSTNAMELEN];
    char *hostlist[1];
    struct hostInfo *hostinfo;
    char  * szFileName1, * szFileName2;

    if (logclass & (LC_FILE))
        ls_syslog(LOG_DEBUG,"equivalentXferFile(), ls_getmnthost() for '%s'",
                szLocalFile);

    hostlist[0] = szRhost;
    hostinfo = ls_gethostinfo((char *)NULL, (int *)NULL, (char **)hostlist, 1, 0);
    if ( hostinfo == (struct hostInfo *)NULL ) {
	return -1;
    } else {
	if ( strcmp(hostinfo->hostType, "NTX86") == 0
             || strcmp(hostinfo->hostType, "NTALPHA") == 0) {
	    return (1);
	}
    }

    if ((pszH = ls_getmnthost(szLocalFile)) == NULL) {
        return -1;
    }

    strcpy(szHost1, pszH);

    if (logclass & (LC_FILE))
        ls_syslog(LOG_DEBUG,
	    "equivalentXferFile(),ls_rgetmnthost() for '%s' on '%s'"
            , szLocalFile, szRhost);

    if ((pszH = ls_rgetmnthost(szRhost, szRemoteFile)) == NULL) {
        return -1;
    }

    strcpy(szHost2, pszH);

    szFileName1 = strrchr(lsXfer->ppszHostFnames[0],'/');
    szFileName2 = strrchr(lsXfer->ppszDestFnames[0],'/');
    if (szFileName1 == NULL)
        szFileName1 = lsXfer->ppszHostFnames[0];
    else szFileName1 ++;
    if (szFileName2 == NULL)
        szFileName2 = lsXfer->ppszDestFnames[0];
    else szFileName2 ++;
    if ( psLstat->st_ino == psRstat->st_ino
         && (strcmp(szFileName1,szFileName2) == 0)
         && equalHost_(szHost1,szHost2)) {
         return 0;
    }
    return(1);

}
Exemplo n.º 10
0
int
putInLists (char *word, struct admins *admins, int *numAds, char *forWhat)
{
  static char fname[] = "putInLists";
  struct passwd *pw;
  char **tempNames;
  int i, *tempIds, *tempGids;

  if ((pw = getpwlsfuser_ (word)) == NULL)
    {
      if (logclass & LC_TRACE)
	{
	  ls_syslog (LOG_DEBUG, _i18n_msg_get (ls_catd, NL_SETN, 5410, "%s: <%s> is not a valid user on this host"), fname, word);	/* catgets 5410 */
	}
    }
  if (isInlist (admins->adminNames, word, admins->nAdmins))
    {
      ls_syslog (LOG_WARNING, _i18n_msg_get (ls_catd, NL_SETN, 5411, "%s: Duplicate user name <%s> %s; ignored"), fname, word, forWhat);	/* catgets 5411 */
      return (0);
    }
  admins->adminIds[admins->nAdmins] = (pw == NULL) ? -1 : pw->pw_uid;
  admins->adminGIds[admins->nAdmins] = (pw == NULL) ? -1 : pw->pw_gid;
  admins->adminNames[admins->nAdmins] = putstr_ (word);
  admins->nAdmins += 1;

  if (admins->nAdmins >= *numAds)
    {
      *numAds = *numAds * 2;
      tempIds = (int *) realloc (admins->adminIds, *numAds * sizeof (int));
      tempGids = (int *) realloc (admins->adminGIds, *numAds * sizeof (int));
      tempNames =
	(char **) realloc (admins->adminNames, *numAds * sizeof (char *));
      if (tempIds == NULL || tempGids == NULL || tempNames == NULL)
	{
	  ls_syslog (LOG_ERR, I18N_FUNC_FAIL_M, fname, "realloc");
	  FREEUP (tempIds);
	  FREEUP (tempGids);
	  FREEUP (tempNames);

	  FREEUP (admins->adminIds);
	  FREEUP (admins->adminGIds);
	  for (i = 0; i < admins->nAdmins; i++)
	    FREEUP (admins->adminNames[i]);
	  FREEUP (admins->adminNames);
	  admins->nAdmins = 0;
	  lserrno = LSE_MALLOC;
	  return (-1);
	}
      else
	{
	  admins->adminIds = tempIds;
	  admins->adminGIds = tempGids;
	  admins->adminNames = tempNames;
	}
    }
  return (0);
}
Exemplo n.º 11
0
static int
xdr_thresholds(XDR *xdrs, struct jobSpecs *jobSpecs)
{
    static char fname[] = "xdr_thresholds";
    int i, j;

    if (xdrs->x_op == XDR_DECODE) {
        jobSpecs->thresholds.loadSched = NULL; 
        jobSpecs->thresholds.loadStop = NULL; 
    }

    if (xdrs->x_op == XDR_FREE) {
        for(i=0; i < jobSpecs->thresholds.nThresholds; i++) {
            FREEUP(jobSpecs->thresholds.loadSched[i]);
            FREEUP(jobSpecs->thresholds.loadStop[i]);
        }
        FREEUP(jobSpecs->thresholds.loadSched);
        FREEUP(jobSpecs->thresholds.loadStop);
        return(TRUE);
    }

    if (!(xdr_int(xdrs, &jobSpecs->thresholds.nIdx) && 
         xdr_int(xdrs, &jobSpecs->thresholds.nThresholds))) {
	ls_syslog(LOG_ERR, I18N_JOB_FAIL_S_S, fname, 
		  lsb_jobid2str(jobSpecs->jobId), 
		  "xdr_int", "nIdx/nThresholds");
        return(FALSE);
    }
    if (xdrs->x_op == XDR_DECODE) {
	jobSpecs->thresholds.loadSched = (float **) 
	       my_calloc (jobSpecs->thresholds.nThresholds, sizeof(float *), fname);
	jobSpecs->thresholds.loadStop = (float **) 
	       my_calloc (jobSpecs->thresholds.nThresholds, sizeof(float *), fname);
        for (i = 0; i < jobSpecs->thresholds.nThresholds; i++) {
            jobSpecs->thresholds.loadSched[i] = (float *)
                 my_calloc (jobSpecs->thresholds.nIdx, sizeof(float), fname);
            jobSpecs->thresholds.loadStop[i] = (float *)
                my_calloc (jobSpecs->thresholds.nIdx, sizeof(float), fname);
        }
    }

    for (j = 0; j < jobSpecs->thresholds.nThresholds; j++) {
        for (i = 0; i < jobSpecs->thresholds.nIdx; i++) {
            if (!(xdr_float(xdrs, &jobSpecs->thresholds.loadStop[j][i]) &&
	          xdr_float(xdrs, &jobSpecs->thresholds.loadSched[j][i]))) {
		ls_syslog(LOG_ERR, I18N_JOB_FAIL_S_S, fname, 
			  lsb_jobid2str(jobSpecs->jobId), 
			  "xdr_float", "loadStop/loadSched");
                return(FALSE);
            }
	}
    }
    return (TRUE);

} 
Exemplo n.º 12
0
bool_t 
xdr_sbdPackage1 (XDR *xdrs, struct sbdPackage *sbdPackage, struct LSFHeader *hdr)
{
    static char      fname[] = "xdr_sbdPackage1";
    int i;

    
    if (!(xdr_int(xdrs, &sbdPackage->uJobLimit))) {
        ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL, fname, 
	          "xdr_int", "uJobLimit");
        return(FALSE);
    }

    if (!(xdr_int(xdrs, &sbdPackage->rusageUpdateRate) &&
          xdr_int(xdrs, &sbdPackage->rusageUpdatePercent)))
        return(FALSE);

    
    if (!xdr_int(xdrs, &sbdPackage->jobTerminateInterval)) {
        ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL, fname, 
		"xdr_int", "jobTerminateInterval");
	return (FALSE); 
    }

	
    
    if (xdrs->x_op == XDR_ENCODE || (xdrs->x_op != XDR_FREE)) {

        if (!xdr_int(xdrs, &sbdPackage->nAdmins))
            return FALSE;

        if (xdrs->x_op == XDR_DECODE && sbdPackage->nAdmins > 0) {
            sbdPackage->admins
               = (char **) calloc (sbdPackage->nAdmins, sizeof (char *));
            if (sbdPackage->admins == NULL) {
                sbdPackage->nAdmins = 0;
                return (FALSE);
            }
        }
        for (i = 0; i < sbdPackage->nAdmins; i++) {
            if (!xdr_var_string (xdrs, &sbdPackage->admins[i]))
                return (FALSE);
        }
    } 
    
    if (xdrs->x_op == XDR_FREE) {
        for (i = 0; i < sbdPackage->nAdmins; i++) {
	    FREEUP(sbdPackage->admins[i]);
        }
	FREEUP(sbdPackage->admins);
    }

    return(TRUE);
} 
Exemplo n.º 13
0
bool_t 
xdr_jobSetup (XDR *xdrs, struct jobSetup *jsetup, struct LSFHeader *hdr)
{
    static char fname[]="xdr_jobSetup";
    char *sp1, *sp2, *sp3;
    int jobArrId, jobArrElemId;
    if (xdrs->x_op == XDR_ENCODE) {
	jobId64To32(jsetup->jobId, &jobArrId, &jobArrElemId);
    }    
    if (!(xdr_int(xdrs, &jobArrId) &&
	  xdr_int(xdrs, &jsetup->jStatus) &&
	  xdr_float(xdrs, &jsetup->cpuTime) &&
	  xdr_int(xdrs, &jsetup->w_status) &&
	  xdr_int(xdrs, &jsetup->reason) &&
	  xdr_int(xdrs, &jsetup->jobPid) &&
	  xdr_int(xdrs, &jsetup->jobPGid) &&
	  xdr_int(xdrs, &jsetup->execGid) &&	  
	  xdr_int(xdrs, &jsetup->execUid) &&
	  xdr_int(xdrs, &jsetup->execJobFlag))) {	
	ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "xdr_int");
	return (FALSE);
    }

    if (!xdr_arrayElement(xdrs, (char *) &jsetup->lsfRusage, hdr,
                          xdr_lsfRusage))
	return (FALSE);

    sp1 = jsetup->execUsername;
    sp2 = jsetup->execHome;
    sp3 = jsetup->execCwd;

    if (xdrs->x_op == XDR_DECODE) {
	sp1[0] = '\0';
	sp2[0] = '\0';
	sp3[0] = '\0';
    }

    if (!(xdr_string(xdrs, &sp1, MAX_LSB_NAME_LEN) &&
	  xdr_string(xdrs, &sp2, MAXFILENAMELEN) &&
	  xdr_string(xdrs, &sp3, MAXFILENAMELEN))) {
	ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "xdr_string");
	return (FALSE);
    }
    if (!xdr_int(xdrs, &jobArrElemId)) {
        return (FALSE);
    }

    if (xdrs->x_op == XDR_DECODE) {
	jobId32To64(&jsetup->jobId,jobArrId,jobArrElemId);
    }      

    return (TRUE);
} 
Exemplo n.º 14
0
void
jobSuspendAction(struct jobCard *jp,
                 int sigValue,
                 int suspReasons,
                 int suspSubReasons)
{
    static char fname[] = "jobSuspendAction";

    if (logclass & (LC_TRACE | LC_SCHED | LC_EXEC))
        ls_syslog(LOG_DEBUG1, "%s: Suspend job %s; reasons=%x, subresons=%d, sigValue=%d, status=%x",
		  fname, lsb_jobid2str(jp->jobSpecs.jobId),
		  jp->jobSpecs.reasons,
		  jp->jobSpecs.subreasons, sigValue, jp->jobSpecs.jStatus);


    jp->actReasons = suspReasons;
    jp->actSubReasons = suspSubReasons;



    if (!JOB_RUNNING(jp))
        return;


    if( jp->postJobStarted ) {
        return;
    }

    if (IS_SUSP (jp->jobSpecs.jStatus)) {
        if (jp->jobSpecs.reasons & suspReasons)
            return;
        else if (jp->jobSpecs.sigMap[-sigValue] == 0)
            return;
    }


    if ((jp->jobSpecs.actPid)
        && ((jp->jobSpecs.actValue == sigValue)
            || (jp->jobSpecs.actValue == (sigValue + jp->jobSpecs.sigMap[-sigValue]))))
    return;

    if (logclass & (LC_TRACE | LC_SCHED | LC_EXEC))
        ls_syslog(LOG_DEBUG1, "%s: Call jobSigStart(sigValue =%d) to suspend job", fname, sigValue + jp->jobSpecs.sigMap[-(sigValue)]);

    jobSigStart(jp,
                sigValue + jp->jobSpecs.sigMap[-(sigValue)],
                0,
                0,
                SIGLOG);

    sbdlog_newstatus(jp);
}
Exemplo n.º 15
0
int
fcp (char *file1, char *file2, struct hostent *hp)
{
  static char fname[] = "fcp()";
  struct stat sbuf;
  int fd1, fd2;
  char buf[BSIZE];
  int cc;

  fd1 = myopen_ (file1, O_RDONLY, 0, hp);
  if (fd1 < 0)
    return -1;

  if (fstat (fd1, &sbuf) < 0)
    {
      ls_syslog (LOG_ERR, I18N_FUNC_S_FAIL_M, fname, "fstat", file1);
      close (fd1);
      return -1;
    }

  fd2 = myopen_ (file2, O_CREAT | O_TRUNC | O_WRONLY, (int) sbuf.st_mode, hp);
  if (fd2 < 0)
    {
      ls_syslog (LOG_ERR, I18N_FUNC_S_FAIL_M, fname, "creat", file1);
      close (fd1);
      return -1;
    }

  for (;;)
    {
      cc = read (fd1, buf, BSIZE);
      if (cc == 0)
	break;
      if (cc < 0)
	{
	  close (fd1);
	  close (fd2);
	  return -1;
	}
      if (write (fd2, buf, cc) != cc)
	{
	  close (fd1);
	  close (fd2);
	  return -1;
	}
    }

  close (fd1);
  close (fd2);
  return (0);
}
Exemplo n.º 16
0
char *
runEGroup_(char *type, char *gname)
{
    static char fname[] = "runEGroup";
    struct lenData ed;
    char lsfUserName[MAXLSFNAMELEN];
    char egroupPath[MAXFILENAMELEN];
    char *argv[4];
    char *managerIdStr;
    int uid;
    struct stat sbuf;

    sprintf(egroupPath, "%s/%s", genParams_[LSF_SERVERDIR].paramValue,
	    EGROUPNAME);

    argv[0] = egroupPath;
    argv[1] = type;
    argv[2] = gname;
    argv[3] = NULL;

    uid = getuid();
    if (uid == 0 && (managerIdStr = getenv("LSB_MANAGERID")) != NULL) {
	uid = atoi(managerIdStr);
        if (getUserByUid(uid, lsfUserName, sizeof(lsfUserName)) < 0) {
            ls_syslog(LOG_ERR, I18N_FUNC_D_FAIL_MM, fname, "getUserByUid", uid);
            return NULL;
        }
    } else {
        if (getUser(lsfUserName, sizeof(lsfUserName)) < 0) {
            ls_syslog(LOG_ERR, I18N_FUNC_FAIL_MM, fname, "getUser");
            return NULL;
        }
    }

    if (stat(egroupPath, &sbuf) < 0) {
	ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL_M, fname, "stat", egroupPath);
	return NULL;
    }

    if (getEData(&ed, argv, lsfUserName) < 0) {
	ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL_M, fname, "getEData", egroupPath);
	return NULL;
    }

    if (ed.len > 0) {
	ed.data[ed.len] = '\0';
	return ed.data;
    }

    return NULL;
}
Exemplo n.º 17
0
int
getElock(void)
{
    static char fname[] = "getElock";
    int  force = 0;
    int  retry;
    char *myhostnm, *mastername;
    struct stat statbuf;
    time_t lastmodtime;
    char  first = TRUE;
    char buf[MAXHOSTNAMELEN+8];
    int  lock_fd = -1;

    if (lsb_CheckMode)
        return 0;

    if ((myhostnm = ls_getmyhostname()) == NULL) {
        ls_syslog(LOG_ERR, I18N_FUNC_FAIL_MM, fname, "ls_getmyhostname");
        return MASTER_FATAL;
    }

    sprintf(lockfile, "%s/logdir/%s",
            daemonParams[LSB_SHAREDIR].paramValue,
            EVENT_LOCK_FILE);
access:

    chuser(managerId);
    if (force)
        lock_fd = open(lockfile, O_RDWR | O_CREAT | O_TRUNC, 0644);
    else
        lock_fd = open(lockfile, O_RDWR | O_CREAT | O_EXCL, 0644);

    if (lock_fd >= 0) {
        sprintf(buf, "%s:%d", myhostnm, (int)getpid());
        write(lock_fd, buf, strlen(buf));
        close(lock_fd);
        chuser(batchId);
        ls_syslog(LOG_INFO, "%s: Got lock file", fname);
        gotLock = TRUE;
        return 0;
    } else if (errno == EEXIST) {
        int fd,cc,i,pid;

        fd = open(lockfile, O_RDONLY, 0444);
        chuser(batchId);
        if (fd < 0) {
            ls_syslog(LOG_ERR, "\
%s: Can't open existing lock file <%s>: %m", fname, lockfile);
            return MASTER_FATAL;
        }
Exemplo n.º 18
0
static int
jobResumeAction (struct jobCard *jp, int sigValue, int suspReason)
{
    static char fname[] = "jobResumeAction";


    if (jp->jobSpecs.reasons & SUSP_MBD_LOCK) {

        return -1;
    };


    if (jp->jobSpecs.actPid)
        return 0;


    if (!(jp->jobSpecs.reasons & suspReason))
        return -1;

    if (logclass & (LC_TRACE | LC_SCHED | LC_EXEC))
        ls_syslog(LOG_DEBUG1, "%s: Try to resume job %s with the current reason %d and the triggered reason %d;",
                 fname, lsb_jobid2str(jp->jobSpecs.jobId), jp->jobSpecs.reasons, suspReason);

    if (jobSigStart(jp, sigValue, 0, 0, SIGLOG) < 0)
        if (jobsig(jp, 0, FALSE) < 0) {

            SBD_SET_STATE(jp, JOB_STAT_EXIT);
            return -1;
        }
    sbdlog_newstatus(jp);
    return 0;

}
Exemplo n.º 19
0
int
job_resume (struct jobCard *jp)
{
    static char fname[] = "job_resume";
    int rep;

    if (jp->jobSpecs.actPid)
	return 0;

    if (jobsig(jp, SIGCONT, FALSE) < 0)
        return -1;

    SBD_SET_STATE(jp, JOB_STAT_RUN);

    jp->jobSpecs.reasons = 0;
    jp->jobSpecs.subreasons = 0;
    rep = status_job (BATCH_STATUS_JOB, jp, jp->jobSpecs.jStatus,
		      ERR_NO_ERROR);
    if (rep < 0)
        jp->notReported++;
    else {
	if (jp->notReported > 0)
            jp->notReported = 0;
    }
    if (logclass & (LC_TRACE | LC_SCHED | LC_EXEC))
        ls_syslog(LOG_DEBUG1, "%s: Resume job %s",
                               fname, lsb_jobid2str(jp->jobSpecs.jobId));
    return 0;
}
Exemplo n.º 20
0
int
ackReturnCode_(int s)
{
    struct LSFHeader repHdr;
    int rc;
    char hostname[MAXHOSTNAMELEN];
    static char fname[] = "ackReturnCode_";

    if (logclass & (LC_TRACE))
	ls_syslog(LOG_DEBUG, "%s: Entering this routine...", fname);

    gethostbysock_(s, hostname);
    currentSN = _getcurseqno_(hostname);
    rc = expectReturnCode_(s, currentSN, &repHdr);
    if (rc < 0)
        return rc;

    lsf_res_version = (int)repHdr.version;

    rc = resRC2LSErr_(repHdr.opCode);

    if (rc == 0)
        return 0;
    else
	return -1;

}
Exemplo n.º 21
0
static int
chuserId (uid_t uid)
{

  if (seteuid(uid) < 0) {
      ls_syslog(LOG_ERR, "%s: Failed to change to uid <%d>: %m", __func__, uid);
      if (lsb_CheckMode) {
	   lsb_CheckError = FATAL_ERR;
	   return -1;
      } else {
	   die(MASTER_FATAL);
      }
  }

  if (uid == 0) {
      if (setreuid(0, 0) < 0) {
          ls_syslog(LOG_ERR, "\
%s: Failed to change to uid <%d>: %m", __func__, uid);
          if (lsb_CheckMode) {
              lsb_CheckError = FATAL_ERR;
              return -1;
          } else {
              if (masterme)
                  die(MASTER_FATAL);
              else
                  die(SLAVE_FATAL);
          }
      }
  }
Exemplo n.º 22
0
static int
intoPidList(struct lsPidInfo *pinfo)
{
    pidList[npidList].pid = pinfo->pid;
    pidList[npidList].ppid = pinfo->ppid;
    pidList[npidList].pgid = pinfo->pgid;
    pidList[npidList].jobid = pinfo->jobid;
 
    npidList++;
    
    if (npidList % PID_LIST_SIZE == 0) {
	struct pidInfo *tmpPtr;
		    
	tmpPtr = (struct pidInfo *) realloc((char *) pidList,
					    (npidList + PID_LIST_SIZE) *
					    sizeof(struct pidInfo));
	if (tmpPtr == NULL) {
	    ls_syslog(LOG_ERR, I18N_FUNC_D_FAIL_M, "intoPidList", "realloc", 
			(npidList + PID_LIST_SIZE) * sizeof(struct pidInfo));
	    return (-1);
	}
	pidList = tmpPtr;
    }

    return (0);
} 
Exemplo n.º 23
0
int
getAuth_(struct lsfAuth *auth, char *host)
{
    auth->uid = getuid();

    if (getUser(auth->lsfUserName, sizeof(auth->lsfUserName)) < 0) {
        ls_syslog(LOG_DEBUG, I18N_FUNC_FAIL_MM, "getAuth", "getUser");
        lserrno = LSE_BADUSER;
        return -1;
    }

    auth->gid = getgid();

    if (!genParams_[LSF_AUTH].paramValue)
        auth->kind = CLIENT_SETUID;
    else if (!strcmp(genParams_[LSF_AUTH].paramValue, AUTH_IDENT))
        auth->kind = CLIENT_IDENT;
    else if (!strcmp(genParams_[LSF_AUTH].paramValue, AUTH_PARAM_EAUTH)) {
        auth->kind = CLIENT_EAUTH;
        return getEAuth(&auth->k.eauth, host);
    } else
        auth->kind = CLIENT_SETUID;

    return 0;
}
Exemplo n.º 24
0
void
do_jobSyslog(XDR * xdrs, int chfd, struct LSFHeader * reqHdr)
{
    static char        fname[] = "do_jobSyslog()";
    struct jobSyslog   sysMsg;

    if (logclass & LC_TRACE)
        ls_syslog(LOG_DEBUG, "%s: Entering ...", fname);

    if (!xdr_jobSyslog(xdrs, &sysMsg, reqHdr)) {
        ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "xdr_syslog");
        return;
    }
    if (replyHdrWithRC(LSBE_NO_ERROR, chfd, -1) < 0)
        ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "replyHdrWithRC");
    ls_syslog(sysMsg.logLevel, sysMsg.msg);
}
Exemplo n.º 25
0
/* prm_init()
 */
int
prm_init(LIST_T *qList)
{
    if (logclass & LC_PREEMPT)
        ls_syslog(LOG_INFO, "%s: plugin initialized", __func__);

    return 0;
}
Exemplo n.º 26
0
void
lsb_merr(char *s)
{
    char fname[] = "lsb_merr";
    FILE *mail;
    char *myhostnm;

    if (lsb_CheckMode)
        return;

    if ((myhostnm = ls_getmyhostname()) == NULL) {
        ls_syslog(LOG_ERR, I18N_FUNC_FAIL_MM, fname, "ls_getmyhostname");
        if (masterme)
            die(MASTER_FATAL);
        else
            die (SLAVE_FATAL);
    }
    if (lsbManager == NULL || (getpwnam(lsbManager)) == NULL) {
        if (lsbManager == NULL)
            ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 8601,
                                             "%s: LSF administrator name is NULL"), /* catgets 8601 */
                      fname);
        else
            ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 8602,
                                             "%s: Bad LSF administrator name <%s>"), /* catgets 8602 */
                      fname,
                      lsbManager);
        if (masterme)
            die (MASTER_FATAL);
        else
            die (SLAVE_FATAL);
    }
    mail = smail(lsbManager, myhostnm);

    if (masterme)
        fprintf(mail, _i18n_msg_get(ls_catd, NL_SETN, 3201,
                                    "Subject: mbatchd on %s: %s\n"), /* catgets 3201 */
                myhostnm, s);
    else
        fprintf(mail, _i18n_msg_get(ls_catd, NL_SETN, 3202,
                                    "Subject: sbatchd on %s: %s\n"), /* catgets 3202 */
                myhostnm, s);

    mclose(mail);
}
Exemplo n.º 27
0
int
ctrlQueue (struct controlReq *qcReq, struct lsfAuth *auth)
{
  struct qData *qp;

  if ((qp = getQueueData (qcReq->name)) == NULL)
    return (LSBE_BAD_QUEUE);

  if (!isAuthManager (auth) && auth->uid != 0 && !isAuthQueAd (qp, auth))
    {
      ls_syslog (LOG_CRIT, I18N (7511, "ctrlQueue: uid <%d> not allowed to perform control operation"), auth->uid);	/* catgets 7511 */
      return (LSBE_PERMISSION);
    }

  if ((qcReq->opCode < QUEUE_OPEN) || (qcReq->opCode > QUEUE_INACTIVATE))
    return (LSBE_LSBLIB);

  if (qcReq->opCode == QUEUE_ACTIVATE && !(qp->qStatus & QUEUE_STAT_RUN))
    {
      qp->qStatus |= QUEUE_STAT_ACTIVE;
      log_queuestatus (qp, qcReq->opCode, auth->uid, auth->lsfUserName);
      return (LSBE_QUEUE_WINDOW);
    }

  if (((qp->qStatus & QUEUE_STAT_OPEN) &&
       (qcReq->opCode == QUEUE_OPEN))
      || (!(qp->qStatus & QUEUE_STAT_OPEN) &&
	  (qcReq->opCode == QUEUE_CLOSED))
      || ((qp->qStatus & QUEUE_STAT_ACTIVE) &&
	  (qcReq->opCode == QUEUE_ACTIVATE))
      || (!(qp->qStatus & QUEUE_STAT_ACTIVE) &&
	  (qcReq->opCode == QUEUE_INACTIVATE)))
    return (LSBE_NO_ERROR);

  if (qcReq->opCode == QUEUE_OPEN)
    {
      qp->qStatus |= QUEUE_STAT_OPEN;
      log_queuestatus (qp, qcReq->opCode, auth->uid, auth->lsfUserName);
    }
  if (qcReq->opCode == QUEUE_CLOSED)
    {
      qp->qStatus &= ~QUEUE_STAT_OPEN;
      log_queuestatus (qp, qcReq->opCode, auth->uid, auth->lsfUserName);
    }
  if (qcReq->opCode == QUEUE_ACTIVATE)
    {
      qp->qStatus |= QUEUE_STAT_ACTIVE;
      log_queuestatus (qp, qcReq->opCode, auth->uid, auth->lsfUserName);
    }
  if (qcReq->opCode == QUEUE_INACTIVATE)
    {
      qp->qStatus &= ~QUEUE_STAT_ACTIVE;
      log_queuestatus (qp, qcReq->opCode, auth->uid, auth->lsfUserName);
    }
  return (LSBE_NO_ERROR);

}
Exemplo n.º 28
0
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);
}
Exemplo n.º 29
0
static void
initChildRes (char *envdir)
{
  static char fname[] = "initChildRes";
  int i, maxfds;

  getLogClass_ (resParams[LSF_DEBUG_RES].paramValue,
		resParams[LSF_TIME_RES].paramValue);

  openChildLog ("res", resParams[LSF_LOGDIR].paramValue,
		(debug > 1), &(resParams[LSF_LOG_MASK].paramValue));

  if ((Myhost = ls_getmyhostname ()) == NULL)
    {
      ls_syslog (LOG_ERR, I18N_FUNC_FAIL_M, fname, "ls_getmyhostname");
      resExit_ (-1);
    }
  client_cnt = child_cnt = 0;

  for (i = 0; i < MAXCLIENTS_HIGHWATER_MARK + 1; i++)
    {
      clients[i] = NULL;
    }
  children = calloc (sysconf (_SC_OPEN_MAX), sizeof (struct children *));
  if (!children)
    {
      ls_syslog (LOG_ERR, I18N_FUNC_FAIL_M, fname, "calloc");
      resExit_ (-1);
    }
  maxfds = sysconf (_SC_OPEN_MAX);

  for (i = 0; i < maxfds; i++)
    {
      children[i] = NULL;
    }

  initConn2NIOS ();
  resNotifyList = listCreate ("resNotifyList");
  if (!resNotifyList)
    {
      ls_syslog (LOG_ERR, I18N_FUNC_FAIL_M, fname, "listCreate");
      resExit_ (-1);
    }
}
Exemplo n.º 30
0
static int
callLimTcp_(char *reqbuf,
            char **rep_buf,
            int req_size,
            struct LSFHeader *replyHdr,
            int options)
{
    static char fname[]="callLimTcp_";
    char retried = FALSE;
    int cc;
    XDR xdrs;
    struct Buffer sndbuf;
    struct Buffer rcvbuf;

    if (logclass & (LC_COMM | LC_TRACE))
        ls_syslog(LOG_DEBUG2,"%s: Entering...req_size=%d",fname, req_size);

    *rep_buf = NULL;
    if (!sockIds_[TCP].sin_addr.s_addr) {
        if (ls_getmastername() == NULL)
            return(-1);
    }

contact:
    if (limchans_[TCP] < 0) {

        limchans_[TCP] = chanClientSocket_(AF_INET, SOCK_STREAM, 0);
        if (limchans_[TCP] < 0 )
            return(-1);

        cc = chanConnect_(limchans_[TCP],
                          &sockIds_[TCP],
                          conntimeout_ * 1000,
                          0);
        if (cc < 0) {
            ls_syslog(LOG_DEBUG,"\
%s: failed in connecting to limChans_[TCP]=<%d> <%s>",
                      fname, limchans_[TCP], sockAdd2Str_(&sockIds_[TCP]));
            if (errno == ECONNREFUSED || errno == ENETUNREACH) {
                if (errno == ECONNREFUSED) {
                    lserrno = LSE_LIM_DOWN;
                }
                if (! retried) {
                    if (ls_getmastername() != NULL) {
                        retried = 1;
                        CLOSECD(limchans_[TCP]);
                        goto contact;
                    }
                }
            }
            sockIds_[TCP].sin_addr.s_addr = 0;
            sockIds_[TCP].sin_port        = 0;
            CLOSECD(limchans_[TCP]);
            return(-1);
        }