示例#1
0
文件: qstop.c 项目: bayucan/pbspro
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 */

	/*test for real deal or just version and exit*/

	PRINT_VERSION_AND_EXIT(argc, argv);

#ifdef WIN32
	if (winsock_init()) {
		return 1;
	}
#endif

	if (argc == 1) {
		fprintf(stderr, "Usage: qstop [queue][@server] ...\n");
		fprintf(stderr, "       qstop --version\n");
		exit(1);
	}

	/*perform needed security library initializations (including none)*/

	if (CS_client_init() != CS_SUCCESS) {
		fprintf(stderr, "qstop: unable to initialize security library.\n");
		exit(1);
	}

	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;
	}

	/*cleanup security library initializations before exiting*/
	CS_close_app();

	exit(exitstatus);
}
示例#2
0
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);
  }
示例#3
0
文件: qstart.c 项目: boegel/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 {True}.  If the
   * batch request is accepted, the server will start scheduling or routing
   * requests in 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: qstart [queue][@server] ...\n");
    exit(1);
    }
  else if (argc > 1 && argv[1][0] == '-')
    {
    fprintf(stderr, "Usage: qstart [queue][@server] ...\n");
    exit(1);
    }
  
  for (dest = 1; dest < argc; dest++)
    if (parse_destination_id(argv[dest], &queue, &server) == 0)
      execute(queue, server);
    else
      {
      fprintf(stderr, "qstart: illegally formed destination: %s\n",
              argv[dest]);
      exitstatus = 1;
      }

  exit(exitstatus);
  }
示例#4
0
int main(

  int    argc,
  char **argv)

  {
  int c;
  int errflg = 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;

#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, 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, 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, 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, ATTR_l, resource_name, optargout, op);
          }

        break;

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

      case 'q':
        strncpy(destination, optarg, PBS_MAXROUTEDEST);
        check_op(optarg, pop, optargout);
        set_attrop(&select_list, 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, 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, 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, ATTR_u, NULL, optarg, op);

        break;

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

      case 'N':
        op = EQ;
        set_attrop(&select_list, 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)
    {
    fprintf(stderr, "qselect: cannot connect to server %s (errno=%d) %s\n",
            pbs_server, pbs_errno, pbs_strerror(pbs_errno));
    exit(pbs_errno);
    }

  selectjob_list = pbs_selectjob(connect, select_list, exec_only ? EXECQUEONLY : NULL);

  if (selectjob_list == NULL)
    {
    if (pbs_errno != 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",
                pbs_errno,
                pbs_strerror(pbs_errno));
        }

      exit(pbs_errno);
      }
    }
  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);
  }
示例#5
0
int
main(int argc, char **argv, char **envp) /* qselect */
{
    int c;
    int errflg=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_MAXQUEUENAME+1] = "";
    char server_out[MAXSERVERNAME] = "";

    char *queue_name_out;
    char *server_name_out;

    int connect;
    char **selectjob_list;
    char *res_pos;
    char *pc;
    time_t after;
    char a_value[80];
    char extendopts[4] = "";
    char *attr_time = NULL;
    struct ecl_attribute_errors *err_list;
    char *resc_time = NULL;

#define GETOPT_ARGS "a:A:c:h:HJl:N:p:q:r:s:t:Tu:xP:"

    /*test for real deal or just version and exit*/

    execution_mode(argc, argv);

#ifdef WIN32
    winsock_init();
#endif

    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, ATTR_a, NULL, a_value, op);
            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;
            }
            set_attrop(&select_list, ATTR_c, NULL, optargout, op);
            break;
        case 'h':
            check_op(optarg, pop, optargout);
            pc = optargout;
            while (isspace((int)*pc)) pc++;
            set_attrop(&select_list, ATTR_h, NULL, optargout, op);
            break;
        case 'J':
            op = EQ;
            set_attrop(&select_list, ATTR_array, NULL, "True", 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, ATTR_l, resource_name, optargout, op);
            }
            break;
        case 'p':
            check_op(optarg, pop, optargout);
            set_attrop(&select_list, ATTR_p, NULL, optargout, op);
            break;
        case 'q':
            strcpy(destination, optarg);
            check_op(optarg, pop, optargout);
            set_attrop(&select_list, ATTR_q, NULL, optargout, op);
            break;
        case 'r':
            op = EQ;
            pc = optarg;
            while (isspace((int)(*pc))) pc++;
            if (*pc != 'y' && *pc != 'n') { /* qselect specific check - stays */
                fprintf(stderr, "qselect: illegal -r value\n");
                errflg++;
                break;
            }
            set_attrop(&select_list, ATTR_r, NULL, pc, op);
            break;
        case 's':
            check_op(optarg, pop, optargout);
            pc = optargout;
            while (isspace((int)(*pc))) pc++;
            set_attrop(&select_list, ATTR_state, NULL, optargout, op);
            break;
        case 't':
            if (get_tsubopt(*optarg, &attr_time, &resc_time)) {
                fprintf(stderr, "qselect: illegal -t value\n");
                errflg++;
                break;
            }
            /* 1st character possess the subopt, so send optarg++ */
            optarg ++;
            check_op(optarg, pop, optargout);
            if ((after = cvtdate(optargout)) < 0) {
                fprintf(stderr, "qselect: illegal -t value\n");
                errflg++;
                break;
            }
            sprintf(a_value, "%ld", (long)after);
            set_attrop(&select_list, attr_time, resc_time, a_value, op);
            break;
        case 'T':
            if (strchr(extendopts, (int)'T') == NULL)
                (void)strcat(extendopts, "T");
            break;
        case 'x':
            if (strchr(extendopts, (int)'x') == NULL)
                (void)strcat(extendopts, "x");
            break;
        case 'H':
            op = EQ;
            if (strchr(extendopts, (int)'x') == NULL)
                (void)strcat(extendopts, "x");
            set_attrop(&select_list, ATTR_state, NULL, "FM", op);
            break;
        case 'u':
            op = EQ;
            set_attrop(&select_list, ATTR_u, NULL, optarg, op);
            break;
        case 'A':
            op = EQ;
            set_attrop(&select_list, ATTR_A, NULL, optarg, op);
            break;
        case 'P':
            op = EQ;
            set_attrop(&select_list, ATTR_project, NULL, optarg, op);
            break;
        case 'N':
            op = EQ;
            set_attrop(&select_list, ATTR_N, NULL, optarg, op);
            break;
        default :
            errflg++;
        }

    if (errflg || (optind < argc)) {
        print_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);
            }
        }
    }

    /*perform needed security library initializations (including none)*/

    if (CS_client_init() != CS_SUCCESS) {
        fprintf(stderr, "qselect: unable to initialize security library.\n");
        exit(2);
    }

    connect = cnt2server(server_out);
    if (connect <= 0) {
        fprintf(stderr, "qselect: cannot connect to server %s (errno=%d)\n",
                pbs_server, pbs_errno);

        /*cleanup security library initializations before exiting*/
        CS_close_app();

        exit(pbs_errno);
    }

    if (extendopts[0] == '\0')
        selectjob_list = pbs_selectjob(connect, select_list, NULL);
    else
        selectjob_list = pbs_selectjob(connect, select_list, extendopts);
    if (selectjob_list == NULL) {
        if ((err_list = pbs_get_attributes_in_error(connect)))
            handle_attribute_errors(err_list);

        if (pbs_errno != PBSE_NONE) {
            errmsg = pbs_geterrmsg(connect);
            if (errmsg != NULL) {
                fprintf(stderr, "qselect: %s\n", errmsg);
            } else {
                fprintf(stderr, "qselect: Error (%d) selecting jobs\n", pbs_errno);
            }

            /*
             * If the server is not configured for history jobs i.e.
             * job_history_enable svr attr is unset/set to FALSE, qselect
             * command with -x/-H option is being used, then pbs_selectjob()
             * will return PBSE_JOBHISTNOTSET error code. But command will
             * exit with exit code '0'after printing the corresponding error
             * message. i.e. "job_history_enable is set to false"
             */
            if (pbs_errno == PBSE_JOBHISTNOTSET)
                pbs_errno = 0;

            /*cleanup security library initializations before exiting*/
            CS_close_app();
            exit(pbs_errno);
        }
    } 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);

    /*cleanup security library initializations before exiting*/
    CS_close_app();

    exit(0);
}
示例#6
0
文件: qmove.c 项目: A9-William/pbspro
int
main(int argc, char **argv, char **envp) /* qmove */
{
	int any_failed=0;

	char job_id[PBS_MAXCLTJOBID];		/* from the command line */
	char destination[PBS_MAXSERVERNAME];	/* from the command line */
	char *q_n_out, *s_n_out;

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

	/*test for real deal or just version and exit*/

	execution_mode(argc, argv);

#ifdef WIN32
	winsock_init();
#endif

	if (argc < 3) {
		static char usage[]="usage: qmove destination job_identifier...\n";
		static char usag2[]="       qmove --version\n";
		fprintf(stderr, usage);
		fprintf(stderr, usag2);
		exit(2);
	}

	strcpy(destination, argv[1]);
	if (parse_destination_id(destination, &q_n_out, &s_n_out)) {
		fprintf(stderr, "qmove: illegally formed destination: %s\n", destination);
		exit(2);
	}

	/*perform needed security library initializations (including none)*/

	if (CS_client_init() != CS_SUCCESS) {
		fprintf(stderr, "qmove: unable to initialize security library.\n");
		exit(2);
	}

	for (optind = 2; 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, "qmove: illegally formed job identifier: %s\n", job_id);
			any_failed = 1;
			continue;
		}
cnt:
		connect = cnt2server(server_out);
		if (connect <= 0) {
			fprintf(stderr, "qmove: cannot connect to server %s (errno=%d)\n",
				pbs_server, pbs_errno);
			any_failed = pbs_errno;
			continue;
		}

		stat = pbs_movejob(connect, job_id_out, destination, NULL);
		if (stat && (pbs_errno != PBSE_UNKJOBID)) {
			if (stat != PBSE_NEEDQUET) {
				prt_job_err("qmove", connect, job_id_out);
				any_failed = pbs_errno;
			} else {
				fprintf(stderr, "qmove: Queue type not set for queue \'%s\'\n", destination);
			}
		} else if (stat && (pbs_errno == 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("qmove", connect, job_id_out);
			any_failed = pbs_errno;
		}

		pbs_disconnect(connect);
	}

	/*cleanup security library initializations before exiting*/
	CS_close_app();

	exit(any_failed);
}