Exemple #1
0
struct jRusage *getJInfo_(int npgid, int *pgid, int options, int cpgid)
{
    static char fname[] = "lib.pim.c/getJInfo_()";
    struct jRusage *jru;

    static char pfile[MAXFILENAMELEN];
    char *myHost;
    static struct sockaddr_in pimAddr;
    struct LSFHeader sendHdr, recvHdr, hdrBuf;
    int s, cc;
    struct timeval timeOut;
    static time_t lastTime = 0, lastUpdateNow = 0;
    time_t now;
    static time_t pimSleepTime = PIM_SLEEP_TIME;
    static bool_t periodicUpdateOnly = FALSE;
    
    now = time(0);

    if (logclass & LC_PIM)
       ls_syslog(LOG_DEBUG3,"now = %ld, lastTime = %ld, sleepTime = %ld",
	   now, lastUpdateNow, pimSleepTime);
    argOptions = options;

    if (lastTime == 0) {
	struct hostent *hp;
        struct config_param *plp;

        for (plp = pimParams; plp->paramName != NULL; plp++) {
             if (plp->paramValue != NULL) {
                 FREEUP (plp->paramValue);
             }
        }
 	
	if (initenv_(pimParams, NULL) < 0) {
	    if (logclass & LC_PIM)
		ls_syslog(LOG_DEBUG, "%s: initenv_() failed: %M", fname);
	    return NULL;
	}

	if ((myHost = ls_getmyhostname()) == NULL) {
	    if (logclass & LC_PIM)
		ls_syslog(LOG_DEBUG,
			  "%s: ls_getmyhostname() failed: %m", fname);
	    return (NULL);
	}
	
	if (pimParams[LSF_PIM_INFODIR].paramValue)
	    sprintf(pfile, "%s/pim.info.%s",
		    pimParams[LSF_PIM_INFODIR].paramValue, myHost);
	else {
	    if (pimParams[LSF_LIM_DEBUG].paramValue) {
		if (pimParams[LSF_LOGDIR].paramValue)
		    sprintf(pfile, "%s/pim.info.%s",
			    pimParams[LSF_LOGDIR].paramValue, myHost);
		else
		    sprintf(pfile, "/tmp/pim.info.%s.%d", myHost, (int)getuid());
	    } else {
		sprintf(pfile, "/tmp/pim.info.%s", myHost);
	    }
	}
	
	if (pimParams[LSF_PIM_SLEEPTIME].paramValue) {
	    if ((pimSleepTime =
		 atoi(pimParams[LSF_PIM_SLEEPTIME].paramValue)) < 0) {
		if (logclass & LC_PIM)
		    ls_syslog(LOG_DEBUG, "LSF_PIM_SLEEPTIME value <%s> must be a positive integer, defaulting to %d", pimParams[LSF_PIM_SLEEPTIME].paramValue, PIM_SLEEP_TIME);
		pimSleepTime = PIM_SLEEP_TIME;
	    }
	}

        if (pimParams[LSF_PIM_SLEEPTIME_UPDATE].paramValue != NULL
            && strcasecmp(pimParams[LSF_PIM_SLEEPTIME_UPDATE].paramValue, "y") == 0) { 
            periodicUpdateOnly = TRUE;
            if (logclass & LC_PIM)
                ls_syslog(LOG_DEBUG, "%s: Only to call pim each PIM_SLEEP_TIME interval", fname);
        }

	if ((hp = Gethostbyname_(myHost)) == NULL) {
	    return NULL;
	}

	memset((char *) &pimAddr, 0, sizeof(pimAddr));
	memcpy((char *) &pimAddr.sin_addr, (char *) hp->h_addr,
	       (int)hp->h_length);
	pimAddr.sin_family = AF_INET;
    }


    if (now - lastUpdateNow >= pimSleepTime || (options & PIM_API_UPDATE_NOW)) {
        if (logclass & LC_PIM)
	    ls_syslog(LOG_DEBUG,"%s: update now", fname);
	lastUpdateNow = now;	

	if ((s = TcpCreate_(FALSE, 0)) < 0) {
	    if (logclass & LC_PIM)
		ls_syslog(LOG_DEBUG, "%s: tcpCreate failed: %m", fname);
	    return (NULL);
	}

	if (pimPort(&pimAddr, pfile) == -1) {
	    close(s);
	    return (NULL);
	}
	
	if (b_connect_(s, (struct sockaddr *) &pimAddr, sizeof(pimAddr), 0)
	    == -1) {
	    if (logclass & LC_PIM)
		ls_syslog(LOG_DEBUG, "%s: b_connect() failed: %m", fname);
	    lserrno = LSE_CONN_SYS;
	    close(s);
	    return (NULL);
	}

	initLSFHeader_(&sendHdr);
	initLSFHeader_(&recvHdr);
    
	sendHdr.opCode = options;
	sendHdr.refCode = (short) now & 0xffff;
	sendHdr.reserved = cpgid;

	if ((cc = writeEncodeHdr_(s, &sendHdr, b_write_fix)) < 0) {
	    if (logclass & LC_PIM)
		ls_syslog(LOG_DEBUG,
			  "%s: writeEncodeHdr failed cc=%d: %M", fname, cc);
	    close(s);
	    return (NULL);
	}

	timeOut.tv_sec = 10;
	timeOut.tv_usec = 0;
	if ((cc = rd_select_(s, &timeOut)) < 0) {
	    if (logclass & LC_PIM)
		ls_syslog(LOG_DEBUG, "%s: rd_select_ cc=%d: %m", fname, cc);
	    close(s);
	    return (NULL);
	}

	if ((cc = lsRecvMsg_(s, (char *) &hdrBuf, sizeof(hdrBuf), &recvHdr,
			     NULL, NULL, b_read_fix)) < 0) {
	    if (logclass & LC_PIM)
		ls_syslog(LOG_DEBUG, "%s: lsRecvMsg_ failed cc=%d: %M",
			  fname, cc);
	    close(s);
	    return (NULL);
	}
	close(s);

	if (recvHdr.refCode != sendHdr.refCode) {
	    if (logclass & LC_PIM)
		ls_syslog(LOG_DEBUG,
			  "%s: recv refCode=%d not equal to send refCode=%d, server is not PIM",
			  fname, (int) recvHdr.refCode, (int) sendHdr.refCode);
	    return (NULL);
	}
        if (logclass & LC_PIM)
	    ls_syslog(LOG_DEBUG,"%s updated now",fname);
	if (!readPIMFile(pfile)) {
		ls_syslog(LOG_ERR, I18N_FUNC_FAIL,  fname, "readPIMFile"); 
		return(NULL);
	}
    }

    lastTime = now;

    if ((jru = readPIMInfo(npgid, pgid)) == NULL &&
	!(options & PIM_API_UPDATE_NOW) 
	&& (periodicUpdateOnly == FALSE
	    || (periodicUpdateOnly == TRUE
		&& now - lastUpdateNow >= pimSleepTime))) {
	if (hitPGid > 0) {
	   jru = getJInfo_(npgid, pgid, options | PIM_API_UPDATE_NOW, hitPGid);
	   hitPGid = 0;
	   return jru;
	}
	else {
	   return (getJInfo_(npgid, pgid, options | PIM_API_UPDATE_NOW, cpgid));
	}
    }
    return jru;
	
	
} 
Exemple #2
0
int
ls_connect(char *host)
{
    struct  hostent *hp;
    int     s, descriptor[2], size;
    char    official[MAXHOSTNAMELEN];
    struct resConnect connReq;
    char *reqBuf;
    struct lsfAuth auth;
    int resTimeout;



    if (genParams_[LSF_RES_TIMEOUT].paramValue)
	resTimeout = atoi(genParams_[LSF_RES_TIMEOUT].paramValue);
    else
	resTimeout = RES_TIMEOUT;

    if (_isconnected_(host, descriptor))
        return(descriptor[0]);

    if ((hp = Gethostbyname_(host)) == NULL) {
        lserrno = LSE_BAD_HOST;
        return -1;
    }

    strcpy(official, hp->h_name);
    memcpy((char *)&res_addr_.sin_addr,(char *)hp->h_addr,(int)hp->h_length);
    if ((rootuid_) && (genParams_[LSF_AUTH].paramValue == NULL)) {
        if (currentsocket_ > (FIRST_RES_SOCK + totsockets_ - 1)) {
            lserrno = LSE_NOMORE_SOCK;
            return -1;
        }
        s = currentsocket_;
        currentsocket_++;
    } else {
        if ((s = CreateSockEauth_(SOCK_STREAM)) < 0)
            return -1;
    }

    putEauthClientEnvVar("user");
    putEauthServerEnvVar("res");

#ifdef INTER_DAEMON_AUTH

    putEnv("LSF_EAUTH_AUX_PASS", "yes");
#endif


    if (getAuth_(&auth, official) == -1) {
	closesocket(s);
	return -1;
    }

    runEsub_(&connReq.eexec, NULL);

    size = sizeof(struct LSFHeader) + sizeof(connReq) +
	   sizeof(struct lsfAuth) +
	   ALIGNWORD_(connReq.eexec.len) +
	   sizeof(int) * 5 ;

    if ((reqBuf = malloc(size)) == NULL) {
	lserrno = LSE_MALLOC;
	goto Fail;
    }

    if (b_connect_(s, (struct sockaddr *)&res_addr_,
				 sizeof(res_addr_), resTimeout) < 0) {
	lserrno = LSE_CONN_SYS;
	goto Fail;
    }

    if (callRes_(s, RES_CONNECT, (char *) &connReq, reqBuf,
		 size, xdr_resConnect, 0, 0, &auth) == -1) {
	goto Fail;
    }

    if (connReq.eexec.len > 0)
	free(connReq.eexec.data);

    free(reqBuf);

    (void)connected_(official, s, -1, currentSN);

    return(s);

  Fail:
    CLOSESOCKET(s);

    if (connReq.eexec.len > 0)
	free(connReq.eexec.data);

    free(reqBuf);
    return -1;
}