예제 #1
0
int
sendCmdBill_ (int s, resCmd cmd, struct resCmdBill *cmdmsg, int *retsock,
	     struct timeval *timeout)

{
    char *buf;
    int  i,bufsize,cc;

    bufsize = 1024;
    bufsize = bufsize + ALIGNWORD_(strlen(cmdmsg->cwd)) + sizeof(int);
    for (i=0; cmdmsg->argv[i]; i++)
        bufsize = bufsize + ALIGNWORD_(strlen(cmdmsg->argv[i])) + sizeof(int);
    if ((buf=malloc(bufsize)) == NULL) {
        lserrno = LSE_MALLOC;
        return -1;
    }

    umask(cmdmsg->filemask = (int)umask(0));
    cmdmsg->priority = 0;
    if (getLimits(cmdmsg->lsfLimits) < 0) {
	lserrno = LSE_LIMIT_SYS;
        free(buf);
	return -1;
    }
    cc=callRes_(s, cmd, (char *) cmdmsg, buf, bufsize, xdr_resCmdBill,
		retsock, timeout, NULL);
    free(buf);
    return cc;

}
예제 #2
0
LS_REQUEST_T *
lsGetIRProcRusage_(char *host, int tid, int pid, struct jRusage *ru,
		 appCompletionHandler appHandler,
		 void *appExtra)
{
    struct {
	struct LSFHeader hdr;
	struct resRusage rusageReq;
    } requestBuf;

    struct lsRequest *request;
    struct resRusage rusageReq;
    int s;
    int descriptor[2];

    if (_isconnected_(host, descriptor))
      s = descriptor[0];
    else {
	lserrno = LSE_LOSTCON;
	return NULL;
    }

    if (!FD_ISSET(s,&connection_ok_)){
	FD_SET(s,&connection_ok_);
	if (ackReturnCode_(s) < 0) {
	    closesocket(s);
	    _lostconnection_(host);
	    return NULL;
	}
    }

    rusageReq.rid = pid;
    rusageReq.whatid = RES_RID_ISPID;

    if (callRes_(s, RES_RUSAGE, (char *)&rusageReq, (char *)&requestBuf,
		 sizeof(requestBuf), xdr_resGetRusage, 0, 0, NULL) == -1) {
	closesocket(s);
	_lostconnection_(host);
	return NULL;
    }

    request = lsReqHandCreate_(tid,
			       currentSN,
			       s,
			       (void *)ru,
			       rgetRusageCompletionHandler_,
			       appHandler,
			       appExtra);

    if (request == NULL)
        return NULL;

    if (lsQueueDataAppend_((char *)request, requestQ)) {
        lsReqFree_(request);
        return NULL;
    }

    return(request);

}
예제 #3
0
int
lsRGetpgrp_(int sock, int taskid, int pid)
{
    struct _buf_ {
	struct LSFHeader hdrBuf;
	struct resPid pidBuf;
    } buf;
    LS_REQUEST_T *request;
    char host[MAXHOSTNAMELEN];

    struct resPid pidReq;
    int s, pgid;

    s = sock;
    gethostbysock_(s, host);

    if (!FD_ISSET(s,&connection_ok_)){
        FD_SET(s,&connection_ok_);
        if (ackReturnCode_(s) < 0) {
            closesocket(s);
            _lostconnection_(host);
            return (-1);
        }
    }

    pidReq.rpid = taskid;
    pidReq.pid = pid;

    if (callRes_(s, RES_GETPID, (char *) &pidReq, (char *) &buf,
		 sizeof(buf), xdr_resGetpid, 0, 0, NULL) == -1) {
        closesocket(s);
        _lostconnection_(host);
        return (-1);
    }

    request = lsReqHandCreate_(taskid, 
			       currentSN, 
			       s, 
			       (void *)&pgid,
			       rgetpidCompletionHandler_,
			       (appCompletionHandler) NULL,
			       NULL);

    if (request == NULL)
        return(-1);

    if (lsQueueDataAppend_((char *)request, requestQ))
        return(-1);

    if (lsReqWait_(request, 0) < 0)
        return (-1);

    lsReqFree_(request);

    return(pgid);

} 
예제 #4
0
int
do_rstty2_(int s, int io_fd, int redirect, int async)
{
    char buf[MSGSIZE];
    char *cp;

    static int termFlag = FALSE;
    static struct resStty tty;

    if (!termFlag) {
        termFlag = TRUE;
	tcgetattr(io_fd, &tty.termattr);

	if (getpgrp(0) != tcgetpgrp(io_fd)) {
	    tty.termattr.c_cc[VEOF] = 04;
	    tty.termattr.c_lflag |= ICANON;
	    tty.termattr.c_lflag |= ECHO;
	}
	if (redirect)
	    tty.termattr.c_lflag &= ~ECHO;

	if ((cp = getenv("LINES")) != NULL)
	    tty.ws.ws_row = atoi(cp);
	else
	    tty.ws.ws_row = 24;
	if ((cp = getenv("COLUMNS")) != NULL)
	    tty.ws.ws_col = atoi(cp);
	else
	    tty.ws.ws_col = 80;
	tty.ws.ws_xpixel = tty.ws.ws_ypixel = 0;
    }

    if (!async) {
        if (callRes_(s, RES_INITTTY, (char *) &tty, buf, MSGSIZE,
		  xdr_resStty, 0, 0, NULL) == -1)
	    return -1;
    } else {
        if (callRes_(s, RES_INITTTY_ASYNC, (char *) &tty, buf, MSGSIZE,
                  xdr_resStty, 0, 0, NULL) == -1)
            return -1;
    }

    return 0;
}
예제 #5
0
void *
lsRGetpidAsync_(int taskid, int *pid)
{
    struct _buf_ {
	struct LSFHeader hdrBuf;
	struct resPid pidBuf;
    } buf;
    LS_REQUEST_T *request;

    struct resPid pidReq;
    int s;
    struct tid *tid;
    char host[MAXHOSTNAMELEN];

    if ((tid = tid_find(taskid)) == NULL) {
        return(NULL);
    }

    s = tid->sock;
    gethostbysock_(s, host);

    if (!FD_ISSET(s,&connection_ok_)){
        FD_SET(s,&connection_ok_);
        if (ackReturnCode_(s) < 0) {
            closesocket(s);
            _lostconnection_(host);
            return (NULL);
        }
    }

    pidReq.rpid = taskid;
    pidReq.pid = -1;

    if (callRes_(s, RES_GETPID, (char *) &pidReq, (char *) &buf,
		 sizeof(buf), xdr_resGetpid, 0, 0, NULL) == -1) {
        closesocket(s);
        _lostconnection_(host);
        return (NULL);
    }

    
    request = lsReqHandCreate_(taskid, 
			       currentSN, 
			       s, 
			       (void *)pid,
			       rgetpidCompletionHandler_,
			       (appCompletionHandler) NULL,
			       NULL);

    if (request != NULL)
        if (lsQueueDataAppend_((char *)request, requestQ))
            return(NULL);

    return (void *)request;

} 
예제 #6
0
int
oneResDebug (struct debugReq  *pdebug , char *hostname)
{
    int s, descriptor[2];
    char space[ ]=" ";
    struct debugReq debugData;

    struct {
	struct LSFHeader hdr;
	struct debugReq d; 
     } buf;

     if (_isconnected_(hostname, descriptor))
	 s = descriptor[0];
     else if ((s = ls_connect(hostname)) < 0)
	 return -1;

      if (!FD_ISSET(s,&connection_ok_)){
	  FD_SET(s,&connection_ok_);
	  if (ackReturnCode_(s) < 0) {
	      closesocket(s);
	      _lostconnection_(hostname);
	      return -1;
            }
        }

       debugData.opCode = pdebug->opCode;
       debugData.logClass = pdebug->logClass;
       debugData.level    = pdebug->level;
       debugData.hostName = space;
       debugData.options  = pdebug->options;
       strcpy(debugData.logFileName, pdebug->logFileName);

       if (callRes_(s, RES_DEBUGREQ, (char *) &debugData, (char *) &buf,
			sizeof(buf), xdr_debugReq, 0, 0, NULL) == -1) {
           closesocket(s);
	   _lostconnection_(hostname);
	   return( -1 );
	  }

	if (ackReturnCode_(s) < 0) {
	    closesocket(s);
	    _lostconnection_(hostname);
	    return( -1 );
	 }

    return 0;
} 
예제 #7
0
int
ls_chdir(char *host, char *dir)
{
    int s, descriptor[2];
    struct {
	struct LSFHeader hdr;
	struct resChdir ch;
    } buf;
    struct resChdir chReq;

    if (_isconnected_(host, descriptor))
	s = descriptor[0];
    else if ((s = ls_connect(host)) < 0)
	return -1;

    if (!FD_ISSET(s,&connection_ok_)){
	FD_SET(s,&connection_ok_);
	if (ackReturnCode_(s) < 0) {
	   closesocket(s);
	   _lostconnection_(host);
	   return -1;
        }
    }

    if (dir[0] != '/' && dir[1] != ':' && (dir[0] != '\\' || dir[1] != '\\')) {
        lserrno = LSE_BAD_ARGS;
        return -1;
    }

    strcpy(chReq.dir, dir);

    if (callRes_(s, RES_CHDIR, (char *) &chReq, (char *) &buf,
		 sizeof(buf), xdr_resChdir, 0, 0, NULL) == -1) {
	closesocket(s);
	_lostconnection_(host);
        return -1;
    }

    if (ackReturnCode_(s) < 0) {
        if (lserrno == LSE_RES_DIRW)
            return -2;
        else
            return -1;
    }

    return 0;
}
예제 #8
0
LS_REQUEST_T *
lsIRGetRusage_(int rpid,
	       struct jRusage *ru,
	       appCompletionHandler appHandler,
	       void *appExtra,
	       int options)
{
    struct {
	struct LSFHeader hdr;
	struct resRusage rusageReq;
    } requestBuf;

    struct lsRequest *request;

    struct resRusage rusageReq;
    int s;
    struct tid *tid;
    char host[MAXHOSTNAMELEN];

    if ((tid = tid_find(rpid)) == NULL) {
        return NULL;
    }

    s = tid->sock;
    gethostbysock_(s, host);

    if (!FD_ISSET(s,&connection_ok_)){
        FD_SET(s,&connection_ok_);
        if (ackReturnCode_(s) < 0) {
           closesocket(s);
           _lostconnection_(host);
           return NULL;
        }
    }

    rusageReq.rid = rpid;
    if (options == 0 || (options & RID_ISTID))
        rusageReq.whatid = RES_RID_ISTID;
    else
        rusageReq.whatid = RES_RID_ISPID;

    if (callRes_(s, RES_RUSAGE, (char *)&rusageReq, (char *)&requestBuf,
		 sizeof(requestBuf), xdr_resGetRusage, 0, 0, NULL) == -1) {
	closesocket(s);
	_lostconnection_(host);
	return NULL;
    }

    request = lsReqHandCreate_(rpid,
			       currentSN,
			       s,
			       (void *)ru,
			       rgetRusageCompletionHandler_,
			       appHandler,
			       appExtra);

    if (request == NULL)
        return NULL;

    if (lsQueueDataAppend_((char *)request, requestQ)) {
        lsReqFree_(request);
        return NULL;
    }

    return(request);
}
예제 #9
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;
}
예제 #10
0
int
rsetenv_ (char *host, char **envp, int option)
{
    int    descriptor[2];
    struct resSetenv envMsg;
    char   *sendBuf;
    int    bufferSize;
    int    i, s;
    resCmd resCmdOption;

    bufferSize = 512;

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

    if (!envp)
        return 0;

    for(i=0; envp[i] != NULL; i++)
        bufferSize = bufferSize + ALIGNWORD_(strlen(envp[i])) + sizeof(int);

    sendBuf = (char *)malloc(bufferSize);
    if (sendBuf == NULL) {
        lserrno = LSE_MALLOC;
        goto err;
    }

    if (_isconnected_(host, descriptor))
	s = descriptor[0];
    else if ((s = ls_connect(host)) < 0) {
        free(sendBuf);
	goto err;
    }

    if (!FD_ISSET(s,&connection_ok_)){
	FD_SET(s,&connection_ok_);
	if (ackReturnCode_(s) < 0) {
	   closesocket(s);
	   _lostconnection_(host);
           free(sendBuf);
	   goto err;
        }
    }

    envMsg.env = envp;
    if (option == RSETENV_SYNCH)
        resCmdOption = RES_SETENV;
    else if (option == RSETENV_ASYNC)
        resCmdOption = RES_SETENV_ASYNC;
    if (callRes_(s, resCmdOption, (char *) &envMsg, sendBuf, bufferSize,
		 xdr_resSetenv, 0, 0, NULL) == -1) {
	closesocket(s);
	_lostconnection_(host);
        free(sendBuf);
        goto err;
    }
    free(sendBuf);

    if (option == RSETENV_SYNCH){
        if (ackReturnCode_(s) < 0) {
	    closesocket(s);
	    _lostconnection_(host);
            goto err;
        }
    }

    return 0;

err:

    return -1;
}
예제 #11
0
int
sendSig_(char *host, int rid, int sig, int options)
{
    struct {
        struct LSFHeader hdr;
        struct resRKill rk;
    } buf;
    struct resRKill killReq;
    int descriptor[2];
    int s;

    if (_isconnected_(host, descriptor))
      s = descriptor[0];
    else {
	lserrno = LSE_LOSTCON;
	return -1;
    }

    if (!FD_ISSET(s,&connection_ok_)){
	FD_SET(s,&connection_ok_);
	if (ackReturnCode_(s) < 0) {
	    closesocket(s);
	    _lostconnection_(host);
	    return -1;
	}
    }
    if ( sig >= NSIG || sig < 0 ){
	lserrno = LSE_BAD_ARGS;
	return( -1 );
    }

    killReq.rid = rid;

    if (options & RSIG_ID_ISTID) {
	killReq.whatid = RES_RID_ISTID;
    } else if (options & RSIG_ID_ISPID) {
	killReq.whatid = RES_RID_ISPID;
    } else {
	lserrno = LSE_BAD_ARGS;
	return -1;
    }

    killReq.signal = sig_encode(sig);

    if (callRes_(s, RES_RKILL, (char *) &killReq, (char *) &buf,
		 sizeof(buf), xdr_resRKill, 0, 0, NULL) == -1) {
	closesocket(s);
	_lostconnection_(host);
	return -1;
    }

    if (ackReturnCode_(s) < 0) {
	if (options & RSIG_KEEP_CONN)
	    return -1;

	closesocket(s);
	_lostconnection_(host);
	return( -1 );
    }
    return 0;
}
예제 #12
0
int
lsGetRProcRusage(char *host, int pid, struct jRusage *ru, int options)
{
    struct {
	struct LSFHeader hdr;
	struct resRusage rusageReq;
    } requestBuf;

    struct lsRequest *request;
    struct resRusage rusageReq;
    int s;
    int descriptor[2];

    if (_isconnected_(host, descriptor))
      s = descriptor[0];
    else {
	lserrno = LSE_LOSTCON;
	return -1;
    }

    if (!FD_ISSET(s,&connection_ok_)){
	FD_SET(s,&connection_ok_);
	if (ackReturnCode_(s) < 0) {
	    closesocket(s);
	    _lostconnection_(host);
	    return -1;
	}
    }

    rusageReq.rid = pid;
    rusageReq.whatid = RES_RID_ISPID;

    if (options & RES_RPID_KEEPPID) {
	rusageReq.options |= RES_RPID_KEEPPID;
    } else {
	rusageReq.options = 0;
    }

    if (callRes_(s, RES_RUSAGE, (char *)&rusageReq, (char *)&requestBuf,
		 sizeof(requestBuf), xdr_resGetRusage, 0, 0, NULL) == -1) {
	closesocket(s);
	_lostconnection_(host);
	return -1;
    }

    request = lsReqHandCreate_(pid,
			       currentSN,
			       s,
			       (void *)ru,
			       rgetRusageCompletionHandler_,
			       NULL,
			       NULL);

    if (request == NULL)
        return -1;

    if (lsQueueDataAppend_((char *)request, requestQ))
        return -1;


    if (! request)
	return -1;

    if (lsReqWait_(request, 0) < 0)
        return -1;

    lsReqFree_(request);

    return 0;

}
예제 #13
0
int
ls_rescontrol(char *host, int opCode, int data)
{
    int       s;
    int       descriptor[2];
    int       cc;
    struct    resControl ctrl;
    struct {
	struct LSFHeader    hdr;
	struct resControl   c;
    } buf;
    struct timeval    timeout;

    
    if (genParams_[LSF_RES_TIMEOUT].paramValue) {
	timeout.tv_sec  = atoi(genParams_[LSF_RES_TIMEOUT].paramValue);
    } else {
	timeout.tv_sec = LSF_RES_TIMEOUT;
    }

    timeout.tv_usec = 0;

    if (_isconnected_(host, descriptor))
	s = descriptor[0];
    else if ((s = ls_connect(host)) < 0)
	return -1;

    if (!FD_ISSET(s,&connection_ok_)){
	FD_SET(s,&connection_ok_);

	
	cc = rd_select_(s, &timeout);
	if (cc <= 0) {
	    closesocket(s);
	    _lostconnection_(host);
	    lserrno =  LSE_TIME_OUT;
	    return -1;
	}
	
	if (ackReturnCode_(s) < 0) {
	    closesocket(s);
	    _lostconnection_(host);
	    return -1;
        }
    }

    if (opCode    != RES_CMD_REBOOT 
	&& opCode != RES_CMD_SHUTDOWN  
	&& opCode != RES_CMD_LOGON 
	&& opCode != RES_CMD_LOGOFF) {
        lserrno = LSE_BAD_OPCODE;
	return -1;
    }

    ctrl.opCode = opCode;
    ctrl.data   = data;

    if (callRes_(s, RES_CONTROL, (char *) &ctrl, (char *) &buf,
		 sizeof(buf), xdr_resControl, 0, 0, NULL) == -1) {
	closesocket(s);
	_lostconnection_(host);
	return( -1 );
    }

    
    cc = rd_select_(s, &timeout);
    if (cc <= 0) {
	closesocket(s);
	_lostconnection_(host);
	lserrno =  LSE_TIME_OUT;
	return -1;
    }
    
    if (ackReturnCode_(s) < 0) {
	closesocket(s);
	_lostconnection_(host);
	return( -1 );
    }

    return 0;
}