コード例 #1
0
ファイル: momctl.c プロジェクト: gto11520/torque
int send_command(

  struct tcp_chan *chan,
  int              cmd)

  {
  int rc;

  rc = diswsi(chan,cmd);

  if (cmd == RM_CMD_CONFIG)
    {
    diswst(chan,ConfigBuf);
    }

  DIS_tcp_wflush(chan);
  if (cmd == RM_CMD_CLOSE)
    DIS_tcp_close(chan);

  return(rc);
  } /* END send_command() */
コード例 #2
0
ファイル: momctl.c プロジェクト: adaptivecomputing/torque
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() */