void get_status_info(

    struct tcp_chan          *chan,
    std::vector<std::string> &status)

{
    char           *ret_info;
    int             rc;

    while (((ret_info = disrst(chan, &rc)) != NULL) &&
            (rc == DIS_SUCCESS))
    {
        if (!strcmp(ret_info, IS_EOL_MESSAGE))
        {
            free(ret_info);
            ret_info = NULL;
            break;
        }

        status.push_back(ret_info);
        free(ret_info);
        ret_info = NULL;
    }

    if (ret_info != NULL)
        free(ret_info);
} /* END get_status_info() */
Example #2
0
char *read_mom_reply(

  int             *local_errno, /* O */
  struct tcp_chan *chan)

  {
  int   rc;
  char *value = NULL;

  if (check_success(chan))
    return(NULL);

  value = disrst(chan,&rc);

  if (rc != DIS_SUCCESS)
    {
    if (value != NULL)
      free(value);

    *local_errno = rc;

    return(NULL);
    }

  return(value);
  } /* END read_mom_reply() */
dynamic_string *get_status_info(

  struct tcp_chan *chan)

  {
  dynamic_string *ds = get_dynamic_string(-1, NULL);
  char           *ret_info;
  int             rc;

  if (ds == NULL)
    return(NULL);
  
  while (((ret_info = disrst(chan, &rc)) != NULL) && 
         (rc == DIS_SUCCESS))
    {
    if (!strcmp(ret_info, IS_EOL_MESSAGE))
      {
      free(ret_info);
      break;
      }

    copy_to_end_of_dynamic_string(ds, ret_info);
    free(ret_info);
    }

  return(ds);
  } /* END get_status_info() */
Example #4
0
/**
 * @brief
 *		Read a release nodes from job request off the wire.
 *
 * @param[in]	sock	- socket where you reads the request.
 * @param[in]	preq	- the batch_request structure containing the request details.
 *
 * @return int
 *
 * @retval	0	- if successful
 * @retval	!= 0	- if not successful (an error encountered along the way)
 */
int
decode_DIS_RelnodesJob(int sock, struct batch_request *preq)
{
	int rc;

	preq->rq_ind.rq_relnodes.rq_node_list = NULL;

	rc = disrfst(sock, PBS_MAXSVRJOBID+1, preq->rq_ind.rq_relnodes.rq_jid);
	if (rc)
		return rc;

	preq->rq_ind.rq_relnodes.rq_node_list = disrst(sock, &rc);
	return rc;
}
Example #5
0
int
decode_DIS_ReqExtend(int sock, struct batch_request *preq)
{
	int i;
	int rc;

	i = disrui(sock, &rc);	/* indicates if an extension exists */

	if (rc == 0) {
		if (i != 0) {
			preq->rq_extend = disrst(sock, &rc);
		}
	}
	return (rc);
}
Example #6
0
/**
 * @brief
 *		Read a bunch of strings into a NULL terminated array.
 *		The strings are regular null terminated char arrays
 *		and the string array is NULL terminated.
 *
 *		Pass in array location to hold the allocated array
 *		and return an error value if there is a problem.  If
 *		an error does occur, arrloc is not changed.
 *
 * @param[in]	stream	- socket where you reads the request.
 * @param[out]	arrloc	- NULL terminated array where strings are stored.
 *
 * @return	error code
 */
static int
read_carray(int stream, char ***arrloc)
{
	int	i, num, ret;
	char	*cp, **carr;

	if (arrloc == NULL)
		return PBSE_INTERNAL;

	num = 4;	/* keep track of the number of array slots */
	carr = (char **)calloc(sizeof(char **), num);
	if (carr == NULL)
		return PBSE_SYSTEM;

	for (i=0;; i++) {
		cp = disrst(stream, &ret);
		if ((cp == NULL) || (ret != DIS_SUCCESS)) {
			arrayfree(carr);
			if (cp != NULL)
				free(cp);
			return PBSE_SYSTEM;
		}
		if (*cp == '\0') {
			free(cp);
			break;
		}
		if (i == num-1) {
			char	**hold;

			hold = (char **)realloc(carr,
				num * 2 * sizeof(char **));
			if (hold == NULL) {
				arrayfree(carr);
				free(cp);
				return PBSE_SYSTEM;
			}
			carr = hold;

			/* zero the last half of the now doubled carr */
			memset(&carr[num], 0, num * sizeof(char **));
			num *= 2;
		}
		carr[i] = cp;
	}
	carr[i] = NULL;
	*arrloc = carr;
	return ret;
}
Example #7
0
int
decode_DIS_MessageJob(int sock, struct batch_request *preq)
{
	int rc;

	preq->rq_ind.rq_message.rq_text = 0;

	rc = disrfst(sock, PBS_MAXSVRJOBID+1, preq->rq_ind.rq_message.rq_jid);
	if (rc) return rc;

	preq->rq_ind.rq_message.rq_file = disrui(sock, &rc);
	if (rc) return rc;

	preq->rq_ind.rq_message.rq_text = disrst(sock, &rc);
	return rc;
}
Example #8
0
/**
 * @brief
 * 		process the reply received for a request issued to
 *		  another server via issue_request()
 *
 * 		Reads the reply from the RPP stream and executes the work task associated
 * 		with the RPP reply message. The RPP request for which this reply arrived
 * 		is matched by comparing the msgid of the reply with the msgid of the work
 * 		tasks stored in the msr_deferred_cmds list of the mom for this stream.
 *
 * @param[in] handle - RPP handle on which reply/close arrived
 *
 * @return void
 */
void
process_DreplyRPP(int handle)
{
	struct work_task	*ptask;
	int			 rc;
	struct batch_request	*request;
	struct batch_reply *reply;
	char 		*msgid = NULL;
	mominfo_t *pmom = 0;

	if ((pmom = tfind2((u_long) handle, 0, &streams)) == NULL)
		return;

	DIS_rpp_reset();

	/* find the work task for the socket, it will point us to the request */
	msgid = disrst(handle, &rc);

	if (!msgid || rc) { /* rpp connection actually broke, cull all pending requests */
		while ((ptask = (struct work_task *)GET_NEXT((((mom_svrinfo_t *) (pmom->mi_data))->msr_deferred_cmds)))) {
			/* no need to compare wt_event with handle, since the
			 * task list is for this mom and so it will always match
			 */
			if (ptask->wt_type == WORK_Deferred_Reply) {
				request = ptask->wt_parm1;
				if (request) {
					request->rq_reply.brp_code = rc;
					request->rq_reply.brp_choice = BATCH_REPLY_CHOICE_NULL;
				}
			}

			ptask->wt_aux = PBSE_NORELYMOM;
			pbs_errno = PBSE_NORELYMOM;

			if (ptask->wt_event2)
				free(ptask->wt_event2);

			dispatch_task(ptask);
		}
	} else {
		/* we read msgid fine, so proceed to match it and process the respective task */

		/* get the task list */
		ptask = (struct work_task *)GET_NEXT((((mom_svrinfo_t *) (pmom->mi_data))->msr_deferred_cmds));

		while (ptask) {

			char *cmd_msgid = ptask->wt_event2;

			if (strcmp(cmd_msgid, msgid) == 0) {

				if (ptask->wt_type == WORK_Deferred_Reply)
					request = ptask->wt_parm1;
				else
					request = NULL;

				if (!request) {
					if ((reply = (struct batch_reply *) malloc(sizeof(struct batch_reply))) == 0) {
						delete_task(ptask);
						free(cmd_msgid);
						log_err(errno, msg_daemonname, "Out of memory creating batch reply");
						return;
					}
					(void) memset(reply, 0, sizeof(struct batch_reply));
				} else {
					reply = &request->rq_reply;
				}

				/* read and decode the reply */
				if ((rc = DIS_reply_read(handle, reply, 1)) != 0) {
					reply->brp_code = rc;
					reply->brp_choice = BATCH_REPLY_CHOICE_NULL;
					ptask->wt_aux = PBSE_NORELYMOM;
					pbs_errno = PBSE_NORELYMOM;
				} else {
					ptask->wt_aux = reply->brp_code;
					pbs_errno = reply->brp_code;
				}

				ptask->wt_parm3 = reply; /* set the reply in case callback fn uses without having a preq */

				dispatch_task(ptask);

				if (!request)
					PBSD_FreeReply(reply);

				free(cmd_msgid);

				break;
			}
			ptask = (struct work_task *) GET_NEXT(ptask->wt_linkobj2);
		}
		free(msgid); /* the msgid read should be free after use in matching */
	}
}
Example #9
0
int
decode_DIS_attrl(int sock, struct attrl **ppatt)
{
	int		 hasresc;
	int		 i;
	unsigned int	 numpat;
	struct attrl  *pat      = 0;
	struct attrl  *patprior = 0;
	int		 rc;


	numpat = disrui(sock, &rc);
	if (rc) return rc;

	for (i=0; i < numpat; ++i) {

		(void) disrui(sock, &rc);
		if (rc) break;

		pat = malloc(sizeof(struct attrl));
		if (pat == 0)
			return DIS_NOMALLOC;

		pat->next     = (struct attrl *)0;
		pat->name     = (char *)0;
		pat->resource = (char *)0;
		pat->value    = (char *)0;

		pat->name = disrst(sock, &rc);
		if (rc)	break;

		hasresc = disrui(sock, &rc);
		if (rc) break;
		if (hasresc) {
			pat->resource = disrst(sock, &rc);
			if (rc) break;
		}

		pat->value = disrst(sock, &rc);
		if (rc) break;

#ifdef NAS /* localmod 005 */
		pat->op = (enum batch_op) disrui(sock, &rc);
#else
		pat->op = disrui(sock, &rc);
#endif /* localmod 005 */
		if (rc) break;

		if (i == 0) {
			/* first one, link to passing in pointer */
			*ppatt = pat;
		} else {
			patprior->next = pat;
		}
		patprior = pat;
	}

	if (rc)
		PBS_free_aopl((struct attropl *)pat);
	return rc;
}
Example #10
0
int
decode_DIS_attropl(int sock, struct attropl **ppatt)
  {
  int   hasresc;
  unsigned int  i;
  unsigned int  name_len;
  unsigned int  numpat;

  struct attropl  *pat = NULL;

  struct attropl  *patprior = NULL;
  int   rc;


  numpat = disrui(sock, &rc);

  if (rc) return rc;

  for (i = 0; i < numpat; ++i)
    {

    name_len = disrui(sock, &rc); /* name_len is unused here */

    if (rc) break;

    pat = malloc(sizeof(struct attropl));

    if (pat == 0)
      return DIS_NOMALLOC;

    pat->next     = (struct attropl *)0;

    pat->name     = (char *)0;

    pat->resource = (char *)0;

    pat->value    = (char *)0;

    pat->name = disrst(sock, &rc);

    if (rc) break;

    hasresc = disrui(sock, &rc);

    if (rc) break;

    if (hasresc)
      {
      pat->resource = disrst(sock, &rc);

      if (rc) break;
      }

    pat->value = disrst(sock, &rc);

    if (rc) break;

    pat->op = (enum batch_op)disrui(sock, &rc);

    if (rc) break;

    if (i == 0)
      {
      /* first one, link to passing in pointer */
      *ppatt = pat;
      }
    else
      {
      patprior->next = pat;
      }

    patprior = pat;
    }

  if (rc)
    PBS_free_aopl(pat);

  return rc;
  }
Example #11
0
/**
 * @brief
 *	vn_decode_DIS_V3 - decode version 3 vnode information from Mom
 *
 * @par Functionality:
 *	See vn_decode_DIS() above, This is called from there to decode
 *	V3 information.
 *
 * @param[in]	fd  -     socket descriptor from which to read
 * @param[out]	rcp -     pointer to place to return error code if error.
 *
 * @return	vnl_t *
 * @retval	pointer to decoded vnode information which has been malloc-ed.
 * @retval	NULL on error, see rcp value
 *
 * @par Side Effects: None
 *
 * @par MT-safe: yes
 *
 */
static vnl_t *
vn_decode_DIS_V3(int fd, int *rcp)
{
	unsigned int	i, j;
	unsigned int	size;
	time_t		t;
	vnl_t		*vnlp;

	if ((vnlp = malloc(sizeof(vnl_t))) == NULL) {
		*rcp = DIS_NOMALLOC;
		return ((vnl_t *) NULL);
	}

	t = (time_t) disrsl(fd, rcp);
	if (*rcp != DIS_SUCCESS)
		return ((vnl_t *) NULL);
	else
		vnlp->vnl_modtime = t;
	size = disrui(fd, rcp);
	if (*rcp != DIS_SUCCESS)
		return ((vnl_t *) NULL);
	else
		vnlp->vnl_nelem = vnlp->vnl_used = size;

	if ((vnlp->vnl_list = calloc(vnlp->vnl_nelem,
		sizeof(vnal_t))) == NULL) {
		free(vnlp);
		*rcp = DIS_NOMALLOC;
		return ((vnl_t *) NULL);
	}

	for (i = 0; i < vnlp->vnl_used; i++) {
		vnal_t		*curreslist = VNL_NODENUM(vnlp, i);

		/*
		 *	In case an error occurs and we need to free
		 *	whatever's been allocated so far, we use the
		 *	vnal_cur entry to record the number of vnal_t
		 *	entries to free.
		 */
		vnlp->vnl_cur = i;

		curreslist->vnal_id = disrst(fd, rcp);
		if (*rcp != DIS_SUCCESS)
			return (free_and_return(vnlp));

		size = disrui(fd, rcp);
		if (*rcp != DIS_SUCCESS)
			return (free_and_return(vnlp));
		else
			curreslist->vnal_nelem = curreslist->vnal_used = size;
		if ((curreslist->vnal_list = calloc(curreslist->vnal_nelem,
			sizeof(vna_t))) == NULL)
			return (free_and_return(vnlp));

		for (j = 0; j < size; j++) {
			vna_t	*curres = VNAL_NODENUM(curreslist, j);

			/*
			 *	In case an error occurs and we need to free
			 *	whatever's been allocated so far, we use the
			 *	vnal_cur entry to record the number of vna_t
			 *	entries to free.
			 */
			curreslist->vnal_cur = j;

			curres->vna_name = disrst(fd, rcp);
			if (*rcp != DIS_SUCCESS)
				return (free_and_return(vnlp));
			curres->vna_val = disrst(fd, rcp);
			if (*rcp != DIS_SUCCESS)
				return (free_and_return(vnlp));
		}
	}

	*rcp = DIS_SUCCESS;
	return (vnlp);
}