int
main(int argc, char **argv)
{
	int c;
	struct varnish_stats *VSL_stats;
	int delay = 1, once = 0, xml = 0;
	const char *n_arg = NULL;
	const char *fields = NULL;

	while ((c = getopt(argc, argv, "1f:ln:Vw:x")) != -1) {
		switch (c) {
		case '1':
			once = 1;
			break;
		case 'f':
			fields = optarg;
			break;
		case 'l':
			list_fields();
			exit(0);
		case 'n':
			n_arg = optarg;
			break;
		case 'V':
			varnish_version("varnishstat");
			exit(0);
		case 'w':
			delay = atoi(optarg);
			break;
		case 'x':
			xml = 1;
			break;
		default:
			usage();
		}
	}

	if ((VSL_stats = VSL_OpenStats(n_arg)) == NULL)
		exit(1);

	if (fields != NULL && !valid_fields(fields)) {
		usage();
		exit(1);
	}
	
	if (xml) 
		do_xml(VSL_stats, fields);
	else if (once)
		do_once(VSL_stats, fields);
	else
		do_curses(VSL_stats, delay, fields);

	exit(0);
}
int
main(int argc, char **argv)
{
	struct VSM_data *vd;
	int o, once = 0;
	float period = 60; /* seconds */

	vd = VSM_New();

	while ((o = getopt(argc, argv, VSL_ARGS "1fVp:")) != -1) {
		switch (o) {
		case '1':
			AN(VSL_Arg(vd, 'd', NULL));
			once = 1;
			break;
		case 'f':
			f_flag = 1;
			break;
		case 'p':
			errno = 0;
			period = strtol(optarg, NULL, 0);
			if (errno != 0)  {
				fprintf(stderr,
				    "Syntax error, %s is not a number", optarg);
				exit(1);
			}
			break;
		case 'V':
			VCS_Message("varnishtop");
			exit(0);
		case 'm':
			fprintf(stderr, "-m is not supported\n");
			exit(1);
		default:
			if (VSL_Arg(vd, o, optarg) > 0)
				break;
			usage();
		}
	}

	if (VSM_Open(vd)) {
		fprintf(stderr, "%s\n", VSM_Error(vd));
		exit (1);
	}

	if (once) {
		do_once(vd);
	} else {
		do_curses(vd, period);
	}
	exit(0);
}
int main( void )
{
#ifndef REGTEST
    TESTCASE(count == 0);
    call_once(&once, do_once);
    TESTCASE(count == 1);
    call_once(&once, do_once);
    TESTCASE(count == 1);
    do_once();
    TESTCASE(count == 2);
#endif
    return TEST_RESULTS;
}
Exemple #4
0
int
main(int argc, char * const *argv)
{
	int c;
	struct VSM_data *vd;
	int delay = 1, once = 0, xml = 0, json = 0, do_repeat = 0;

	vd = VSM_New();

	while ((c = getopt(argc, argv, VSC_ARGS "1f:lVw:xjt:")) != -1) {
		switch (c) {
		case '1':
			once = 1;
			break;
		case 'l':
			list_fields(vd);
			exit(0);
		case 'V':
			VCS_Message("varnishstat");
			exit(0);
		case 'w':
			do_repeat = 1;
			delay = atoi(optarg);
			break;
		case 'x':
			xml = 1;
			break;
		case 'j':
			json = 1;
			break;
		default:
			if (VSC_Arg(vd, c, optarg) > 0)
				break;
			usage();
		}
	}

	if (VSM_Open(vd)) {
		fprintf(stderr, "%s\n", VSM_Error(vd));
		exit(1);
	}
	if (!(xml || json || once)) {
		do_curses(vd, delay);
		exit(0);
	}

	while (1) {
		if (xml)
			do_xml(vd);
		else if (json)
			do_json(vd);
		else if (once)
			do_once(vd, VSC_Main(vd, NULL));
		else {
			assert(0);
		}
		if (!do_repeat) break;

		// end of output block marker.
		printf("\n");

		sleep(delay);
	}
	exit(0);
}
Exemple #5
0
int
main(int argc, char * const *argv)
{
	struct VSM_data *vd;
	double t_arg = 5.0, t_start = NAN;
	int once = 0, xml = 0, json = 0, f_list = 0, curses = 0;
	signed char opt;
	int i;

	VUT_Init(progname, argc, argv, &vopt_spec);
	vd = VSM_New();
	AN(vd);

	while ((opt = getopt(argc, argv, vopt_spec.vopt_optstring)) != -1) {
		switch (opt) {
		case '1':
			once = 1;
			break;
		case 'h':
			/* Usage help */
			usage(0);
		case 'l':
			f_list = 1;
			break;
		case 't':
			if (!strcasecmp(optarg, "off"))
				t_arg = -1.;
			else {
				t_arg = VNUM(optarg);
				if (isnan(t_arg))
					VUT_Error(1, "-t: Syntax error");
				if (t_arg < 0.)
					VUT_Error(1, "-t: Range error");
			}
			break;
		case 'V':
			VCS_Message("varnishstat");
			exit(0);
		case 'x':
			xml = 1;
			break;
		case 'j':
			json = 1;
			break;
		default:
			i = VSC_Arg(vd, opt, optarg);
			if (i < 0)
				VUT_Error(1, "%s", VSM_Error(vd));
			if (!i)
				usage(1);
		}
	}

	if (optind != argc)
		usage(1);

	if (!(xml || json || once || f_list))
		curses = 1;

	while (1) {
		i = VSM_Open(vd);
		if (!i)
			break;
		if (isnan(t_start) && t_arg > 0.) {
			fprintf(stderr, "Can't open log -"
			    " retrying for %.0f seconds\n", t_arg);
			t_start = VTIM_real();
		}
		if (t_arg <= 0.)
			break;
		if (VTIM_real() - t_start > t_arg)
			break;
		VSM_ResetError(vd);
		VTIM_sleep(0.5);
	}

	if (curses) {
		if (i && t_arg >= 0.)
			VUT_Error(1, "%s", VSM_Error(vd));
		do_curses(vd, 1.0);
		exit(0);
	}

	if (i)
		VUT_Error(1, "%s", VSM_Error(vd));

	if (xml)
		do_xml(vd);
	else if (json)
		do_json(vd);
	else if (once)
		do_once(vd);
	else if (f_list)
		list_fields(vd);
	else
		assert(0);

	exit(0);
}