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

  int    argc,
  char **argv)

  {
  /*
   *  This routine sends a Manage request to the batch server specified by
   * the destination.  The ENABLED queue attribute is set to {True}.  If the
   * batch request is accepted, the server will accept Queue Job requests for
   * the specified queue.
   */

  int dest;  /* Index into the destination array (argv) */
  char *queue; /* Queue name part of destination */
  char *server; /* Server name part of destination */

  if (argc == 1)
    {
    fprintf(stderr, "Usage: qenable [queue][@server] ...\n");
    exit(1);
    }
  else if (argc > 1 && argv[1][0] == '-')
    {
    /* make it look like some kind of help is available */
    fprintf(stderr, "Usage: qenable [queue][@server] ...\n");
    exit(1);
    }
  
  initialize_network_info();

  for (dest = 1; dest < argc; dest++)
    if (parse_destination_id(argv[dest], &queue, &server) == 0)
      execute(queue, server);
    else
      {
      fprintf(stderr, "qenable: illegally formed destination: %s\n",
              argv[dest]);
      exitstatus = 1;
      }

  exit(exitstatus);
  }
コード例 #2
0
ファイル: qstop.c プロジェクト: actorquedeveloper/torque
int
main(int argc, char **argv)
{
    /*
     *  This routine sends a Manage request to the batch server specified by
     * the destination.  The STARTED queue attribute is set to {False}.  If the
     * batch request is accepted, the server will stop scheduling or routing
     * requests for the specified queue.
     */

    int dest;  /* Index into the destination array (argv) */
    char *queue; /* Queue name part of destination */
    char *server; /* Server name part of destination */

    if (argc == 1)
    {
        fprintf(stderr, "Usage: qstop [queue][@server] ...\n");
        exit(1);
    }
    else if (argc > 1 && argv[1][0] == '-')
    {
        fprintf(stderr, "Usage: qstop [queue][@server] ...\n");
        exit(1);
    }

    initialize_network_info();

    for (dest = 1; dest < argc; dest++)
        if (parse_destination_id(argv[dest], &queue, &server) == 0)
            execute(queue, server);
        else
        {
            fprintf(stderr, "qstop: illegally formed destination: %s\n",
                    argv[dest]);
            exitstatus = 1;
        }

    exit(exitstatus);
}
コード例 #3
0
ファイル: qchkpt.c プロジェクト: actorquedeveloper/torque
int main(int argc, char **argv) /* qchkpt */
{
    int any_failed = 0;
    static char usage[] = "Usage: qchkpt job_id ...\n";

    char job_id[PBS_MAXCLTJOBID];       /* from the command line */

    char job_id_out[PBS_MAXCLTJOBID] = "";
    char server_out[MAXSERVERNAME] = "";
    char rmt_server[MAXSERVERNAME] = "";

    if (argc == 1)
    {
        fprintf(stderr, "%s", usage);
        return 1;
    }

    initialize_network_info();

    for (optind = 1; optind < argc; optind++)
    {
        int connect;
        int stat = 0;
        int located = FALSE;

        snprintf(job_id, sizeof(job_id), "%s", argv[optind]);

        if (get_server(job_id, job_id_out, sizeof(job_id_out), server_out, sizeof(server_out)))
        {
            fprintf(stderr, "qchkpt: illegally formed job identifier: %s\n", job_id);
            any_failed = 1;
            continue;
        }

cnt:

        connect = cnt2server(server_out);

        if (connect <= 0)
        {
            any_failed = -1 * connect;

            if (server_out[0] != '\0')
                fprintf(stderr, "qchkpt: cannot connect to server %s (errno=%d)\n",
                        server_out, any_failed);
            else
                fprintf(stderr, "qchkpt: cannot connect to server %s (errno=%d)\n",
                        pbs_server, any_failed);
            continue;
        }

        stat = pbs_checkpointjob_err(connect, job_id_out, NULL, &any_failed);

        if (stat &&
                (any_failed != PBSE_UNKJOBID))
        {
            prt_job_err("qchkpt", connect, job_id_out);
        }
        else if (stat &&
                 (any_failed == PBSE_UNKJOBID) &&
                 !located)
        {
            located = TRUE;

            if (locate_job(job_id_out, server_out, rmt_server))
            {
                pbs_disconnect(connect);
                strcpy(server_out, rmt_server);
                goto cnt;
            }

            prt_job_err("qchkpt", connect, job_id_out);
        }

        pbs_disconnect(connect);
    }

    return any_failed;
}
コード例 #4
0
ファイル: pbs_track.c プロジェクト: bmdaw/torque
int main(

  int    argc,
  char **argv) /* pbs_track */

  {
  int ArgIndex;
  int NumErrs = 0;

  char *Args[MAXARGS];
  int   aindex = 0;

  int   rc;
  int   pid;

  char tmpJobID[PBS_MAXCLTJOBID];        /* from the command line */

  char JobID[PBS_MAXCLTJOBID];  /* modified job ID for MOM/server consumption */
  char ServerName[MAXSERVERNAME];

  int  DoBackground = 0;

  tmpJobID[0] = '\0';

  initialize_network_info();

  /* USAGE: pbs_track [-j <JOBID>] -- a.out arg1 arg2 ... argN */

#define GETOPT_ARGS "bj:"

  while ((ArgIndex = getopt(argc, argv, GETOPT_ARGS)) != EOF)
    {
    switch (ArgIndex)
      {

      case 'b':

        /* background process */

        DoBackground = 1;

        break;

      case 'j':

        strncpy(tmpJobID, optarg, sizeof(tmpJobID));

        if (tmpJobID[PBS_MAXCLTJOBID-1] != '\0')
          {
          /* truncation occurred! */

          fprintf(stderr, "pbs_track: given job ID too large (> %d)\n",
                  PBS_MAXCLTJOBID);

          exit(-1);
          }

        break;

      default:

        NumErrs++;

        break;
      }
    }

  if ((NumErrs > 0) ||
      (optind >= argc) ||
      (tmpJobID[0] == '\0'))
    {
    static char Usage[] = "USAGE: pbs_track [-j <JOBID>] [-b] -- a.out arg1 arg2 ... argN\n";
    fprintf(stderr, "%s", Usage);
    exit(2);
    }

  if (getenv(NO_SERVER_SUFFIX) != NULL)
    {
    snprintf(JobID, sizeof(JobID), "%s", tmpJobID);
    }
  else
    {
    if (get_server(tmpJobID, JobID, sizeof(JobID), ServerName, sizeof(ServerName)))
      {
      fprintf(stderr, "pbs_track: illegally formed job identifier: '%s'\n", JobID);
      exit(1);
      }
    }

  /* gather a.out and other arguments */

  aindex = 0;

  for (;optind < argc;optind++)
    {
    Args[aindex++] = strdup(argv[optind]);
    printf("Got arg: %s\n",
           Args[aindex-1]);
    }

  Args[aindex] = NULL;

  /* decide if we should fork or not */

  pid = 1;

  if (DoBackground == 1)
    {
    printf("FORKING!\n");

    pid = fork();
    }

  if ((DoBackground == 0) || (pid == 0))
    {
    /* either parent or child, depending on the setting */

    /* call tm_adopt() to start tracking this process */

    rc = tm_adopt(JobID, TM_ADOPT_JOBID, getpid());

    switch (rc)
      {

      case TM_SUCCESS:

        /* success! */

        break;

      case TM_ENOTFOUND:

        fprintf(stderr, "pbs_track: MOM could not find job %s\n",
                JobID);

        break;

      case TM_ESYSTEM:

      case TM_ENOTCONNECTED:

        fprintf(stderr, "pbs_track: error occurred while trying to communication with pbs_mom: %s (%d)\n",
                pbse_to_txt(rc),
                rc);

        break;

      default:

        /* Unexpected error occurred */

        fprintf(stderr, "pbs_track: unexpected error %s (%d) occurred\n",
                pbse_to_txt(rc),
                rc);

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

    if (rc != TM_SUCCESS)
      {
      exit(-1);
      }

    /* do the exec */

    if (execvp(Args[0], Args) == -1)
      {
      fprintf(stderr,"execvp failed with error %d, message:\n%s\n",
        errno,
        strerror(errno));
      }
    }  /* END if ((DoBackground == 0) || (pid == 0)) */
  else if (pid > 0)
    {
    /* parent*/

    fclose(stdin);
    fclose(stdout);
    fclose(stderr);
    }
  else if (pid < 0)
    {
    fprintf(stderr, "pbs_track: could not fork (%d:%s)\n",
            errno,
            strerror(errno));
    }

  exit(0);
  }  /* END main() */
コード例 #5
0
ファイル: qterm.c プロジェクト: actorquedeveloper/torque
int main(

  int    argc,  /* I */
  char **argv)  /* I */

  {
  /*
   * This routine sends a Server Shutdown request to the batch server.  If the
   * batch request is accepted, and the type is IMMEDIATE, then no more jobs
   * are accepted and all jobs are checkpointed or killed.  If the type is
   * DELAY, then only privileged users can submit jobs, and jobs will be
   * checkpointed if available.
   */

  static char opts[] = "t:";  /* See man getopt */
  int s;                  /* The execute line option */
  static char usage[] = "Usage: qterm [-t immediate|delay|quick] [server ...]\n";
  char *type = NULL;      /* Pointer to the type of termination */
  int manner;             /* The type of termination */
  int errflg = 0;         /* Error flag */

  initialize_network_info();

  /* Command line options */

  while ((s = getopt(argc, argv, opts)) != EOF)
    {
    switch (s)
      {

      case 't':

        type = optarg;

        break;

      case '?':

      default:

        errflg++;

        break;
      }
    }  /* END while() */

  if (errflg)
    {
      fprintf(stderr, "%s",
            usage);

    exit(1);
    }

  if (type == NULL)
    {
    /* use 'quick' as default */

    manner = SHUT_QUICK;
    }
  else
    {
    if (!strcasecmp(type, "delay"))
      {
      manner = SHUT_DELAY;
      }
    else if (!strcasecmp(type, "immediate"))
      {
      manner = SHUT_IMMEDIATE;
      }
    else if (!strcasecmp(type, "quick"))
      {
      manner = SHUT_QUICK;
      }
    else
      {
      /* invalid type specified */

	fprintf(stderr, "%s",
              usage);

      exit(1);
      }
    }

  if (optind < argc)
    {
    /* shutdown each specified server */

    for (;optind < argc;optind++)
      {
      execute(manner, argv[optind]);
      }
    }
  else
    {
    /* shutdown default server */

    execute(manner, "");
    }

  exit(exitstatus);

  /*NOTREACHED*/

  return(0);
  }  /* END main() */
コード例 #6
0
ファイル: qhold.c プロジェクト: dhill12/test
int main(
    
  int    argc,
  char **argv) /* qhold */
  
  {
  int c;
  int errflg = 0;
  int any_failed = 0;
  int u_cnt, o_cnt, s_cnt;
  char *pc;
  char  extend[1024];

  char job_id[PBS_MAXCLTJOBID];       /* from the command line */

  char job_id_out[PBS_MAXCLTJOBID];
  char server_out[MAXSERVERNAME];
  char rmt_server[MAXSERVERNAME];

#define MAX_HOLD_TYPE_LEN 32
  char hold_type[MAX_HOLD_TYPE_LEN+1];

#define GETOPT_ARGS "h:t:"

  hold_type[0] = '\0';
  extend[0] = '\0';

  initialize_network_info();

  while ((c = getopt(argc, argv, GETOPT_ARGS)) != EOF)
    switch (c)
      {

      case 'h':

        while (isspace((int)*optarg)) optarg++;

        if (strlen(optarg) == 0)
          {
          fprintf(stderr, "qhold: illegal -h value\n");
          errflg++;
          break;
          }

        pc = optarg;

        u_cnt = o_cnt = s_cnt = 0;

        while (*pc)
          {
          if (*pc == 'u')
            u_cnt++;
          else if (*pc == 'o')
            o_cnt++;
          else if (*pc == 's')
            s_cnt++;
          else
            {
            fprintf(stderr, "qhold: illegal -h value\n");
            errflg++;
            break;
            }

          pc++;
          }

        strcpy(hold_type, optarg);

        break;

      case 't':

        pc = optarg;

        if (strlen(pc) == 0)
          {
          fprintf(stderr, "qhold: illegal -t value (array range cannot be zero length)\n");

          errflg++;

          break;
          }

        snprintf(extend,sizeof(extend),"%s%s",
          ARRAY_RANGE,
          pc);

        break;

      default :
        errflg++;
      }

  if (errflg || optind >= argc)
    {
    static char usage[] = "usage: qhold [-h hold_list] [-t array_range] job_identifier...\n";
    fprintf(stderr,"%s", usage);
    exit(2);
    }

  for (; optind < argc; optind++)
    {
    int connect;
    int stat = 0;
    int located = FALSE;

    strcpy(job_id, argv[optind]);

    if (get_server(job_id, job_id_out, server_out))
      {
      fprintf(stderr, "qhold: illegally formed job identifier: %s\n", job_id);
      any_failed = 1;
      continue;
      }

cnt:

    connect = cnt2server(server_out);

    if (connect <= 0)
      {
      any_failed = -1 * connect;

      fprintf(stderr, "qhold: cannot connect to server %s (errno=%d) %s\n",
              pbs_server, any_failed, pbs_strerror(any_failed));
      
      continue;
      }

    if (extend[0] == '\0')
      stat = pbs_holdjob_err(connect, job_id_out, hold_type, NULL, &any_failed);
    else
      stat = pbs_holdjob_err(connect, job_id_out, hold_type, extend, &any_failed);

    if (stat &&
        (any_failed != PBSE_UNKJOBID))
      {
      prt_job_err("qhold", connect, job_id_out);
      }
    else if (stat && 
             (any_failed != PBSE_UNKJOBID) &&
             !located)
      {
      located = TRUE;

      if (locate_job(job_id_out, server_out, rmt_server))
        {
        pbs_disconnect(connect);
        strcpy(server_out, rmt_server);
        goto cnt;
        }

      prt_job_err("qhold", connect, job_id_out);
      }

    pbs_disconnect(connect);
    }

  exit(any_failed);
  }
コード例 #7
0
ファイル: qrun.c プロジェクト: VladimirStarostenkov/torque
int main(

  int    argc,  /* I */
  char **argv)  /* I */

  {
  /*
   *  This routine sends a Run Job request to the batch server.  If the
   * batch request is accepted, the server will have started the execution
   * of the job.
   */

  char job[PBS_MAXCLTJOBID];      /* Job Id */
  char server[MAXSERVERNAME];   /* Server name */
  char *location = NULL;          /* Where to run the job */

  static char opts[] = "aH:";     /* See man getopt */
  static const char *usage = "Usage: qrun [-a] [-H host] job_id ...\n";
  int s;
  int errflg = 0;
  int runAsync = FALSE;

  initialize_network_info();

  /* Command line options */

  while ((s = getopt(argc, argv, opts)) != EOF)
    {
    switch (s)
      {

      case 'a': /* Async job start */

        runAsync = TRUE;

        break;

      case 'H':

        if (strlen(optarg) == 0)
          {
          fprintf(stderr, "qrun: illegal -H value\n");
          errflg++;
          break;
          }

        location = optarg;

        break;

      case '?':

      default:

        errflg++;

        break;
      }  /* END switch(s) */
    }    /* END while (getopt() != -1) */

  if (errflg || (optind >= argc))
    {
    fprintf(stderr,"%s", usage);

    exit(1);
    }

  for (;optind < argc;optind++)
    {
    if (get_server(argv[optind], job, sizeof(job), server, sizeof(server)))
      {
      fprintf(stderr, "qrun: illegally formed job identifier: %s\n",
              argv[optind]);

      exitstatus = 1;

      continue;
      }

    execute(job, server, location, runAsync);
    }  /* END for (;optind) */

  exit(exitstatus);

  /*NOTREACHED*/

  return(0);
  }  /* END main() */
コード例 #8
0
ファイル: qdel.c プロジェクト: actorquedeveloper/torque-old
int main(

  int    argc,
  char **argv)

  {
  int c;
  int errflg = 0;
  int any_failed = 0;
  int purge_completed = FALSE;
  int located = FALSE;
  char *pc;

  char job_id[PBS_MAXCLTJOBID]; /* from the command line */

  char job_id_out[PBS_MAXCLTJOBID];
  char server_out[MAXSERVERNAME] = "";
  char rmt_server[MAXSERVERNAME] = "";

  char extend[1024];

#define GETOPT_ARGS "acm:pW:t:"

  initialize_network_info();
  extend[0] = '\0';

  while ((c = getopt(argc, argv, GETOPT_ARGS)) != EOF)
    {
    switch (c)
      {

      case 'a': /* Async job deletion */

        if (extend[0] != '\0')
          {
          errflg++;

          break;
          }

        strcpy(extend, DELASYNC);

        break;

      case 'c':

        if (extend[0] != '\0')
          {
          errflg++;

          break;
          }

        snprintf(extend,sizeof(extend),"%s%ld",PURGECOMP,(long)(time(NULL)));
        purge_completed = TRUE;

        break;

      case 'm':

        /* add delete message */

        if (extend[0] != '\0')
          {
          /* extension option already specified */

          errflg++;

          break;
          }

        strncpy(extend, optarg, sizeof(extend));

        break;

      case 'p':

        if (extend[0] != '\0')
          {
          errflg++;

          break;
          }

        strcpy(extend, DELPURGE);

        strcat(extend, "1");

        break;

      case 't':

        if (extend[0] != '\0')
          {
          errflg++;

          break;
          }

        pc = optarg;

        if (strlen(pc) == 0)
          {
          fprintf(stderr, "qdel: illegal -t value (array range cannot be zero length)\n");

          errflg++;

          break;
          }

        snprintf(extend,sizeof(extend),"%s%s",
          ARRAY_RANGE,
          pc);

        break;

      case 'W':

        if (extend[0] != '\0')
          {
          errflg++;

          break;
          }

        pc = optarg;

        if (strlen(pc) == 0)
          {
          fprintf(stderr, "qdel: illegal -W value\n");

          errflg++;

          break;
          }

        while (*pc != '\0')
          {
          if (!isdigit(*pc))
            {
            fprintf(stderr, "qdel: illegal -W value\n");

            errflg++;

            break;
            }

          pc++;
          }

        strcpy(extend, DELDELAY);

        strcat(extend, optarg);

        break;

      default:

        errflg++;

        break;
      }
    }    /* END while (c) */

  if (purge_completed)
    {
    strcpy(server_out,pbs_default());
    goto cnt;
    }

  if ((errflg != 0) || (optind >= argc))
    {
    static char usage[] = "usage: qdel [{ -a | -c | -p | -t | -W delay | -m message}] [<JOBID>[<JOBID>]|'all'|'ALL']...\n";

    fprintf(stderr, "%s", usage);

    fprintf(stderr, "       -a -c, -m, -p, -t, and -W are mutually exclusive\n");

    exit(2);
    }

  for (;optind < argc;optind++)
    {
    int connect;
    int stat = 0;

    /* check to see if user specified 'all' to delete all jobs */

    snprintf(job_id, sizeof(job_id), "%s", argv[optind]);

    if (get_server(job_id, job_id_out, sizeof(job_id_out), server_out, sizeof(server_out)))
      {
      fprintf(stderr, "qdel: illegally formed job identifier: %s\n",
              job_id);

      any_failed = 1;

      continue;
      }

cnt:

    connect = cnt2server(server_out);

    if (connect <= 0)
      {
      any_failed = -1 * connect;

      if(server_out[0] != 0)
        fprintf(stderr, "qdel: cannot connect to server %s (errno=%d) %s\n",
              server_out,
              any_failed,
              pbs_strerror(any_failed));
      else
        fprintf(stderr, "qdel: cannot connect to server %s (errno=%d) %s\n",
              pbs_server,
              any_failed,
              pbs_strerror(any_failed));

      continue;
      }

    stat = pbs_deljob_err(connect, job_id_out, extend, &any_failed);

    if (stat &&
        (any_failed != PBSE_UNKJOBID))
      {
      prt_job_err("qdel", connect, job_id_out);
      }
    else if (stat && 
             (any_failed != PBSE_UNKJOBID) &&
             !located)
      {
      located = TRUE;

      if (locate_job(job_id_out, server_out, rmt_server))
        {
        pbs_disconnect(connect);

        strcpy(server_out, rmt_server);

        goto cnt;
        }

      prt_job_err("qdel", connect, job_id_out);
      }

    pbs_disconnect(connect);
    }

  exit(any_failed);
  }  /* END main() */
コード例 #9
0
ファイル: qgpumode.c プロジェクト: actorquedeveloper/torque
int main(

  int    argc,
  char **argv)

  {
  int   c;
  int   errflg = 0;
  char *gpuid = NULL;
  int   gpumode = -1;

  char *mom_node = NULL;

  initialize_network_info();

#define GETOPT_ARGS "H:g:m:"

  while ((c = getopt(argc, argv, GETOPT_ARGS)) != EOF)
    {
    switch (c)
      {

      case 'H':

        if (strlen(optarg) == 0)
          {
          fprintf(stderr, "qgpumode: illegal -H value\n");
          errflg++;
          break;
          }

        mom_node = optarg;

        break;

      case 'g':

        if (strlen(optarg) == 0)
          {
          fprintf(stderr, "qgpumode: illegal -g value\n");
          errflg++;
          break;
          }

        gpuid = optarg;

        break;

      case 'm':

        gpumode = atoi(optarg);
        
        if (gpumode < 0 || gpumode > 3)
          {
          fprintf(stderr, "qgpumode: illegal -m value\n");
          errflg++;
          }

        break;

      default:

        errflg++;

        break;
      }
    }    /* END while (c) */

  if (errflg || (mom_node == NULL) || (gpuid == NULL) || (gpumode == -1))
    {
    static char usage[] = "usage: qgpumode -H host -g gpuid -m mode\n";

    fprintf(stderr, "%s", usage);

    exit(2);
    }

  execute(mom_node, gpuid, gpumode, "");

  exit(exitstatus);

  /*NOTREACHED*/

  return(0);
  }  /* END main() */
コード例 #10
0
ファイル: qorder.c プロジェクト: actorquedeveloper/torque
int main(

  int    argc,   /* I */
  char **argv)   /* I */

  {
  char job_id1[PBS_MAXCLTJOBID+1];  /* from the command line */
  char job_id2[PBS_MAXCLTJOBID+1];  /* from the command line */
  char job_id1_out[PBS_MAXCLTJOBID+1];
  char job_id2_out[PBS_MAXCLTJOBID+1];
  char *pn;
  int  port1 = 0;
  int  port2 = 0;
  char server_out1[MAXSERVERNAME+1];
  char server_out2[MAXSERVERNAME+1];
  char svrtmp[MAXSERVERNAME+1] = "";
  int connect;
  int stat = 0;
  int rc = 0;
  int local_errno = 0;

  if (argc != 3)
    {
    static char usage[] = "usage: qorder job_identifier job_identifier\n";

    fprintf(stderr, "%s",
            usage);

    exit(2);
    }

  snprintf(job_id1, sizeof(job_id1), "%s", argv[1]);

  snprintf(job_id2, sizeof(job_id2), "%s", argv[2]);

  svrtmp[0] = '\0';

  initialize_network_info();

  if (get_server(job_id1, job_id1_out, sizeof(job_id1_out), svrtmp, sizeof(svrtmp)))
    {
    fprintf(stderr, "qorder: illegally formed job identifier: %s\n",
            job_id1);

    exit(1);
    }

  if (*svrtmp == '\0')
    {
    if ((pn = pbs_default()))
      {
      strcpy(svrtmp, pn);
      }
    else
      {
      fprintf(stderr, "qorder: could not get default server: %s\n",
              job_id1);

      exit(1);
      }
    }

  if ((pn = strchr(svrtmp, (int)':')) != 0)
    {
    *pn = '\0';

    port1 = atoi(pn + 1);
    }

  if (get_fullhostname(svrtmp, server_out1, MAXSERVERNAME, NULL) != 0)
    {
    fprintf(stderr, "qorder: invalid server name: %s\n",
            job_id1);

    exit(1);
    }

  svrtmp[0] = '\0';

  if (get_server(job_id2, job_id2_out, sizeof(job_id2_out), svrtmp, sizeof(svrtmp)))
    {
    fprintf(stderr, "qorder: illegally formed job identifier: %s\n",
            job_id2);

    exit(1);
    }

  if (*svrtmp == '\0')
    {
    if ((pn = pbs_default()))
      {
      strcpy(svrtmp, pn);
      }
    else
      {
      fprintf(stderr, "qorder: could not get default server: %s\n",
              job_id1);

      exit(1);
      }
    }

  if ((pn = strchr(svrtmp, (int)':')) != 0)
    {
    *pn = '\0';

    port2 = atoi(pn + 1);
    }

  if (get_fullhostname(svrtmp, server_out2, MAXSERVERNAME, NULL) != 0)
    {
    fprintf(stderr, "qorder: invalid server name: %s\n",
            job_id2);

    exit(1);
    }

  if ((strcmp(server_out1, server_out2) != 0) || (port1 != port2))
    {
    fprintf(stderr, "qorder: both jobs ids must specify the same server\n");

    exit(1);
    }

  if (pn != NULL)
    *pn = ':'; /* restore : if it was present */

  connect = cnt2server(svrtmp);

  if (connect <= 0)
    {
    local_errno = -1 * connect;

    if (svrtmp[0] != 0)
      fprintf(stderr, "qorder: cannot connect to server %s (errno=%d) %s\n",
            svrtmp,
            local_errno,
            pbs_strerror(local_errno));
    else
      fprintf(stderr, "qorder: cannot connect to server %s (errno=%d) %s\n",
            pbs_server,
            local_errno,
            pbs_strerror(local_errno));

    exit(1);
    }

  stat = pbs_orderjob_err(connect, job_id1_out, job_id2_out, NULL, &local_errno);

  if (stat != 0)
    {
    prt_job_err("qorder", connect, "");

    rc = local_errno;
    }

  pbs_disconnect(connect);

  exit(rc);
  }  /* END main() */
コード例 #11
0
ファイル: qselect.c プロジェクト: VladimirStarostenkov/torque
int main(

  int    argc,
  char **argv)

  {
  int c;
  int errflg = 0;
  int any_failed = 0;
  char *errmsg;

#define MAX_OPTARG_LEN 256
#define MAX_RESOURCE_NAME_LEN 256
  char optargout[MAX_OPTARG_LEN+1];
  char resource_name[MAX_RESOURCE_NAME_LEN+1];

  enum batch_op op;
  enum batch_op *pop = &op;

  struct attropl *select_list = 0;

  static char destination[PBS_MAXROUTEDEST+1] = "";
  char server_out[MAXSERVERNAME] = "";

  char *queue_name_out;
  char *server_name_out;

  int connect;
  char **selectjob_list;
  char *res_pos;
  char *pc;
  int u_cnt, o_cnt, s_cnt, n_cnt;
  time_t after;
  char a_value[80];
  int exec_only = 0;

  if (getenv("PBS_QSTAT_EXECONLY") != NULL)
    exec_only = 1;
  
  initialize_network_info();

#define GETOPT_ARGS "a:A:ec:h:l:N:p:q:r:s:u:"

  while ((c = getopt(argc, argv, GETOPT_ARGS)) != EOF)
    switch (c)
      {

      case 'a':
        check_op(optarg, pop, optargout);

        if ((after = cvtdate(optargout)) < 0)
          {
          fprintf(stderr, "qselect: illegal -a value\n");
          errflg++;
          break;
          }

        sprintf(a_value, "%ld", (long)after);

        set_attrop(&select_list, (char *)ATTR_a, NULL, a_value, op);
        break;

      case 'e':
        exec_only = 1;
        break;

      case 'c':
        check_op(optarg, pop, optargout);
        pc = optargout;

        while (isspace((int)*pc)) pc++;

        if (strlen(pc) == 0)
          {
          fprintf(stderr, "qselect: illegal -c value\n");
          errflg++;
          break;
          }

        if (strcmp(pc, "u") == 0)
          {
          if ((op != EQ) && (op != NE))
            {
            fprintf(stderr, "qselect: illegal -c value\n");
            errflg++;
            break;
            }
          }
        else if ((strcmp(pc, "n") != 0) &&
                 (strcmp(pc, "s") != 0) &&
                 (strcmp(pc, "c") != 0))
          {
          if (strncmp(pc, "c=", 2) != 0)
            {
            fprintf(stderr, "qselect: illegal -c value\n");
            errflg++;
            break;
            }

          pc += 2;

          if (strlen(pc) == 0)
            {
            fprintf(stderr, "qselect: illegal -c value\n");
            errflg++;
            break;
            }

          while (*pc != '\0')
            {
            if (!isdigit((int)*pc))
              {
              fprintf(stderr, "qselect: illegal -c value\n");
              errflg++;
              break;
              }

            pc++;
            }
          }

        set_attrop(&select_list, (char *)ATTR_c, NULL, optargout, op);

        break;

      case 'h':
        check_op(optarg, pop, optargout);
        pc = optargout;

        while (isspace((int)*pc)) pc++;

        if (strlen(pc) == 0)
          {
          fprintf(stderr, "qselect: illegal -h value\n");
          errflg++;
          break;
          }

        u_cnt = o_cnt = s_cnt = n_cnt = 0;

        while (*pc)
          {
          if (*pc == 'u')
            u_cnt++;
          else if (*pc == 'o')
            o_cnt++;
          else if (*pc == 's')
            s_cnt++;
          else if (*pc == 'n')
            n_cnt++;
          else
            {
            fprintf(stderr, "qselect: illegal -h value\n");
            errflg++;
            break;
            }

          pc++;
          }

        if (n_cnt && (u_cnt + o_cnt + s_cnt))
          {
          fprintf(stderr, "qselect: illegal -h value\n");
          errflg++;
          break;
          }

        set_attrop(&select_list, (char *)ATTR_h, NULL, optargout, op);

        break;

      case 'l':
        res_pos = optarg;

        while (*res_pos != '\0')
          {
          if (check_res_op(res_pos, resource_name, pop, optargout, &res_pos) != 0)
            {
            errflg++;
            break;
            }

          set_attrop(&select_list, (char *)ATTR_l, resource_name, optargout, op);
          }

        break;

      case 'p':
        check_op(optarg, pop, optargout);
        set_attrop(&select_list, (char *)ATTR_p, NULL, optargout, op);
        break;

      case 'q':
        strncpy(destination, optarg, PBS_MAXROUTEDEST);
        check_op(optarg, pop, optargout);
        set_attrop(&select_list, (char *)ATTR_q, NULL, optargout, op);
        break;

      case 'r':
        op = EQ;
        pc = optarg;

        while (isspace((int)(*pc))) pc++;

        if (strlen(pc) != 1)
          {
          fprintf(stderr, "qsub: illegal -r value\n");
          errflg++;
          break;
          }

        if (*pc != 'y' && *pc != 'n')
          {
          fprintf(stderr, "qsub: illegal -r value\n");
          errflg++;
          break;
          }

        set_attrop(&select_list, (char *)ATTR_r, NULL, pc, op);

        break;

      case 's':
        check_op(optarg, pop, optargout);
        pc = optargout;

        while (isspace((int)(*pc))) pc++;

        if (strlen(optarg) == 0)
          {
          fprintf(stderr, "qselect: illegal -s value\n");
          errflg++;
          break;
          }

        while (*pc)
          {
          if (*pc != 'C' && *pc != 'E' && *pc != 'H' && 
              *pc != 'Q' && *pc != 'R' && *pc != 'T' && 
              *pc != 'W')
            {
            fprintf(stderr, "qselect: illegal -s value\n");
            errflg++;
            break;
            }

          pc++;
          }

        set_attrop(&select_list, (char *)ATTR_state, NULL, optargout, op);

        break;

      case 'u':
        op = EQ;

        if (parse_at_list(optarg, FALSE, FALSE))
          {
          fprintf(stderr, "qselect: illegal -u value\n");
          errflg++;
          break;
          }

        set_attrop(&select_list, (char *)ATTR_u, NULL, optarg, op);

        break;

      case 'A':
        op = EQ;
        set_attrop(&select_list, (char *)ATTR_A, NULL, optarg, op);
        break;

      case 'N':
        op = EQ;
        set_attrop(&select_list, (char *)ATTR_N, NULL, optarg, op);
        break;

      default :
        errflg++;
      }

  if (errflg || (optind < argc))
    {
    static char usage[] = "usage: qselect \
                          [-a [op]date_time] [-A account_string] [-e] [-c [op]interval] \n\
                          [-h hold_list] [-l resource_list] [-N name] [-p [op]priority] \n\
                          [-q destination] [-r y|n] [-s states] [-u user_name]\n";
    fprintf(stderr,"%s", usage);
    exit(2);
    }

  if (notNULL(destination))
    {
    if (parse_destination_id(destination, &queue_name_out, &server_name_out))
      {
      fprintf(stderr, "qselect: illegally formed destination: %s\n", destination);
      exit(2);
      }
    else
      {
      if (notNULL(server_name_out))
        {
        strcpy(server_out, server_name_out);
        }
      }
    }

  connect = cnt2server(server_out);

  if (connect <= 0)
    {
    any_failed = -1 * connect;

    if (server_out[0] != 0)
      fprintf(stderr, "qselect: cannot connect to server %s (errno=%d) %s\n",
            server_out, any_failed, pbs_strerror(any_failed));
    else
      fprintf(stderr, "qselect: cannot connect to server %s (errno=%d) %s\n",
            pbs_server, any_failed, pbs_strerror(any_failed));

    exit(any_failed);
    }

  selectjob_list = pbs_selectjob_err(connect, select_list, exec_only ? (char *)EXECQUEONLY : NULL, &any_failed);

  if (selectjob_list == NULL)
    {
    if (any_failed != PBSE_NONE)
      {
      errmsg = pbs_geterrmsg(connect);

      if (errmsg != NULL)
        {
        fprintf(stderr, "qselect: %s\n", errmsg);
        }
      else
        {
        fprintf(stderr, "qselect: Error (%d - %s) selecting jobs\n",
                any_failed,
                pbs_strerror(any_failed));
        }

      exit(any_failed);
      }
    }
  else     /* got some jobs ids */
    {
    int i = 0;

    while (selectjob_list[i] != NULL)
      {
      printf("%s\n", selectjob_list[i++]);
      }

    free(selectjob_list);
    }

  pbs_disconnect(connect);

  exit(0);
  }