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() */
Beispiel #2
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);
  }
Beispiel #3
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() */
Beispiel #4
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() */
Beispiel #5
0
void DIS_tcp_close(

  struct tcp_chan *chan)

  {
  DIS_tcp_cleanup(chan);
  }
Beispiel #6
0
static int delrm(

  int stream)

  {

  struct out *op, *prev = NULL;

  for (op = outs[stream % HASHOUT];op;op = op->next)
    {
    if (op->chan->sock == stream)
      break;

    prev = op;
    }  /* END for (op) */

  if (op != NULL)
    {
    close(stream);

    if (prev != NULL)
      prev->next = op->next;
    else
      outs[stream % HASHOUT] = op->next;

    DIS_tcp_cleanup(op->chan);
    free(op);

    return(0);
    }

  return(-1);
  }  /* END delrm() */
Beispiel #7
0
void tasks_free(

  job *pj)

  {
  task            *tp = (task *)GET_NEXT(pj->ji_tasks);
  obitent         *op;
  infoent         *ip;
  container::item_container<struct tcp_chan *> freed_chans;

  while (tp != NULL)
    {
    op = (obitent *)GET_NEXT(tp->ti_obits);

    while (op != NULL)
      {
      delete_link(&op->oe_next);

      free(op);

      op = (obitent *)GET_NEXT(tp->ti_obits);
      }  /* END while (op != NULL) */

    ip = (infoent *)GET_NEXT(tp->ti_info);

    while (ip != NULL)
      {
      delete_link(&ip->ie_next);

      free(ip->ie_name);
      free(ip->ie_info);
      free(ip);

      ip = (infoent *)GET_NEXT(tp->ti_info);
      }

    if (tp->ti_chan != NULL)
      {
      char ptr[50];
      sprintf(ptr,"%p",(void *)tp->ti_chan);
      freed_chans.lock();
      if(freed_chans.insert(tp->ti_chan,ptr))
        {
        close_conn(tp->ti_chan->sock, FALSE);
        DIS_tcp_cleanup(tp->ti_chan);
        }
      freed_chans.unlock();
        
      tp->ti_chan = NULL;
      }

    delete_link(&tp->ti_jobtask);

    free(tp);

    tp = (task *)GET_NEXT(pj->ji_tasks);
    }  /* END while (tp != NULL) */

  return;
  }  /* END tasks_free() */
Beispiel #8
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() */
Beispiel #9
0
void tasks_free(

  job *pj)

  {
  task            *tp = (task *)GET_NEXT(pj->ji_tasks);
  obitent         *op;
  infoent         *ip;
  resizable_array *freed_chans = initialize_resizable_array(30);

  while (tp != NULL)
    {
    op = (obitent *)GET_NEXT(tp->ti_obits);

    while (op != NULL)
      {
      delete_link(&op->oe_next);

      free(op);

      op = (obitent *)GET_NEXT(tp->ti_obits);
      }  /* END while (op != NULL) */

    ip = (infoent *)GET_NEXT(tp->ti_info);

    while (ip != NULL)
      {
      delete_link(&ip->ie_next);

      free(ip->ie_name);
      free(ip->ie_info);
      free(ip);

      ip = (infoent *)GET_NEXT(tp->ti_info);
      }

    if (tp->ti_chan != NULL)
      {
      if (is_present(freed_chans, tp->ti_chan) == FALSE)
        {
        insert_thing(freed_chans, tp->ti_chan);
        close_conn(tp->ti_chan->sock, FALSE);
        DIS_tcp_cleanup(tp->ti_chan);
        }
        
      tp->ti_chan = NULL;
      }

    delete_link(&tp->ti_jobtask);

    free(tp);

    tp = (task *)GET_NEXT(pj->ji_tasks);
    }  /* END while (tp != NULL) */

  free_resizable_array(freed_chans);

  return;
  }  /* END tasks_free() */
Beispiel #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;
  }
Beispiel #11
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() */
Beispiel #12
0
void DIS_tcp_close(
    
  struct tcp_chan *chan)

  {
  int sock = chan->sock;
  DIS_tcp_cleanup(chan);
  if (sock != -1)
    close(sock);
  }
Beispiel #13
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);
  }
Beispiel #14
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() */
Beispiel #15
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() */
Beispiel #16
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);
  }
Beispiel #17
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() */
Beispiel #18
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() */
Beispiel #19
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() */
int send_request_to_remote_server(
    
  int            conn,
  batch_request *request)

  {
  struct attropl   *patrl;

  struct svrattrl  *psvratl;
  int               rc = PBSE_NONE;
  int               tmp_rc = PBSE_NONE;
  int               sock = 0;
  char              log_buf[LOCAL_LOG_BUF_SIZE];
  struct tcp_chan  *chan = NULL;
    
  pthread_mutex_lock(connection[conn].ch_mutex);
  sock = connection[conn].ch_socket;
  pthread_mutex_unlock(connection[conn].ch_mutex);
  
  request->rq_conn = sock;
  
  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    log_err(PBSE_MEM_MALLOC, __func__,
      "Could not allocate memory for socket buffer");
    close_conn(sock, FALSE);
    return(PBSE_MEM_MALLOC);
    }
  /* the request is bound to another server, encode/send the request */
  switch (request->rq_type)
    {
    case PBS_BATCH_DeleteJob:
 
      rc = PBSD_mgr_put(
             conn,
             PBS_BATCH_DeleteJob,
             MGR_CMD_DELETE,
             MGR_OBJ_JOB,
             request->rq_ind.rq_delete.rq_objname,
             NULL,
             NULL);

      break;

    case PBS_BATCH_HoldJob:

      attrl_fixlink(&request->rq_ind.rq_hold.rq_orig.rq_attr);

      psvratl = (struct svrattrl *)GET_NEXT(request->rq_ind.rq_hold.rq_orig.rq_attr);

      patrl = &psvratl->al_atopl;

      rc = PBSD_mgr_put(
             conn,
             PBS_BATCH_HoldJob,
             MGR_CMD_SET,
             MGR_OBJ_JOB,
             request->rq_ind.rq_hold.rq_orig.rq_objname,
             patrl,
             NULL);

      break;

    case PBS_BATCH_CheckpointJob:

      rc = PBSD_mgr_put(
             conn,
             PBS_BATCH_CheckpointJob,
             MGR_CMD_SET,
             MGR_OBJ_JOB,
             request->rq_ind.rq_hold.rq_orig.rq_objname,
             NULL,
             NULL);

      break;

    case PBS_BATCH_GpuCtrl:

      rc = PBSD_gpu_put(
             conn,
             request->rq_ind.rq_gpuctrl.rq_momnode,
             request->rq_ind.rq_gpuctrl.rq_gpuid,
             request->rq_ind.rq_gpuctrl.rq_gpumode,
             request->rq_ind.rq_gpuctrl.rq_reset_perm,
             request->rq_ind.rq_gpuctrl.rq_reset_vol,
             NULL);

      break;

    case PBS_BATCH_MessJob:

      rc = PBSD_msg_put(
             conn,
             request->rq_ind.rq_message.rq_jid,
             request->rq_ind.rq_message.rq_file,
             request->rq_ind.rq_message.rq_text,
             NULL);

      break;

    case PBS_BATCH_ModifyJob:

    case PBS_BATCH_AsyModifyJob:

      attrl_fixlink(&request->rq_ind.rq_modify.rq_attr);

      patrl = (struct attropl *) & ((struct svrattrl *)GET_NEXT(
                                      request->rq_ind.rq_modify.rq_attr))->al_atopl;

      rc = PBSD_mgr_put(
             conn,
             request->rq_type,
             MGR_CMD_SET,
             MGR_OBJ_JOB,
             request->rq_ind.rq_modify.rq_objname,
             patrl,
             NULL);

      break;

    case PBS_BATCH_Rerun:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_Rerun, msg_daemonname)))
        break;

      if ((rc = encode_DIS_JobId(chan, request->rq_ind.rq_rerun)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, 0)))
        break;

      rc = DIS_tcp_wflush(chan);

      break;

    case PBS_BATCH_RegistDep:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_RegistDep, msg_daemonname)))
        break;

      if ((rc = encode_DIS_Register(chan, request)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, 0)))
        break;

      rc = DIS_tcp_wflush(chan);

      break;

    case PBS_BATCH_AsySignalJob:

    case PBS_BATCH_SignalJob:

      rc = PBSD_sig_put(
             conn,
             request->rq_ind.rq_signal.rq_jid,
             request->rq_ind.rq_signal.rq_signame,
             request->rq_extra);

      break;

    case PBS_BATCH_StatusJob:

      rc = PBSD_status_put(
             conn,
             PBS_BATCH_StatusJob,
             request->rq_ind.rq_status.rq_id,
             NULL,
             NULL);

      break;

    case PBS_BATCH_TrackJob:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_TrackJob, msg_daemonname)))
        break;

      if ((rc = encode_DIS_TrackJob(chan, request)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, 0)))
        break;

      rc = DIS_tcp_wflush(chan);

      break;

    case PBS_BATCH_ReturnFiles:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_ReturnFiles, msg_daemonname)))
        break;

      if ((rc = encode_DIS_ReturnFiles(chan, request)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, 0)))
        break;

      rc = DIS_tcp_wflush(chan);

      break;

    case PBS_BATCH_CopyFiles:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_CopyFiles, msg_daemonname)))
        break;

      if ((rc = encode_DIS_CopyFiles(chan, request)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, 0)))
        break;

      rc = DIS_tcp_wflush(chan);

      break;

    case PBS_BATCH_DelFiles:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_DelFiles, msg_daemonname)))
        break;

      if ((rc = encode_DIS_CopyFiles(chan, request)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, 0)))
        break;

      rc = DIS_tcp_wflush(chan);

      break;

    case PBS_BATCH_DeleteReservation:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_DeleteReservation, msg_daemonname)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, request->rq_extend)))
        break;

      rc = DIS_tcp_wflush(chan);
      
      break;

    default:

      sprintf(log_buf, msg_issuebad, request->rq_type);

      log_err(-1, __func__, log_buf);

      rc = -1;

      break;
    }  /* END switch (request->rq_type) */

  if ((tmp_rc = DIS_reply_read(chan, &request->rq_reply)) != 0)
    {
    sprintf(log_buf, "DIS_reply_read failed: %d", tmp_rc);
    log_record(PBSEVENT_JOB, PBS_EVENTCLASS_JOB, __func__, log_buf);
    request->rq_reply.brp_code = tmp_rc;
    request->rq_reply.brp_choice = BATCH_REPLY_CHOICE_NULL;
    }  
  DIS_tcp_cleanup(chan);
  svr_disconnect(conn);

  return(rc);
  } /* END send_request_to_remote_server() */
Beispiel #21
0
int PBSD_commit_get_sid(

    int   connect, /* I */
    long *sid,     /* O */
    char *jobid)   /* I */

{
    struct batch_reply *reply;
    int                 rc;
    int                 sock;
    int                 local_errno = 0;
    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(&local_errno, connect);

    pthread_mutex_lock(connection[connect].ch_mutex);
    rc = connection[connect].ch_errno;
    pthread_mutex_unlock(connection[connect].ch_mutex);

    if (reply == NULL)
    {
        /* couldn't read a response */
        if (rc == PBSE_NONE)
            rc = PBSE_PROTOCOL;
    }
    else
    {
        /* read the sid if given and no error */
        if (rc == PBSE_NONE)
        {
            if (reply->brp_choice == BATCH_REPLY_CHOICE_Text)
            {
                if (sid != NULL)
                    *sid = atol(reply->brp_un.brp_txt.brp_str);
            }
            else
                /* (reply->brp_choice == BATCH_REPLY_CHOICE_NULL) */
            {
                *sid = reply->brp_code;
            }
        }

        PBSD_FreeReply(reply);
    }

    return(rc);
} /* END PBSD_commit_get_sid() */
Beispiel #22
0
char *PBSD_queuejob(

    int             connect,     /* I */
    int            *local_errno, /* O */
    char           *jobid,       /* I */
    char           *destin,
    struct attropl *attrib,
    char           *extend)

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

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

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        return(NULL);
    }
    /* first, set up the body of the Queue Job request */
    else if ((rc = encode_DIS_ReqHdr(chan,PBS_BATCH_QueueJob,pbs_current_user)) ||
             (rc = encode_DIS_QueueJob(chan, jobid, destin, attrib)) ||
             (rc = encode_DIS_ReqExtend(chan, extend)))
    {
        pthread_mutex_lock(connection[connect].ch_mutex);
        connection[connect].ch_errtxt = strdup(dis_emsg[rc]);
        pthread_mutex_unlock(connection[connect].ch_mutex);

        *local_errno = PBSE_PROTOCOL;
        DIS_tcp_cleanup(chan);
        return(NULL);
    }

    if (DIS_tcp_wflush(chan))
    {
        *local_errno = PBSE_PROTOCOL;
        DIS_tcp_cleanup(chan);
        return(NULL);
    }

    DIS_tcp_cleanup(chan);

    /* read reply from stream into presentation element */

    reply = PBSD_rdrpy(local_errno, connect);

    pthread_mutex_lock(connection[connect].ch_mutex);
    if (reply == NULL)
    {
    }
    else if (reply->brp_choice &&
             reply->brp_choice != BATCH_REPLY_CHOICE_Text &&
             reply->brp_choice != BATCH_REPLY_CHOICE_Queue)
    {
        *local_errno = PBSE_PROTOCOL;
    }
    else if (connection[connect].ch_errno == 0)
    {
        return_jobid = strdup(reply->brp_un.brp_jid);
    }
    pthread_mutex_unlock(connection[connect].ch_mutex);

    PBSD_FreeReply(reply);

    return(return_jobid);
}  /* END PBSD_queuejob() */
Beispiel #23
0
static int PBSD_scbuf(

    int   c,  /* connection handle     */
    int   reqtype, /* request type */
    int   seq,  /* file chunk sequence number */
    char *buf,  /* file chunk */
    int   len,  /* length of chunk */
    char *jobid,  /* job id (for types 1 and 2 only) */
    enum job_file which) /* standard file type, see libpbs.h */

{

    struct batch_reply *reply;

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

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

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        return(PBSE_MEM_MALLOC);
    }
    else if (jobid == NULL)
        jobid = ""; /* use null string for null pointer */

    if ((rc = encode_DIS_ReqHdr(chan, reqtype, pbs_current_user)) ||
            (rc = encode_DIS_JobFile(chan, seq, buf, len, jobid, which)) ||
            (rc = encode_DIS_ReqExtend(chan, NULL)))
    {
        pthread_mutex_lock(connection[c].ch_mutex);
        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))
    {
        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }
    DIS_tcp_cleanup(chan);

    /* read reply */

    reply = PBSD_rdrpy(&local_errno, c);

    PBSD_FreeReply(reply);

    pthread_mutex_lock(connection[c].ch_mutex);
    rc = connection[c].ch_errno;
    pthread_mutex_unlock(connection[c].ch_mutex);


    return(rc);
}
Beispiel #24
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() */
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() */
/*************************************************
 * svr_is_request
 *
 * Return: svr_is_request always returns a non-zero value
 *         and it must call close_conn to close the connection
 *         before returning. PBSE_SOCKET_CLOSE is the code
 *         for a successful return. But which ever retun
 *         code is iused it must terminate the while loop
 *         in start_process_pbs_server_port.
 *************************************************/
void *svr_is_request(

    void *v)

{
    int                 command = 0;
    int                 ret = DIS_SUCCESS;
    int                 i;
    int                 err;
    char                nodename[PBS_MAXHOSTNAME];
    int                 perm = ATR_DFLAG_MGRD | ATR_DFLAG_MGWR;

    unsigned long       ipaddr;
    unsigned short      mom_port;
    unsigned short      rm_port;
    unsigned long       tmpaddr;
    struct sockaddr_in  addr;
    struct pbsnode     *node = NULL;
    char                log_buf[LOCAL_LOG_BUF_SIZE+1];
    char                msg_buf[80];
    char                tmp[80];
    int                 version;
    struct tcp_chan    *chan;
    long               *args;
    is_request_info    *isr = (is_request_info *)v;

    if (isr == NULL)
        return(NULL);

    chan = isr->chan;
    args = isr->args;

    version = disrsi(chan, &ret);

    if (ret != DIS_SUCCESS)
    {
        log_err(-1,  __func__, "Cannot read version - skipping this request.\n");
        close_conn(chan->sock, FALSE);
        DIS_tcp_cleanup(chan);
        return(NULL);
    }

    command = disrsi(chan, &ret);

    if (ret != DIS_SUCCESS)
    {
        snprintf(log_buf, sizeof(log_buf), "could not read command: %d", ret);
        log_err(-1, __func__, log_buf);
        close_conn(chan->sock, FALSE);
        DIS_tcp_cleanup(chan);
        return(NULL);
    }

    if (LOGLEVEL >= 4)
    {
        snprintf(log_buf, LOCAL_LOG_BUF_SIZE,
                 "message received from sock %d (version %d)",
                 chan->sock,
                 version);

        log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_SERVER, __func__, log_buf);
    }

    /* Just a note to let us know we only do IPv4 for now */
    addr.sin_family = AF_INET;
    memcpy(&addr.sin_addr, (void *)&args[1], sizeof(struct in_addr));
    addr.sin_port = args[2];

    if (version != IS_PROTOCOL_VER)
    {
        netaddr_long(args[1], tmp);
        sprintf(msg_buf, "%s:%ld", tmp, args[2]);

        snprintf(log_buf, LOCAL_LOG_BUF_SIZE, "protocol version %d unknown from %s",
                 version,
                 msg_buf);

        log_err(-1, __func__, log_buf);
        close_conn(chan->sock, FALSE);
        DIS_tcp_cleanup(chan);
        return(NULL);
    }

    /* check that machine is known */
    mom_port = disrsi(chan, &ret);
    rm_port = disrsi(chan, &ret);

    if (LOGLEVEL >= 3)
    {
        netaddr_long(args[1], tmp);
        sprintf(msg_buf, "%s:%ld", tmp, args[2]);
        snprintf(log_buf, LOCAL_LOG_BUF_SIZE,
                 "message received from addr %s: mom_port %d  - rm_port %d",
                 msg_buf,
                 mom_port,
                 rm_port);

        log_event(PBSEVENT_ADMIN,PBS_EVENTCLASS_SERVER,__func__,log_buf);
    }

    ipaddr = args[1];

    if ((node = AVL_find(ipaddr, mom_port, ipaddrs)) != NULL)
    {
        node->lock_node(__func__, "AVL_find", LOGLEVEL);
    } /* END if AVL_find != NULL) */
    else if (allow_any_mom)
    {
        const char *name = get_cached_nameinfo(&addr);

        if (name != NULL)
            snprintf(nodename, sizeof(nodename), "%s", name);
        else if (getnameinfo((struct sockaddr *)&addr, sizeof(addr), nodename, sizeof(nodename)-1, NULL, 0, 0) != 0)
        {
            tmpaddr = ntohl(addr.sin_addr.s_addr);
            sprintf(nodename, "0x%lX", tmpaddr);
        }
        else
            insert_addr_name_info(NULL, nodename);

        err = create_partial_pbs_node(nodename, ipaddr, perm);

        if (err == PBSE_NONE)
        {
            node = AVL_find(ipaddr, 0, ipaddrs);

            node->lock_node(__func__, "no error", LOGLEVEL);
        }
    }

    if (node == NULL)
    {
        /* node not listed in trusted ipaddrs list */
        netaddr_long(args[1], tmp);
        sprintf(msg_buf, "%s:%ld", tmp, args[2]);

        snprintf(log_buf, LOCAL_LOG_BUF_SIZE,
                 "bad attempt to connect from %s (address not trusted - check entry in server_priv/nodes)",
                 msg_buf);

        if (LOGLEVEL >= 2)
        {
            log_record(PBSEVENT_SCHED, PBS_EVENTCLASS_REQUEST, __func__, log_buf);
        }
        else
        {
            log_err(-1, __func__, log_buf);
        }

        close_conn(chan->sock, FALSE);
        DIS_tcp_cleanup(chan);
        return(NULL);
    }

    if (LOGLEVEL >= 3)
    {
        netaddr_long(args[1], tmp);
        sprintf(msg_buf, "%s:%ld", tmp, args[2]);

        snprintf(log_buf, LOCAL_LOG_BUF_SIZE,
                 "message %s (%d) received from mom on host %s (%s) (sock %d)",
                 PBSServerCmds2[command],
                 command,
                 node->get_name(),
                 msg_buf,
                 chan->sock);

        log_event(PBSEVENT_ADMIN,PBS_EVENTCLASS_SERVER,__func__,log_buf);
    }

    mutex_mgr node_mutex(&node->nd_mutex, true);

    switch (command)
    {
    case IS_NULL:  /* a ping from server */

        DBPRT(("%s: IS_NULL\n", __func__))

        break;

    case IS_UPDATE:

        DBPRT(("%s: IS_UPDATE\n", __func__))

        i = disrui(chan, &ret);

        if (ret != DIS_SUCCESS)
        {
            if (LOGLEVEL >= 1)
            {
                snprintf(log_buf, LOCAL_LOG_BUF_SIZE,
                         "IS_UPDATE error %d on node %s\n", ret, node->get_name());

                log_err(ret, __func__, log_buf);
            }

            goto err;
        }

        DBPRT(("%s: IS_UPDATE %s 0x%x\n", __func__, node->get_name(), i))

        update_node_state(node, i);

        if ((node->nd_state & INUSE_DOWN) != 0)
        {
            node->nd_mom_reported_down = TRUE;
        }

        break;

    case IS_STATUS:

    {
        std::string node_name = node->get_name();

        if (LOGLEVEL >= 2)
        {
            snprintf(log_buf, LOCAL_LOG_BUF_SIZE,
                     "IS_STATUS received from %s", node->get_name());

            log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_SERVER, __func__, log_buf);
        }

        node_mutex.unlock();

        ret = is_stat_get(node_name.c_str(), chan);

        node = find_nodebyname(node_name.c_str());

        if (node != NULL)
        {
            node->nd_stream = -1;
            node_mutex.mark_as_locked();

            if (ret == SEND_HELLO)
            {
                //struct hello_info *hi = new hello_info(node->nd_id);
                write_tcp_reply(chan, IS_PROTOCOL, IS_PROTOCOL_VER, IS_STATUS, DIS_SUCCESS);

                hierarchy_handler.sendHierarchyToANode(node);
                ret = DIS_SUCCESS;
            }
            else
                write_tcp_reply(chan,IS_PROTOCOL,IS_PROTOCOL_VER,IS_STATUS,ret);
        }

        if (ret != DIS_SUCCESS)
        {
            if (LOGLEVEL >= 1)
            {
                snprintf(log_buf, LOCAL_LOG_BUF_SIZE,
                         "IS_STATUS error %d on node %s", ret, node_name.c_str());

                log_err(ret, __func__, log_buf);
            }

            goto err;
        }

        break;
    }

    default:

        snprintf(log_buf, LOCAL_LOG_BUF_SIZE,
                 "unknown command %d sent from %s",
                 command,
                 node->get_name());

        log_err(-1, __func__, log_buf);

        goto err;

        break;
    }  /* END switch (command) */

    /* must be closed because mom opens and closes this connection each time */
    close_conn(chan->sock, FALSE);
    DIS_tcp_cleanup(chan);

    return(NULL);

err:

    /* a DIS write error has occurred */

    if (node != NULL)
    {
        if (LOGLEVEL >= 1)
        {
            DBPRT(("%s: error processing node %s\n",
                   __func__,
                   node->get_name()))
        }

        netaddr_long(args[1], tmp);
        sprintf(msg_buf, "%s:%ld", tmp, args[2]);

        sprintf(log_buf, "%s from %s(%s)",
                dis_emsg[ret],
                node->get_name(),
                msg_buf);
    }
    else
    {
Beispiel #27
0
char *pbs_locjob_err(
    
  int   c,
  char *jobid,
  char *extend,
  int  *local_errno)

  {
  int rc;

  struct batch_reply *reply;
  char       *ploc = (char *)0;
  int sock;
  struct tcp_chan *chan = NULL;

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

  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);
    return NULL;
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_LocateJob, pbs_current_user))
      || (rc = encode_DIS_JobId(chan, jobid))
      || (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);

    *local_errno = PBSE_PROTOCOL;
    DIS_tcp_cleanup(chan);
    return(NULL);
    }

  /* write data over tcp stream */

  if (DIS_tcp_wflush(chan))
    {
    pthread_mutex_unlock(connection[c].ch_mutex);

    *local_errno = PBSE_PROTOCOL;
    DIS_tcp_cleanup(chan);
    return(NULL);
    }

  /* read reply from stream */

  reply = PBSD_rdrpy(local_errno,c);

  if (reply == NULL)
    {
    *local_errno = PBSE_PROTOCOL;
    }
  else if (reply->brp_choice != BATCH_REPLY_CHOICE_NULL &&
           reply->brp_choice != BATCH_REPLY_CHOICE_Text &&
           reply->brp_choice != BATCH_REPLY_CHOICE_Locate)
    {
#ifndef NDEBUG
    fprintf(stderr, "advise: pbs_locjob\tUnexpected reply choice\n\n");
#endif /* NDEBUG */
    *local_errno = PBSE_PROTOCOL;
    }
  else if (connection[c].ch_errno == 0)
    {
    ploc = strdup(reply->brp_un.brp_locate);
    }

  PBSD_FreeReply(reply);

  pthread_mutex_unlock(connection[c].ch_mutex);
  DIS_tcp_cleanup(chan);
  return(ploc);
  } /* END pbs_locjob_err() */
struct batch_reply *PBSD_rdrpy(

  int *local_errno, /* O */
  int  c)           /* I */

  {
  int      rc;

  struct batch_reply *reply;
  int      sock;
  const char    *the_msg = NULL;
  struct tcp_chan *chan = NULL;

  sock = connection[c].ch_socket;
  /* clear any prior error message */

  if (connection[c].ch_errtxt != NULL)
    {
    free(connection[c].ch_errtxt);

    connection[c].ch_errtxt = NULL;
    }

  if ((reply = (struct batch_reply *)calloc(1, sizeof(struct batch_reply))) == NULL)
    {
    connection[c].ch_errno = PBSE_SYSTEM;

    *local_errno = PBSE_SYSTEM;

    return(NULL);
    }

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    }
  else if ((rc = decode_DIS_replyCmd(chan, reply)))
    {
    free(reply);

    if (chan->IsTimeout == TRUE)
      {
      *local_errno = PBSE_TIMEOUT;
      }
    else
      {
      *local_errno = PBSE_PROTOCOL;
      }

    connection[c].ch_errno = *local_errno;
    
    if ((rc >= 0) &&
        (rc <= DIS_INVALID))
      {
      if ((the_msg = dis_emsg[rc]) != NULL)
        {
        connection[c].ch_errtxt = strdup(the_msg);
        }
      }

    DIS_tcp_cleanup(chan);

    return(NULL);
    }

  DIS_tcp_cleanup(chan);

  connection[c].ch_errno = reply->brp_code;

  *local_errno = reply->brp_code;

  if (reply->brp_choice == BATCH_REPLY_CHOICE_Text)
    {
    if ((the_msg = reply->brp_un.brp_txt.brp_str) != NULL)
      {
      connection[c].ch_errtxt = strdup(the_msg);
      }
    }

  return(reply);
  }  /* END PBSD_rdrpy() */
Beispiel #29
0
int pbs_stagein(
    
  int   c,
  char *jobid,
  char *location,
  char *extend)

  {
  int                   rc;
  int                   local_errno = 0;

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


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

  if (location == (char *)0)
    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 stagein request, a run request with a different id */
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_StageIn, pbs_current_user)) ||
      (rc = encode_DIS_RunJob(chan, jobid, location, 0)) ||
      (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);
  }
Beispiel #30
0
int PBSD_QueueJob_hash(

    int             connect,     /* I */
    char           *jobid,       /* I */
    char           *destin,
    memmgr        **mm,
    job_data       *job_attr,
    job_data       *res_attr,
    char           *extend,
    char          **job_id,
    char          **msg)

{
    struct batch_reply *reply;
    int                 rc = PBSE_NONE;
    int                 sock;
    int                 tmp_size = 0;
    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_PROTOCOL);
    }
    /* first, set up the body of the Queue Job request */
    else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_QueueJob, pbs_current_user)) ||
             (rc = encode_DIS_QueueJob_hash(chan, jobid, destin, mm, job_attr, res_attr)) ||
             (rc = encode_DIS_ReqExtend(chan, extend)))
    {
        pthread_mutex_lock(connection[connect].ch_mutex);
        if (connection[connect].ch_errtxt == NULL)
        {
            if ((rc >= 0) &&
                    (rc <= DIS_INVALID))
                connection[connect].ch_errtxt = memmgr_strdup(mm, (char *)dis_emsg[rc], &tmp_size);
        }
        *msg = memmgr_strdup(mm, connection[connect].ch_errtxt, &tmp_size);

        pthread_mutex_unlock(connection[connect].ch_mutex);

        DIS_tcp_cleanup(chan);

        return(rc);
    }

    if ((rc = DIS_tcp_wflush(chan)))
    {
        pthread_mutex_lock(connection[connect].ch_mutex);
        if (connection[connect].ch_errtxt == NULL)
        {
            *msg = memmgr_strdup(mm, connection[connect].ch_errtxt, &tmp_size);
        }
        pthread_mutex_unlock(connection[connect].ch_mutex);

        DIS_tcp_cleanup(chan);

        return(rc);
    }

    DIS_tcp_cleanup(chan);

    /* read reply from stream into presentation element */
    reply = PBSD_rdrpy(&rc, connect);

    pthread_mutex_lock(connection[connect].ch_mutex);
    if (reply == NULL)
    {
        if (rc == PBSE_TIMEOUT)
            rc = PBSE_EXPIRED;
    }
    else if (reply->brp_choice &&
             reply->brp_choice != BATCH_REPLY_CHOICE_Text &&
             reply->brp_choice != BATCH_REPLY_CHOICE_Queue)
    {
        rc = PBSE_PROTOCOL;

        if (connection[connect].ch_errtxt == NULL)
        {
            *msg = memmgr_strdup(mm, connection[connect].ch_errtxt, &tmp_size);
        }
    }
    else if (reply->brp_choice == BATCH_REPLY_CHOICE_Text)
    {
        *msg = memmgr_strdup(mm, reply->brp_un.brp_txt.brp_str, &tmp_size);
    }
    else if (connection[connect].ch_errno == 0)
    {
        *job_id = memmgr_strdup(mm, reply->brp_un.brp_jid, &tmp_size);
    }

    pthread_mutex_unlock(connection[connect].ch_mutex);

    PBSD_FreeReply(reply);

    return rc;
}  /* END PBSD_queuejob() */