Date: Tue, 16 Mar 1999 00:06:45 -0500 (EST) From: Brian Haug <haug@hawaii.conterra.com> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/10610: date enhancement Message-ID: <199903160506.AAA05691@hawaii.conterra.com>
index | next in thread | raw e-mail
>Number: 10610
>Category: bin
>Synopsis: New options to date to slowly adjust time with adjtime(2)
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Mon Mar 15 21:10:00 PST 1999
>Closed-Date:
>Last-Modified:
>Originator: Brian Haug
>Release: FreeBSD 3.1-RELEASE i386 (?? submitting from different machine)
>Organization:
None
>Environment:
Generic BSD environment
>Description:
SVR4 implementations of date have a -a option which allows the time
to slowly be adjusted with the adjtime system call. I've also
provided a -T option which adjust the time like the -a option but
does not require the user to calculate the delta.
>How-To-Repeat:
Not applicapble
>Fix:
The BRH define was to keep track of the changes, I suggest removing it.
*** /usr/src/bin/date/date.c.old Sun Mar 14 08:15:47 1999
--- /usr/src/bin/date/date.c Mon Mar 15 08:19:05 1999
***************
*** 1,3 ****
--- 1,4 ----
+ #define BRH
/*
* Copyright (c) 1985, 1987, 1988, 1993
* The Regents of the University of California. All rights reserved.
***************
*** 62,67 ****
--- 63,72 ----
time_t tval;
int retval, nflag;
+ #ifdef BRH
+ int aflag, Tflag;
+ char *aval;
+ #endif
static void setthetime __P((const char *, const char *));
static void badformat __P((void));
***************
*** 91,98 ****
--- 96,118 ----
tz.tz_dsttime = tz.tz_minuteswest = 0;
rflag = 0;
set_timezone = 0;
+ #ifdef BRH
+ while ((ch = getopt(argc, argv, "a:d:f:nr:t:uv:T")) != -1)
+ #else
while ((ch = getopt(argc, argv, "d:f:nr:t:uv:")) != -1)
+ #endif
switch((char)ch) {
+ #ifdef BRH
+ /* adjust time slowly to specified time */
+ case 'T':
+ Tflag = 1;
+ break;
+ /* adjust time slowly by amount specified */
+ case 'a':
+ aflag = 1;
+ aval = optarg;
+ break;
+ #endif
case 'd': /* daylight savings time */
tz.tz_dsttime = strtol(optarg, &endptr, 10) ? 1 : 0;
if (endptr == optarg || *endptr != '\0')
***************
*** 146,152 ****
--- 166,178 ----
++argv;
}
+ #ifdef BRH
+ if (aflag) {
+ setthetime(fmt, aval);
+ } else if (*argv) {
+ #else
if (*argv) {
+ #endif
setthetime(fmt, *argv);
++argv;
} else if (fmt != NULL)
***************
*** 178,183 ****
--- 204,218 ----
register struct tm *lt;
struct timeval tv;
const char *dot, *t;
+ #ifdef BRH
+ time_t ctval; /* current time_t value */
+ int sign = 1;
+
+ if (aflag && '-' == *p) {
+ sign = -1;
+ p++;
+ }
+ #endif
if (fmt != NULL) {
lt = localtime(&tval);
***************
*** 202,209 ****
--- 237,269 ----
badformat();
}
+ #ifdef BRH
+ if (aflag) {
+ tv.tv_usec = 0;
+ if (NULL != dot) {
+ int scale = 1000000;
+
+ dot++;
+ while (isdigit(*dot)) {
+ scale /= 10;
+ tv.tv_usec += scale * (*dot - '0');
+ dot++;
+ }
+ }
+ tv.tv_sec = strtol(p, NULL, 10) * sign;
+ if (-1 == adjtime(&tv, (struct timeval *)NULL)) {
+ err(1, "adjtime (timeval)");
+ }
+ return;
+ }
+ #endif
+
lt = localtime(&tval);
+ #ifdef BRH
+ if (Tflag && (ctval = mktime(lt)) == -1)
+ errx(1, "nonexistant time");
+ #endif
if (dot != NULL) { /* .ss */
dot++; /* *dot++ = '\0'; */
if (strlen(dot) != 2)
***************
*** 252,257 ****
--- 312,329 ----
errx(1, "nonexistent time");
/* set the time */
+ #ifdef BRH
+ if (Tflag) {
+ tv.tv_sec = tval - ctval;
+ tv.tv_usec = 0;
+ if (-1 == adjtime(&tv, (struct timeval *)NULL)) {
+ err(1, "adjtime(timeval)");
+ }
+ /* should something be logged to wtmp? */
+ /* should info be passed to ntp? */
+ return;
+ }
+ #endif
if (nflag || netsettime(tval)) {
logwtmp("|", "date", "");
tv.tv_sec = tval;
***************
*** 277,283 ****
--- 349,359 ----
usage()
{
(void)fprintf(stderr, "%s\n%s\n",
+ #ifdef BRH
+ "usage: date [-nu] [-d dst] [-r seconds] [-t west] [-T|-a delta]"
+ #else
"usage: date [-nu] [-d dst] [-r seconds] [-t west] "
+ #endif
"[-v[+|-]val[ymwdHM]] ... ",
" [-f fmt date | [[[[yy]mm]dd]HH]MM[.ss]] [+format]");
exit(1);
*** /usr/src/bin/date/date.1.old Sun Mar 14 08:15:44 1999
--- /usr/src/bin/date/date.1 Mon Mar 15 12:37:52 1999
***************
*** 47,52 ****
--- 47,53 ----
.Op Fl d Ar dst
.Op Fl r Ar seconds
.Op Fl t Ar minutes_west
+ .Op Fl T | Fl a Ar delta
.Op Fl v Ns Ar [+|-]val Ns Op ymwdHM
.Ar ...
.Op Fl f Ar fmt Ar date | [[[[yy]mm]dd]HH]MM[\&.ss]
***************
*** 60,65 ****
--- 61,76 ----
.Pp
The options are as follows:
.Bl -tag -width Ds
+ .It Fl a
+ Adjust the time by
+ .Ar delta
+ seconds. If
+ .Ar delta
+ is positive, the clock will be sped up by the
+ .Xr adjtime 2
+ function. If
+ .Ar delta
+ is negative, the clock will be slowed down.
.It Fl d
Set the kernel's value for daylight savings time.
If
***************
*** 103,108 ****
--- 114,126 ----
.Ql tz_minuteswest
by future calls to
.Xr gettimeofday 2 .
+ .It Fl T
+ Similar to the
+ .Fl a
+ option, the time will be adjusted, however the utility calculates the value
+ to pass to the
+ .Xr adjtime 2
+ function based on the time specified.
.It Fl u
Display or set the date in
.Tn UCT
***************
*** 266,271 ****
--- 284,290 ----
a record of the user setting the time
.El
.Sh SEE ALSO
+ .Xr adjtime 2 ,
.Xr gettimeofday 2 ,
.Xr strftime 3 ,
.Xr strptime 3 ,
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199903160506.AAA05691>
