diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-12-02 02:02:26 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-12-02 02:02:26 +0000 |
commit | 5827c88596da439109b473bf46af8fde94a5c55a (patch) | |
tree | 209cdba2f56a8c3179a77de79436de581c58ee9c /bin/date/date.c | |
parent | c1654cb0181dc613499e0421e46ace08cb71d9d6 (diff) |
add -a to use adjtime(), like rdate(1) does
Diffstat (limited to 'bin/date/date.c')
-rw-r--r-- | bin/date/date.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/bin/date/date.c b/bin/date/date.c index 8a949caaeac..ed9c5e5cefe 100644 --- a/bin/date/date.c +++ b/bin/date/date.c @@ -1,4 +1,4 @@ -/* $OpenBSD: date.c,v 1.18 2001/09/06 13:29:08 mpech Exp $ */ +/* $OpenBSD: date.c,v 1.19 2001/12/02 02:02:25 deraadt Exp $ */ /* $NetBSD: date.c,v 1.11 1995/09/07 06:21:05 jtc Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: date.c,v 1.18 2001/09/06 13:29:08 mpech Exp $"; +static char rcsid[] = "$OpenBSD: date.c,v 1.19 2001/12/02 02:02:25 deraadt Exp $"; #endif #endif /* not lint */ @@ -70,6 +70,7 @@ extern char *__progname; time_t tval; int retval, nflag; +int slidetime; static void setthetime __P((char *)); static void badformat __P((void)); @@ -93,6 +94,9 @@ main(argc, argv) case 'd': /* daylight saving time */ tz.tz_dsttime = atoi(optarg) ? 1 : 0; break; + case 'a': + slidetime++; + break; case 'n': /* don't set network */ nflag = 1; break; @@ -232,12 +236,24 @@ setthetime(p) /* set the time */ if (nflag || netsettime(tval)) { - logwtmp("|", "date", ""); - tv.tv_sec = tval; - tv.tv_usec = 0; - if (settimeofday(&tv, NULL)) - errx(1, "settimeofday"); - logwtmp("{", "date", ""); + if (slidetime) { + struct timeval tv_current; + + if (gettimeofday(&tv_current, NULL) == -1) + err(1, "Could not get local time of day"); + + tv.tv_sec = tval - tv_current.tv_sec; + tv.tv_usec = 0; + if (adjtime(&tv, NULL) == -1) + errx(1, "adjtime"); + } else { + logwtmp("|", "date", ""); + tv.tv_sec = tval; + tv.tv_usec = 0; + if (settimeofday(&tv, NULL)) + errx(1, "settimeofday"); + logwtmp("{", "date", ""); + } } if ((p = getlogin()) == NULL) @@ -256,7 +272,7 @@ static void usage() { (void)fprintf(stderr, - "usage: %s [-nu] [-d dst] [-r seconds] [-t west] [+format]\n", + "usage: %s [-anu] [-d dst] [-r seconds] [-t west] [+format]\n", __progname); (void)fprintf(stderr, "%-*s[[[[[[cc]yy]mm]dd]HH]MM[.SS]]\n", strlen(__progname) + 8, ""); |