Esempio n. 1
0
int main(int argc, char *argv[])
{
        /* Initialize various components. */
        init_common();
        init_driver();

        if (parse_arguments(argc, argv) != OK) {
                printf("usage: %s -d <address> -wmin # -wmax # -l # [-w #] [-p #] [-c #] [-i #] [-o #] [-n #] [-q %%] [-r %%] [-e %%] [-t %%] [-seed #] [-altered 0] [-spread #] [-z]",
                        argv[0]);
#ifdef STANDALONE
#ifdef LIBPQ
                printf(" -z #");
#endif /* LIBPQ */
#endif /* STANDALONE */
                printf("\n\n");
#ifdef STANDALONE
                printf("-dbname <connect_string>\n");
                printf("\tdatabase connect string\n");
#ifdef LIBPQ
                printf("-z #\n");
                printf("\tpostmaster listener port\n");
#endif /* LIBPQ */
#ifdef LIBMYSQL
		printf("-z #\n");
		printf("\tmysql server listener port\n");
#endif /* LIBMYSQL */
#ifdef LIBDRIZZLE
		printf("-z #\n");
		printf("\tdrizzle server listener port\n");
#endif /* LIBDRIZZLE */
#else /* STANDALONE */
                printf("-d <address>\n");
                printf("\tnetwork address where client program is running\n");
                printf("-p #\n");
                printf("\tclient port, default %d\n", CLIENT_PORT);
#endif /* STANDALONE */
                printf("\n");
                printf("-l #\n");
                printf("\tthe duration of the run in seconds\n");
                printf("\n");
                printf("-wmin #\n");
                printf("\tlower warehouse id\n");
                printf("-wmax #\n");
                printf("\tupper warehouse id\n");
                printf("-w #\n");
                printf("\twarehouse cardinality, default 1\n");
                printf("-c #\n");
                printf("\tcustomer cardinality, default %d\n", CUSTOMER_CARDINALITY);
                printf("-i #\n");
                printf("\titem cardinality, default %d\n", ITEM_CARDINALITY);
                printf("-o #\n");
                printf("\torder cardinality, default %d\n", ORDER_CARDINALITY);
                printf("-n #\n");
                printf("\tnew-order cardinality, default %d\n", NEW_ORDER_CARDINALITY);
                printf("\n");
                printf("-q %%\n");
                printf("\tmix percentage of Payment transaction, default %0.2f\n",
                        MIX_PAYMENT);
                printf("-r %%\n");
                printf("\tmix percentage of Order-Status transaction, default %0.2f\n",
                        MIX_ORDER_STATUS);
                printf("-e %%\n");
                printf("\tmix percentage of Delivery transaction, default %0.2f\n",
                        MIX_DELIVERY);
                printf("-t %%\n");
                printf("\tmix percentage of Stock-Level transaction, default %0.2f\n",
                        MIX_STOCK_LEVEL);
                printf("\n");
                printf("-ktd #\n");
                printf("\tdelivery keying time, default %d s\n", KEY_TIME_DELIVERY);
                printf("-ktn #\n");
                printf("\tnew-order keying time, default %d s\n", KEY_TIME_NEW_ORDER);
                printf("-kto #\n");
                printf("\torder-status keying time, default %d s\n",
                        KEY_TIME_ORDER_STATUS);
                printf("-ktp #\n");
                printf("\tpayment keying time, default %d s\n", KEY_TIME_PAYMENT);
                printf("-kts #\n");
                printf("\tstock-level keying time, default %d s\n",
                        KEY_TIME_STOCK_LEVEL);
                printf("-ttd #\n");
                printf("\tdelivery thinking time, default %d ms\n",
                        THINK_TIME_DELIVERY);
                printf("-ttn #\n");
                printf("\tnew-order thinking time, default %d ms\n",
                        THINK_TIME_NEW_ORDER);
                printf("-tto #\n");
                printf("\torder-status thinking time, default %d ms\n",
                        THINK_TIME_ORDER_STATUS);
                printf("-ttp #\n");
                printf("\tpayment thinking time, default %d ms\n", THINK_TIME_PAYMENT);
                printf("-tts #\n");
                printf("\tstock-level thinking time, default %d ms\n",
                        THINK_TIME_STOCK_LEVEL);
                printf("\n");
                printf("-tpw #\n");
                printf("\tterminals started per warehouse, default 10\n");

                printf("\n");
                printf("-seed #\n");
                printf("\trandom number seed\n");
                printf("-altered [0/1]\n");
                printf("\trun with a thread per user, -altered 1\n");
                printf("-sleep #\n");
                printf("\tnumber of milliseconds to sleep between terminal creation\n");
                printf("-spread #\n");
                printf("\tfancy warehouse skipping trick for low i/o runs\n");

                printf("-z #\n");
                printf("\tperform database integrity check\n");
#ifdef STANDALONE
                printf("\nDriver is in STANDALONE mode.\n");
#endif /* STANDALONE */

                return 1;
        }
        create_pid_file();

        if(init_logging() != OK || init_driver_logging() != OK) {
                printf("cannot init driver\n");
                return 1;
        };

        /* Sanity check on the parameters. */
        if (w_id_min > w_id_max) {
                printf("wmin cannot be larger than wmax\n");
                return 1;
        }
        if (w_id_max > table_cardinality.warehouses) {
                printf("wmax cannot be larger than w\n");
                return 1;
        }

        if (recalculate_mix() != OK) {
                printf("invalid transaction mix: -e %0.2f. -r %0.2f. -q %0.2f. -t %0.2f. causes new-order mix of %0.2f.\n",
                        transaction_mix.delivery_actual,
                        transaction_mix.order_status_actual,
                        transaction_mix.payment_actual,
                        transaction_mix.stock_level_actual,
                        transaction_mix.new_order_actual);
                return 1;
        }

        /* Double check database table cardinality. */
        printf("\n");
        printf("database table cardinalities:\n");
        printf("warehouses = %d\n", table_cardinality.warehouses);
        printf("districts = %d\n", table_cardinality.districts);
        printf("customers = %d\n", table_cardinality.customers);
        printf("items = %d\n", table_cardinality.items);
        printf("orders = %d\n", table_cardinality.orders);
        printf("stock = %d\n", table_cardinality.items);
        printf("new-orders = %d\n", table_cardinality.new_orders);
        printf("\n");

        /* Double check the transaction mix. */
        printf("transaction mix:\n");
        printf("new-order mix %0.2f\n", transaction_mix.new_order_actual);
        printf("payment mix %0.2f\n", transaction_mix.payment_actual);
        printf("order-status mix %0.2f\n", transaction_mix.order_status_actual);
        printf("delivery mix %0.2f\n", transaction_mix.delivery_actual);
        printf("stock-level mix %0.2f\n", transaction_mix.stock_level_actual);
        printf("\n");

        /* Double check the transaction threshold. */
        printf("transaction thresholds:\n");
        printf("new-order threshold %0.2f\n",
                transaction_mix.new_order_threshold);
        printf("payment threshold %0.2f\n", transaction_mix.payment_threshold);
        printf("order-status threshold %0.2f\n",
                transaction_mix.order_status_threshold);
        printf("delivery threshold %0.2f\n",
                transaction_mix.delivery_threshold);
        printf("stock-level threshold %0.2f\n",
                transaction_mix.stock_level_threshold);
        printf("\n");

        /* Double check the keying time. */
        printf("delivery keying time %d s\n", key_time.delivery);
        printf("new_order keying time %d s\n", key_time.new_order);
        printf("order-status keying time %d s\n", key_time.order_status);
        printf("payment keying time %d s\n", key_time.payment);
        printf("stock-level keying time %d s\n", key_time.stock_level);
        printf("\n");

        /* Double check the thinking time. */

        printf("delivery thinking time %d ms\n", think_time.delivery);
        printf("new_order thinking time %d ms\n", think_time.new_order);
        printf("order-status thinking time %d ms\n", think_time.order_status);
        printf("payment thinking time %d ms\n", think_time.payment);
        printf("stock-level thinking time %d ms\n", think_time.stock_level);
        printf("\n");

        printf("w_id range %d to %d\n", w_id_min, w_id_max);
        printf("\n");

        printf("%d terminals per warehouse\n", terminals_per_warehouse);
        printf("\n");

        printf("%d second steady state duration\n", duration);
        printf("\n");

        if (perform_integrity_check && integrity_terminal_worker() != OK) {
           printf("You used wrong parameters or something wrong with database.\n");
           return 1;
        }

        start_driver();

        return 0;
}
Esempio n. 2
0
static void
find_driver(void)
{
	u_short msg;
	const struct sockaddr_storage *host;
	socklen_t hostlen;
	unsigned num;
	int i, c;

	msg = C_PLAYER;
#ifdef MONITOR
	if (Am_monitor) {
		msg = C_MONITOR;
	}
#endif

	serverlist_query(msg);
	num = serverlist_num();
	if (num == 0) {
		start_driver();
		sleep(2);
		/* try again */
		serverlist_query(msg);
		num = serverlist_num();
		if (num == 0) {
			/* give up */
			return;
		}
	}

	if (num == 1) {
		host = serverlist_gethost(0, &hostlen);
	} else {
		clear_the_screen();
		move(1, 0);
		addstr("Pick one:");
		for (i = 0; i < HEIGHT - 4 && i < (int)num; i++) {
			move(3 + i, 0);
			host = serverlist_gethost(i, &hostlen);
			printw("%8c    %.64s", 'a' + i,
			       lookuphost(host, hostlen));
		}
		move(4 + i, 0);
		addstr("Enter letter: ");
		refresh();
		while (1) {
			c = getchar();
			if (c == EOF) {
				leavex(1, "EOF on stdin");
			}
			if (islower((unsigned char)c) && c - 'a' < i) {
				break;
			}
			beep();
			refresh();
		}
		clear_the_screen();
		host = serverlist_gethost(c - 'a', &hostlen);
	}

	/* XXX fix this (won't work in ipv6) */
	assert(hostlen == sizeof(Daemon));
	memcpy(&Daemon, host, sizeof(Daemon));
}
Esempio n. 3
0
BOOL CdenableSysInstallStart(void)
{
	return(start_driver());
}
Esempio n. 4
0
/*
 * main:
 *	Main program for local process
 */
int
main(int ac, char **av)
{
	char *term;
	int c;
	int enter_status;
	bool Query_driver = false;
	bool Show_scores = false;

	enter_status = env_init(Q_CLOAK);
	while ((c = getopt(ac, av, "Sbcfh:l:mn:op:qst:w:")) != -1) {
		switch (c) {
		case 'l':	/* rsh compatibility */
		case 'n':
			(void) strncpy(name, optarg, sizeof(name));
			break;
		case 't':
			team = *optarg;
			if (!isdigit((unsigned char)team)) {
				warnx("Team names must be numeric");
				team = ' ';
			}
			break;
		case 'o':
#ifndef OTTO
			warnx("The -o flag is reserved for future use.");
			goto usage;
#else
			Otto_mode = true;
			break;
#endif
		case 'm':
#ifdef MONITOR
			Am_monitor = true;
#else
			warnx("The monitor was not compiled in.");
#endif
			break;
#ifdef INTERNET
		case 'S':
			Show_scores = true;
			break;
		case 'q':	/* query whether hunt is running */
			Query_driver = true;
			break;
		case 'w':
			Send_message = optarg;
			break;
		case 'h':
			contacthost = optarg;
			break;
		case 'p':
			contactportstr = optarg;
			contactport = atoi(contactportstr);
			break;
#else
		case 'S':
		case 'q':
		case 'w':
		case 'h':
		case 'p':
			wanrx("Need TCP/IP for S, q, w, h, and p options.");
			break;
#endif
		case 'c':
			enter_status = Q_CLOAK;
			break;
		case 'f':
#ifdef FLY
			enter_status = Q_FLY;
#else
			warnx("The flying code was not compiled in.");
#endif
			break;
		case 's':
			enter_status = Q_SCAN;
			break;
		case 'b':
			no_beep = !no_beep;
			break;
		default:
		usage:
			fputs(
"usage:\thunt [-qmcsfS] [-n name] [-t team] [-p port] [-w message] [host]\n",
			stderr);
			exit(1);
		}
	}
#ifdef INTERNET
	if (optind + 1 < ac)
		goto usage;
	else if (optind + 1 == ac)
		contacthost = av[ac - 1];
#else
	if (optind < ac)
		goto usage;
#endif

#ifdef INTERNET
	serverlist_setup(contacthost, contactport);

	if (Show_scores) {
		const struct sockaddr_storage *host;
		socklen_t hostlen;
		u_short msg = C_SCORES;
		unsigned i;

		serverlist_query(msg);
		for (i = 0; i < serverlist_num(); i++) {
			host = serverlist_gethost(i, &hostlen);
			dump_scores(host, hostlen);
		}
		exit(0);
	}
	if (Query_driver) {
		const struct sockaddr_storage *host;
		socklen_t hostlen;
		u_short msg = C_MESSAGE;
		u_short num_players;
		unsigned i;

		serverlist_query(msg);
		for (i = 0; i < serverlist_num(); i++) {
			host = serverlist_gethost(i, &hostlen);
			num_players = ntohs(serverlist_getresponse(i));

			printf("%d player%s hunting on %s!\n",
				num_players, (num_players == 1) ? "" : "s",
				lookuphost(host, hostlen));
		}
		exit(0);
	}
#endif
#ifdef OTTO
	if (Otto_mode)
		(void) strncpy(name, "otto", sizeof(name));
	else
#endif
	fill_in_blanks();

	(void) fflush(stdout);
	if (!isatty(0) || (term = getenv("TERM")) == NULL)
		errx(1, "no terminal type");
	if (!initscr())
		errx(0, "couldn't initialize screen");
	(void) noecho();
	(void) cbreak();
	in_visual = true;
	if (LINES < SCREEN_HEIGHT || COLS < SCREEN_WIDTH)
		leavex(1, "Need a larger window");
	clear_the_screen();
	(void) signal(SIGINT, intr);
	(void) signal(SIGTERM, sigterm);
	(void) signal(SIGUSR1, sigusr1);
	(void) signal(SIGPIPE, SIG_IGN);

	for (;;) {
#ifdef INTERNET
		find_driver();

		if (Daemon.sin_port == 0)
			leavex(1, "Game not found, try again");

	jump_in:
		do {
			int option;

			huntsocket = socket(SOCK_FAMILY, SOCK_STREAM, 0);
			if (huntsocket < 0)
				err(1, "socket");
			option = 1;
			if (setsockopt(huntsocket, SOL_SOCKET, SO_USELOOPBACK,
			    &option, sizeof option) < 0)
				warn("setsockopt loopback");
			errno = 0;
			if (connect(huntsocket, (struct sockaddr *) &Daemon,
			    DAEMON_SIZE) < 0) {
				if (errno != ECONNREFUSED) {
					leave(1, "connect");
				}
			}
			else
				break;
			sleep(1);
		} while (close(huntsocket) == 0);
#else /* !INTERNET */
		/*
		 * set up a socket
		 */

		if ((huntsocket = socket(SOCK_FAMILY, SOCK_STREAM, 0)) < 0)
			err(1, "socket");

		/*
		 * attempt to connect the socket to a name; if it fails that
		 * usually means that the driver isn't running, so we start
		 * up the driver.
		 */

		Daemon.sun_family = SOCK_FAMILY;
		(void) strcpy(Daemon.sun_path, huntsockpath);
		if (connect(huntsocket, &Daemon, DAEMON_SIZE) < 0) {
			if (errno != ENOENT) {
				leavex(1, "connect2");
			}
			start_driver();

			do {
				(void) close(huntsocket);
				if ((huntsocket = socket(SOCK_FAMILY, SOCK_STREAM,
				    0)) < 0)
					err(1, "socket");
				sleep(2);
			} while (connect(huntsocket, &Daemon, DAEMON_SIZE) < 0);
		}
#endif

		do_connect(name, sizeof(name), team, enter_status);
#ifdef INTERNET
		if (Send_message != NULL) {
			do_message();
			if (enter_status == Q_MESSAGE)
				break;
			Send_message = NULL;
			/* don't continue as that will call find_driver */
			goto jump_in;
		}
#endif
		playit();
		if ((enter_status = quit(enter_status)) == Q_QUIT)
			break;
	}
	leavex(0, NULL);
	/* NOTREACHED */
	return(0);
}