Use err(3).
Sync man page and usage string. Strcpy -> strncpy from OpenBSD. -Wall cleaning. Obtained from: OpenBSD
This commit is contained in:
parent
a9e8f80739
commit
06457d2f32
@ -32,12 +32,12 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)acksend.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.6 $"
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
@ -56,7 +56,8 @@ xmit(type, seq, addr)
|
||||
msg.tsp_type = type;
|
||||
msg.tsp_seq = seq;
|
||||
msg.tsp_vers = TSPVERSION;
|
||||
(void)strcpy(msg.tsp_name, hostname);
|
||||
(void)strncpy(msg.tsp_name, hostname, sizeof msg.tsp_name-1);
|
||||
msg.tsp_name[sizeof msg.tsp_name-1] = '\0';
|
||||
bytenetorder(&msg);
|
||||
if (sendto(sock, (char *)&msg, sizeof(struct tsp), 0,
|
||||
(struct sockaddr*)addr, sizeof(struct sockaddr)) < 0) {
|
||||
|
@ -32,12 +32,12 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)byteorder.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.1.1.1 $"
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
|
@ -32,12 +32,12 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)candidate.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.1.1.1 $"
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
@ -80,7 +80,8 @@ election(net)
|
||||
fprintf(fd, "This machine is a candidate time master\n");
|
||||
msg.tsp_type = TSP_ELECTION;
|
||||
msg.tsp_vers = TSPVERSION;
|
||||
(void)strcpy(msg.tsp_name, hostname);
|
||||
(void)strncpy(msg.tsp_name, hostname, sizeof msg.tsp_name-1);
|
||||
msg.tsp_name[sizeof msg.tsp_name-1] = '\0';
|
||||
bytenetorder(&msg);
|
||||
if (sendto(sock, (char *)&msg, sizeof(struct tsp), 0,
|
||||
(struct sockaddr*)&net->dest_addr,
|
||||
@ -139,7 +140,9 @@ election(net)
|
||||
/* no master for another round */
|
||||
htp = addmach(resp->tsp_name,&from,fromnet);
|
||||
msg.tsp_type = TSP_REFUSE;
|
||||
(void)strcpy(msg.tsp_name, hostname);
|
||||
(void)strncpy(msg.tsp_name, hostname,
|
||||
sizeof msg.tsp_name-1);
|
||||
msg.tsp_name[sizeof msg.tsp_name-1] = '\0';
|
||||
answer = acksend(&msg, &htp->addr, htp->name,
|
||||
TSP_ACK, 0, htp->noanswer);
|
||||
if (!answer) {
|
||||
|
@ -32,12 +32,12 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)cksum.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.3 $"
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
|
@ -32,12 +32,12 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)correct.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.16 $"
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "globals.h"
|
||||
#include <math.h>
|
||||
@ -84,7 +84,9 @@ correct(avdelta)
|
||||
mstotvround(&to.tsp_time, corr);
|
||||
to.tsp_type = TSP_ADJTIME;
|
||||
}
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
answer = acksend(&to, &htp->addr, htp->name,
|
||||
TSP_ACK, 0, 0);
|
||||
if (!answer) {
|
||||
|
@ -34,7 +34,7 @@
|
||||
*/
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.15 $"
|
||||
#ident "$Revision: 1.1.1.1 $"
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -44,6 +44,7 @@
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <netdb.h>
|
||||
@ -66,7 +67,6 @@
|
||||
#define SECDAY (24*SECHR)
|
||||
#endif /* sgi */
|
||||
|
||||
extern int errno;
|
||||
extern int sock;
|
||||
|
||||
/* Best expected round trip for a measurement.
|
||||
|
@ -32,12 +32,12 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)master.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.1.1.1 $"
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "globals.h"
|
||||
#include <sys/file.h>
|
||||
@ -150,7 +150,9 @@ master()
|
||||
to.tsp_vers = TSPVERSION;
|
||||
to.tsp_seq = sequence++;
|
||||
to.tsp_hopcnt = MAX_HOPCNT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
bytenetorder(&to);
|
||||
if (sendto(sock, (char *)&to,
|
||||
sizeof(struct tsp), 0,
|
||||
@ -179,7 +181,9 @@ master()
|
||||
#ifdef sgi
|
||||
(void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec);
|
||||
#else
|
||||
(void)strcpy(newdate, ctime(&msg->tsp_time.tv_sec));
|
||||
(void)strncpy(newdate, ctime(&msg->tsp_time.tv_sec),
|
||||
sizeof newdate-1);
|
||||
newdate[sizeof newdate-1] = '\0';
|
||||
#endif /* sgi */
|
||||
if (!good_host_name(msg->tsp_name)) {
|
||||
syslog(LOG_NOTICE,
|
||||
@ -200,7 +204,9 @@ master()
|
||||
#ifdef sgi
|
||||
(void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec);
|
||||
#else
|
||||
(void)strcpy(newdate, ctime(&msg->tsp_time.tv_sec));
|
||||
(void)strncpy(newdate, ctime(&msg->tsp_time.tv_sec),
|
||||
sizeof newdate-1);
|
||||
newdate[sizeof newdate-1] = '\0';
|
||||
#endif /* sgi */
|
||||
htp = findhost(msg->tsp_name);
|
||||
if (htp == 0) {
|
||||
@ -248,9 +254,12 @@ master()
|
||||
(void)addmach(msg->tsp_name, &from,fromnet);
|
||||
}
|
||||
taddr = from;
|
||||
(void)strcpy(tname, msg->tsp_name);
|
||||
(void)strncpy(tname, msg->tsp_name, sizeof tname-1);
|
||||
tname[sizeof tname-1] = '\0';
|
||||
to.tsp_type = TSP_QUIT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
answer = acksend(&to, &taddr, tname,
|
||||
TSP_ACK, 0, 1);
|
||||
if (answer == NULL) {
|
||||
@ -267,7 +276,9 @@ master()
|
||||
*/
|
||||
if (!fromnet || fromnet->status != MASTER)
|
||||
break;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
|
||||
/* The other master often gets into the same state,
|
||||
* with boring results if we stay at it forever.
|
||||
@ -275,7 +286,9 @@ master()
|
||||
ntp = fromnet; /* (acksend() can leave fromnet=0 */
|
||||
for (i = 0; i < 3; i++) {
|
||||
to.tsp_type = TSP_RESOLVE;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
answer = acksend(&to, &ntp->dest_addr,
|
||||
ANYADDR, TSP_MASTERACK,
|
||||
ntp, 0);
|
||||
@ -320,7 +333,9 @@ master()
|
||||
*/
|
||||
htp = addmach(msg->tsp_name, &from,fromnet);
|
||||
to.tsp_type = TSP_QUIT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
answer = acksend(&to, &htp->addr, htp->name,
|
||||
TSP_ACK, 0, 1);
|
||||
if (!answer) {
|
||||
@ -364,11 +379,13 @@ mchgdate(msg)
|
||||
char olddate[32];
|
||||
struct timeval otime, ntime;
|
||||
|
||||
(void)strcpy(tname, msg->tsp_name);
|
||||
(void)strncpy(tname, msg->tsp_name, sizeof tname-1);
|
||||
tname[sizeof tname-1] = '\0';
|
||||
|
||||
xmit(TSP_DATEACK, msg->tsp_seq, &from);
|
||||
|
||||
(void)strcpy(olddate, date());
|
||||
(void)strncpy(olddate, date(), sizeof olddate-1);
|
||||
olddate[sizeof olddate-1] = '\0';
|
||||
|
||||
/* adjust time for residence on the queue */
|
||||
(void)gettimeofday(&otime, 0);
|
||||
@ -503,7 +520,8 @@ spreadtime()
|
||||
dictate = 2;
|
||||
for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) {
|
||||
to.tsp_type = TSP_SETTIME;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname, sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
(void)gettimeofday(&to.tsp_time, 0);
|
||||
answer = acksend(&to, &htp->addr, htp->name,
|
||||
TSP_ACK, 0, htp->noanswer);
|
||||
@ -787,7 +805,8 @@ newslave(msg)
|
||||
if (now.tv_sec >= fromnet->slvwait.tv_sec+3
|
||||
|| now.tv_sec < fromnet->slvwait.tv_sec) {
|
||||
to.tsp_type = TSP_SETTIME;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname, sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
(void)gettimeofday(&to.tsp_time, 0);
|
||||
answer = acksend(&to, &htp->addr,
|
||||
htp->name, TSP_ACK,
|
||||
|
@ -32,12 +32,12 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)measure.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.2 $"
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "globals.h"
|
||||
#include <netinet/in_systm.h>
|
||||
@ -274,8 +274,7 @@ measure(maxmsec, wmsec, hname, addr, print)
|
||||
}
|
||||
} else if (print) {
|
||||
if (errno != 0)
|
||||
fprintf(stderr, "measure %s: %s\n", hname,
|
||||
strerror(errno));
|
||||
warn("measure %s", hname);
|
||||
} else {
|
||||
if (errno != 0) {
|
||||
syslog(LOG_ERR, "measure %s: %m", hname);
|
||||
|
@ -32,12 +32,12 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)networkdelta.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.4 $"
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
|
@ -32,12 +32,12 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)readmsg.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.17 $"
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
@ -393,7 +393,8 @@ masterack()
|
||||
|
||||
resp = msgin;
|
||||
resp.tsp_vers = TSPVERSION;
|
||||
(void)strcpy(resp.tsp_name, hostname);
|
||||
(void)strncpy(resp.tsp_name, hostname, sizeof resp.tsp_name-1);
|
||||
resp.tsp_name[sizeof resp.tsp_name-1] = '\0';
|
||||
|
||||
switch(msgin.tsp_type) {
|
||||
|
||||
|
@ -32,12 +32,12 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)slave.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.1.1.1 $"
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "globals.h"
|
||||
#include <setjmp.h>
|
||||
@ -151,7 +151,9 @@ slave()
|
||||
to.tsp_vers = TSPVERSION;
|
||||
to.tsp_seq = sequence++;
|
||||
to.tsp_hopcnt = MAX_HOPCNT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
bytenetorder(&to);
|
||||
if (sendto(sock, (char *)&to, sizeof(struct tsp), 0,
|
||||
(struct sockaddr*)&ntp->dest_addr,
|
||||
@ -265,8 +267,11 @@ slave()
|
||||
* the following line is necessary due to syslog
|
||||
* calling ctime() which clobbers the static buffer
|
||||
*/
|
||||
(void)strcpy(olddate, date());
|
||||
(void)strcpy(newdate, ctime(&msg->tsp_time.tv_sec));
|
||||
(void)strncpy(olddate, date(), sizeof olddate-1);
|
||||
olddate[sizeof olddate-1] = '\0';
|
||||
(void)strncpy(newdate, ctime(&msg->tsp_time.tv_sec),
|
||||
sizeof newdate-1);
|
||||
newdate[sizeof newdate-1] = '\0';
|
||||
#endif /* sgi */
|
||||
|
||||
if (!good_host_name(msg->tsp_name)) {
|
||||
@ -357,7 +362,9 @@ slave()
|
||||
#ifdef sgi
|
||||
(void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec);
|
||||
#else
|
||||
(void)strcpy(newdate, ctime(&msg->tsp_time.tv_sec));
|
||||
(void)strncpy(newdate, ctime(&msg->tsp_time.tv_sec),
|
||||
sizeof newdate-1);
|
||||
newdate[sizeof newdate-1] = '\0';
|
||||
#endif /* sgi */
|
||||
schgdate(msg, newdate);
|
||||
break;
|
||||
@ -368,7 +375,9 @@ slave()
|
||||
#ifdef sgi
|
||||
(void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec);
|
||||
#else
|
||||
(void)strcpy(newdate, ctime(&msg->tsp_time.tv_sec));
|
||||
(void)strncpy(newdate, ctime(&msg->tsp_time.tv_sec),
|
||||
sizeof newdate-1);
|
||||
newdate[sizeof newdate-1] = '\0';
|
||||
#endif /* sgi */
|
||||
htp = findhost(msg->tsp_name);
|
||||
if (0 == htp) {
|
||||
@ -422,8 +431,12 @@ slave()
|
||||
refusetime = ntime.tv_sec + 30;
|
||||
}
|
||||
taddr = from;
|
||||
(void)strcpy(tname, msg->tsp_name);
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(tname, msg->tsp_name,
|
||||
sizeof tname-1);
|
||||
tname[sizeof tname-1] = '\0';
|
||||
(void)strncpy(to.tsp_name, hostname,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
answerdelay();
|
||||
if (!acksend(&to, &taddr, tname,
|
||||
TSP_ACK, 0, 0))
|
||||
@ -434,7 +447,9 @@ slave()
|
||||
} else { /* fromnet->status == MASTER */
|
||||
htp = addmach(msg->tsp_name, &from,fromnet);
|
||||
to.tsp_type = TSP_QUIT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
if (!acksend(&to, &htp->addr, htp->name,
|
||||
TSP_ACK, 0, htp->noanswer)) {
|
||||
syslog(LOG_ERR,
|
||||
@ -453,7 +468,9 @@ slave()
|
||||
* more than one master: the first slave to
|
||||
* come up will notify here the situation.
|
||||
*/
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
|
||||
/* The other master often gets into the same state,
|
||||
* with boring results.
|
||||
@ -487,7 +504,9 @@ slave()
|
||||
to.tsp_type = TSP_MSITEREQ;
|
||||
to.tsp_vers = TSPVERSION;
|
||||
to.tsp_seq = 0;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
answer = acksend(&to, &slavenet->dest_addr,
|
||||
ANYADDR, TSP_ACK,
|
||||
slavenet, 0);
|
||||
@ -495,11 +514,14 @@ slave()
|
||||
&& good_host_name(answer->tsp_name)) {
|
||||
setmaster(answer);
|
||||
to.tsp_type = TSP_ACK;
|
||||
(void)strcpy(to.tsp_name, answer->tsp_name);
|
||||
(void)strncpy(to.tsp_name, answer->tsp_name,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
bytenetorder(&to);
|
||||
if (sendto(sock, (char *)&to,
|
||||
sizeof(struct tsp), 0,
|
||||
(struct sockaddr*)&taddr, sizeof(taddr)) < 0) {
|
||||
(struct sockaddr*)&taddr,
|
||||
sizeof(taddr)) < 0) {
|
||||
trace_sendto_err(taddr.sin_addr);
|
||||
}
|
||||
}
|
||||
@ -544,9 +566,13 @@ slave()
|
||||
if (answer == NULL)
|
||||
break;
|
||||
taddr = from;
|
||||
(void)strcpy(tname, answer->tsp_name);
|
||||
(void)strncpy(tname, answer->tsp_name,
|
||||
sizeof tname-1);
|
||||
tname[sizeof tname-1] = '\0';
|
||||
to.tsp_type = TSP_QUIT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
if (!acksend(&to, &taddr, tname,
|
||||
TSP_ACK, 0, 1)) {
|
||||
syslog(LOG_ERR,
|
||||
@ -599,7 +625,9 @@ slave()
|
||||
htp = addmach(answer->tsp_name,
|
||||
&from,ntp);
|
||||
to.tsp_type = TSP_QUIT;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname,
|
||||
sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
if (!acksend(&to,&htp->addr,htp->name,
|
||||
TSP_ACK, 0, htp->noanswer)) {
|
||||
syslog(LOG_ERR,
|
||||
@ -635,7 +663,9 @@ setmaster(msg)
|
||||
&& (slavenet != old_slavenet
|
||||
|| strcmp(msg->tsp_name, master_name)
|
||||
|| old_status != status)) {
|
||||
(void)strcpy(master_name, msg->tsp_name);
|
||||
(void)strncpy(master_name, msg->tsp_name,
|
||||
sizeof master_name-1);
|
||||
master_name[sizeof master_name-1] = '\0';
|
||||
old_slavenet = slavenet;
|
||||
old_status = status;
|
||||
|
||||
@ -683,7 +713,8 @@ schgdate(msg, newdate)
|
||||
|
||||
to.tsp_type = TSP_SETDATEREQ;
|
||||
to.tsp_time = msg->tsp_time;
|
||||
(void)strcpy(to.tsp_name, hostname);
|
||||
(void)strncpy(to.tsp_name, hostname, sizeof to.tsp_name-1);
|
||||
to.tsp_name[sizeof to.tsp_name-1] = '\0';
|
||||
if (!acksend(&to, &slavenet->dest_addr,
|
||||
ANYADDR, TSP_DATEACK,
|
||||
slavenet, 0))
|
||||
|
@ -53,7 +53,7 @@ at boot time from the
|
||||
file.
|
||||
It synchronizes the host's time with the time of other
|
||||
machines in a local area network running
|
||||
.Nm timed .
|
||||
.Nm Ns .
|
||||
These time servers will slow down the clocks of some machines
|
||||
and speed up the clocks of others to bring them to the average network time.
|
||||
The average network time is computed from measurements of clock differences
|
||||
@ -62,11 +62,11 @@ using the
|
||||
timestamp request message.
|
||||
.Pp
|
||||
The service provided by
|
||||
.Nm timed
|
||||
.Nm
|
||||
is based on a master-slave
|
||||
scheme.
|
||||
When
|
||||
.Nm timed
|
||||
.Nm
|
||||
is started on a machine, it asks the master for the network time
|
||||
and sets the host's clock to that time.
|
||||
After that, it accepts synchronization messages periodically sent by
|
||||
@ -85,7 +85,7 @@ a new master from among slaves running with the
|
||||
.Fl M
|
||||
flag.
|
||||
A
|
||||
.Nm timed
|
||||
.Nm
|
||||
running without the
|
||||
.Fl M
|
||||
or
|
||||
@ -104,8 +104,9 @@ The
|
||||
.Fl d
|
||||
flag is for debugging the daemon.
|
||||
It causes the program to not put itself into the background.
|
||||
.Pp
|
||||
Normally
|
||||
.Nm timed
|
||||
.Nm
|
||||
checks for a master time server on each network to which
|
||||
it is connected, except as modified by the options described below.
|
||||
It will request synchronization service from the first master server
|
||||
@ -153,7 +154,9 @@ If it finds masters on more than one network, it chooses one network
|
||||
on which to be a "slave," and then periodically checks the other
|
||||
networks to see if the masters there have disappeared.
|
||||
.Pp
|
||||
One way to synchronize a group of machines is to use an NTP daemon to
|
||||
One way to synchronize a group of machines is to use an
|
||||
.Tn NTP
|
||||
daemon to
|
||||
synchronize the clock of one machine to a distant standard or a radio
|
||||
receiver and
|
||||
.Fl F Ar hostname
|
||||
@ -173,10 +176,10 @@ Complaints about machines that failed to respond to initial time
|
||||
settings are often associated with "multi-homed" machines
|
||||
that looked for time masters on more than one network and eventually
|
||||
chose to become a slave on the other network.
|
||||
.Sh WARNING
|
||||
.Sh WARNINGS
|
||||
If two or more time daemons, whether
|
||||
.Nm timed ,
|
||||
.Xr NTP ,
|
||||
.Nm Ns ,
|
||||
.Tn NTP ,
|
||||
try to adjust the same clock, temporal chaos will result.
|
||||
If both
|
||||
.Nm
|
||||
@ -184,11 +187,15 @@ and another time daemon are run on the same machine,
|
||||
ensure that the
|
||||
.Fl F
|
||||
flag is used, so that
|
||||
.Nm timed
|
||||
.Nm
|
||||
never attempts to adjust the local clock.
|
||||
.Pp
|
||||
The protocol is based on UDP/IP broadcasts. All machines within
|
||||
the range of a broadcast that are using the TSP protocol must cooperate.
|
||||
The protocol is based on
|
||||
.Tn UDP/IP
|
||||
broadcasts. All machines within
|
||||
the range of a broadcast that are using the
|
||||
.Tn TSP
|
||||
protocol must cooperate.
|
||||
There cannot be more than a single administrative domain using the
|
||||
.Fl F
|
||||
flag among all machines reached by a broadcast packet.
|
||||
|
@ -32,19 +32,19 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1985, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)timed.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.3 $"
|
||||
#endif /* sgi */
|
||||
|
||||
#define TSPTYPES
|
||||
#include "globals.h"
|
||||
#include <net/if.h>
|
||||
@ -113,6 +113,7 @@ double tot_ticks, hr_ticks;
|
||||
int bufspace = 60*1024;
|
||||
#endif
|
||||
|
||||
static void usage __P((void));
|
||||
|
||||
/*
|
||||
* The timedaemons synchronize the clocks of hosts in a local area network.
|
||||
@ -150,22 +151,12 @@ main(argc, argv)
|
||||
struct sockaddr_in server;
|
||||
u_short port;
|
||||
char c;
|
||||
extern char *optarg;
|
||||
extern int optind, opterr;
|
||||
#ifdef sgi
|
||||
FILE *timetrim_st;
|
||||
#endif
|
||||
|
||||
#define IN_MSG "timed: -i and -n make no sense together\n"
|
||||
#ifdef sgi
|
||||
struct tms tms;
|
||||
#define USAGE "timed: [-dtM] [-i net|-n net] [-F host1 host2 ...] [-G netgp] [-P trimfile]\n"
|
||||
#else
|
||||
#ifdef HAVENIS
|
||||
#define USAGE "timed: [-dtM] [-i net|-n net] [-F host1 host2 ...] [-G netgp]\n"
|
||||
#else
|
||||
#define USAGE "timed: [-dtM] [-i net|-n net] [-F host1 host2 ...]\n"
|
||||
#endif /* HAVENIS */
|
||||
#endif /* sgi */
|
||||
|
||||
#ifdef lint
|
||||
@ -178,7 +169,7 @@ main(argc, argv)
|
||||
|
||||
#ifdef sgi
|
||||
if (0 > syssgi(SGI_GETTIMETRIM, &timetrim)) {
|
||||
perror("timed: syssgi(GETTIMETRIM)");
|
||||
warn("syssgi(GETTIMETRIM)");
|
||||
timetrim = 0;
|
||||
}
|
||||
tot_ticks = hr_ticks = times(&tms);
|
||||
@ -197,8 +188,7 @@ main(argc, argv)
|
||||
|
||||
case 'n':
|
||||
if (iflag) {
|
||||
fprintf(stderr, IN_MSG);
|
||||
exit(1);
|
||||
errx(1, "-i and -n make no sense together");
|
||||
} else {
|
||||
nflag = ON;
|
||||
addnetname(optarg);
|
||||
@ -207,8 +197,7 @@ main(argc, argv)
|
||||
|
||||
case 'i':
|
||||
if (nflag) {
|
||||
fprintf(stderr, IN_MSG);
|
||||
exit(1);
|
||||
errx(1, "-i and -n make no sense together");
|
||||
} else {
|
||||
iflag = ON;
|
||||
addnetname(optarg);
|
||||
@ -225,10 +214,8 @@ main(argc, argv)
|
||||
debug = 1;
|
||||
break;
|
||||
case 'G':
|
||||
if (goodgroup != 0) {
|
||||
fprintf(stderr,"timed: only one net group\n");
|
||||
exit(1);
|
||||
}
|
||||
if (goodgroup != 0)
|
||||
errx(1, "only one net group");
|
||||
goodgroup = optarg;
|
||||
break;
|
||||
#ifdef sgi
|
||||
@ -237,8 +224,7 @@ main(argc, argv)
|
||||
timetrim_st = fopen(timetrim_fn, "r+");
|
||||
if (0 == timetrim_st) {
|
||||
if (errno != ENOENT) {
|
||||
(void)fprintf(stderr,"timed: ");
|
||||
perror(timetrim_fn);
|
||||
warn("%s", timetrim_fn);
|
||||
timetrim_fn = 0;
|
||||
}
|
||||
} else {
|
||||
@ -255,13 +241,13 @@ main(argc, argv)
|
||||
|| (i == 3
|
||||
&& trim != rint(adj*CLK_TCK/ticks))) {
|
||||
if (trace && i != EOF)
|
||||
(void)fprintf(stderr,
|
||||
"timed: unrecognized contents in %s\n",
|
||||
warn(
|
||||
"unrecognized contents in %s",
|
||||
timetrim_fn);
|
||||
} else {
|
||||
if (0 > syssgi(SGI_SETTIMETRIM,
|
||||
trim)) {
|
||||
perror("timed: syssgi(SETTIMETRIM)");
|
||||
warn("syssgi(SETTIMETRIM)");
|
||||
} else {
|
||||
timetrim = trim;
|
||||
}
|
||||
@ -276,15 +262,12 @@ main(argc, argv)
|
||||
#endif /* sgi */
|
||||
|
||||
default:
|
||||
fprintf(stderr, USAGE);
|
||||
exit(1);
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (optind < argc) {
|
||||
fprintf(stderr, USAGE);
|
||||
exit(1);
|
||||
}
|
||||
if (optind < argc)
|
||||
usage();
|
||||
|
||||
/* If we care about which machine is the master, then we must
|
||||
* be willing to be a master
|
||||
@ -292,10 +275,8 @@ main(argc, argv)
|
||||
if (0 != goodgroup || 0 != goodhosts)
|
||||
Mflag = 1;
|
||||
|
||||
if (gethostname(hostname, sizeof(hostname) - 1) < 0) {
|
||||
perror("gethostname");
|
||||
exit(1);
|
||||
}
|
||||
if (gethostname(hostname, sizeof(hostname) - 1) < 0)
|
||||
err(1, "gethostname");
|
||||
self.l_bak = &self;
|
||||
self.l_fwd = &self;
|
||||
self.h_bak = &self;
|
||||
@ -307,29 +288,23 @@ main(argc, argv)
|
||||
add_good_host(hostname,1);
|
||||
|
||||
srvp = getservbyname("timed", "udp");
|
||||
if (srvp == 0) {
|
||||
fprintf(stderr, "unknown service 'timed/udp'\n");
|
||||
exit(1);
|
||||
}
|
||||
if (srvp == 0)
|
||||
errx(1, "unknown service 'timed/udp'");
|
||||
port = srvp->s_port;
|
||||
bzero(&server, sizeof(struct sockaddr_in));
|
||||
server.sin_port = srvp->s_port;
|
||||
server.sin_family = AF_INET;
|
||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sock < 0) {
|
||||
perror("socket");
|
||||
exit(1);
|
||||
}
|
||||
if (sock < 0)
|
||||
err(1, "socket");
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&on,
|
||||
sizeof(on)) < 0) {
|
||||
perror("setsockopt");
|
||||
exit(1);
|
||||
}
|
||||
sizeof(on)) < 0)
|
||||
err(1, "setsockopt");
|
||||
if (bind(sock, (struct sockaddr*)&server, sizeof(server))) {
|
||||
if (errno == EADDRINUSE)
|
||||
fprintf(stderr,"timed: time daemon already running\n");
|
||||
warnx("time daemon already running");
|
||||
else
|
||||
perror("bind");
|
||||
warn("bind");
|
||||
exit(1);
|
||||
}
|
||||
#ifdef sgi
|
||||
@ -337,10 +312,8 @@ main(argc, argv)
|
||||
* handle many slaves with our buffer
|
||||
*/
|
||||
if (0 > setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char*)&bufspace,
|
||||
sizeof(bufspace))) {
|
||||
perror("setsockopt");
|
||||
exit(1);
|
||||
}
|
||||
sizeof(bufspace)))
|
||||
err(1, "setsockopt");
|
||||
#endif /* sgi */
|
||||
|
||||
/* choose a unique seed for random number generation */
|
||||
@ -366,14 +339,11 @@ main(argc, argv)
|
||||
if (nentp != 0) {
|
||||
nt->net = nentp->n_net;
|
||||
} else if (nt->net == INADDR_NONE) {
|
||||
fprintf(stderr, "timed: unknown net %s\n", nt->name);
|
||||
exit(1);
|
||||
errx(1, "unknown net %s", nt->name);
|
||||
} else if (nt->net == INADDR_ANY) {
|
||||
fprintf(stderr, "timed: bad net %s\n", nt->name);
|
||||
exit(1);
|
||||
errx(1, "bad net %s", nt->name);
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"timed: warning: %s unknown in /etc/networks\n",
|
||||
warnx("warning: %s unknown in /etc/networks",
|
||||
nt->name);
|
||||
}
|
||||
|
||||
@ -386,10 +356,8 @@ main(argc, argv)
|
||||
}
|
||||
ifc.ifc_len = sizeof(buf);
|
||||
ifc.ifc_buf = buf;
|
||||
if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
|
||||
perror("timed: get interface configuration");
|
||||
exit(1);
|
||||
}
|
||||
if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0)
|
||||
err(1, "get interface configuration");
|
||||
ntp = NULL;
|
||||
#ifdef sgi
|
||||
#define size(p) (sizeof(*ifr) - sizeof(ifr->ifr_name)) /* XXX hack. kludge */
|
||||
@ -411,7 +379,7 @@ main(argc, argv)
|
||||
ifreqf = *ifr;
|
||||
|
||||
if (ioctl(sock, SIOCGIFFLAGS, (char *)&ifreqf) < 0) {
|
||||
perror("get interface flags");
|
||||
warn("get interface flags");
|
||||
continue;
|
||||
}
|
||||
if ((ifreqf.ifr_flags & IFF_UP) == 0)
|
||||
@ -423,7 +391,7 @@ main(argc, argv)
|
||||
|
||||
|
||||
if (ioctl(sock, SIOCGIFNETMASK, (char *)&ifreq) < 0) {
|
||||
perror("get netmask");
|
||||
warn("get netmask");
|
||||
continue;
|
||||
}
|
||||
ntp->mask = ((struct sockaddr_in *)
|
||||
@ -431,7 +399,7 @@ main(argc, argv)
|
||||
|
||||
if (ifreqf.ifr_flags & IFF_BROADCAST) {
|
||||
if (ioctl(sock, SIOCGIFBRDADDR, (char *)&ifreq) < 0) {
|
||||
perror("get broadaddr");
|
||||
warn("get broadaddr");
|
||||
continue;
|
||||
}
|
||||
ntp->dest_addr = *(struct sockaddr_in *)&ifreq.ifr_broadaddr;
|
||||
@ -442,7 +410,7 @@ main(argc, argv)
|
||||
} else {
|
||||
if (ioctl(sock, SIOCGIFDSTADDR,
|
||||
(char *)&ifreq) < 0) {
|
||||
perror("get destaddr");
|
||||
warn("get destaddr");
|
||||
continue;
|
||||
}
|
||||
ntp->dest_addr = *(struct sockaddr_in *)&ifreq.ifr_dstaddr;
|
||||
@ -455,7 +423,7 @@ main(argc, argv)
|
||||
if (ntp->net.s_addr == htonl(nt->net))
|
||||
break;
|
||||
}
|
||||
if (nflag && !nt || iflag && nt)
|
||||
if ((nflag && !nt) || (iflag && nt))
|
||||
continue;
|
||||
|
||||
ntp->next = NULL;
|
||||
@ -469,10 +437,8 @@ main(argc, argv)
|
||||
}
|
||||
if (ntp)
|
||||
(void) free((char *)ntp);
|
||||
if (nettab == NULL) {
|
||||
fprintf(stderr, "timed: no network usable\n");
|
||||
exit(1);
|
||||
}
|
||||
if (nettab == NULL)
|
||||
errx(1, "no network usable");
|
||||
|
||||
|
||||
#ifdef sgi
|
||||
@ -568,9 +534,26 @@ main(argc, argv)
|
||||
slave();
|
||||
}
|
||||
/* NOTREACHED */
|
||||
#ifdef lint
|
||||
return(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
#ifdef sgi
|
||||
fprintf(stderr, "%s\n%s\n",
|
||||
"usage: timed [-dtM] [-i net|-n net] [-F host1 host2 ...]",
|
||||
" [-G netgp] [-P trimfile]");
|
||||
#else
|
||||
#ifdef HAVENIS
|
||||
fprintf(stderr,
|
||||
"usage: timed [-dtM] [-i net|-n net] [-F host1 host2 ...] [-G netgp]\n");
|
||||
#else
|
||||
fprintf(stderr,
|
||||
"usage: timed [-dtM] [-i net|-n net] [-F host1 host2 ...]\n");
|
||||
#endif /* HAVENIS */
|
||||
#endif /* sgi */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -590,7 +573,8 @@ suppress(addr, name,net)
|
||||
if (trace)
|
||||
fprintf(fd, "suppress: %s\n", name);
|
||||
tgt = *addr;
|
||||
(void)strcpy(tname, name);
|
||||
(void)strncpy(tname, name, sizeof tname-1);
|
||||
tname[sizeof tname-1] = '\0';
|
||||
|
||||
while (0 != readmsg(TSP_ANY, ANYADDR, &wait, net)) {
|
||||
if (trace)
|
||||
@ -600,7 +584,8 @@ suppress(addr, name,net)
|
||||
|
||||
syslog(LOG_NOTICE, "suppressing false master %s", tname);
|
||||
msg.tsp_type = TSP_QUIT;
|
||||
(void)strcpy(msg.tsp_name, hostname);
|
||||
(void)strncpy(msg.tsp_name, hostname, sizeof msg.tsp_name-1);
|
||||
msg.tsp_name[sizeof msg.tsp_name-1] = '\0';
|
||||
(void)acksend(&msg, &tgt, tname, TSP_ACK, 0, 1);
|
||||
}
|
||||
|
||||
@ -618,7 +603,8 @@ lookformaster(ntp)
|
||||
|
||||
/* look for master */
|
||||
resp.tsp_type = TSP_MASTERREQ;
|
||||
(void)strcpy(resp.tsp_name, hostname);
|
||||
(void)strncpy(resp.tsp_name, hostname, sizeof resp.tsp_name-1);
|
||||
resp.tsp_name[sizeof resp.tsp_name-1] = '\0';
|
||||
answer = acksend(&resp, &ntp->dest_addr, ANYADDR,
|
||||
TSP_MASTERACK, ntp, 0);
|
||||
if (answer != 0 && !good_host_name(answer->tsp_name)) {
|
||||
@ -673,7 +659,8 @@ lookformaster(ntp)
|
||||
}
|
||||
|
||||
ntp->status = SLAVE;
|
||||
(void)strcpy(mastername, answer->tsp_name);
|
||||
(void)strncpy(mastername, answer->tsp_name, sizeof mastername-1);
|
||||
mastername[sizeof mastername-1] = '\0';
|
||||
masteraddr = from;
|
||||
|
||||
/*
|
||||
@ -691,7 +678,9 @@ lookformaster(ntp)
|
||||
if (answer != NULL &&
|
||||
strcmp(answer->tsp_name, mastername) != 0) {
|
||||
conflict.tsp_type = TSP_CONFLICT;
|
||||
(void)strcpy(conflict.tsp_name, hostname);
|
||||
(void)strncpy(conflict.tsp_name, hostname,
|
||||
sizeof conflict.tsp_name-1);
|
||||
conflict.tsp_name[sizeof conflict.tsp_name-1] = '\0';
|
||||
if (!acksend(&conflict, &masteraddr, mastername,
|
||||
TSP_ACK, 0, 0)) {
|
||||
syslog(LOG_ERR,
|
||||
@ -853,10 +842,8 @@ addnetname(name)
|
||||
while (*netlist)
|
||||
netlist = &((*netlist)->next);
|
||||
*netlist = (struct nets *)malloc(sizeof **netlist);
|
||||
if (*netlist == 0) {
|
||||
fprintf(stderr,"malloc failed\n");
|
||||
exit(1);
|
||||
}
|
||||
if (*netlist == 0)
|
||||
errx(1, "malloc failed");
|
||||
bzero((char *)*netlist, sizeof(**netlist));
|
||||
(*netlist)->name = name;
|
||||
}
|
||||
@ -884,7 +871,7 @@ add_good_host(name, perm)
|
||||
|
||||
hentp = gethostbyname(name);
|
||||
if (0 == hentp && perm)
|
||||
(void)fprintf(stderr, "unknown host %s\n", name);
|
||||
warnx("unknown host %s", name);
|
||||
}
|
||||
|
||||
|
||||
@ -897,9 +884,11 @@ get_goodgroup(force)
|
||||
# define NG_DELAY (30*60*CLK_TCK) /* 30 minutes */
|
||||
static unsigned long last_update = -NG_DELAY;
|
||||
unsigned long new_update;
|
||||
struct hosttbl *htp;
|
||||
struct goodhost *ghp, **ghpp;
|
||||
#ifdef HAVENIS
|
||||
struct hosttbl *htp;
|
||||
char *mach, *usr, *dom;
|
||||
#endif /* HAVENIS */
|
||||
struct tms tm;
|
||||
|
||||
|
||||
|
@ -32,12 +32,12 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.10 $"
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "timedc.h"
|
||||
#include <sys/file.h>
|
||||
@ -46,6 +46,7 @@ static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93";
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
@ -103,7 +104,7 @@ daydiff(hostname)
|
||||
sec = 0;
|
||||
if (sendto(sock, &sec, sizeof(sec), 0,
|
||||
(struct sockaddr*)&dayaddr, sizeof(dayaddr)) < 0) {
|
||||
perror("sendto(sock)");
|
||||
warn("sendto(sock)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -113,9 +114,9 @@ daydiff(hostname)
|
||||
i = select(sock+1, &ready, (fd_set *)0,
|
||||
(fd_set *)0, &tout);
|
||||
if (i < 0) {
|
||||
if (errno = EINTR)
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
perror("select(date read)");
|
||||
warn("select(date read)");
|
||||
return 0;
|
||||
}
|
||||
if (0 == i)
|
||||
@ -124,14 +125,13 @@ daydiff(hostname)
|
||||
fromlen = sizeof(from);
|
||||
if (recvfrom(sock,&sec,sizeof(sec),0,
|
||||
&from,&fromlen) < 0) {
|
||||
perror("recvfrom(date read)");
|
||||
warn("recvfrom(date read)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
sec = ntohl(sec);
|
||||
if (sec < BU) {
|
||||
fprintf(stderr,
|
||||
"%s says it is before 1970: %lu",
|
||||
warnx("%s says it is before 1970: %lu",
|
||||
hostname, sec);
|
||||
return 0;
|
||||
}
|
||||
@ -143,7 +143,7 @@ daydiff(hostname)
|
||||
}
|
||||
|
||||
/* if we get here, we tried too many times */
|
||||
fprintf(stderr,"%s will not tell us the date\n", hostname);
|
||||
warnx("%s will not tell us the date", hostname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ clockdiff(argc, argv)
|
||||
struct servent *sp;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: clockdiff host ... \n");
|
||||
printf("usage: timedc clockdiff host ...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -190,8 +190,7 @@ clockdiff(argc, argv)
|
||||
/* get the address for the date ready */
|
||||
sp = getservbyname(DATE_PORT, DATE_PROTO);
|
||||
if (!sp) {
|
||||
(void)fprintf(stderr, "%s/%s is an unknown service\n",
|
||||
DATE_PORT, DATE_PROTO);
|
||||
warnx("%s/%s is an unknown service", DATE_PORT, DATE_PROTO);
|
||||
dayaddr.sin_port = 0;
|
||||
} else {
|
||||
dayaddr.sin_port = sp->s_port;
|
||||
@ -201,8 +200,7 @@ clockdiff(argc, argv)
|
||||
argc--; argv++;
|
||||
hp = gethostbyname(*argv);
|
||||
if (hp == NULL) {
|
||||
fprintf(stderr, "timedc: %s: ", *argv);
|
||||
herror(0);
|
||||
warnx("%s: %s", *argv, hstrerror(h_errno));
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -285,13 +283,13 @@ msite(argc, argv)
|
||||
char *tgtname;
|
||||
|
||||
if (argc < 1) {
|
||||
printf("Usage: msite [hostname]\n");
|
||||
printf("usage: timedc msite [host ...]\n");
|
||||
return;
|
||||
}
|
||||
|
||||
srvp = getservbyname("timed", "udp");
|
||||
if (srvp == 0) {
|
||||
fprintf(stderr, "udp/timed: unknown service\n");
|
||||
warnx("udp/timed: unknown service");
|
||||
return;
|
||||
}
|
||||
dest.sin_port = srvp->s_port;
|
||||
@ -303,20 +301,20 @@ msite(argc, argv)
|
||||
tgtname = (i >= argc) ? myname : argv[i];
|
||||
hp = gethostbyname(tgtname);
|
||||
if (hp == 0) {
|
||||
fprintf(stderr, "timedc: %s: ", tgtname);
|
||||
herror(0);
|
||||
warnx("%s: %s", tgtname, hstrerror(h_errno));
|
||||
continue;
|
||||
}
|
||||
bcopy(hp->h_addr, &dest.sin_addr.s_addr, hp->h_length);
|
||||
|
||||
(void)strcpy(msg.tsp_name, myname);
|
||||
(void)strncpy(msg.tsp_name, myname, sizeof msg.tsp_name-1);
|
||||
msg.tsp_name[sizeof msg.tsp_name-1] = '\0';
|
||||
msg.tsp_type = TSP_MSITE;
|
||||
msg.tsp_vers = TSPVERSION;
|
||||
bytenetorder(&msg);
|
||||
if (sendto(sock, &msg, sizeof(struct tsp), 0,
|
||||
(struct sockaddr*)&dest,
|
||||
sizeof(struct sockaddr)) < 0) {
|
||||
perror("sendto");
|
||||
warn("sendto");
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -330,7 +328,7 @@ msite(argc, argv)
|
||||
cc = recvfrom(sock, &msg, sizeof(struct tsp), 0,
|
||||
&from, &length);
|
||||
if (cc < 0) {
|
||||
perror("recvfrom");
|
||||
warn("recvfrom");
|
||||
continue;
|
||||
}
|
||||
bytehostorder(&msg);
|
||||
@ -372,13 +370,13 @@ testing(argc, argv)
|
||||
struct tsp msg;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: election host1 [host2 ...]\n");
|
||||
printf("usage: timedc election host1 [host2 ...]\n");
|
||||
return;
|
||||
}
|
||||
|
||||
srvp = getservbyname("timed", "udp");
|
||||
if (srvp == 0) {
|
||||
fprintf(stderr, "udp/timed: unknown service\n");
|
||||
warnx("udp/timed: unknown service");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -386,8 +384,7 @@ testing(argc, argv)
|
||||
argc--; argv++;
|
||||
hp = gethostbyname(*argv);
|
||||
if (hp == NULL) {
|
||||
fprintf(stderr, "timedc: %s: ", *argv);
|
||||
herror(0);
|
||||
warnx("%s: %s", *argv, hstrerror(h_errno));
|
||||
argc--; argv++;
|
||||
continue;
|
||||
}
|
||||
@ -403,7 +400,7 @@ testing(argc, argv)
|
||||
if (sendto(sock, &msg, sizeof(struct tsp), 0,
|
||||
(struct sockaddr*)&sin,
|
||||
sizeof(struct sockaddr)) < 0) {
|
||||
perror("sendto");
|
||||
warn("sendto");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -428,13 +425,13 @@ tracing(argc, argv)
|
||||
struct servent *srvp;
|
||||
|
||||
if (argc != 2) {
|
||||
printf("Usage: tracing { on | off }\n");
|
||||
printf("usage: timedc trace { on | off }\n");
|
||||
return;
|
||||
}
|
||||
|
||||
srvp = getservbyname("timed", "udp");
|
||||
if (srvp == 0) {
|
||||
fprintf(stderr, "udp/timed: unknown service\n");
|
||||
warnx("udp/timed: unknown service");
|
||||
return;
|
||||
}
|
||||
dest.sin_port = srvp->s_port;
|
||||
@ -452,12 +449,13 @@ tracing(argc, argv)
|
||||
onflag = OFF;
|
||||
}
|
||||
|
||||
(void)strcpy(msg.tsp_name, myname);
|
||||
(void)strncpy(msg.tsp_name, myname, sizeof msg.tsp_name-1);
|
||||
msg.tsp_name[sizeof msg.tsp_name-1] = '\0';
|
||||
msg.tsp_vers = TSPVERSION;
|
||||
bytenetorder(&msg);
|
||||
if (sendto(sock, &msg, sizeof(struct tsp), 0,
|
||||
(struct sockaddr*)&dest, sizeof(struct sockaddr)) < 0) {
|
||||
perror("sendto");
|
||||
warn("sendto");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -470,7 +468,7 @@ tracing(argc, argv)
|
||||
cc = recvfrom(sock, &msg, sizeof(struct tsp), 0,
|
||||
&from, &length);
|
||||
if (cc < 0) {
|
||||
perror("recvfrom");
|
||||
warn("recvfrom");
|
||||
return;
|
||||
}
|
||||
bytehostorder(&msg);
|
||||
@ -494,7 +492,7 @@ priv_resources()
|
||||
|
||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sock < 0) {
|
||||
perror("opening socket");
|
||||
warn("opening socket");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
@ -505,20 +503,20 @@ priv_resources()
|
||||
if (bind(sock, (struct sockaddr*)&sin, sizeof (sin)) >= 0)
|
||||
break;
|
||||
if (errno != EADDRINUSE && errno != EADDRNOTAVAIL) {
|
||||
perror("bind");
|
||||
warn("bind");
|
||||
(void) close(sock);
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
if (port == IPPORT_RESERVED / 2) {
|
||||
fprintf(stderr, "all reserved ports in use\n");
|
||||
warnx("all reserved ports in use");
|
||||
(void) close(sock);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
sock_raw = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
|
||||
if (sock_raw < 0) {
|
||||
perror("opening raw socket");
|
||||
warn("opening raw socket");
|
||||
(void) close(sock);
|
||||
return(-1);
|
||||
}
|
||||
|
@ -32,7 +32,11 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "timedc.h"
|
||||
|
@ -56,21 +56,21 @@ Measure the differences between machines' clocks,
|
||||
Find the location where the master time server is running,
|
||||
.It
|
||||
Enable or disable tracing of messages received by
|
||||
.Xr timed ,
|
||||
.Xr timed 8 ,
|
||||
and
|
||||
.It
|
||||
Perform various debugging actions.
|
||||
.El
|
||||
.Pp
|
||||
Without any arguments,
|
||||
.Nm timedc
|
||||
.Nm
|
||||
will prompt for commands from the standard input.
|
||||
If arguments are supplied,
|
||||
.Nm timedc
|
||||
.Nm
|
||||
interprets the first argument as a command and the remaining
|
||||
arguments as parameters to the command. The standard input
|
||||
may be redirected causing
|
||||
.Nm timedc
|
||||
.Nm
|
||||
to read commands from a file.
|
||||
Commands may be abbreviated;
|
||||
recognized commands are:
|
||||
@ -97,9 +97,9 @@ Show the master time server for specified host(s).
|
||||
Enable or disable the tracing of incoming messages to
|
||||
.Xr timed
|
||||
in the file
|
||||
.Pa /var/log/timed.log.
|
||||
.Pa /var/log/timed.log .
|
||||
.Pp
|
||||
.It Ic election Ar host
|
||||
.It Ic election Ar host1 Op Ar host2 ...
|
||||
Asks the daemon
|
||||
on the target host to reset its "election" timers and to ensure that
|
||||
a time master has been elected.
|
||||
|
@ -32,27 +32,28 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1985, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)timedc.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef sgi
|
||||
#ident "$Revision: 1.6 $"
|
||||
#endif
|
||||
|
||||
#include "timedc.h"
|
||||
#include <strings.h>
|
||||
#include <signal.h>
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <setjmp.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int trace = 0;
|
||||
FILE *fd = 0;
|
||||
@ -75,10 +76,8 @@ main(argc, argv)
|
||||
/*
|
||||
* security dictates!
|
||||
*/
|
||||
if (priv_resources() < 0) {
|
||||
fprintf(stderr, "Could not get privileged resources\n");
|
||||
exit(1);
|
||||
}
|
||||
if (priv_resources() < 0)
|
||||
errx(1, "could not get privileged resources");
|
||||
(void) setuid(getuid());
|
||||
|
||||
if (--argc > 0) {
|
||||
|
@ -46,8 +46,6 @@
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern int errno;
|
||||
|
||||
#define ON 1
|
||||
#define OFF 0
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user