static int no_dns = 0;
-/* ================================================== */
-/* Forward prototypes */
-
-static void process_cmd_manual_list(const char *line);
-static void process_cmd_manual_delete(const char *line);
-
/* ================================================== */
/* Ought to extract some code from util.c to make
a new set of utilities that can be linked into either
msg->data.manual.option = htonl(1);
} else if (!strncmp(p, "reset", 5)) {
msg->data.manual.option = htonl(2);
- } else if (!strncmp(p, "list", 4)) {
- process_cmd_manual_list(p);
- return 0;
- } else if (!strncmp(p, "delete", 6)) {
- process_cmd_manual_delete(p+6);
- return 0;
} else {
return 0;
}
}
}
- if (status != STT_SUCCESS) {
+ if (status != STT_SUCCESS &&
+ status != STT_ACCESSALLOWED && status != STT_ACCESSDENIED) {
return 0;
}
/* ================================================== */
-static void
+static int
process_cmd_sources(char *line)
{
CMD_Request request;
printf(" +/- ");
print_microseconds(latest_meas_err);
printf("\n");
+ } else {
+ return 0;
}
}
+ } else {
+ return 0;
}
-
+ return 1;
}
/* ================================================== */
-static void
+static int
process_cmd_sourcestats(char *line)
{
CMD_Request request;
printf(" %10.3f %10.3f ", resid_freq_ppm, skew_ppm);
print_microseconds(sd_us);
printf("\n");
+ } else {
+ return 0;
}
}
+ } else {
+ return 0;
}
-
+ return 1;
}
/* ================================================== */
-static void
+static int
process_cmd_tracking(char *line)
{
CMD_Request request;
printf("Skew : %.3f ppm\n", skew_ppm);
printf("Root delay : %.6f seconds\n", root_delay);
printf("Root dispersion : %.6f seconds\n", root_dispersion);
+ return 1;
}
+ return 0;
}
/* ================================================== */
-static void
+static int
process_cmd_rtcreport(char *line)
{
CMD_Request request;
printf("\n");
printf("RTC is fast by : %12.6f seconds\n", coef_seconds_fast);
printf("RTC gains time at : %9.3f ppm\n", coef_gain_rate_ppm);
+ return 1;
}
+ return 0;
}
/* ================================================== */
/* New implementation of clients command */
-static void
+static int
process_cmd_clients(char *line)
{
CMD_Request request;
goto finished;
}
} else {
- return;
+ return 0;
}
} while (1); /* keep going until all subnets have been expanded,
down to single nodes */
finished:
- return;
-
+ return 1;
}
/* ================================================== */
/* Process the manual list command */
-static void
+static int
process_cmd_manual_list(const char *line)
{
CMD_Request request;
residual = WIRE2REAL(sample->residual);
printf("%2d %s %10.2f %10.2f %10.2f\n", i, time_to_log_form(when.tv_sec), slewed_offset, orig_offset, residual);
}
+ return 1;
}
-
+ return 0;
}
/* ================================================== */
-static void
-process_cmd_manual_delete(const char *line)
+static int
+process_cmd_manual_delete(CMD_Request *msg, const char *line)
{
int index;
- CMD_Request request;
- CMD_Reply reply;
if (sscanf(line, "%d", &index) != 1) {
fprintf(stderr, "Bad syntax for manual delete command\n");
- return;
+ return 0;
}
- request.command = htons(REQ_MANUAL_DELETE);
- request.data.manual_delete.index = htonl(index);
-
- request_reply(&request, &reply, RPY_NULL, 1);
+ msg->command = htons(REQ_MANUAL_DELETE);
+ msg->data.manual_delete.index = htonl(index);
+ return 1;
}
/* ================================================== */
-static void
+static int
process_cmd_settime(char *line)
{
struct timeval ts;
new_afreq_ppm = WIRE2REAL(reply.data.manual_timestamp.new_afreq_ppm);
printf("Clock was %.2f seconds fast. Frequency change = %.2fppm, new frequency = %.2fppm\n",
offset, dfreq_ppm, new_afreq_ppm);
+ return 1;
}
}
-
+ return 0;
}
/* ================================================== */
/* ================================================== */
-static void
+static int
process_cmd_activity(const char *line)
{
CMD_Request request;
(long) ntohl(reply.data.activity.offline),
(long) ntohl(reply.data.activity.burst_online),
(long) ntohl(reply.data.activity.burst_offline));
+ return 1;
}
+ return 0;
}
/* ================================================== */
static int
-process_line(char *line)
+process_line(char *line, int *quit)
{
char *p;
- int quit;
int do_normal_submit;
+ int ret;
CMD_Request tx_message;
CMD_Reply rx_message;
- quit = 0;
+ *quit = 0;
+ ret = 0;
do_normal_submit = 1;
if (!*p) {
fflush(stderr);
fflush(stdout);
- return quit;
+ return ret;
};
if (!strncmp(p, "offline", 7)) {
do_normal_submit = process_cmd_maxupdateskew(&tx_message, p+13);
} else if (!strncmp(p, "settime", 7)) {
do_normal_submit = 0;
- process_cmd_settime(p+7);
+ ret = process_cmd_settime(p+7);
} else if (!strncmp(p, "local", 5)) {
do_normal_submit = process_cmd_local(&tx_message, p+5);
+ } else if (!strncmp(p, "manual list", 11)) {
+ do_normal_submit = 0;
+ ret = process_cmd_manual_list(p+11);
+ } else if (!strncmp(p, "manual delete", 13)) {
+ do_normal_submit = process_cmd_manual_delete(&tx_message, p+13);
} else if (!strncmp(p, "manual", 6)) {
do_normal_submit = process_cmd_manual(&tx_message, p+6);
} else if (!strncmp(p, "sourcestats", 11)) {
do_normal_submit = 0;
- process_cmd_sourcestats(p+11);
+ ret = process_cmd_sourcestats(p+11);
} else if (!strncmp(p, "sources", 7)) {
do_normal_submit = 0;
- process_cmd_sources(p+7);
+ ret = process_cmd_sources(p+7);
} else if (!strncmp(p, "rekey", 5)) {
process_cmd_rekey(&tx_message, p+5);
} else if (!strncmp(p, "allow all", 9)) {
process_cmd_writertc(&tx_message, p+7);
} else if (!strncmp(p, "rtcdata", 7)) {
do_normal_submit = 0;
- process_cmd_rtcreport(p);
+ ret = process_cmd_rtcreport(p);
} else if (!strncmp(p, "trimrtc", 7)) {
process_cmd_trimrtc(&tx_message, p);
} else if (!strncmp(p, "cyclelogs", 9)) {
} else if (!strncmp(p, "doffset", 7)) {
process_cmd_doffset(&tx_message, p+7);
} else if (!strncmp(p, "tracking", 8)) {
- process_cmd_tracking(p+8);
+ ret = process_cmd_tracking(p+8);
do_normal_submit = 0;
} else if (!strncmp(p, "clients", 7)) {
- process_cmd_clients(p+7);
+ ret = process_cmd_clients(p+7);
do_normal_submit = 0;
} else if (!strncmp(p, "makestep", 8)) {
process_cmd_makestep(&tx_message, p+8);
} else if (!strncmp(p, "activity", 8)) {
- process_cmd_activity(p+8);
+ ret = process_cmd_activity(p+8);
do_normal_submit = 0;
} else if (!strncmp(p, "help", 4)) {
do_normal_submit = 0;
give_help();
+ ret = 1;
} else if (!strncmp(p, "quit", 4)) {
do_normal_submit = 0;
- quit = 1;
+ *quit = 1;
+ ret = 1;
} else if (!strncmp(p, "exit", 4)) {
do_normal_submit = 0;
- quit = 1;
+ *quit = 1;
+ ret = 1;
} else {
fprintf(stderr, "Unrecognized command\n");
do_normal_submit = 0;
}
if (do_normal_submit) {
- request_reply(&tx_message, &rx_message, RPY_NULL, 1);
+ ret = request_reply(&tx_message, &rx_message, RPY_NULL, 1);
}
fflush(stderr);
fflush(stdout);
- return quit;
+ return ret;
}
/* ================================================== */
-static void
+static int
process_args(int argc, char **argv)
{
- int total_length, i;
+ int total_length, i, ret, quit;
char *line;
total_length = 0;
}
strcat(line, "\n");
- process_line(line);
+ ret = process_line(line, &quit);
free(line);
- return;
+ return ret;
}
/* ================================================== */
char *line;
const char *progname = argv[0];
const char *hostname = "localhost";
- int quit = 0;
+ int quit = 0, ret = 1;
int port = DEFAULT_CANDM_PORT;
/* Parse command line options */
open_io(hostname, port);
if (argc > 0) {
- process_args(argc, argv);
+ ret = process_args(argc, argv);
} else {
do {
line = read_line();
if (line) {
- quit = process_line(line);
+ ret = process_line(line, &quit);
}else {
/* supply the final '\n' when user exits via ^D */
if( on_terminal ) printf("\n");
close_io();
- return 0;
+ return !ret;
}