4
4
* usage: clktest -b bps -f -t timeo -s cmd -c char1 -a char2 /dev/whatever
10
#include <sys/socket.h>
12
#include <netinet/in.h>
13
#include <sys/ioctl.h>
18
#include "../include/ntp_fp.h"
19
#include "../include/ntp.h"
20
#include "../include/ntp_unixtime.h"
7
#include "clktest-opts.h"
22
9
#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
39
30
#define BLOCKSIGMASK (sigmask(SIGIO)|sigmask(SIGALRM))
68
# ifdef HAVE_SYS_CLKDEFS_H
69
# include <sys/clkdefs.h>
71
# define DEFMAGIC "\r"
32
#define progname clktestOptions.pzProgName
75
34
struct timeval timeout = { 0 };
80
39
u_long magic1 = DEFMAGIC;
81
40
u_long magic2 = DEFMAGIC;
87
44
int ttflags = RAW|EVENP|ODDP;
112
68
struct sgttyb ttyb;
113
69
struct itimerval itimer;
114
extern int ntp_optind;
115
extern char *ntp_optarg;
123
while ((c = ntp_getopt(argc, argv, "a:b:c:dfs:t:")) != EOF)
129
if (!atouint(ntp_optarg, &tmp)) {
130
(void) fprintf(stderr,
131
"%s: argument for -%c must be integer\n",
143
magic[strlen(magic)+1] = '\0';
144
magic[strlen(magic)] = tmp;
148
if (!atouint(ntp_optarg, &tmp)) {
153
while (spd->bps != 0)
154
if ((int)tmp == spd->bps)
157
(void) fprintf(stderr,
158
"%s: speed %lu is unsupported\n",
172
cmdlen = strlen(ntp_optarg);
179
if (!atouint(ntp_optarg, &tmp))
182
timeout.tv_sec = (long)tmp;
190
if (errflg || ntp_optind+1 != argc) {
191
(void) fprintf(stderr,
193
"usage: %s [-b bps] [-c magic1] [-a magic2] [-f] [-s cmd] [-t timeo] tty_device\n",
196
"usage: %s [-b bps] [-c magic1] [-c magic2]... [-f] [-s cmd] [-t timeo] tty_device\n",
76
int ct = optionProcess( &clktestOptions, argc, argv );
77
if (HAVE_OPT(COMMAND) && (strlen(OPT_ARG(COMMAND)) == 0)) {
78
fputs( "The command option string must not be empty\n", stderr );
79
USAGE( EXIT_FAILURE );
82
if ((argc -= ct) != 1) {
83
fputs( "Missing tty device name\n", stderr );
84
USAGE( EXIT_FAILURE );
203
89
if (!strlen(magic))
204
90
strcpy(magic,DEFMAGIC);
208
fd = open(argv[ntp_optind], O_RDWR, 0777);
210
fd = open(argv[ntp_optind], O_RDONLY, 0777);
93
fd = open(*argv, HAVE_OPT(TIMEOUT) ? O_RDWR : O_RDONLY, 0777);
212
(void) fprintf(stderr, "%s: open(%s): ", progname,
95
fprintf(stderr, "%s: open(%s): ", progname, *argv);
290
172
(void) signal(SIGALRM, alarming);
173
timeout.tv_sec = OPT_VALUE_TIMEOUT;
291
174
itimer.it_interval = itimer.it_value = timeout;
292
175
setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);