[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[patch] "show remainder" option for rdate
- To: tech@openbsd.org
- Subject: [patch] "show remainder" option for rdate
- From: Fabio Olive Leite <olive@unixforge.org>
- Date: Wed, 3 Mar 2004 16:33:53 -0300
- Content-Disposition: inline
- User-Agent: KMail/1.5.3
Hi people,
While trying to make sense out of time keeping in my old Pentium 233
MMX, which advances about half a second every hour, I implemented a
"-r" option on rdate that shows the remainder of the last adjtime(2)
call. Maybe it will be useful for someone else.
Index: rdate.8
===================================================================
RCS file: /cvs/src/usr.sbin/rdate/rdate.8,v
retrieving revision 1.26
diff -u -r1.26 rdate.8
--- rdate.8 18 Feb 2004 20:10:53 -0000 1.26
+++ rdate.8 3 Mar 2004 18:07:31 -0000
@@ -37,7 +37,7 @@
.Nd set the system's date from a remote host
.Sh SYNOPSIS
.Nm rdate
-.Op Fl 46acnpsv
+.Op Fl 46acnprsv
.Ar host
.Sh DESCRIPTION
.Nm
@@ -78,6 +78,10 @@
Use SNTP (RFC 1361) instead of the RFC 868 time protocol.
.It Fl p
Do not set, just print the remote time.
+.It Fl r
+Show the remainder from the last
+.Xr adjtime 2
+call.
.It Fl s
Do not print the time.
.It Fl v
Index: rdate.c
===================================================================
RCS file: /cvs/src/usr.sbin/rdate/rdate.c,v
retrieving revision 1.22
diff -u -r1.22 rdate.c
--- rdate.c 18 Feb 2004 20:10:53 -0000 1.22
+++ rdate.c 3 Mar 2004 18:07:31 -0000
@@ -79,6 +79,7 @@
(void) fprintf(stderr, " -c: correct leap second count\n");
(void) fprintf(stderr, " -n: use SNTP instead of RFC868 time
protocol\n");
(void) fprintf(stderr, " -p: just print, don't set\n");
+ (void) fprintf(stderr, " -r: show remainder from last adjtime\n");
(void) fprintf(stderr, " -s: just set, don't print\n");
(void) fprintf(stderr, " -v: verbose output\n");
}
@@ -87,15 +88,15 @@
main(int argc, char **argv)
{
int pr = 0, silent = 0, ntp = 0, verbose = 0;
- int slidetime = 0, corrleaps = 0;
+ int slidetime = 0, corrleaps = 0, showremainder = 0;
char *hname;
extern int optind;
int c;
int family = PF_UNSPEC;
- struct timeval new, adjust;
+ struct timeval new, adjust, remainder;
- while ((c = getopt(argc, argv, "46psancv")) != -1)
+ while ((c = getopt(argc, argv, "46prsancv")) != -1)
switch (c) {
case '4':
family = PF_INET;
@@ -109,6 +110,10 @@
pr++;
break;
+ case 'r':
+ showremainder++;
+ break;
+
case 's':
silent++;
break;
@@ -152,7 +157,7 @@
err(1, "Could not set time of day");
logwtmp("{", "date", "");
} else {
- if (adjtime(&adjust, NULL) == -1)
+ if (adjtime(&adjust, &remainder) == -1)
err(1, "Could not adjust time of day");
}
}
@@ -161,13 +166,14 @@
struct tm *ltm;
char buf[80];
time_t tim = new.tv_sec;
- double adjsec;
+ double adjsec, remainsec;
ltm = localtime(&tim);
(void) strftime(buf, sizeof buf, "%a %b %e %H:%M:%S %Z %Y\n", ltm);
(void) fputs(buf, stdout);
adjsec = adjust.tv_sec + adjust.tv_usec / 1.0e6;
+ remainsec = remainder.tv_sec + remainder.tv_usec / 1.0e6;
if (slidetime || verbose) {
if (ntp)
@@ -179,6 +185,10 @@
"%s: adjust local clock by %ld seconds\n",
__progname, adjust.tv_sec);
}
+ if (!pr && slidetime && showremainder)
+ (void) fprintf(stdout,
+ "%s: remainder from last adjtime was %.6f seconds\n",
+ __progname, remainsec);
}
return 0;
--
-= Fábio Olivé Leite =-
olive at unixforge . org
http://unixforge.org/~olive/