Exemple #1
0
int main(int argc, char **argv) {
	nmsg_res res;

	/* parse command line arguments */
	argv_process(args, argc, argv);

	if (ctx.debug < 1)
		ctx.debug = 1;
	nmsg_set_debug(ctx.debug);
	res = nmsg_init();
	if (res != nmsg_res_success) {
		fprintf(stderr, "nmsgtool: unable to initialize libnmsg\n");
		return (EXIT_FAILURE);
	}
	if (ctx.debug >= 2)
#ifdef HAVE_LIBXS
		fprintf(stderr, "nmsgtool: version " VERSION "\n");
#else /* HAVE_LIBXS */
		fprintf(stderr, "nmsgtool: version " VERSION " (without libxs support)\n");
#endif /* HAVE_LIBXS */

	/* initialize the nmsg_io engine */
	ctx.io = nmsg_io_init();
	assert(ctx.io != NULL);
	nmsg_io_set_close_fp(ctx.io, io_close);

	/* process arguments and load inputs/outputs into the nmsg_io engine */
	process_args(&ctx);

	setup_signals();

	/* run the nmsg_io engine */
	res = nmsg_io_loop(ctx.io);

	/* cleanup */
	if (ctx.pidfile != NULL) {
		if (unlink(ctx.pidfile) != 0) {
			fprintf(stderr, "nmsgtool: unlink() failed: %s\n",
				strerror(errno));
		}
	}
	nmsg_io_destroy(&ctx.io);
#ifdef HAVE_LIBXS
	if (ctx.xs_ctx)
		xs_term(ctx.xs_ctx);
#endif /* HAVE_LIBXS */
	free(ctx.endline_str);
	argv_cleanup(args);

	return (res);
}
int
main(int argc, char **argv) {
	assert(nmsg_init() == nmsg_res_success);
	assert(nmsg_msgmod_lookup_byname("base", "pkt") != NULL);

	setup_io();
	process_args(argc, argv);
	setup_pcap();
	setup_threads();

	signal(SIGINT, shutdown_handler);
	signal(SIGTERM, shutdown_handler);

	if (nmsg_io_loop(io) != nmsg_res_success)
		errx(EXIT_FAILURE, "nmsg_io_loop() failed");

	cleanup();

	return (EXIT_SUCCESS);
}