Ejemplo n.º 1
0
int
PBSD_msg_put(int c, char *jobid, int fileopt, char *msg, char *extend, int rpp, char **msgid)
{
	int rc = 0;
	int sock;

	if (!rpp) {
		sock = connection[c].ch_socket;
		DIS_tcp_setup(sock);
	} else {
		sock = c;
		if ((rc = is_compose_cmd(sock, IS_CMD, msgid)) != DIS_SUCCESS)
			return rc;
	}

	if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_MessJob,
		pbs_current_user)) ||
		(rc = encode_DIS_MessageJob(sock, jobid, fileopt, msg)) ||
		(rc = encode_DIS_ReqExtend(sock, extend))) {
		return (pbs_errno = PBSE_PROTOCOL);
	}
	if (DIS_wflush(sock, rpp)) {
		pbs_errno = PBSE_PROTOCOL;
		rc	  = pbs_errno;
	}

	return rc;
}
Ejemplo n.º 2
0
/**
 * @brief
 * 	-PBS_resc() - internal common code for sending resource requests
 *
 * @par Functionality:
 *	Formats and sends the requests for pbs_rescquery(), pbs_rescreserve(),
 *	and pbs_rescfree().   Note, while the request is overloaded for all
 *	three, each has its own expected reply format.
 *
 * @param[in] c - communication handle
 * @param[in] reqtype - request type
 * @param[in] rescl- pointer to resource list
 * @param[in] ct - count of query strings
 * @param[in] rh - resource handle
 *
 * @return      int
 * @retval      0       success
 * @retval      !0      error
 *
 */
static int
PBS_resc(int c, int reqtype, char **rescl, int ct, pbs_resource_t rh)
{
	int rc;
	int sock;

	sock = connection[c].ch_socket;

	/* setup DIS support routines for following DIS calls */

	DIS_tcp_setup(sock);

	if ((rc = encode_DIS_ReqHdr(sock, reqtype, pbs_current_user)) ||
		(rc = encode_DIS_Resc(sock, rescl, ct, rh)) ||
		(rc = encode_DIS_ReqExtend(sock, (char *)0))) {
		connection[c].ch_errtxt = strdup(dis_emsg[rc]);
		if (connection[c].ch_errtxt == NULL) {
			pbs_errno = PBSE_SYSTEM;
		} else {
			pbs_errno = PBSE_PROTOCOL;
		}
		return (pbs_errno);
	}
	if (DIS_tcp_wflush(sock)) {
		return (pbs_errno = PBSE_PROTOCOL);
	}
	return (0);
}
Ejemplo n.º 3
0
static int dis_reply_write(

  int                 sfds,    /* I */
  struct batch_reply *preply)  /* I */

  {
  int              rc = PBSE_NONE;
  char             log_buf[LOCAL_LOG_BUF_SIZE];
  struct tcp_chan *chan = NULL;

  /* setup for DIS over tcp */
  if ((chan = DIS_tcp_setup(sfds)) == NULL)
    {
    }

  /* send message to remote client */
  else if ((rc = encode_DIS_reply(chan, preply)) ||
           (rc = DIS_tcp_wflush(chan)))
    {
    sprintf(log_buf, "DIS reply failure, %d", rc);

    log_event(PBSEVENT_SYSTEM, PBS_EVENTCLASS_REQUEST, __func__, log_buf);

    /* don't need to get the lock here because we already have it from process request */
    close_conn(sfds, FALSE);
    }

  if (chan != NULL)
    DIS_tcp_cleanup(chan);

  return(rc);
  }  /* END dis_reply_write() */
Ejemplo n.º 4
0
int
PBSD_py_spawn_put(int c, char *jobid, char **argv, char **envp, int rpp, char **msgid)
{
	int rc = 0;
	int sock;

	if (!rpp) {
		sock = connection[c].ch_socket;
		DIS_tcp_setup(sock);
	} else {
		sock = c;
		if ((rc = is_compose_cmd(sock, IS_CMD, msgid)) != DIS_SUCCESS)
			return rc;
	}

	if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_PySpawn,
		pbs_current_user)) ||
		(rc = encode_DIS_PySpawn(sock, jobid, argv, envp)) ||
		(rc = encode_DIS_ReqExtend(sock, NULL))) {
			return (pbs_errno = PBSE_PROTOCOL);
	}

	if (DIS_wflush(sock, rpp)) {
		pbs_errno = PBSE_PROTOCOL;
		rc = pbs_errno;
	}

	return rc;
}
Ejemplo n.º 5
0
/**
 * @brief read a batch reply from the given socket
 *
 * @param[in] sock - The socket fd to read from
 * @param[out] rc  - Return DIS error code
 *
 * @return Batch reply structure
 * @retval  !NULL - Success
 * @retval   NULL - Failure
 *
 */
struct batch_reply *
PBSD_rdrpy_sock(int sock, int *rc)
{
	struct batch_reply *reply;
	time_t old_timeout;

	*rc = DIS_SUCCESS;
	/* clear any prior error message */
	if ((reply = (struct batch_reply *)malloc(sizeof(struct batch_reply))) == 0) {
		pbs_errno = PBSE_SYSTEM;
		return ((struct batch_reply *)0);
	}
	(void)memset(reply, 0, sizeof(struct batch_reply));

	DIS_tcp_setup(sock);
	old_timeout = pbs_tcp_timeout;
	if (pbs_tcp_timeout < PBS_DIS_TCP_TIMEOUT_LONG)
		pbs_tcp_timeout = PBS_DIS_TCP_TIMEOUT_LONG;

	if ((*rc = decode_DIS_replyCmd(sock, reply)) != 0) {
		(void)free(reply);
		pbs_errno = PBSE_PROTOCOL;
		return (struct batch_reply *)NULL;
	}
	DIS_tcp_reset(sock, 0);		/* reset DIS read buffer */
	pbs_tcp_timeout = old_timeout;

	pbs_errno = reply->brp_code;
	return reply;
}
Ejemplo n.º 6
0
int pbs_disconnect(

  int connect)  /* I (socket descriptor) */

  {
  int  sock;

  /* send close-connection message */

  sock = connection[connect].ch_socket;

  DIS_tcp_setup(sock);

  if (encode_DIS_ReqHdr(sock, PBS_BATCH_Disconnect, pbs_current_user) == 0)
    {
    DIS_tcp_wflush(sock);
    }
  close(sock);

  DIS_tcp_release(sock);

  if (connection[connect].ch_errtxt != (char *)NULL)
    free(connection[connect].ch_errtxt);

  connection[connect].ch_errno = 0;

  connection[connect].ch_inuse = 0;

  return(0);
  }  /* END pbs_disconnect() */
Ejemplo n.º 7
0
static int addrm(

  int stream)  /* I */

  {

  struct out *op, **head;

  if ((op = (struct out *)calloc(1, sizeof(struct out))) == NULL)
    {
    return(errno);
    }
  else if ((op->chan = DIS_tcp_setup(stream)) == NULL)
    {
    free(op);
    return errno;
    }

  head = &outs[stream % HASHOUT];

  op->len = -1;
  op->next = *head;
  *head = op;
  return 0;
  }
Ejemplo n.º 8
0
static int dis_reply_write(

  int                 sfds,    /* I */
  struct batch_reply *preply)  /* I */

  {
  int rc;

  /* setup for DIS over tcp */

  DIS_tcp_setup(sfds);

  /* send message to remote client */

  if ((rc = encode_DIS_reply(sfds, preply)) ||
      (rc = DIS_tcp_wflush(sfds)))
    {
    sprintf(log_buffer, "DIS reply failure, %d",
            rc);

    LOG_EVENT(
      PBSEVENT_SYSTEM,
      PBS_EVENTCLASS_REQUEST,
      "dis_reply_write",
      log_buffer);

    close_conn(sfds);
    }

  return(rc);
  }  /* END dis_reply_write() */
Ejemplo n.º 9
0
int
__pbs_orderjob(int c, char *job1, char *job2, char *extend)
{
	struct batch_reply *reply;
	int rc;
	int sock;


	if ((job1 == NULL) || (*job1 == '\0') ||
		(job2 == NULL) || (*job2 == '\0'))
		return (pbs_errno = PBSE_IVALREQ);

	sock = connection[c].ch_socket;

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return pbs_errno;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return pbs_errno;

	/* setup DIS support routines for following DIS calls */

	DIS_tcp_setup(sock);

	if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_OrderJob, pbs_current_user)) ||
		(rc = encode_DIS_MoveJob(sock, job1, job2)) ||
		(rc = encode_DIS_ReqExtend(sock, extend))) {
		connection[c].ch_errtxt = strdup(dis_emsg[rc]);
		if (connection[c].ch_errtxt == NULL) {
			pbs_errno = PBSE_SYSTEM;
		} else {
			pbs_errno = PBSE_PROTOCOL;
		}
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}
	if (DIS_tcp_wflush(sock)) {
		pbs_errno = PBSE_PROTOCOL;
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	/* read reply */

	reply = PBSD_rdrpy(c);

	PBSD_FreeReply(reply);

	rc = connection[c].ch_errno;

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return pbs_errno;

	return rc;
}
Ejemplo n.º 10
0
int parse_response_svr(
    int sock,
    char **err_msg)
  {
  /*
   * PBS_BATCH_PROT_TYPE
   * PBS_BATCH_PROT_VER
   * reply->brp_code
   * reply->brp_auxcode
   * reply->brp_choice
   * if reply->brp_choice == BATCH_REPLY_CHOICE_Text also read:
   * preq->rq_reply.brp_un.brp_txt.brp_str
   * using
   * preq->rq_reply.brp_un.brp_txt.brp_txtlen
   */
  int rc = PBSE_NONE;
  struct batch_reply *reply = NULL;
  char *tmp_val = NULL;
  struct tcp_chan *chan = NULL;
  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    }
  else if ((reply = (struct batch_reply *)calloc(1, sizeof(struct batch_reply))) == NULL)
    {
    }
  else if ((rc = decode_DIS_replyCmd(chan, reply)))
    {
    free(reply);
    if (chan->IsTimeout == TRUE)
      {
      rc = PBSE_TIMEOUT;
      }
    else
      {
      rc = PBSE_PROTOCOL;
      }
    if ((tmp_val = pbs_strerror(rc)) == NULL)
      {
      char err_buf[80];
      snprintf(err_buf, 79, "Error creating error message for code %d", rc);
      *err_msg = strdup(err_buf);
      }
    else
      *err_msg = strdup(tmp_val);
    }
  else
    {
    rc = reply->brp_code;
    if (reply->brp_code != PBSE_NONE)
      {
      *err_msg = strdup(reply->brp_un.brp_txt.brp_str);
      }
    free(reply);
    }
  DIS_tcp_cleanup(chan);
  return rc;
  }
Ejemplo n.º 11
0
void *start_process_request(void *vp)
  {
  int sock = *(int *)vp;
  struct tcp_chan *chan = NULL;
  if ((chan = DIS_tcp_setup(sock)) == NULL)
    return NULL;
  process_request(chan);
  DIS_tcp_cleanup(chan);
  return(NULL);
  }
Ejemplo n.º 12
0
int PBSD_selectattr_put(

  int             c,
  int             type,
  struct attropl *attropl,
  struct attrl   *attrib,
  char           *extend)

  {
  int rc = PBSE_NONE;
  int sock;
  struct tcp_chan *chan = NULL;
  
  if ((c < 0) || 
      (c >= PBS_NET_MAX_CONNECTIONS))
    {
    return(PBSE_IVALREQ);
    }

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    rc = PBSE_PROTOCOL;
    return rc;
    }
  else if ((rc = encode_DIS_ReqHdr(chan, type, pbs_current_user)) ||
      (rc = encode_DIS_attropl(chan, attropl)) ||
      (rc = encode_DIS_attrl(chan, attrib)) ||
      (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return (PBSE_PROTOCOL);
    }

  pthread_mutex_unlock(connection[c].ch_mutex);

  /* write data */

  if (DIS_tcp_wflush(chan))
    {
    rc = PBSE_PROTOCOL;
    }

  DIS_tcp_cleanup(chan);
  return rc;
  } /* END PBSD_selectattr_put() */
Ejemplo n.º 13
0
int PBSD_rdytocmt(

  int   connect,
  char *jobid)

  {
  int                 rc;

  struct batch_reply *reply;
  int                 sock;
  struct tcp_chan *chan = NULL;
  
  if ((connect < 0) || 
      (connect >= PBS_NET_MAX_CONNECTIONS))
    {
    return(PBSE_IVALREQ);
    }

  pthread_mutex_lock(connection[connect].ch_mutex);
  sock = connection[connect].ch_socket;
  pthread_mutex_unlock(connection[connect].ch_mutex);

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    return(PBSE_MEM_MALLOC);
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_RdytoCommit, pbs_current_user)) ||
      (rc = encode_DIS_JobId(chan, jobid)) ||
      (rc = encode_DIS_ReqExtend(chan, NULL)))
    {
    pthread_mutex_lock(connection[connect].ch_mutex);
    connection[connect].ch_errtxt = strdup(dis_emsg[rc]);
    pthread_mutex_unlock(connection[connect].ch_mutex);
    DIS_tcp_cleanup(chan);
    return(PBSE_PROTOCOL);
    }

  if (DIS_tcp_wflush(chan))
    {
    DIS_tcp_cleanup(chan);
    return(PBSE_PROTOCOL);
    }
  DIS_tcp_cleanup(chan);

  /* read reply */

  reply = PBSD_rdrpy(&rc, connect);

  PBSD_FreeReply(reply);

  return(rc);
  }
Ejemplo n.º 14
0
int
PBSD_ucred(int c, char *user, int type, char *buf, int len)
{
	int			rc;
	struct batch_reply	*reply = NULL;
	int			sock;

	sock = connection[c].ch_socket;

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return pbs_errno;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return pbs_errno;

	DIS_tcp_setup(sock);

	if ((rc =encode_DIS_ReqHdr(sock, PBS_BATCH_UserCred, pbs_current_user)) ||
		(rc = encode_DIS_UserCred(sock, user, type, buf, len)) ||
		(rc = encode_DIS_ReqExtend(sock, (char *)0))) {
		connection[c].ch_errtxt = strdup(dis_emsg[rc]);
		if (connection[c].ch_errtxt == NULL) {
			pbs_errno = PBSE_SYSTEM;
		} else {
			pbs_errno = PBSE_PROTOCOL;
		}
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}
	if (DIS_tcp_wflush(sock)) {
		pbs_errno = PBSE_PROTOCOL;
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	reply = PBSD_rdrpy(c);

	PBSD_FreeReply(reply);

	rc = connection[c].ch_errno;

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return pbs_errno;

	return rc;
}
Ejemplo n.º 15
0
int PBSD_status_put(

    int           c,
    int           function,
    char         *id,
    struct attrl *attrib,
    char         *extend)

{
    int rc = 0;
    int sock;
    struct tcp_chan *chan = NULL;

    if ((c < 0) ||
            (c >= PBS_NET_MAX_CONNECTIONS))
    {
        return(PBSE_IVALREQ);
    }

    mutex_mgr ch_mutex = mutex_mgr(connection[c].ch_mutex, false);

    sock = connection[c].ch_socket;

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        rc = PBSE_MEM_MALLOC;
        return rc;
    }
    else if ((rc = encode_DIS_ReqHdr(chan, function, pbs_current_user)) ||
             (rc = encode_DIS_Status(chan, id, attrib)) ||
             (rc = encode_DIS_ReqExtend(chan, extend)))
    {
        connection[c].ch_errtxt = strdup(dis_emsg[rc]);

        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }

    ch_mutex.unlock();

    if (DIS_tcp_wflush(chan))
    {
        rc = PBSE_PROTOCOL;
    }

    /* success */

    DIS_tcp_cleanup(chan);
    return(PBSE_NONE);
}  /* END PBSD_status_put() */
Ejemplo n.º 16
0
int pbs_lock(

  int   c,      /* I */
  int   action, /* I */
  char *extend) /* I */

  {

  struct batch_reply *reply;

  int rc = 0;
  int sock;

  /* send request */

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  DIS_tcp_setup(sock);

  if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_SchedulerLock, pbs_current_user)) ||
      (rc = encode_DIS_SchedLock(sock, action)) ||
      (rc = encode_DIS_ReqExtend(sock, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pbs_errno = PBSE_PROTOCOL;

    return(pbs_errno);
    }

  if (DIS_tcp_wflush(sock))
    {
    pbs_errno = PBSE_PROTOCOL;

    return(pbs_errno);
    }

  /* read in reply */

  reply = PBSD_rdrpy(c);
  rc = connection[c].ch_errno;

  PBSD_FreeReply(reply);

  return(rc);
  }  /* END pbs_terminate() */
Ejemplo n.º 17
0
int PBSD_mgr_put(

  int             c,        /* I */
  int             function, /* I */
  int             command,  /* I */
  int             objtype,  /* I */
  char           *objname,  /* I */
  struct attropl *aoplp,    /* I */
  char           *extend)   /* I */

  {
  int rc = PBSE_NONE;
  int sock;
  struct tcp_chan *chan = NULL;

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    rc = PBSE_PROTOCOL;
    return(rc);
    }
  else if ((rc = encode_DIS_ReqHdr(chan, function, pbs_current_user)) ||
           (rc = encode_DIS_Manage(chan, command, objtype, objname, aoplp)) ||
           (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    rc = PBSE_PROTOCOL; /* We shouldn't be overridding this error!!! */
    return rc;
    }

  if (DIS_tcp_wflush(chan))
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    rc = PBSE_PROTOCOL;
    }

  pthread_mutex_unlock(connection[c].ch_mutex);
  DIS_tcp_cleanup(chan);
  return rc;
  }  /* END PBSD_mgr_put() */
Ejemplo n.º 18
0
int pbs_disconnect_socket(

  int sock)  /* I (socket descriptor) */

  {
  char tmp_buf[THE_BUF_SIZE / 4];
  struct tcp_chan *chan = NULL;

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    }
  else if ((encode_DIS_ReqHdr(chan,PBS_BATCH_Disconnect, pbs_current_user) == 0)
      && (DIS_tcp_wflush(chan) == 0))
    {
    int atime;
    struct sigaction act;
    struct sigaction oldact;

    /* set alarm to break out of potentially infinite read */
/*    act.sa_handler = SIG_IGN; */
    act.sa_handler = empty_alarm_handler;  /* need SOME handler or blocking read never gets interrupted */

    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    sigaction(SIGALRM, &act, &oldact);
    atime = alarm(5);

    while (1)
      {
      /* wait for server to close connection */
      /* NOTE:  if read of 'sock' is blocking, request below may hang forever
         -- hence the signal handler above */
      if (read_ac_socket(sock, &tmp_buf, sizeof(tmp_buf)) < 1)
        break;
      }

    alarm(atime);
    sigaction(SIGALRM, &oldact, NULL);
    }

  if (chan != NULL)
    DIS_tcp_cleanup(chan);
  close(sock);
  return(0);
  }  /* END pbs_disconnect_socket() */
Ejemplo n.º 19
0
int PBSD_commit(

    int   connect,  /* I */
    char *jobid)    /* I */

{

    struct batch_reply *reply;
    int                 rc;
    int                 sock;
    struct tcp_chan *chan = NULL;

    pthread_mutex_lock(connection[connect].ch_mutex);
    sock = connection[connect].ch_socket;
    pthread_mutex_unlock(connection[connect].ch_mutex);

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        return(PBSE_MEM_MALLOC);
    }
    else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_Commit, pbs_current_user)) ||
             (rc = encode_DIS_JobId(chan, jobid)) ||
             (rc = encode_DIS_ReqExtend(chan, NULL)))
    {
        pthread_mutex_lock(connection[connect].ch_mutex);
        connection[connect].ch_errtxt = strdup(dis_emsg[rc]);
        pthread_mutex_unlock(connection[connect].ch_mutex);
        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }

    if (DIS_tcp_wflush(chan))
    {
        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }
    DIS_tcp_cleanup(chan);

    /* PBSD_rdrpy sets connection[connect].ch_errno */
    reply = PBSD_rdrpy(&rc, connect);

    PBSD_FreeReply(reply);
    return(rc);
}  /* END PBSD_commit() */
Ejemplo n.º 20
0
int PBSD_async_sig_put(

    int   c,
    char *jobid,
    char *signal,
    char *extend)

{
    int sock;
    int rc = 0;
    struct tcp_chan *chan = NULL;

    pthread_mutex_lock(connection[c].ch_mutex);

    sock = connection[c].ch_socket;
    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        rc = PBSE_PROTOCOL;
        return rc;
    }
    else if ((rc = encode_DIS_ReqHdr(chan,PBS_BATCH_SignalJob,pbs_current_user))
             || (rc = encode_DIS_SignalJob(chan,jobid,signal))
             || (rc = encode_DIS_ReqExtend(chan,extend)))
    {
        connection[c].ch_errtxt = strdup(dis_emsg[rc]);

        pthread_mutex_unlock(connection[c].ch_mutex);
        DIS_tcp_cleanup(chan);
        return (PBSE_PROTOCOL);
    }

    pthread_mutex_unlock(connection[c].ch_mutex);

    if (DIS_tcp_wflush(chan))
    {
        rc = PBSE_PROTOCOL;
    }

    DIS_tcp_cleanup(chan);
    return(rc);
} /* END PBSD_async_sig_put() */
Ejemplo n.º 21
0
static int PBS_resc(
    
  int          c,
  int          reqtype, 
  char       **rescl,
  int          ct,
  resource_t   rh)
  {
  int rc;
  int sock;
  struct tcp_chan *chan = NULL;

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    rc = PBSE_PROTOCOL;
    return rc;
    }
  else if ((rc = encode_DIS_ReqHdr(chan, reqtype, pbs_current_user)) ||
      (rc = encode_DIS_Resc(chan, rescl, ct, rh)) ||
      (rc = encode_DIS_ReqExtend(chan, (char *)0)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return (PBSE_PROTOCOL);
    }

  if (DIS_tcp_wflush(chan))
    {
    rc = PBSE_PROTOCOL;
    }

  DIS_tcp_cleanup(chan);
  return rc;
  } /* END PBS_resc() */
Ejemplo n.º 22
0
int PBSD_status_put(

  int           c,
  int           function,
  char         *id,
  struct attrl *attrib,
  char         *extend)

  {
  int rc = 0;
  int sock;

  sock = connection[c].ch_socket;

  DIS_tcp_setup(sock);

  if ((rc = encode_DIS_ReqHdr(sock, function, pbs_current_user)) ||
      (rc = encode_DIS_Status(sock, id, attrib)) ||
      (rc = encode_DIS_ReqExtend(sock, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pbs_errno = PBSE_PROTOCOL;

    return(pbs_errno);
    }

  if (DIS_tcp_wflush(sock))
    {
    pbs_errno = PBSE_PROTOCOL;

    return(pbs_errno);
    }

  /* success */

  return(0);
  }  /* END PBSD_status_put() */
Ejemplo n.º 23
0
int PBSD_gpu_put(
    
  int   c,
  char *node,
  char *gpuid,
  int   gpumode,
  int   reset_perm,
  int   reset_vol,
  char *extend)
  
  {
  int sock;
  int rc = 0;
  struct tcp_chan *chan = NULL;

  sock = connection[c].ch_socket;
  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    return PBSE_PROTOCOL;
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_GpuCtrl, pbs_current_user)) ||
      (rc = encode_DIS_GpuCtrl(chan, node, gpuid, gpumode, reset_perm, reset_vol)) ||
      (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);
    DIS_tcp_cleanup(chan);
    return(PBSE_PROTOCOL);
    }

  if (DIS_tcp_wflush(chan))
    {
    rc = PBSE_PROTOCOL;
    }

  DIS_tcp_cleanup(chan);
  return(rc);
  }
Ejemplo n.º 24
0
int PBSD_munge_authenticate(

  int psock,  /* I */
  int handle) /* I */

  {
  int                 rc;

  munge_ctx_t         mctx = NULL;
  munge_err_t         mret = EMUNGE_SNAFU;
  char               *mcred = NULL;

  /* user id and name stuff */
  struct passwd      *pwent;
  uid_t               myrealuid;
  struct batch_reply *reply;
  unsigned short      user_port = 0;
  struct sockaddr_in  sockname;
  socklen_t           socknamelen = sizeof(sockname);
  struct tcp_chan    *chan;

  if ((mctx = munge_ctx_create()) == NULL)
    {
    return(-1);
    }

  if ((mret = munge_encode (&mcred, mctx, NULL, 0)) != EMUNGE_SUCCESS)
    {
    const char *merrmsg = NULL;
    if (!(merrmsg = munge_ctx_strerror(mctx)))
      {
      merrmsg = munge_strerror(mret);
      }

    fprintf(stderr, "munge_encode failed: %s (%d)\n", merrmsg, mret);
    munge_ctx_destroy(mctx);
    return(PBSE_MUNGE_NOT_FOUND); /*TODO more fine-grained error codes? */
    }
  
  munge_ctx_destroy(mctx);

  /* We got the certificate. Now make the PBS_BATCH_AltAuthenUser request */
  myrealuid = getuid();
  pwent = getpwuid(myrealuid);
  
  rc = getsockname(psock, (struct sockaddr *)&sockname, &socknamelen);
  
  if (rc == -1)
    {
    fprintf(stderr, "getsockname failed: %d\n", errno);
    return(-1);
    }
  
  user_port = ntohs(sockname.sin_port);
  
  if ((chan = DIS_tcp_setup(psock)) == NULL)
    {
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_AltAuthenUser, pwent->pw_name)) ||
           (rc = diswui(chan, user_port)) ||
           (rc = diswst(chan, mcred)) ||
           (rc = encode_DIS_ReqExtend(chan, NULL)) ||
           (rc = DIS_tcp_wflush(chan)))
    {
    PBSD_munge_cred_destroy(&mcred);
    /* ERROR */
    return(rc);
    }
  else
    {
    int local_err = PBSE_NONE;
    PBSD_munge_cred_destroy(&mcred);
    /* read the reply */
    if ((reply = PBSD_rdrpy(&local_err, handle)) != NULL)
      free(reply);
    
    return(PBSE_NONE);
    }

  return(-1);
  }
Ejemplo n.º 25
0
int PBSD_munge_authenticate(

  int psock,  /* I */
  int handle) /* I */

  {
  int                 rc = PBSE_NONE;

  int                 fd;
  FILE               *munge_pipe;
  char                munge_buf[MUNGE_SIZE];
  char                munge_command[MUNGE_SIZE];
  char               *ptr; /* pointer to the current place to copy data into munge_buf */
  int                 bytes_read;
  int                 total_bytes_read = 0;
  int                 local_errno = 0;
  
  /* user id and name stuff */
  struct passwd      *pwent;
  uid_t               myrealuid;
  struct batch_reply *reply;
  unsigned short      user_port = 0;
  struct sockaddr_in  sockname;
  socklen_t           socknamelen = sizeof(sockname);
  struct tcp_chan *chan = NULL;

  snprintf(munge_command,sizeof(munge_command),
    "munge -n 2>/dev/null");

  memset(munge_buf, 0, MUNGE_SIZE);
  ptr = munge_buf; 

  if ((munge_pipe = popen(munge_command,"r")) == NULL)
    {
    /* FAILURE */
    return(-1);
    }

  fd = fileno(munge_pipe);

  while ((bytes_read = read_ac_socket(fd, ptr, MUNGE_SIZE - total_bytes_read)) > 0)
    {
    total_bytes_read += bytes_read;
    ptr += bytes_read;
    }

  pclose(munge_pipe);

  if (bytes_read == -1)
    {
    /* read failed */
    local_errno = errno;
    log_err(local_errno, __func__, "error reading pipe in PBSD_munge_authenticate");
    return -1;
    }
  
  /* if we got no bytes back then Munge may not be installed etc. */
  if (total_bytes_read == 0)
    {
    return(PBSE_MUNGE_NOT_FOUND);
    }

  /* We got the certificate. Now make the PBS_BATCH_AltAuthenUser request */
  myrealuid = getuid();  
  pwent = getpwuid(myrealuid);
  
  rc = getsockname(psock, (struct sockaddr *)&sockname, &socknamelen);
  
  if (rc == -1)
    {
    fprintf(stderr, "getsockname failed: %d\n", errno);
    return rc;
    }
  
  user_port = ntohs(sockname.sin_port);
  
  if ((chan = DIS_tcp_setup(psock)) == NULL)
    {
    rc = PBSE_MEM_MALLOC;
    }
  else if ((rc = encode_DIS_ReqHdr(chan,PBS_BATCH_AltAuthenUser,pwent->pw_name)) ||
           (rc = diswui(chan, user_port)) ||
           (rc = diswst(chan, munge_buf)) ||
           (rc = encode_DIS_ReqExtend(chan, NULL)) ||
           (rc = DIS_tcp_wflush(chan)))
    {
    /* ERROR */
    }
  else
    {
    /* read the reply */
    if ((reply = PBSD_rdrpy(&local_errno, handle)) != NULL)
      free(reply);

    rc = PBSE_NONE;
    }
  if (chan != NULL)
    DIS_tcp_cleanup(chan);
  return rc;
  } /* END PBSD_munge_authenticate() */
Ejemplo n.º 26
0
int pbs_original_connect(

  char *server)  /* I (FORMAT:  NULL | '\0' | HOSTNAME | HOSTNAME:PORT )*/

  {
  struct sockaddr_in server_addr;

  struct hostent *hp;
  int out;
  int i;
#ifdef GSSAPI
  int neediff = 0;
#endif
  int auth;

  struct passwd *pw;
  int use_unixsock = 0;
#ifdef ENABLE_UNIX_SOCKETS

  struct sockaddr_un unserver_addr;
  char hnamebuf[256];
#endif

  char  *ptr;

  /* reserve a connection state record */

  out = -1;

  for (i = 1;i < NCONNECTS;i++)
    {
    if (connection[i].ch_inuse)
      continue;

    out = i;

    connection[out].ch_inuse  = 1;

    connection[out].ch_errno  = 0;

    connection[out].ch_socket = -1;

    connection[out].ch_errtxt = NULL;

    break;
    }

  if (out < 0)
    {
    pbs_errno = PBSE_NOCONNECTS;

    if (getenv("PBSDEBUG"))
      fprintf(stderr, "ALERT:  cannot locate free channel\n");

    /* FAILURE */

    return(-1);
    }

  /* get server host and port */

  server = PBS_get_server(server, &server_port);

  if (server == NULL)
    {
    connection[out].ch_inuse = 0;
    pbs_errno = PBSE_NOSERVER;

    if (getenv("PBSDEBUG"))
      fprintf(stderr, "ALERT:  PBS_get_server() failed\n");

    return(-1);
    }

  /* determine who we are */

  pbs_current_uid = getuid();

  if ((pw = getpwuid(pbs_current_uid)) == NULL)
    {
    pbs_errno = PBSE_SYSTEM;

    if (getenv("PBSDEBUG"))
      {
      fprintf(stderr, "ALERT:  cannot get password info for uid %ld\n",
              (long)pbs_current_uid);
      }

    return(-1);
    }

  strcpy(pbs_current_user, pw->pw_name);

  pbs_server = server;    /* set for error messages from commands */


#ifdef ENABLE_UNIX_SOCKETS
  /* determine if we want to use unix domain socket */

  if (!strcmp(server, "localhost"))
    use_unixsock = 1;
  else if ((gethostname(hnamebuf, sizeof(hnamebuf) - 1) == 0) && !strcmp(hnamebuf, server))
    use_unixsock = 1;

  /* NOTE: if any part of using unix domain sockets fails,
   * we just cleanup and try again with inet sockets */

  /* get socket */

  if (use_unixsock)
    {
    connection[out].ch_socket = socket(AF_UNIX, SOCK_STREAM, 0);

    if (connection[out].ch_socket < 0)
      {
      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot create socket:  errno=%d (%s)\n",
                errno,
                strerror(errno));
        }

      connection[out].ch_inuse = 0;

      pbs_errno = PBSE_PROTOCOL;

      use_unixsock = 0;
      }
    }

  /* and connect... */

  if (use_unixsock)
    {
    unserver_addr.sun_family = AF_UNIX;
    strcpy(unserver_addr.sun_path, TSOCK_PATH);

    if (connect(
          connection[out].ch_socket,
          (struct sockaddr *)&unserver_addr,
          (strlen(unserver_addr.sun_path) + sizeof(unserver_addr.sun_family))) < 0)
      {
      close(connection[out].ch_socket);

      connection[out].ch_inuse = 0;
      pbs_errno = errno;

      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot connect to server, errno=%d (%s)\n",
                errno,
                strerror(errno));
        }

      use_unixsock = 0;  /* will try again with inet socket */
      }
    }

  if (use_unixsock)
    {
    if (!send_unix_creds(connection[out].ch_socket))
      {
      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot send unix creds to pbs_server:  errno=%d (%s)\n",
                errno,
                strerror(errno));
        }

      close(connection[out].ch_socket);

      connection[out].ch_inuse = 0;
      pbs_errno = PBSE_PROTOCOL;

      use_unixsock = 0;  /* will try again with inet socket */
      }
    }

#endif /* END ENABLE_UNIX_SOCKETS */

  if (!use_unixsock)
    {

    /* at this point, either using unix sockets failed, or we determined not to
     * try */

    connection[out].ch_socket = socket(AF_INET, SOCK_STREAM, 0);

    if (connection[out].ch_socket < 0)
      {
      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot connect to server \"%s\", errno=%d (%s)\n",
                server,
                errno,
                strerror(errno));
        }

      connection[out].ch_inuse = 0;

      pbs_errno = PBSE_PROTOCOL;

      return(-1);
      }

    /* connection succeeded re-mark as used */
    connection[out].ch_inuse = 1;

    server_addr.sin_family = AF_INET;

    hp = NULL;
    hp = gethostbyname(server);
  /* setup DIS support routines for following pbs_* calls */

    if (hp == NULL)
      {
      close(connection[out].ch_socket);
      connection[out].ch_inuse = 0;
      pbs_errno = PBSE_BADHOST;

      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot get servername (%s) errno=%d (%s)\n",
                (server != NULL) ? server : "NULL",
                errno,
                strerror(errno));
        }

      return(-1);
      }

    memcpy((char *)&server_addr.sin_addr, hp->h_addr_list[0], hp->h_length);

    server_addr.sin_port = htons(server_port);

    if (connect(
          connection[out].ch_socket,
          (struct sockaddr *)&server_addr,
          sizeof(server_addr)) < 0)
      {
      close(connection[out].ch_socket);

      connection[out].ch_inuse = 0;
      pbs_errno = errno;

      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot connect to server, errno=%d (%s)\n",
                errno,
                strerror(errno));
        }

      return(-1);
      }

  DIS_tcp_setup(connection[out].ch_socket);

  if ((ptr = getenv("PBSAPITIMEOUT")) != NULL)
    {
    pbs_tcp_timeout = strtol(ptr,NULL,0);	

    if (pbs_tcp_timeout <= 0)
      {
      pbs_tcp_timeout = 10800;      /* set for 3 hour time out */
      }
    }
  else
    {
    pbs_tcp_timeout = 10800;      /* set for 3 hour time out */
    }


  /* If we have GSSAPI, then try gssapi authentication first.  If that fails, fall back to iff.
     If there's no GSSAPI, then just use iff.
   */
#ifdef GSSAPI
  if (!getenv("TORQUE_IGNORE_KERBEROS") &&
      !ignore_kerberos_for_connection &&
      pbsgss_can_get_creds())
    {
    if (encode_DIS_ReqHdr(connection[out].ch_socket, PBS_BATCH_GSSAuthenUser, pbs_current_user) ||
        encode_DIS_ReqExtend(connection[out].ch_socket,0))
      {
      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr,"ERROR:  cannot authenticate connection with gssapi, errno=%d (%s)\n", errno, strerror(errno));
        }
      neediff = 1;
      }
    else
      {
      DIS_tcp_wflush(connection[out].ch_socket);
      if (pbsgss_client_authenticate(server,connection[out].ch_socket,1,1) != 0)
        {
        neediff = 1;
        if (getenv("PBSDEBUG"))
          {
          fprintf(stderr,"ERROR:  cannot authenticate connection, errno=%d (%s)\n", errno, strerror(errno));
          }
        }
      }
    }
  else
    {
    neediff = 1;
    }

  if (neediff)
    {
#endif

    /* FIXME: is this necessary?  Contributed by one user that fixes a problem,
       but doesn't fix the same problem for another user! */
#if 0
#if defined(__hpux)
    /*HP-UX : avoiding socket caching */
    send(connection[out].ch_socket, '?', 1, MSG_OOB);

#endif
#endif

    /* Have pbs_iff authenticate connection */

    if ((ENABLE_TRUSTED_AUTH == FALSE) && ((auth = PBSD_authenticate(connection[out].ch_socket)) != 0))
      {
      close(connection[out].ch_socket);

      connection[out].ch_inuse = 0;

      if (auth == ENOENT)
        {
        pbs_errno = ENOENT;
        
        if (getenv("PBSDEBUG"))
          {
          fprintf(stderr, "ERROR:  cannot find pbs_iif executable\n");
          }
        }
      else
        {
      pbs_errno = PBSE_PERM;

      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot authenticate connection to server \"%s\", errno=%d (%s)\n",
                server,
                errno,
                strerror(errno));
        }
        }

      return(-1);
      }
#ifdef GSSAPI
    } /* END if neediff */
#endif

    } /* END !useunix */

  DIS_tcp_setup(connection[out].ch_socket);

  if ((ptr = getenv("PBSAPITIMEOUT")) != NULL)
    {
    pbs_tcp_timeout = strtol(ptr, NULL, 0);

    if (pbs_tcp_timeout <= 0)
      {
      pbs_tcp_timeout = 10800;      /* set for 3 hour time out */
      }
    }
  else
    {
    pbs_tcp_timeout = 10800;      /* set for 3 hour time out */
    }

  return(out);
  }  /* END pbs_original_connect() */
Ejemplo n.º 27
0
int pbs_asyrunjob_err(

  int   c,
  char *jobid,    /* I */
  char *location,
  char *extend,
  int  *local_errno)

  {
  int                 rc;

  struct batch_reply *reply;
  unsigned int        resch = 0;
  int                 sock;
  struct tcp_chan *chan = NULL;

  if ((c < 0) || (jobid == NULL) || (*jobid == '\0'))
    {
    return(PBSE_IVALREQ);
    }

  if (location == NULL)
    location = "";

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    rc = PBSE_PROTOCOL;
    return rc;
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_AsyrunJob, pbs_current_user))
      || (rc = encode_DIS_RunJob(chan, jobid, location, resch))
      || (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return(PBSE_PROTOCOL);
    }

  if (DIS_tcp_wflush(chan))
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return(PBSE_PROTOCOL);
    }

  /* get reply */

  reply = PBSD_rdrpy(local_errno, c);

  rc = connection[c].ch_errno;

  pthread_mutex_unlock(connection[c].ch_mutex);

  PBSD_FreeReply(reply);
  DIS_tcp_cleanup(chan);
  return(rc);
  }  /* END pbs_asyrunjob_err() */
Ejemplo n.º 28
0
int pbs_runjob_err(

  int   c,
  char *jobid,
  char *location,
  char *extend,
  int  *rc)

  {
  struct batch_reply   *reply;
  unsigned int          resch = 0;
  int                   sock;
  struct tcp_chan *chan = NULL;

  /* NOTE:  set_task sets WORK_Deferred_Child : request remains until child terminates */

  if ((jobid == NULL) ||
      (*jobid == '\0'))
    {
    *rc = PBSE_IVALREQ;
    return (*rc) * -1;
    }
  
  if ((c < 0) || 
      (c >= PBS_NET_MAX_CONNECTIONS))
    {
    return(PBSE_IVALREQ * -1);
    }

  if (location == NULL)
    {
    location = (char *)"";
    }

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    *rc = PBSE_PROTOCOL;
    return(*rc);
    }
  /* send run request */
  else if ((*rc = encode_DIS_ReqHdr(chan, PBS_BATCH_RunJob, pbs_current_user)) ||
           (*rc = encode_DIS_RunJob(chan, jobid, location, resch)) ||
           (*rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[*rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);

    DIS_tcp_cleanup(chan);

    return(PBSE_PROTOCOL);
    }

  if ((*rc = DIS_tcp_wflush(chan)) != PBSE_NONE)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    
    DIS_tcp_cleanup(chan);

    return(PBSE_PROTOCOL);
    }

  /* get reply */

  reply = PBSD_rdrpy(rc, c);

/*  *rc = connection[c].ch_errno; */

  pthread_mutex_unlock(connection[c].ch_mutex);

  PBSD_FreeReply(reply);
    
  DIS_tcp_cleanup(chan);

  return(*rc);
  }  /* END pbs_runjob_err() */
Ejemplo n.º 29
0
int do_mom(

  char *HPtr,
  int   MOMPort,
  int   CmdIndex)

  {
  int socket;
  int local_errno = 0;
  struct tcp_chan *chan = NULL;
  int rc;

  if ((socket = openrm(HPtr, MOMPort)) < 0)
    {
    /* FAILURE */

    extern char TRMEMsg[];

    fprintf(stderr, "cannot connect to MOM on node '%s', errno=%d (%s)\n",
      HPtr,
      errno,
      strerror(errno));

    if (TRMEMsg[0] != '\0')
      {
      fprintf(stderr, " %s\n",
              TRMEMsg);
      }

    return(socket);
    }
  else if ((chan = DIS_tcp_setup(socket)) == NULL)
    {
    fprintf(stderr, "%s: can not allocate memory of socket buffers\n", __func__);
    return -1;
    }

  /* send protocol and version, plus how many queries we're sending */
  if (QueryI == 0)
    QueryI = 1;

  if (start_dialogue(chan) != DIS_SUCCESS)
    {
    fprintf(stderr,"ERROR:    Unable to write the number of queries to %s (errno=%d-%s)\n",
        HPtr,
        errno,
        strerror(errno));
    
    send_command(chan,RM_CMD_CLOSE);

    DIS_tcp_cleanup(chan);

    return(-1);
    }

  if (IsVerbose == TRUE)
    {
    fprintf(stderr, "INFO:     successfully connected to %s\n",
            HPtr);
    }

  switch (CmdIndex)
    {

    case momClear:

      {
      char tmpLine[1024];

      char *Value;

      snprintf(tmpLine, 1024, "clearjob=%s",
               (JPtr != NULL) ? JPtr : "all");

      if (send_command_str(chan, RM_CMD_REQUEST, tmpLine) != 0)
        {
        /* FAILURE */

        fprintf(stderr,"ERROR:    cannot request job clear on %s (errno=%d-%s)\n",
          HPtr,
          errno,
          strerror(errno));

        send_command(chan,RM_CMD_CLOSE);

        return(-1);
        }

      if ((Value = (char *)read_mom_reply(&local_errno, chan)) == NULL)
        {
        /* FAILURE */

        fprintf(stderr,"ERROR:    job clear failed on %s (errno=%d - %s: %d - %s)\n",
          HPtr,
          errno,
          pbs_strerror(errno),
          local_errno,
          pbs_strerror(local_errno));

        send_command(chan,RM_CMD_CLOSE);

        return(-1);
        }

      /* job cleared */

      fprintf(stdout,"job clear request successful on %s\n",
        HPtr);

      free(Value);
      }  /* END BLOCK (case momClear) */

    break;

    case momShutdown:

      {
      if ((send_command(chan,RM_CMD_SHUTDOWN) != PBSE_NONE) ||
          (check_success(chan) != PBSE_NONE))
        {
        /* FAILURE */

        fprintf(stderr,"ERROR:    cannot shutdown mom daemon on %s (errno=%d-%s)\n",
          HPtr,
          errno,
          pbs_strerror(errno));

        send_command(chan,RM_CMD_CLOSE);

        exit(EXIT_FAILURE);
        }

      fprintf(stdout, "shutdown request successful on %s\n",
        HPtr);
      }    /* END BLOCK */

    break;

    case momReconfig:

      {
      if ((send_command(chan,RM_CMD_CONFIG) != PBSE_NONE) ||
          (check_success(chan) != PBSE_NONE))
        {
        /* FAILURE */

        fprintf(stderr,"ERROR:    cannot reconfigure mom on %s (errno=%d-%s)\n",
          HPtr,
          errno,
          pbs_strerror(errno));

        send_command(chan,RM_CMD_CLOSE);

        return(-1);
        }

      fprintf(stdout, "reconfig successful on %s\n",
        HPtr);
      }  /* END BLOCK (case momReconfig) */

    break;

    case momLayout:
        
      char *value;

      if (send_command(chan, RM_CMD_LAYOUT) != PBSE_NONE)
        {
        fprintf(stdout, "Layout command failed to send to mom\n");
        return(-1);
        }
        
      if ((value = read_mom_reply(&local_errno, chan)) == NULL)
        {
        fprintf(stdout, "Could not read a layout reply from the mom\n");
        return(-1);
        }
      else
        {
        fprintf(stdout, "%s", value);
        free(value);
        }

      break;

    case momQuery:

    default:

      {
      char *ptr;

      int  rindex;

      char *Value;

      for (rindex = 0; rindex < QueryI; rindex++)
        {
        if (send_command_str(chan, RM_CMD_REQUEST, Query[rindex]) != 0)
          {
          fprintf(stderr,"ERROR:    cannot add query for '%s' on %s (errno=%d-%s)\n",
            Query[rindex],
            HPtr,
            errno,
            pbs_strerror(errno));
          }
        }

      for (rindex = 0;rindex < QueryI;rindex++)
        {
        if ((ptr = strchr(Query[rindex],'=')) != NULL)
          {
          *ptr = '\0';
          }

        if ((Value = (char *)read_mom_reply(&local_errno, chan)) == NULL)
          {
          fprintf(stderr, "ERROR:    query[%d] '%s' failed on %s (errno=%d - %s : %d - %s)\n",
            rindex,
            Query[rindex],
            HPtr,
            errno,
            pbs_strerror(errno),
            local_errno,
            pbs_strerror(local_errno));
            return(-1);

          }
        else
          {
          if (!strncmp(Query[rindex], "diag", strlen("diag")))
            {
            fprintf(stdout, "%s\n",
              Value);
            }
          else if (!strncmp(Query[rindex], "cycle", strlen("cycle")))
            {
            fprintf(stdout, "mom %s successfully cycled %s\n",
              HPtr,
              Value);
            }
          else
            {
            fprintf(stdout, "%12s: %12s = '%s'\n",
              HPtr,
              Query[rindex],
              Value);
            }
          }

        free(Value);

        if (ptr != NULL)
          {
          *ptr = '=';
          }
        }  /* END for (rindex) */
      }    /* END BLOCK (case momQuery) */

    break;
    }  /* END switch(CmdIndex) */
  rc = diswsi(chan, RM_PROTOCOL);

  if (rc != DIS_SUCCESS)
    goto do_mom_fail;

  rc = diswsi(chan, RM_PROTOCOL_VER);

  if (rc != DIS_SUCCESS)
    goto do_mom_fail;

  rc = diswsi(chan, 1);

  if (rc != DIS_SUCCESS)
    goto do_mom_fail;

  /* send_command will free chan */
  send_command(chan,RM_CMD_CLOSE);

  return(0);

do_mom_fail:
  DIS_tcp_close(chan);
  return(rc);

  } /* END do_mom() */
Ejemplo n.º 30
0
int
__pbs_rerunjob(int c, char *jobid, char *extend)
{
	int	rc;
	struct batch_reply *reply;
	int	sock;
	time_t  old_tcp_timeout;

	if ((jobid == NULL) || (*jobid == '\0'))
		return (pbs_errno = PBSE_IVALREQ);

	sock = connection[c].ch_socket;

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return pbs_errno;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return pbs_errno;

	/* setup DIS support routines for following DIS calls */

	DIS_tcp_setup(sock);

	if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_Rerun, pbs_current_user)) ||
		(rc = encode_DIS_JobId(sock, jobid)) ||
		(rc = encode_DIS_ReqExtend(sock, extend))) {
		connection[c].ch_errtxt = strdup(dis_emsg[rc]);
		if (connection[c].ch_errtxt == NULL) {
			pbs_errno = PBSE_SYSTEM;
		} else {
			pbs_errno = PBSE_PROTOCOL;
		}
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	/* write data */

	if (DIS_tcp_wflush(sock)) {
		pbs_errno = PBSE_PROTOCOL;
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	/* Set timeout value to very long value as rerun request */
	/* goes from Server to Mom and may take a long time      */
	old_tcp_timeout = pbs_tcp_timeout;
	pbs_tcp_timeout = PBS_DIS_TCP_TIMEOUT_VLONG;

	/* read reply from stream into presentation element */

	reply = PBSD_rdrpy(c);

	/* reset timeout */
	pbs_tcp_timeout = old_tcp_timeout;


	PBSD_FreeReply(reply);

	rc = connection[c].ch_errno;

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return pbs_errno;

	return rc;
}