Skip to content

Commit

Permalink
Remove -n flag, fix setting date / time
Browse files Browse the repository at this point in the history
r342139 bork setting the date. This fixes it by simply removing the -n
flag.

Differential Revision: https://reviews.freebsd.org/D19668
  • Loading branch information
bsdimp committed Mar 21, 2019
1 parent fa61805 commit 8671ff6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 56 deletions.
38 changes: 5 additions & 33 deletions bin/date/date.1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
.\" @(#)date.1 8.3 (Berkeley) 4/28/95
.\" $FreeBSD$
.\"
.Dd March 12, 2019
.Dd March 20, 2019
.Dt DATE 1
.Os
.Sh NAME
Expand All @@ -52,13 +52,13 @@
.Ar ...
.Op Cm + Ns Ar output_fmt
.Nm
.Op Fl jnu
.Op Fl ju
.Sm off
.Op Oo Oo Oo Oo Ar cc Oc Ar yy Oc Ar mm Oc Ar dd Oc Ar HH
.Ar MM Op Ar .ss
.Sm on
.Nm
.Op Fl jnRu
.Op Fl jRu
.Fl f Ar input_fmt new_date
.Op Cm + Ns Ar output_fmt
.Nm
Expand Down Expand Up @@ -142,16 +142,6 @@ This allows you to use the
flag in addition to the
.Cm +
option to convert one date format to another.
.It Fl n
By default, if the
.Xr timed 8
daemon is running,
.Nm
sets the time on all of the machines in the local group.
The
.Fl n
option suppresses this behavior and causes the time to be set only on the
current machine.
.It Fl R
Use RFC 2822 date and time output format.
This is equivalent to using
Expand Down Expand Up @@ -431,23 +421,6 @@ can be used to parse the output from
.Nm
and express it in Epoch time.
.Sh DIAGNOSTICS
Occasionally, when
.Xr timed 8
synchronizes the time on many hosts, the setting of a new time value may
require more than a few seconds.
On these occasions,
.Nm
prints:
.Ql Network time being set .
The message
.Ql Communication error with timed
occurs when the communication
between
.Nm
and
.Xr timed 8
fails.
.Pp
It is invalid to combine the
.Fl I
flag with either
Expand All @@ -465,8 +438,7 @@ and exits with an error status.
.Xr gettimeofday 2 ,
.Xr getutxent 3 ,
.Xr strftime 3 ,
.Xr strptime 3 ,
.Xr timed 8
.Xr strptime 3
.Rs
.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD"
.%A R. Gusella
Expand All @@ -478,7 +450,7 @@ The
utility is expected to be compatible with
.St -p1003.2 .
The
.Fl d , f , I , j , n , r , t ,
.Fl d , f , I , j , r , t ,
and
.Fl v
options are all extensions to the standard.
Expand Down
40 changes: 17 additions & 23 deletions bin/date/date.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void iso8601_usage(const char *);
static void multipleformats(void);
static void printdate(const char *);
static void printisodate(struct tm *);
static void setthetime(const char *, const char *, int, int);
static void setthetime(const char *, const char *, int);
static void usage(void);

static const struct iso8601_fmt {
Expand All @@ -92,7 +92,7 @@ int
main(int argc, char *argv[])
{
int ch, rflag;
bool Iflag, jflag, nflag, Rflag;
bool Iflag, jflag, Rflag;
const char *format;
char buf[1024];
char *fmt;
Expand All @@ -107,8 +107,8 @@ main(int argc, char *argv[])
fmt = NULL;
(void) setlocale(LC_TIME, "");
rflag = 0;
Iflag = jflag = nflag = Rflag = 0;
while ((ch = getopt(argc, argv, "f:I::jnRr:uv:")) != -1)
Iflag = jflag = Rflag = 0;
while ((ch = getopt(argc, argv, "f:I::jRr:uv:")) != -1)
switch((char)ch) {
case 'f':
fmt = optarg;
Expand All @@ -132,9 +132,6 @@ main(int argc, char *argv[])
case 'j':
jflag = 1; /* don't set time */
break;
case 'n': /* don't set network */
nflag = 1;
break;
case 'R': /* RFC 2822 datetime format */
if (Iflag)
multipleformats();
Expand Down Expand Up @@ -179,7 +176,7 @@ main(int argc, char *argv[])
}

if (*argv) {
setthetime(fmt, *argv, jflag, nflag);
setthetime(fmt, *argv, jflag);
++argv;
} else if (fmt != NULL)
usage();
Expand Down Expand Up @@ -250,7 +247,7 @@ printisodate(struct tm *lt)
#define ATOI2(s) ((s) += 2, ((s)[-2] - '0') * 10 + ((s)[-1] - '0'))

static void
setthetime(const char *fmt, const char *p, int jflag, int nflag)
setthetime(const char *fmt, const char *p, int jflag)
{
struct utmpx utx;
struct tm *lt;
Expand Down Expand Up @@ -343,20 +340,17 @@ setthetime(const char *fmt, const char *p, int jflag, int nflag)
errx(1, "nonexistent time");

if (!jflag) {
/* set the time */
if (nflag) {
utx.ut_type = OLD_TIME;
memset(utx.ut_id, 0, sizeof(utx.ut_id));
(void)gettimeofday(&utx.ut_tv, NULL);
pututxline(&utx);
tv.tv_sec = tval;
tv.tv_usec = 0;
if (settimeofday(&tv, NULL) != 0)
err(1, "settimeofday (timeval)");
utx.ut_type = NEW_TIME;
(void)gettimeofday(&utx.ut_tv, NULL);
pututxline(&utx);
}
utx.ut_type = OLD_TIME;
memset(utx.ut_id, 0, sizeof(utx.ut_id));
(void)gettimeofday(&utx.ut_tv, NULL);
pututxline(&utx);
tv.tv_sec = tval;
tv.tv_usec = 0;
if (settimeofday(&tv, NULL) != 0)
err(1, "settimeofday (timeval)");
utx.ut_type = NEW_TIME;
(void)gettimeofday(&utx.ut_tv, NULL);
pututxline(&utx);

if ((p = getlogin()) == NULL)
p = "???";
Expand Down

0 comments on commit 8671ff6

Please sign in to comment.