Exemple #1
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;

}
Exemple #2
0
int
ls_rkill(int rtid, int sig)
{
    int s;
    struct tid *tid;
    char host[MAXHOSTNAMELEN];
    int rc;

    if (rtid < 0) {
	lserrno = LSE_BAD_ARGS;
	return -1;
    }

    if (rtid == 0) {
      	rc = lsRSig_(NULL, rtid, sig, RSIG_ID_ISTID);
	return rc;
    }

    if ((tid = tid_find(rtid)) == NULL) {
        return -1;
    }

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

    rc = lsRSig_(host, rtid, sig, RSIG_ID_ISTID);

    return rc;

}
Exemple #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);

} 
Exemple #4
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;

} 
Exemple #5
0
/* ls_startserver()
 */
int
ls_startserver (char *host, char **server, int options)
{
  int retsock;
  char official[MAXHOSTNAMELEN];
  struct timeval timeout;
  struct sockaddr_in sin;
  int s;
  int descriptor[2];
  struct resCmdBill cmdmsg;
  int resTimeout;
  socklen_t len;

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

  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 (!isatty (0) && !isatty (1))
    options &= ~REXF_USEPTY;
  else if (options & REXF_USEPTY)
    {
      if (rstty_ (host) < 0)
	{
	  _lostconnection_ (host);
	  return (-1);
	}
    }

  if (mygetwd_ (cmdmsg.cwd) == 0)
    {
      closesocket (s);
      _lostconnection_ (host);
      lserrno = LSE_WDIR;
      return (-1);
    }

  if ((retsock = TcpCreate_ (TRUE, 0)) < 0)
    {
      closesocket (s);
      _lostconnection_ (host);
      return (-1);
    }

  len = sizeof (sin);
  if (getsockname (retsock, (struct sockaddr *) &sin, &len) < 0)
    {
      closesocket (retsock);
      closesocket (s);
      _lostconnection_ (host);
      lserrno = LSE_SOCK_SYS;
      return (-1);
    }

  cmdmsg.retport = sin.sin_port;

  cmdmsg.options = options & ~REXF_TASKPORT;
  cmdmsg.rpid = 0;
  cmdmsg.argv = server;

  timeout.tv_usec = 0;
  timeout.tv_sec = resTimeout;

  if (sendCmdBill_ (s, (resCmd) RES_SERVER, &cmdmsg, &retsock, &timeout)
      == -1)
    {
      closesocket (retsock);
      closesocket (s);
      _lostconnection_ (host);
      return (-1);
    }

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

  if (retsock <= 2 && (retsock = get_nonstd_desc_ (retsock)) < 0)
    {
      closesocket (s);
      _lostconnection_ (host);
      lserrno = LSE_SOCK_SYS;
      return (-1);
    }

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

  return (retsock);

}				/* ls_startserver() */
Exemple #6
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);
}
Exemple #7
0
int callRes_(int s,
             resCmd cmd,
             char *data,
             char *reqBuf,
             int reqLen,
	     bool_t (*xdrFunc)(),
             int *rd,
             struct timeval *timeout,
	     struct lsfAuth *auth)
{
    int                  cc;
    int                  t;
    struct sockaddr_in   from;
    socklen_t            fromsize;
    int                  nready;
    sigset_t             oldMask;
    sigset_t             newMask;
    char                 hostname[MAXHOSTNAMELEN];

    blockALL_SIGS_(&newMask, &oldMask);

    memset(hostname, 0, sizeof(hostname));

    currentSN = REQUESTSN;

    gethostbysock_(s, hostname);
    if (strcmp(hostname, "LSF_HOST_NULL"))
	_setcurseqno_(hostname, currentSN);

    if ((cc = lsSendMsg_(s,
                         cmd,
                         0,
                         data,
                         reqBuf,
                         reqLen,
                         xdrFunc,
			 b_write_fix,
                         auth)) < 0) {
        sigprocmask(SIG_SETMASK, &oldMask, NULL);
        return -1;
    }

    if (!rd) {
        sigprocmask(SIG_SETMASK, &oldMask, NULL);
        return 0;
    }

    nready = rd_select_(*rd, timeout);
    if (nready <= 0) {
        if (nready == 0)
            lserrno = LSE_TIME_OUT;
        else
            lserrno = LSE_SELECT_SYS;
        sigprocmask(SIG_SETMASK, &oldMask, NULL);
        return -1;
    }

    fromsize = sizeof(from);
    t = b_accept_(*rd, (struct sockaddr *)&from, &fromsize);
    if (t < 0) {
        lserrno = LSE_ACCEPT_SYS;
        sigprocmask(SIG_SETMASK, &oldMask, NULL);
        return -1;
    }

    closesocket(*rd);
    *rd = t;

    sigprocmask(SIG_SETMASK, &oldMask, NULL);

    return 0;

} /* callRes_() */
Exemple #8
0
int
lsMsgSnd_(int taskid, char *buffer, int len, int options)
{
    struct LSFHeader header;
    char headerBuf[sizeof(struct LSFHeader)];
    XDR xdrs;
    struct tid *tEnt;
    int rc;
    char hostname[MAXHOSTNAMELEN];

    tEnt = tid_find(taskid);
    if (! tEnt)
	return -1;

    if (tEnt->sock < 0) {
	lserrno = LSE_LOSTCON;
	return -1;
    }

#ifdef OS_HAS_PTHREAD
    pthread_mutex_lock(&fdLSLIBWriteMutex);
#endif

    header.opCode = RES_NONRES;
    header.refCode = currentSN = REQUESTSN;
    header.length = len;
    header.reserved = taskid;

    gethostbysock_(tEnt->sock, hostname);
    if (strcmp(hostname, "LSF_HOST_NULL"))
	_setcurseqno_(hostname, currentSN);

    xdrmem_create(&xdrs, headerBuf, LSF_HEADER_LEN, XDR_ENCODE);
    if (!xdr_LSFHeader(&xdrs, &header)) {
	lserrno = LSE_BAD_XDR;
	xdr_destroy(&xdrs);
	rc = -1;
        goto AbortSnd;
    }
    xdr_destroy(&xdrs);

    rc = b_write_fix(tEnt->sock, headerBuf, LSF_HEADER_LEN);
    if (rc < 0) {
	if (errno == EPIPE) {

	    close(tEnt->sock);
	    tEnt->sock = -1;
	    _lostconnection_(hostname);
	    lserrno = LSE_LOSTCON;
	}
        rc = -1;
        goto AbortSnd;
    }

    rc = b_write_fix(tEnt->sock, buffer, len);
    if (rc < 0) {
	if (errno == EPIPE) {
	    close(tEnt->sock);
	    tEnt->sock = -1;
	    _lostconnection_(hostname);
	    lserrno = LSE_LOSTCON;
	}
        rc = -1;
        goto AbortSnd;
    }
    if (ackReturnCode_(tEnt->sock) < 0) {
        rc = -1;
        goto AbortSnd;
    }

  AbortSnd:

#ifdef OS_HAS_PTHREAD
    pthread_mutex_unlock(&fdLSLIBWriteMutex);
#endif

    return rc;

}