Esempio n. 1
0
int
lsb_reconfig (int configFlag)
{
  mbdReqType mbdReqtype;
  XDR xdrs;
  char request_buf[MSGSIZE];
  char *reply_buf;
  int cc;
  struct LSFHeader hdr;
  struct lsfAuth auth;
  int tmp;

  mbdReqtype = BATCH_RECONFIG;

  if (authTicketTokens_ (&auth, NULL) == -1)
    return (-1);

  xdrmem_create (&xdrs, request_buf, MSGSIZE, XDR_ENCODE);

  initLSFHeader_ (&hdr);
  hdr.opCode = mbdReqtype;
  tmp = (short) configFlag;
  hdr.reserved = tmp;

  if (!xdr_encodeMsg (&xdrs, NULL, &hdr, NULL, 0, &auth))
    {
      lsberrno = LSBE_XDR;
      return (-1);
    }

  if ((cc = callmbd (NULL, request_buf, XDR_GETPOS (&xdrs), &reply_buf,
		     &hdr, NULL, NULL, NULL)) == -1)
    {
      xdr_destroy (&xdrs);
      return (-1);
    }
  xdr_destroy (&xdrs);
  if (cc)
    free (reply_buf);

  lsberrno = hdr.opCode;
  if (lsberrno == LSBE_NO_ERROR)
    return (0);
  else
    return (-1);
}
Esempio n. 2
0
static int
signalJob_(int sigValue, LS_LONG_INT jobId, time_t period, int options)
{
    struct signalReq signalReq;
    char request_buf[MSGSIZE];
    char *reply_buf;
    XDR xdrs;
    mbdReqType mbdReqtype;
    int cc;
    struct LSFHeader hdr;
    struct lsfAuth auth;

    signalReq.jobId = jobId;

    if (authTicketTokens_(&auth, NULL) == -1)
        return -1;

    signalReq.sigValue = sigValue;
    signalReq.chkPeriod = period;
    signalReq.actFlags = options;

    signalReq.sigValue = sig_encode(signalReq.sigValue);

    mbdReqtype = BATCH_JOB_SIG;
    xdrmem_create(&xdrs, request_buf, MSGSIZE, XDR_ENCODE);

    initLSFHeader_(&hdr);
    hdr.opCode = mbdReqtype;
    if (!xdr_encodeMsg(&xdrs,
                       (char *)&signalReq,
                       &hdr,
                       xdr_signalReq,
                       0,
                       &auth)) {
        lsberrno = LSBE_XDR;
        xdr_destroy(&xdrs);
        return -1;
    }

    if ((cc = callmbd(NULL,
                      request_buf,
                      XDR_GETPOS(&xdrs),
                      &reply_buf,
                      &hdr,
                      NULL,
                      NULL,
                      NULL)) < 0) {
        xdr_destroy(&xdrs);
        return -1;
    }

    xdr_destroy(&xdrs);

    if (cc)
        free(reply_buf);

    lsberrno = hdr.opCode;
    if (lsberrno == LSBE_NO_ERROR || lsberrno == LSBE_JOB_DEP)
        return 0;

    return -1 ;
}
Esempio n. 3
0
int 
lsb_switchjob (LS_LONG_INT jobId, char *queue)
{
    struct jobSwitchReq jobSwitchReq;
    char request_buf[MSGSIZE];
    char *reply_buf;
    XDR xdrs;
    mbdReqType mbdReqtype;
    int cc;
    struct LSFHeader hdr;
    struct lsfAuth auth;


    if (jobId <= 0 || queue == 0) {
	lsberrno = LSBE_BAD_ARG;
	return(-1);
    }
    if (queue && (strlen (queue) >= MAX_LSB_NAME_LEN - 1)) {
        lsberrno = LSBE_BAD_QUEUE;
        return(-1);
    }


    if (authTicketTokens_(&auth, NULL) == -1)
	return (-1);
    
    jobSwitchReq.jobId = jobId;
    strcpy (jobSwitchReq.queue, queue);


    
    
    mbdReqtype = BATCH_JOB_SWITCH;
    xdrmem_create(&xdrs, request_buf, MSGSIZE, XDR_ENCODE);
    initLSFHeader_(&hdr);
    hdr.opCode = mbdReqtype;
    if (!xdr_encodeMsg(&xdrs, (char *)&jobSwitchReq, &hdr, xdr_jobSwitchReq,
		       0, &auth)) {
        lsberrno = LSBE_XDR;
        return(-1);
    }

    
    if ((cc = callmbd (NULL, request_buf, XDR_GETPOS(&xdrs), &reply_buf, 
                       &hdr, NULL, NULL, NULL)) == -1)
    {
	xdr_destroy(&xdrs);
	return (-1);
    }

    xdr_destroy(&xdrs);
    lsberrno = hdr.opCode;
    if (cc)
	free(reply_buf);

    if (lsberrno == LSBE_NO_ERROR)
        return(0);
    else
	return(-1);

} 
Esempio n. 4
0
int 
lsb_hostcontrol (char *host, int opCode)
{
    XDR xdrs;
    char request_buf[MSGSIZE];
    char *reply_buf, *contactHost = NULL;
    static struct controlReq hostControlReq;
    int cc;
    struct LSFHeader hdr;
    struct lsfAuth auth;

    
    if (hostControlReq.name == NULL) {
        hostControlReq.name = (char *) malloc (MAXHOSTNAMELEN);
        if (hostControlReq.name == NULL) {
            lsberrno = LSBE_NO_MEM;
            return(-1);
        }
    }
    if (opCode != HOST_OPEN && opCode != HOST_CLOSE &&
        opCode != HOST_REBOOT && opCode != HOST_SHUTDOWN) {
        lsberrno = LSBE_BAD_ARG;
        return (-1);
    }
    if (host) 
        if (strlen (host) >= MAXHOSTNAMELEN - 1) {
            lsberrno = LSBE_BAD_ARG;
            return (-1);
        }
    
    hostControlReq.opCode = opCode;
    if (host)
	strcpy(hostControlReq.name, host);
    else {
	char *h;
        if ((h = ls_getmyhostname()) == NULL) {
            lsberrno = LSBE_LSLIB;
            return(-1);
        }
	strcpy(hostControlReq.name, h);
    }
    
    switch (opCode) {
    case HOST_REBOOT:
	hdr.opCode = CMD_SBD_REBOOT;
        contactHost = host;
	break;
    case HOST_SHUTDOWN:
	hdr.opCode = CMD_SBD_SHUTDOWN;
        contactHost = host;
	break;
    default:
	hdr.opCode = BATCH_HOST_CTRL;
	break;
    }
   
    
    if (authTicketTokens_(&auth, contactHost) == -1)
	return (-1);

    
    xdrmem_create(&xdrs, request_buf, MSGSIZE, XDR_ENCODE);

    if (!xdr_encodeMsg(&xdrs, (char*) &hostControlReq, &hdr, 
		      xdr_controlReq, 0, &auth)) {
        lsberrno = LSBE_XDR;
        return(-1);
    }

    if (opCode == HOST_REBOOT || opCode == HOST_SHUTDOWN) {
	
	if ((cc = cmdCallSBD_(hostControlReq.name, request_buf,
			      XDR_GETPOS(&xdrs), &reply_buf, 
			      &hdr, NULL)) == -1)
	    return (-1);
    } else {
	
	if ((cc = callmbd (NULL, request_buf, XDR_GETPOS(&xdrs), &reply_buf, 
			   &hdr, NULL, NULL, NULL)) == -1)
	    return (-1);
    }
	

    lsberrno = hdr.opCode;
    if (cc)
	free(reply_buf);
    if (lsberrno == LSBE_NO_ERROR)
	return(0);
    else
	return(-1);

} 
Esempio n. 5
0
int
lsb_runjob(struct runJobRequest* runJobRequest) 
{
    XDR                   xdrs;
    struct LSFHeader      lsfHeader;
    struct lsfAuth        auth;
    mbdReqType            mbdReqType;
    char                  request_buf[MSGSIZE/2];
    char*                 reply_buf;
    int                   retVal;
    int                   cc;

    
    if (runJobRequest == NULL 
	|| runJobRequest->numHosts == 0 
	|| runJobRequest->hostname == NULL 
	|| runJobRequest->jobId < 0 
	|| (   runJobRequest->options != 0 
	    && ! (runJobRequest->options & 
		  (RUNJOB_OPT_NORMAL | RUNJOB_OPT_NOSTOP))))
	
    {
	lsberrno = LSBE_BAD_ARG;
	return(-1);
    }

    
    if (!( runJobRequest->options & (RUNJOB_OPT_NORMAL | RUNJOB_OPT_NOSTOP))) {
	runJobRequest->options |= RUNJOB_OPT_NORMAL;
    } 

    
    if (authTicketTokens_(&auth, NULL) == -1) {
	lsberrno = LSBE_LSBLIB;
	return (-1);
    }

    
    mbdReqType = BATCH_JOB_FORCE;

    
    xdrmem_create(&xdrs,
		  request_buf,
		  MSGSIZE/2,
		  XDR_ENCODE);

    initLSFHeader_(&lsfHeader);

    lsfHeader.opCode = mbdReqType;

    if (!xdr_encodeMsg(&xdrs,
		       (char *)runJobRequest,
		       &lsfHeader,
		       xdr_runJobReq,
		       0,
		       &auth)) {
	lsberrno = LSBE_XDR;
	xdr_destroy(&xdrs);
	return(-1);
    }


    
    if ((cc = callmbd(NULL, 
		      request_buf, 
		      XDR_GETPOS(&xdrs), 
		      &reply_buf, 
		      &lsfHeader, 
		      NULL, 
		      NULL, 
		      NULL)) == -1) {
	xdr_destroy(&xdrs);
	return(-1);
    }

    
    xdr_destroy(&xdrs);

    
    lsberrno = lsfHeader.opCode;

    if (lsberrno == LSBE_NO_ERROR)
	retVal = 0;
    else
	retVal = -1;

    return(retVal);

}
Esempio n. 6
0
int 
lsb_movejob (LS_LONG_INT jobId, int *position, int opCode)
{
    struct jobMoveReq jobMoveReq;
    char request_buf[MSGSIZE];
    char *reply_buf;
    XDR xdrs;
    mbdReqType mbdReqtype;
    int cc;
    struct LSFHeader hdr;
    struct lsfAuth auth;

    if (opCode != TO_TOP && opCode != TO_BOTTOM) {
	lsberrno = LSBE_BAD_ARG;
	return -1;
    }

    if (position == NULL ) {
	lsberrno = LSBE_BAD_ARG;
	return -1;
    }

    if (jobId <= 0 || *position <= 0) {
	lsberrno = LSBE_BAD_ARG;
	return -1;
    }

    if (authTicketTokens_(&auth, NULL) == -1)
	return -1;
	 
    jobMoveReq.jobId = jobId;
    jobMoveReq.position = *position;
    jobMoveReq.opCode = opCode;

    
    mbdReqtype = BATCH_JOB_MOVE;
    xdrmem_create(&xdrs, request_buf, MSGSIZE, XDR_ENCODE);

    hdr.opCode = mbdReqtype;
    if (!xdr_encodeMsg(&xdrs, (char *) &jobMoveReq, &hdr, xdr_jobMoveReq, 0, &auth)) {
	xdr_destroy(&xdrs);
	lsberrno = LSBE_XDR;
	return -1;
    } 
    
    
    if ((cc = callmbd (NULL, request_buf, XDR_GETPOS(&xdrs), &reply_buf, 
                       &hdr, NULL, NULL, NULL)) == -1)    {
	xdr_destroy(&xdrs);
	return -1;
    }
    xdr_destroy(&xdrs);

    
    lsberrno = hdr.opCode;
    if (lsberrno == LSBE_NO_ERROR) {
        xdrmem_create(&xdrs, reply_buf, XDR_DECODE_SIZE_(cc), XDR_DECODE);
	if (!xdr_jobMoveReq(&xdrs, &jobMoveReq, &hdr)) {
	    lsberrno = LSBE_XDR;
            xdr_destroy(&xdrs);
	    if (cc)
		free(reply_buf);
	    return -1;
        }
        *position = jobMoveReq.position ;
        xdr_destroy(&xdrs);
	if (cc)
	    free(reply_buf);
        return 0;
    }

    if (cc)
	free(reply_buf);
    return -1;

}