Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ SRCS='
ntp_peer.c
ntp_peerset.c
ntp_tools.c
ocx.c
ocx_stdio.c
param.c
pll_std.c
Expand Down
12 changes: 6 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ dummy(void)
}

static int
main_run_tests(int argc, char * const * argv)
main_run_tests(struct ocx *ocx, int argc, char * const * argv)
{

(void)argc;
(void)argv;

Time_Unix_Passive();

TS_RunTest(NULL);
TS_RunTest(ocx);

return (0);
}
Expand All @@ -64,11 +64,11 @@ main(int argc, char * const *argv)
dummy();

if (argc > 1 && !strcmp(argv[1], "--poll-server"))
return (main_poll_server(argc - 1, argv + 1));
return (main_poll_server(NULL, argc - 1, argv + 1));
if (argc > 1 && !strcmp(argv[1], "--sim-client"))
return (main_sim_client(argc - 1, argv + 1));
return (main_sim_client(NULL, argc - 1, argv + 1));
if (argc > 1 && !strcmp(argv[1], "--run-tests"))
return (main_run_tests(argc - 1, argv + 1));
return (main_run_tests(NULL, argc - 1, argv + 1));

return (main_client(argc, argv));
return (main_client(NULL, argc, argv));
}
30 changes: 15 additions & 15 deletions main_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ sig_hup(int siginfo)
}

int
main_client(int argc, char *const *argv)
main_client(struct ocx *ocx, int argc, char *const *argv)
{
int ch;
struct ntp_peer *np;
Expand All @@ -74,21 +74,21 @@ main_client(int argc, char *const *argv)

PLL_Init();

nps = NTP_PeerSet_New(NULL);
nps = NTP_PeerSet_New(ocx);

Param_Register(client_param_table);
NF_Init();

while ((ch = getopt(argc, argv, "p:t:")) != -1) {
switch(ch) {
case 'p':
Param_Tweak(NULL, optarg);
Param_Tweak(ocx, optarg);
break;
case 't':
ArgTracefile(optarg);
ArgTracefile(ocx, optarg);
break;
default:
Fail(NULL, 0,
Fail(ocx, 0,
"Usage %s [-p param] [-t tracefile] servers...",
argv[0]);
break;
Expand All @@ -98,18 +98,18 @@ main_client(int argc, char *const *argv)
argv += optind;

for (ch = 0; ch < argc; ch++)
npeer += NTP_PeerSet_Add(NULL, nps, argv[ch]);
npeer += NTP_PeerSet_Add(ocx, nps, argv[ch]);
if (npeer == 0)
Fail(NULL, 0, "No NTP peers found");
Fail(ocx, 0, "No NTP peers found");

Put(NULL, OCX_TRACE, "# NTIMED Format client 1.0\n");
Put(NULL, OCX_TRACE, "# Found %d peers\n", npeer);
Put(ocx, OCX_TRACE, "# NTIMED Format client 1.0\n");
Put(ocx, OCX_TRACE, "# Found %d peers\n", npeer);

Param_Report(NULL, OCX_TRACE);
Param_Report(ocx, OCX_TRACE);

usc = UdpTimedSocket(NULL);
usc = UdpTimedSocket(ocx);
if (usc == NULL)
Fail(NULL, errno, "Could not open UDP socket");
Fail(ocx, errno, "Could not open UDP socket");

cd = CD_New();

Expand All @@ -120,13 +120,13 @@ main_client(int argc, char *const *argv)

do {
if (restart) {
Debug(NULL, "RESTART\n");
Debug(ocx, "RESTART\n");
TB_generation++;
NTP_PeerSet_Poll(NULL, nps, usc, tdl);
NTP_PeerSet_Poll(ocx, nps, usc, tdl);
restart = 0;
}
(void)signal(SIGHUP, sig_hup);
(void)TODO_Run(NULL, tdl);
(void)TODO_Run(ocx, tdl);
} while (restart);

return (0);
Expand Down
34 changes: 17 additions & 17 deletions main_poll_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ mps_end(struct ocx *ocx, struct todolist *tdl, void *priv)
}

int
main_poll_server(int argc, char *const *argv)
main_poll_server(struct ocx *ocx, int argc, char *const *argv)
{
int ch;
int npeer = 0;
Expand All @@ -97,31 +97,31 @@ main_poll_server(int argc, char *const *argv)
setbuf(stdout, NULL);
setbuf(stderr, NULL);

ArgTracefile("-");
ArgTracefile(ocx, "-");

tdl = TODO_NewList();
Time_Unix_Passive();

npl = NTP_PeerSet_New(NULL);
npl = NTP_PeerSet_New(ocx);
AN(npl);

while ((ch = getopt(argc, argv, "d:m:t:")) != -1) {
switch(ch) {
case 'd':
duration = strtod(optarg, &p);
if (*p != '\0' || duration < 1.0)
Fail(NULL, 0, "Invalid -d argument");
Fail(ocx, 0, "Invalid -d argument");
break;
case 'm':
mon = NTP_Peer_NewLookup(NULL, optarg);
mon = NTP_Peer_NewLookup(ocx, optarg);
if (mon == NULL)
Fail(NULL, 0, "Monitor (-m) didn't resolve.");
Fail(ocx, 0, "Monitor (-m) didn't resolve.");
break;
case 't':
ArgTracefile(optarg);
ArgTracefile(ocx, optarg);
break;
default:
Fail(NULL, 0,
Fail(ocx, 0,
"Usage %s [-d duration] [-m monitor] "
"[-t tracefile] server...", argv[0]);
break;
Expand All @@ -131,30 +131,30 @@ main_poll_server(int argc, char *const *argv)
argv += optind;

for (ch = 0; ch < argc; ch++)
npeer += NTP_PeerSet_Add(NULL, npl, argv[ch]);
Put(NULL, OCX_TRACE, "# NTIMED Format poll-server 1.0\n");
Put(NULL, OCX_TRACE, "# Found %d peers\n", npeer);
npeer += NTP_PeerSet_Add(ocx, npl, argv[ch]);
Put(ocx, OCX_TRACE, "# NTIMED Format poll-server 1.0\n");
Put(ocx, OCX_TRACE, "# Found %d peers\n", npeer);
if (npeer == 0)
Fail(NULL, 0, "No peers found");
Fail(ocx, 0, "No peers found");

NTP_PeerSet_Foreach(np, npl) {
Put(NULL, OCX_TRACE, "# Peer %s %s\n", np->hostname, np->ip);
Put(ocx, OCX_TRACE, "# Peer %s %s\n", np->hostname, np->ip);
np->filter_func = mps_filter;
}

if (mon != NULL)
Put(NULL, OCX_TRACE,
Put(ocx, OCX_TRACE,
"# Monitor %s %s\n", mon->hostname, mon->ip);

usc = UdpTimedSocket(NULL);
usc = UdpTimedSocket(ocx);
assert(usc != NULL);

TODO_ScheduleRel(tdl, mps_end, NULL, duration, 0, "End task");

if (mon != NULL)
TODO_ScheduleRel(tdl, mps_mon, mon, 0, 32, "Monitor");

NTP_PeerSet_Poll(NULL, npl, usc, tdl);
(void)TODO_Run(NULL, tdl);
NTP_PeerSet_Poll(ocx, npl, usc, tdl);
(void)TODO_Run(ocx, tdl);
return (0);
}
22 changes: 11 additions & 11 deletions main_sim_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ SimFile_Open(struct ocx *ocx, const char *fn, struct todolist *tdl,
"XXX: Wrong state (%d) in open_sim_file", s);
}
}
(void)simfile_readline(NULL, tdl, sf);
(void)simfile_readline(ocx, tdl, sf);
return (sf);
}

int
main_sim_client(int argc, char *const *argv)
main_sim_client(struct ocx *ocx, int argc, char *const *argv)
{
int ch;
const char *s_filename = NULL;
Expand All @@ -238,7 +238,7 @@ main_sim_client(int argc, char *const *argv)

PLL_Init();

npl = NTP_PeerSet_New(NULL);
npl = NTP_PeerSet_New(ocx);

Param_Register(client_param_table);
NF_Init();
Expand All @@ -248,21 +248,21 @@ main_sim_client(int argc, char *const *argv)
case 'B':
ch = sscanf(optarg, "%lg,%lg,%lg", &a, &b, &c);
if (ch != 3)
Fail(NULL, 0,
Fail(ocx, 0,
"bad -B argument \"when,freq,phase\"");
Time_Sim_Bump(tdl, a, b, c);
break;
case 's':
s_filename = optarg;
break;
case 'p':
Param_Tweak(NULL, optarg);
Param_Tweak(ocx, optarg);
break;
case 't':
ArgTracefile(optarg);
ArgTracefile(ocx, optarg);
break;
default:
Fail(NULL, 0,
Fail(ocx, 0,
"Usage %s [-s simfile] [-p params] [-t tracefile]"
" [-B when,freq,phase]", argv[0]);
break;
Expand All @@ -271,12 +271,12 @@ main_sim_client(int argc, char *const *argv)
// argc -= optind;
// argv += optind;

Param_Report(NULL, OCX_TRACE);
Param_Report(ocx, OCX_TRACE);

if (s_filename == NULL)
Fail(NULL, 1, "You must specify -s file.");
Fail(ocx, 1, "You must specify -s file.");

sf = SimFile_Open(NULL, s_filename, tdl, npl);
sf = SimFile_Open(ocx, s_filename, tdl, npl);
AN(sf);

cd = CD_New();
Expand All @@ -286,7 +286,7 @@ main_sim_client(int argc, char *const *argv)
np->combiner = CD_AddSource(cd, np->hostname, np->ip);
}

(void)TODO_Run(NULL, tdl);
(void)TODO_Run(ocx, tdl);

return (0);
}
12 changes: 8 additions & 4 deletions ntimed.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#endif
#define NTIMED_H_INCLUDED

#include <stdarg.h>
#include <stdint.h>
#include <unistd.h>
#include "ntimed_queue.h"
Expand Down Expand Up @@ -64,7 +65,10 @@ void Fail(struct ocx *, int err, const char *, ...) \
#define Debug(ocx, ...) Put(ocx, OCX_DEBUG, __VA_ARGS__)
#define DebugHex(ocx, ptr, len) PutHex(ocx, OCX_DEBUG, ptr, len)

void ArgTracefile(const char *fn);
/* ocx_stdio */
void __match_proto__()
putv(struct ocx *ocx, enum ocx_chan chan, const char *fmt, va_list ap);
void ArgTracefile(struct ocx *ocx, const char *fn);

/* param.c -- Parameters **********************************************/

Expand Down Expand Up @@ -186,6 +190,6 @@ struct combiner *CD_AddSource(struct combine_delta *,
* Main functions
*/

int main_client(int argc, char *const *argv);
int main_poll_server(int argc, char *const *argv);
int main_sim_client(int argc, char *const *argv);
int main_client(struct ocx *ocx, int argc, char *const *argv);
int main_poll_server(struct ocx *ocx, int argc, char *const *argv);
int main_sim_client(struct ocx *ocx, int argc, char *const *argv);
2 changes: 1 addition & 1 deletion ntp_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ nf_filter(struct ocx *ocx, const struct ntp_peer *np)

NTP_Tool_Format(buf, sizeof buf, rxp);

Put(NULL, OCX_TRACE, "NTP_Packet %s %s %s\n",
Put(ocx, OCX_TRACE, "NTP_Packet %s %s %s\n",
np->hostname, np->ip, buf);

if (rxp->ntp_leap == NTP_LEAP_UNKNOWN)
Expand Down
Loading