Beispiel #1
0
		Character::Character()
		{
			set_attributes();
			set_resources();
			set_behaviour();
			set_abilities();
			set_event_listeners();
		}
Beispiel #2
0
int
main(int argc, char **argv, char **envp) /* qalter */
{
	int c;
	int errflg=0;
	int any_failed=0;
	char *pc;
	int i;
	struct attrl *attrib = NULL;
	char *keyword;
	char *valuewd;
	char *erplace;
	time_t after;
	char a_value[80];

	char job_id[PBS_MAXCLTJOBID];

	char job_id_out[PBS_MAXCLTJOBID];
	char server_out[MAXSERVERNAME];
	char rmt_server[MAXSERVERNAME];
	struct ecl_attribute_errors *err_list;
#ifdef WIN32
	struct attrl *ap = NULL;
	short int nSizeofHostName = 0;
	char* orig_apvalue = NULL;
	char* temp_apvalue = NULL;
#endif

#define GETOPT_ARGS "a:A:c:e:h:j:k:l:m:M:N:o:p:r:R:S:u:W:P:"

	/*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':
				if ((after = cvtdate(optarg)) < 0) {
					fprintf(stderr, "qalter: illegal -a value\n");
					errflg++;
					break;
				}
				sprintf(a_value, "%ld", (long)after);
				set_attr(&attrib, ATTR_a, a_value);
				break;
			case 'A':
				set_attr(&attrib, ATTR_A, optarg);
				break;
			case 'P':
				set_attr(&attrib, ATTR_project, optarg);
				break;
			case 'c':
				while (isspace((int)*optarg)) optarg++;
				pc = optarg;
				if ((pc[0] == 'u') && (pc[1] == '\0')) {
					fprintf(stderr, "qalter: illegal -c value\n");
					errflg++;
					break;
				}
				set_attr(&attrib, ATTR_c, optarg);
				break;
			case 'e':
				set_attr(&attrib, ATTR_e, optarg);
				break;
			case 'h':
				while (isspace((int)*optarg)) optarg++;
				set_attr(&attrib, ATTR_h, optarg);
				break;
			case 'j':
				set_attr(&attrib, ATTR_j, optarg);
				break;
			case 'k':
				set_attr(&attrib, ATTR_k, optarg);
				break;
			case 'l':
				if ((i = set_resources(&attrib, optarg, TRUE, &erplace)) != 0) {
					if (i > 1) {
						pbs_prt_parse_err("qalter: illegal -l value\n", optarg,
							erplace-optarg, i);

					} else
						fprintf(stderr, "qalter: illegal -l value\n");
					errflg++;
				}
				break;
			case 'm':
				while (isspace((int)*optarg)) optarg++;
				set_attr(&attrib, ATTR_m, optarg);
				break;
			case 'M':
				set_attr(&attrib, ATTR_M, optarg);
				break;
			case 'N':
				set_attr(&attrib, ATTR_N, optarg);
				break;
			case 'o':
				set_attr(&attrib, ATTR_o, optarg);
				break;
			case 'p':
				while (isspace((int)*optarg)) optarg++;
				set_attr(&attrib, ATTR_p, optarg);
				break;
			case 'r':
				if (strlen(optarg) != 1) {
					fprintf(stderr, "qalter: illegal -r value\n");
					errflg++;
					break;
				}
				if (*optarg != 'y' && *optarg != 'n') {
					fprintf(stderr, "qalter: illegal -r value\n");
					errflg++;
					break;
				}
				set_attr(&attrib, ATTR_r, optarg);
				break;
			case 'R':
				set_attr(&attrib, ATTR_R, optarg);
				break;
			case 'S':
				set_attr(&attrib, ATTR_S, optarg);
				break;
			case 'u':
				set_attr(&attrib, ATTR_u, optarg);
				break;
			case 'W':
				while (isspace((int)*optarg)) optarg++;
				if (strlen(optarg) == 0) {
					fprintf(stderr, "qalter: illegal -W value\n");
					errflg++;
					break;
				}
#ifdef WIN32
				back2forward_slash2(optarg);
#endif
				i = parse_equal_string(optarg, &keyword, &valuewd);
				while (i == 1) {
					set_attr(&attrib, keyword, valuewd);
					i = parse_equal_string(NULL, &keyword, &valuewd);
				}
				if (i == -1) {
					fprintf(stderr, "qalter: illegal -W value\n");
					errflg++;
				}
				break;
			case '?':
			default :
				errflg++;
				break;
		}

	if (errflg || optind == argc) {
		print_usage();
		exit(2);
	}

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

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

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

		stat = pbs_alterjob(connect, job_id_out, attrib, NULL);
		if (stat && (pbs_errno != PBSE_UNKJOBID)) {
			if ((err_list = pbs_get_attributes_in_error(connect)))
				handle_attribute_errors(connect, err_list, job_id_out);

			prt_job_err("qalter", connect, job_id_out);
			any_failed = pbs_errno;
		} 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("qalter", connect, job_id_out);
			any_failed = pbs_errno;
		}

		pbs_disconnect(connect);
	}
	CS_close_app();
	exit(any_failed);
}
Beispiel #3
0
/**
 * @brief
 *	processes the argument list for pbs_rsub and validates 
 *	and sets attribute according to the argument value
 * 
 * @param[in] argc - commandline args count
 * @param[in] argv - pointer to argument list
 * @param[in] dest - server option
 *
 * @return errflag
 * @retval 0  Success
 * @retval  !0 Failure
 *
 */
int
process_opts(int argc, char **argv, struct attrl **attrp, char *dest)
{
	int c, i;
	char *erp;
	int errflg = 0;
	char *keyword;
	char *valuewd;
	time_t t;

	char time_buf[80];
	char dur_buf[800];
	char badw[] = "pbs_rsub: illegal -W value\n";
	int opt_re_flg = FALSE;
#ifdef WIN32
	struct attrl *ap = NULL;
	short nSizeofHostName = 0;
	char* orig_apvalue = NULL;
	char* temp_apvalue = NULL;
#endif

	while ((c = getopt(argc, argv, "D:E:I:l:m:M:N:q:r:R:u:U:g:G:H:W:")) != EOF) {
		switch (c) {
			case 'D':
				sprintf(dur_buf, "walltime=%s", optarg);
				if ((i = set_resources(&attrib, dur_buf, 0, &erp)) != 0) {
					fprintf(stderr, "pbs_rsub: illegal -D value\n");
					errflg++;
				}
				break;

			case 'E':
				opt_re_flg = TRUE;
				t = cvtdate(optarg);
				if (t >= 0) {
					(void)sprintf(time_buf, "%ld", (long)t);
					set_attr(&attrib, ATTR_resv_end, time_buf);
					dtend = t;
				}
				else {
					fprintf(stderr, "pbs_rsub: illegal -E time value\n");
					errflg++;
				}
				break;

			case 'I':
				if ((optarg == (char *)0) || (optarg == '\0'))
					set_attr(&attrib, ATTR_inter, "0");
				else {
					char* endptr;
					(void)strtol(optarg, &endptr, 0);
					if (*endptr == '\0') {
						set_attr(&attrib, ATTR_inter, optarg);
					}
					else {
						fprintf(stderr, "pbs_rsub: illegal -I time value\n");
						errflg++;
					}
				}
				break;

			case 'l':
				if ((i = set_resources(&attrib, optarg, 0, &erp)) != 0) {
					if (i > 1) {
						pbs_prt_parse_err("pbs_rsub: illegal -l value\n", optarg,
							(int)(erp-optarg), i);
					} else
						fprintf(stderr, "pbs_rsub: illegal -l value\n");
					errflg++;
				}
				break;

			case 'm':
				while (isspace((int)*optarg))
					optarg++;
				set_attr(&attrib, ATTR_m, optarg);
				break;

			case 'M':
				set_attr(&attrib, ATTR_M, optarg);
				break;

			case 'N':
				set_attr(&attrib, ATTR_resv_name, optarg);
				break;

			case 'q':
				/* destination can only be another server */
				if (optarg[0] != '@') {
					fprintf(stderr, "pbs_rsub: illegal -q value: format \"@server\"\n");
					errflg++;
					break;
				}
				strcpy(dest, &optarg[1]);
				break;

			case 'R':
				opt_re_flg = TRUE;
				t = cvtdate(optarg);
				if (t >= 0) {
					(void)sprintf(time_buf, "%ld", (long)t);
					set_attr(&attrib, ATTR_resv_start, time_buf);
					dtstart = t;
				}
				else {
					fprintf(stderr, "pbs_rsub: illegal -R time value\n");
					errflg++;
				}
				break;

			case 'r':
				is_stdng_resv = 1;
				set_attr(&attrib, ATTR_resv_rrule, optarg);
				set_attr(&attrib, ATTR_resv_standing, "1");
				if (strlen(optarg) > sizeof(rrule)-1) {
					fprintf(stderr, "pbs_rsub: illegal -r value (expression too long)\n");
					errflg++;
					break;
				}
				strcpy(rrule, optarg);
				break;

			case 'u':
				set_attr(&attrib, ATTR_u, optarg);
				break;

			case 'U':
				set_attr(&attrib, ATTR_auth_u, optarg);
				break;

			case 'g':
				set_attr(&attrib, ATTR_g, optarg);
				break;

			case 'G':
				set_attr(&attrib, ATTR_auth_g, optarg);
				break;

			case 'H':
				set_attr(&attrib, ATTR_auth_h, optarg);
				break;

			case 'W':
				while (isspace((int)*optarg))
					optarg++;

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

				i = parse_equal_string(optarg, &keyword, &valuewd);
				while (i == 1) {
					if (strcmp(keyword, ATTR_convert) == 0) {
						qmoveflg = TRUE;
					} else {
						/* unknown "-W" attribute in reservation req */
						fprintf(stderr, "pbs_rsub: unrecognized pair, %s=%s\n",
							keyword, valuewd);
						errflg++;
					}
					if (errflg == 0)
						set_attr(&attrib, keyword, valuewd);

					/* move to next attribute in this "-W" specification */

					i = parse_equal_string((char *)0, &keyword, &valuewd);

				}   /* bottom of inner while loop */

				if (i == -1) {
					fprintf(stderr, badw);
					errflg++;
				}
				break;

			default:
				/* pbs_rsub option not recognized */
				errflg++;

		} /* End of lengthy 'switch on option' constuction */
	}   /* End of lengthy while loop on 'options' */

	if (opt_re_flg == TRUE && qmoveflg ==TRUE) {
		fprintf(stderr, "pbs_rsub: -Wqmove is not compatible with -R or -E option\n");
		errflg++;
	}

	if (!errflg) {
		errflg = (optind != argc);
		if (errflg) {
			fprintf(stderr, "pbs_rsub: directive error: ");
			for (optind=1; optind<argc; optind++)
				fprintf(stderr, "%s ", argv[optind]);
			fprintf(stderr, "\n");
		}
	}

	*attrp = attrib;
	return (errflg);
}