view cmu200/main.c @ 86:348c29b7d02a

fc-cmu200d: ignore SIGPIPE so we don't exit if a client terminates while we are processing a command
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 16 Jul 2017 23:42:29 +0000
parents 3ec82dc1dbda
children
line wrap: on
line source

/*
 * This module contains the main() function for fc-cmu200d.
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

int target_fd;

char *bind_socket_pathname = "/tmp/fc_rftest_socket";
char *cmu200_tx_name = "TX";
int cmu200_rf_port = 2;

main(argc, argv)
	char **argv;
{
	extern char *optarg;
	extern int optind;
	int c;

	while ((c = getopt(argc, argv, "12ac:t:")) != EOF)
		switch (c) {
		case '1':
			cmu200_rf_port = 1;
			continue;
		case '2':
			cmu200_rf_port = 2;
			continue;
		case 'a':
			cmu200_tx_name = "AUXT";
			continue;
		case 'c':
			read_cable_conf_file(optarg);
			continue;
		case 't':
			bind_socket_pathname = optarg;
			continue;
		default:
usage:			fprintf(stderr,
				"usage: %s [options] serial-port baud\n",
				argv[0]);
			exit(1);
		}
	if (argc - optind != 2)
		goto usage;

	open_target_serial(argv[optind], argv[optind+1]);
	set_serial_nonblock(0);
	setlinebuf(stdout);	/* to allow logging with tee */
	init_cmu200();
	create_listener_socket();
	signal(SIGPIPE, SIG_IGN);
	for (;;) {
		get_socket_connection();
		handle_session();
	}
}