view rvinterf/etmsync/tmsmain.c @ 407:19e5a3e2f9c0

fcup-settime: moved time() retrieval a little closer to the output A fundamental problem with all simple time transfer tools is that there is always some delay between the time retrieval on the source system and that transmitted time being set on the destination, and the resulting time on the destination system is off by that delay amount. This delay cannot be fully eliminated when working in a simple environment like ours, but we should make our best effort to minimize it. In the present case, moving the atinterf_init() call before the time() retrieval should make a teensy-tiny improvement.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Aug 2018 21:52:17 +0000
parents 20ed7a320b12
children e40bb5a6c6b9
line wrap: on
line source

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

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "exitcodes.h"

extern char *socket_pathname;
extern char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;

main(argc, argv)
	char **argv;
{
	extern int optind;
	extern char *optarg;
	int c, sopt = 0;
	char command[512];

	while ((c = getopt(argc, argv, "+B:l:p:s:w:")) != EOF)
		switch (c) {
		case 'B':
			rvinterf_Bopt = optarg;
			continue;
		case 'l':
			rvinterf_lopt = optarg;
			continue;
		case 'p':
			rvinterf_ttyport = optarg;
			continue;
		case 's':
			socket_pathname = optarg;
			sopt++;
			continue;
		case 'w':
			rvinterf_wopt = optarg;
			continue;
		case '?':
		default:
			/* error msg already printed */
			exit(ERROR_USAGE);
		}
	if (rvinterf_ttyport) {
		if (sopt) {
			fprintf(stderr,
			"%s error: -p and -s options are mutually exclusive\n",
				argv[0]);
			exit(ERROR_USAGE);
		}
		launch_rvinterf();
	} else {
		if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) {
			fprintf(stderr,
"%s error: -B, -l and -w options are meaningful only when launching rvinterf\n",
				argv[0]);
			exit(ERROR_USAGE);
		}
		connect_local_socket();
	}

	setlinebuf(stdout);
	if (argv[optind])
		return dispatch_ready_argv(argc - optind, argv + optind);
	for (;;) {
		if (isatty(0)) {
			rx_control(0);
			fputs("tmsync> ", stdout);
			fflush(stdout);
		}
		if (!fgets(command, sizeof command, stdin))
			exit(0);
		parse_and_dispatch_cmd(command, 0);
	}
}