kern.boottime was changed from a struct timeval to a struct timespec
in January 2009 (the Christos' time merge, when time_t went to 64 bits). sysctl needs to catch up. (So do other progs, which will happen, eventually, but most of them are unaffected in any practical way.) If you are running a system (NetBSD 6 or later) without this change, try sysctl -nn kern.boottime and marvel at the result (in theory, seconds.microseconds) most probably being something like: jinx$ sysctl -nn kern.boottime 1540801874.999995564 (There is a 1 in 1000 chance your system will have booted in the interval [0 , 999999] nanoseconds after some second, in which case this will not be observed. You should get (almost) the same value after this change - just now it is as it should be (there should now always be 9 digits after the '.'). On the other hand, if you're on a big-endian 64 bit host (running 64 bit sysctl) you would have always seen 0 for the microseconds field. That should be fixed by this. In sysctl(7) also document what we mean by "the time the system booted". XXX Pullup -8 XXX Pullup -7 XXX Pullup -6 (oops, missed that one...)
This commit is contained in:
parent
7008793d77
commit
c576beb79a
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: sysctl.c,v 1.160 2018/02/04 09:03:23 mrg Exp $ */
|
||||
/* $NetBSD: sysctl.c,v 1.161 2018/10/30 19:41:21 kre Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
|
@ -68,7 +68,7 @@ __COPYRIGHT("@(#) Copyright (c) 1993\
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)sysctl.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: sysctl.c,v 1.160 2018/02/04 09:03:23 mrg Exp $");
|
||||
__RCSID("$NetBSD: sysctl.c,v 1.161 2018/10/30 19:41:21 kre Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -2189,32 +2189,32 @@ kern_clockrate(HANDLER_ARGS)
|
|||
static void
|
||||
kern_boottime(HANDLER_ARGS)
|
||||
{
|
||||
struct timeval timeval;
|
||||
struct timespec timespec;
|
||||
time_t boottime;
|
||||
size_t sz;
|
||||
int rc;
|
||||
|
||||
sz = sizeof(timeval);
|
||||
rc = prog_sysctl(name, namelen, &timeval, &sz, NULL, 0);
|
||||
sz = sizeof(timespec);
|
||||
rc = prog_sysctl(name, namelen, ×pec, &sz, NULL, 0);
|
||||
if (rc == -1) {
|
||||
sysctlerror(1);
|
||||
return;
|
||||
}
|
||||
if (sz != sizeof(timeval))
|
||||
if (sz != sizeof(timespec))
|
||||
errx(EXIT_FAILURE, "%s: !returned size wrong!", sname);
|
||||
|
||||
boottime = timeval.tv_sec;
|
||||
boottime = timespec.tv_sec;
|
||||
if (xflag || rflag)
|
||||
display_struct(pnode, sname, &timeval, sz,
|
||||
display_struct(pnode, sname, ×pec, sz,
|
||||
DISPLAY_VALUE);
|
||||
else if (!nflag)
|
||||
/* ctime() provides the \n */
|
||||
printf("%s%s%s", sname, eq, ctime(&boottime));
|
||||
else if (nflag == 1)
|
||||
printf("%ld\n", (long)boottime);
|
||||
printf("%lld\n", (long long)boottime);
|
||||
else
|
||||
printf("%ld.%06ld\n", (long)timeval.tv_sec,
|
||||
(long)timeval.tv_usec);
|
||||
printf("%lld.%9.9ld\n", (long long)timespec.tv_sec,
|
||||
timespec.tv_nsec);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: sysctl.7,v 1.133 2018/10/06 13:53:58 wiz Exp $
|
||||
.\" $NetBSD: sysctl.7,v 1.134 2018/10/30 19:41:21 kre Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
|
@ -29,7 +29,7 @@
|
|||
.\"
|
||||
.\" @(#)sysctl.3 8.4 (Berkeley) 5/9/95
|
||||
.\"
|
||||
.Dd October 5, 2018
|
||||
.Dd October 30, 2018
|
||||
.Dt SYSCTL 7
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -278,7 +278,7 @@ privilege may change the value.
|
|||
.It kern.arandom integer no
|
||||
.It kern.argmax integer no
|
||||
.It kern.boothowto integer no
|
||||
.It kern.boottime struct timeval no
|
||||
.It kern.boottime struct timespec no
|
||||
.It kern.buildinfo string no
|
||||
.\".It kern.bufq node not applicable
|
||||
.It kern.ccpu integer no
|
||||
|
@ -396,9 +396,11 @@ Flags passed from the boot loader; see
|
|||
for the meanings of the flags.
|
||||
.It Li kern.boottime ( Dv KERN_BOOTTIME )
|
||||
A
|
||||
.Vt struct timeval
|
||||
.Vt struct timespec
|
||||
structure is returned.
|
||||
This structure contains the time that the system was booted.
|
||||
That time is defined (for this purpose) to be the time at
|
||||
which the kernel first started accumulating clock ticks.
|
||||
.It Li kern.bufq
|
||||
This variable contains information on the
|
||||
.Xr bufq 9
|
||||
|
|
Loading…
Reference in New Issue