Bugfixing and cleanup

This commit is contained in:
llsth 2015-04-15 23:52:40 +02:00
parent 620823b985
commit b705164771
8 changed files with 68 additions and 52 deletions

View File

@ -31,8 +31,8 @@
#include "ntp.h"
#include "udp.h"
#define ARGSFORMAT "P=PARAM/K,T=TRACEFILE/K,Z=TIMEZONE/K,SERVERS/M,SYNC/S,SAVE/S,QUIET/S"
const char *vers = "\0$VER: ntimed-client 1.0a";
#define ARGSFORMAT "P=PARAM/K,T=TRACEFILE/K,Z=TIMEZONE/K,SERVERS/M,SYNC/S,SAVE/S,SHOW/S,QUIET/S"
const char *vers = "\0$VER: ntimed-poll 0.9 (15.04.2015)";
#define PARAM_CLIENT PARAM_INSTANCE
#define PARAM_TABLE_NAME client_param_table
@ -60,6 +60,7 @@ struct ntimedargs {
char **servers;
long synchronize;
long save;
long show;
long quiet;
};
@ -71,22 +72,37 @@ int main(int argc, char **argv)
{
struct ntimedargs args = {
NULL, NULL, NULL, NULL,
FALSE, FALSE, FALSE
FALSE, FALSE, FALSE, FALSE
};
started_from_wb = (BOOL)argc;
started_from_wb = (argc == 0);
atexit(clean_exit);
rdargs = ReadArgs(ARGS_FORMAT, (APTR)&args, NULL);
if (!rdargs)
{
PrintFault(IoErr(), (ARGPTR)argv[0]);
exit(2);
if(started_from_wb) {
args.servers = (char *[]) {
"0.pool.ntp.org",
"1.pool.ntp.org",
"2.pool.ntp.org",
"3.pool.ntp.org"
};
args.synchronize = TRUE;
args.save = TRUE;
args.quiet = TRUE;
} else {
rdargs = ReadArgs(ARGS_FORMAT, (APTR)&args, NULL);
if (!rdargs)
{
PrintFault(IoErr(), (ARGPTR)argv[0]);
exit(2);
}
}
if (!args.quiet) {
EnableDebug();
if (args.show) {
EnableTraceDebug();
}
}
init_libs(&args);

View File

@ -31,8 +31,8 @@
#include "ntp.h"
#include "udp.h"
#define ARGSFORMAT "D=DURATION/N,M=MONITOR/K,T=TRACEFILE/K,Z=TIMEZONE/K,SERVERS/M,QUIET/S"
const char *vers = "\0$VER: ntimed-poll 1.0a";
#define ARGSFORMAT "D=DURATION/N,M=MONITOR/K,T=TRACEFILE/K,Z=TIMEZONE/K,SERVERS/M,SHOW/S,QUIET/S"
const char *vers = "\0$VER: ntimed-poll 0.9 (15.04.2015)";
void Time_Amiga_Passive(void);
@ -50,6 +50,7 @@ struct ntimedargs {
char *tracefile;
char *timezone;
char **servers;
long show;
long quiet;
};
@ -59,7 +60,7 @@ static void clean_exit();
int main(int argc, char **argv)
{
struct ntimedargs args = { NULL, NULL, "-", NULL, NULL, FALSE };
struct ntimedargs args = { NULL, NULL, NULL, NULL, NULL, FALSE, FALSE };
started_from_wb = (BOOL)argc;
@ -74,7 +75,10 @@ int main(int argc, char **argv)
if (!args.quiet) {
EnableDebug();
EnableTraceDebug();
if (args.show) {
EnableTraceDebug();
}
}
init_libs(&args);
@ -98,13 +102,13 @@ static void init_libs(struct ntimedargs *args)
#ifdef AROS
if(!(SocketBase = OpenLibrary(BSDLIB_NAME, BSDLIB_REV))) {
Put(NULL, OCX_DIAG, "No TCP/IP Stack running.\n");
exit(2);
exit(5);
}
if(SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (IPTR)&errno,
SBTM_SETVAL(SBTC_HERRNOLONGPTR), (IPTR)&h_errno, TAG_DONE)) {
Put(NULL, OCX_DIAG, "Error initializing bsdsocket.\n");
exit(2);
exit(5);
}
#endif
}

View File

@ -26,12 +26,13 @@
*/
#include "ntimed_platform.h"
#include "mem.h"
#include "ntimed.h"
#include "ntp.h"
#include "udp.h"
#define ARGSFORMAT "P=PARAM/K,B=BUMP/K,T=TRACEFILE/K,SIMFILE/A,QUIET/S"
const char *vers = "\0$VER: ntimed-sim 1.0a";
const char *vers = "\0$VER: ntimed-poll 0.9 (15.04.2015)";
#define PARAM_CLIENT PARAM_INSTANCE
#define PARAM_TABLE_NAME client_param_table

25
mem.c
View File

@ -184,20 +184,17 @@ void deallocerror(char *descr, void *p)
Debug(NULL, "Mememory deallocation error (%s) address (%x)\n", descr, p);
}
#ifdef __c_plus
inline void* operator new (size_t size) {
return allocmem(size);
}
char *strdup(const char *s1)
{
char *s2;
size_t len = strlen(s1);
s2 = allocmem(++len);
inline void* operator new[] (size_t size) {
return allocmem(size);
}
if(s2 == NULL)
{
return NULL;
}
inline void operator delete (void* ptr) {
freemem(ptr);
memcpy(s2, s1, --len);
return s2;
}
inline void operator delete[] (void* ptr) {
freemem(ptr);
}
#endif

3
mem.h
View File

@ -33,4 +33,7 @@ void* allocmem(size_t);
void freemem(void*);
void freeall();
#define strdup(s) managed_strdup(s)
char *strdup(const char *s1);
#endif

View File

@ -32,6 +32,7 @@
#include <sys/socket.h>
#include "ntimed.h"
#include "mem.h"
#include "udp.h"
#include "ntp.h"
#include "net_getaddrinfo.h"
@ -53,13 +54,9 @@ NTP_Peer_New(const char *hostname, const void *sa, unsigned salen)
AN(np->sa);
memcpy(np->sa, sa, np->sa_len);
// np->hostname = strdup(hostname);
np->hostname = allocmem(strlen(hostname) + 1);
memcpy(np->hostname, hostname, strlen(hostname) + 1);
np->hostname = strdup(hostname);
AN(np->hostname);
// np->ip = strdup(hbuf);
np->ip = allocmem(strlen(hbuf) + 1);
memcpy(np->ip, hbuf, strlen(hbuf) + 1);
np->ip = strdup(hbuf);
AN(np->ip);
ALLOC_OBJ(np->tx_pkt, NTP_PACKET_MAGIC);

View File

@ -45,6 +45,7 @@
#include <sys/socket.h>
#include "ntimed.h"
#include "mem.h"
#include "ntp.h"
#include "net_getaddrinfo.h"
@ -168,9 +169,7 @@ ntp_peerset_add_group(struct ntp_peerset *nps, const char *name)
ALLOC_OBJ(ng, NTP_GROUP_MAGIC);
AN(ng);
// ng->hostname = strdup(name);
ng->hostname = allocmem(strlen(name) + 1);
memcpy(ng->hostname, name, strlen(name) + 1);
ng->hostname = strdup(name);
AN(ng->hostname);
TAILQ_INSERT_TAIL(&nps->group, ng, list);
nps->ngroup++;

View File

@ -65,8 +65,10 @@
#include <stdlib.h>
#include <string.h>
#include "ntimed_platform.h"
#include "ntimed.h"
extern BOOL started_from_wb;
int repeat_trace = 0;
static FILE *debugfile = NULL;
@ -92,7 +94,6 @@ getdst(enum ocx_chan chan)
void
ArgTracefile(const char *fn)
{
if (tracefile != NULL && tracefile != stdout) {
AZ(fclose(tracefile));
tracefile = NULL;
@ -101,11 +102,6 @@ ArgTracefile(const char *fn)
if (fn == NULL)
return;
if (!strcmp(fn, "-")) {
tracefile = stdout;
return;
}
tracefile = fopen(fn, "w");
if (tracefile == NULL)
Fail(NULL, 1, "Could not open '%s' for writing", fn);
@ -138,15 +134,18 @@ Put(struct ocx *ocx, enum ocx_chan chan, const char *fmt, ...)
va_start(ap, fmt);
dst = getdst(chan);
if (dst != NULL) {
if (dst != NULL && !(started_from_wb && dst == stdout)) {
(void)vfprintf(dst, fmt, ap);
fflush(dst);
}
if (repeat_trace && chan == OCX_TRACE) {
dst = getdst(OCX_DEBUG);
(void)vfprintf(dst, fmt, ap);
fflush(dst);
}
dst = getdst(OCX_DEBUG);
if (
dst != NULL &&
!(started_from_wb && dst == stdout) &&
(repeat_trace && chan == OCX_TRACE)) {
(void)vfprintf(dst, fmt, ap);
fflush(dst);
}
va_end(ap);