コード例 #1
0
ファイル: lib.resctrl.c プロジェクト: CraigNoble/openlava
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;
} 
コード例 #2
0
ファイル: lib.res.c プロジェクト: CraigNoble/openlava
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
ファイル: lib.res.c プロジェクト: CraigNoble/openlava
int
do_rstty1_(char *host, int async)
{
    int s, descriptor[2];
    int redirect, io_fd;

    redirect = 0;
    if (isatty(0)) {
	if (!isatty(1))
	    redirect = 1;
	io_fd = 0;
    } else if (isatty(1)) {
	redirect = 1;
	io_fd = 1;
    } else
	return 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_);
	if (ackReturnCode_(s) < 0) {
	    closesocket(s);
	    _lostconnection_(host);
	    return -1;
        }
    }

    if (do_rstty2_(s, io_fd, redirect, async) == -1) {
	closesocket(s);
	_lostconnection_(host);
        return -1;
    }

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

    return 0;
}
コード例 #4
0
ファイル: lib.res.c プロジェクト: CraigNoble/openlava
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;
}
コード例 #5
0
ファイル: lib.rtask.c プロジェクト: ReiAyanamiQH/jhlava
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);

} 
コード例 #6
0
ファイル: lib.rtask.c プロジェクト: ReiAyanamiQH/jhlava
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;

} 
コード例 #7
0
ファイル: lib.res.c プロジェクト: CraigNoble/openlava
int
lsConnWait_(char *host)
{
    int s;
    int descriptor[2];

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

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

    return 0;
}
コード例 #8
0
ファイル: rex.c プロジェクト: georgemarselis/openlava-macosx
int
ls_rexecve (char *host, char **argv, int options, char **envp)
{
  int d;
  int retsock;
  struct timeval timeout;
  socklen_t len;
  struct sockaddr_in sin;
  int max;
  char sock_buf[20];
  char *new_argv[5];
  char pathbuf[MAXPATHLEN];
  int s;
  int descriptor[2];
  struct resCmdBill cmdmsg;
  int resTimeout;

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

  cmdmsg.options = options & ~REXF_TASKPORT;
  if (cmdmsg.options & REXF_SHMODE)
    cmdmsg.options |= REXF_USEPTY;

  if (!isatty (0) && !isatty (1))
    cmdmsg.options &= ~REXF_USEPTY;
  else if (cmdmsg.options & REXF_USEPTY)
    {
      if (rstty_ (host) < 0)
	{

	  _lostconnection_ (host);
	  return (-1);
	}
    }


  if ((genParams_[LSF_INTERACTIVE_STDERR].paramValue != NULL)
      && (strcasecmp (genParams_[LSF_INTERACTIVE_STDERR].paramValue,
		      "y") == 0))
    {
      cmdmsg.options |= REXF_STDERR;
    }

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

  if (envp)
    {
      if (ls_rsetenv (host, envp) < 0)
	{
	  _lostconnection_ (host);
	  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)
    {
      (void) closesocket (retsock);
      closesocket (s);
      _lostconnection_ (host);
      lserrno = LSE_SOCK_SYS;
      return (-1);
    }

  cmdmsg.retport = sin.sin_port;

  cmdmsg.rpid = 0;
  cmdmsg.argv = argv;
  cmdmsg.priority = 0;

  timeout.tv_usec = 0;
  timeout.tv_sec = resTimeout;
  if (sendCmdBill_ (s, (resCmd) RES_EXEC, &cmdmsg, &retsock, &timeout) == -1)
    {
      closesocket (retsock);
      closesocket (s);
      _lostconnection_ (host);
      return (-1);
    }


  (void) sprintf (sock_buf, "%d", retsock);

  if (initenv_ (NULL, NULL) < 0)
    return (-1);
  strcpy (pathbuf, genParams_[LSF_SERVERDIR].paramValue);
  strcat (pathbuf, "/nios");
  new_argv[0] = pathbuf;
  new_argv[1] = "-n";
  new_argv[2] = sock_buf;

  if (cmdmsg.options & REXF_USEPTY)
    {
      if (cmdmsg.options & REXF_SHMODE)
	new_argv[3] = "2";
      else
	new_argv[3] = "1";
    }
  else
    new_argv[3] = "0";
  new_argv[4] = 0;

  max = sysconf (_SC_OPEN_MAX);
  for (d = 3; d < max; ++d)
    {
      if (d != retsock)
	(void) close (d);
    }

  (void) lsfExecvp (new_argv[0], new_argv);
  lserrno = LSE_EXECV_SYS;
  close (retsock);
  close (s);
  return (-1);
}
コード例 #9
0
ファイル: rex.c プロジェクト: georgemarselis/openlava-macosx
/* 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() */
コード例 #10
0
ファイル: lib.rtask.c プロジェクト: ReiAyanamiQH/jhlava
int
ls_rtaske(char *host, char **argv, int options, char **envp)
{
    static u_short          retport;
    static int              rpid;
    static int              reg_ls_donerex = FALSE;
    struct sockaddr_in      sin;
    int                     max;
    char                    c_chfd[8];
    char                    pathbuf[MAXPATHLEN];
    int                     d;
    int                     niosOptions = 0;
    char                    *new_argv[5];
    int                     pid;
    int                     s;
    int                     descriptor[2];
    struct resCmdBill       cmdmsg;
    struct lslibNiosRTask   taskReq;
    u_short                 taskPort = 0;
    sigset_t                newMask;
    sigset_t                oldMask;
    socklen_t               len;

    if (!reg_ls_donerex) {

        atexit( (void (*) ()) ls_donerex);   
 	reg_ls_donerex = TRUE;
    }

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

    if (blockALL_SIGS_(&newMask, &oldMask) < 0)
        return (-1);

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

    if (!nios_ok_) 
        niosOptions = options & REXF_SYNCNIOS;
    options &= ~REXF_SYNCNIOS;

    cmdmsg.options = options;
    if (cmdmsg.options & REXF_SHMODE)
	cmdmsg.options |= REXF_USEPTY;
    
    if (!isatty(0) && !isatty(1))
	cmdmsg.options &= ~REXF_USEPTY;
    else if (cmdmsg.options & REXF_USEPTY ){
        if (options & REXF_TTYASYNC){
            if (rstty_async_(host) < 0) {
                sigprocmask(SIG_SETMASK, &oldMask, NULL); 
                return (-1);
            }
        } else {
	    if (rstty_(host) < 0) { 
                sigprocmask(SIG_SETMASK, &oldMask, NULL); 
                return (-1);
            }
        }
    }
    
    if ( (genParams_[LSF_INTERACTIVE_STDERR].paramValue != NULL)
	 && (strcasecmp(genParams_[LSF_INTERACTIVE_STDERR].paramValue, 
			"y") == 0) ) {
	cmdmsg.options |= REXF_STDERR;
    }

    if (!nios_ok_) {
       
        initSigHandler(SIGTSTP);
        initSigHandler(SIGTTIN);
        initSigHandler(SIGTTOU);

       
        if (socketpair(AF_UNIX, SOCK_STREAM, 0, cli_nios_fd) < 0) {
            lserrno = LSE_SOCK_SYS;
            sigprocmask(SIG_SETMASK, &oldMask, NULL); 
            closesocket(s);
            return(-1);
        }

        if ((pid = fork()) != 0) { 
            int mypid;

            close(cli_nios_fd[1]);
            mypid = getpid();
            if (b_write_fix(cli_nios_fd[0], (char *) &mypid, sizeof (mypid)) !=
                sizeof (mypid)) {
                close(cli_nios_fd[0]);
                sigprocmask(SIG_SETMASK, &oldMask, NULL); 
                lserrno = LSE_MSG_SYS;
                return (-1);
            }

            if (b_read_fix(cli_nios_fd[0], (char *) &retport, sizeof (u_short))
                != sizeof(u_short) ) {
                close(cli_nios_fd[0]);
                sigprocmask(SIG_SETMASK, &oldMask, NULL); 
                lserrno = LSE_MSG_SYS;
                return (-1);
            }

            nios_ok_ = TRUE;

            if (waitpid(pid, 0, 0) <0) { 
                if (errno != ECHILD) {
                    close(cli_nios_fd[0]);
                    nios_ok_ = FALSE;
                    sigprocmask(SIG_SETMASK, &oldMask, NULL); 
                    lserrno = LSE_WAIT_SYS;
                    return (-1);
                }
            }
        } else {
            if (fork()) { 
                max = sysconf(_SC_OPEN_MAX);
                for (d = 3; d < max; ++d) { 
                    (void)close(d);
                }
                exit(0);
            }
          

            if (initenv_(NULL, NULL) <0)
                exit (-1);
            strcpy(pathbuf, genParams_[LSF_SERVERDIR].paramValue);
            strcat(pathbuf, "/nios");
            sprintf(c_chfd, "%d", cli_nios_fd[1]);  
            new_argv[0] = pathbuf;
            new_argv[1] = c_chfd;
            if (cmdmsg.options & REXF_USEPTY) {
                if (cmdmsg.options & REXF_SHMODE)
                    new_argv[2] = "2";
                else
                    new_argv[2] = "1";
            }
            else
                new_argv[2] = "0";
            new_argv[3] = NULL;

            max = sysconf(_SC_OPEN_MAX);
            for (d = 3; d < max; ++d) { 
                if (d != cli_nios_fd[1])
                    (void)close(d);
            }
          
            for (d = 1; d < NSIG; d++)     
                Signal_(d, SIG_DFL);

          
            sigprocmask(SIG_SETMASK, &oldMask, NULL); 
            (void)lsfExecvp(new_argv[0], new_argv);
            exit(-1);
        }
    }

    if (envp) {
        if (ls_rsetenv_async (host, envp) < 0) {
            sigprocmask(SIG_SETMASK, &oldMask, NULL); 
            return (-1);
        }
    }

    if (rexcwd_[0] != '\0')
        strcpy(cmdmsg.cwd, rexcwd_);
    else if (mygetwd_(cmdmsg.cwd) == 0) {
	closesocket(s);
	_lostconnection_(host);
        lserrno = LSE_WDIR;
        sigprocmask(SIG_SETMASK, &oldMask, NULL); 
        return (-1);
    }

    
    rpid++;

    cmdmsg.rpid = rpid;
    cmdmsg.retport = retport;

    cmdmsg.argv = argv;
    cmdmsg.priority = 0;   

    if (sendCmdBill_(s, (resCmd) RES_EXEC, &cmdmsg, NULL, NULL) == -1) {
	closesocket(s);
	_lostconnection_(host);
        sigprocmask(SIG_SETMASK, &oldMask, NULL); 
	return(-1);
    }

    if (cmdmsg.options & REXF_TASKPORT) {
	
	if ((taskPort = getTaskPort(s)) == 0) {
	    closesocket(s);
	    _lostconnection_(host);
            sigprocmask(SIG_SETMASK, &oldMask, NULL); 
	    return(-1);
	}
    }

    len = sizeof(sin);
    if (getpeername(s, (struct sockaddr *) &sin, &len) <0) {
	closesocket(s);
	_lostconnection_(host);
	lserrno = LSE_SOCK_SYS;
        sigprocmask(SIG_SETMASK, &oldMask, NULL); 
	return(-1);
    }

    SET_LSLIB_NIOS_HDR(taskReq.hdr, LIB_NIOS_RTASK, sizeof(taskReq.r));
    taskReq.r.pid = rpid;
    taskReq.r.peer = sin.sin_addr;
    
    taskReq.r.pid = (niosOptions & REXF_SYNCNIOS)? -rpid : rpid;

    if (b_write_fix(cli_nios_fd[0], (char *) &taskReq, sizeof(taskReq))
	!= sizeof(taskReq)) {
	closesocket(s);
	_lostconnection_(host);
	lserrno = LSE_MSG_SYS;
        sigprocmask(SIG_SETMASK, &oldMask, NULL); 
	return (-1);
    }

    if (tid_register(rpid, s, taskPort, host, options & REXF_TASKINFO) == -1) {
	closesocket(s);
	_lostconnection_(host);
	lserrno = LSE_MALLOC;
        sigprocmask(SIG_SETMASK, &oldMask, NULL); 
	return (-1);
    }

    sigprocmask(SIG_SETMASK, &oldMask, NULL);

    return (rpid);
} 
コード例 #11
0
ファイル: lib.res.c プロジェクト: CraigNoble/openlava
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);
}
コード例 #12
0
ファイル: lib.res.c プロジェクト: CraigNoble/openlava
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;
}
コード例 #13
0
ファイル: lib.res.c プロジェクト: CraigNoble/openlava
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;

}
コード例 #14
0
ファイル: lib.res.c プロジェクト: CraigNoble/openlava
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;
}
コード例 #15
0
ファイル: lib.res.c プロジェクト: CraigNoble/openlava
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;

}
コード例 #16
0
ファイル: lib.resctrl.c プロジェクト: CraigNoble/openlava
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;
}