diff options
author | Jim Meyering <jim@meyering.net> | 2002-07-15 21:08:21 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2002-07-15 21:08:21 +0000 |
commit | 52b40984a2dc3289b40ceda1d4f797455092b9ba (patch) | |
tree | cb0b54ea1cf01e861ba20736e0e8ea468d1f2a71 /src | |
parent | eba70ec3a59ff1d722185f37a40ad453ad6b9c93 (diff) | |
download | coreutils-52b40984a2dc3289b40ceda1d4f797455092b9ba.tar.xz |
Include sys/sysctl.h.
(print_uptime): Add support for determining the boot time on FreeBSD.
Diffstat (limited to 'src')
-rw-r--r-- | src/uptime.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/uptime.c b/src/uptime.c index b3351ef35..9d6df3514 100644 --- a/src/uptime.c +++ b/src/uptime.c @@ -24,6 +24,10 @@ #include <sys/types.h> #include "system.h" +#if HAVE_SYSCTL && HAVE_SYS_SYSCTL_H +# include <sys/sysctl.h> +#endif + #include "error.h" #include "long-options.h" #include "readutmp.h" @@ -80,6 +84,19 @@ print_uptime (int n, const STRUCT_UTMP *this) fclose (fp); } #endif /* HAVE_PROC_UPTIME */ + +#if HAVE_SYSCTL && defined CTL_KERN && defined KERN_BOOTTIME + { + /* FreeBSD specific: fetch sysctl "kern.boottime". */ + static int request[2] = { CTL_KERN, KERN_BOOTTIME }; + struct timeval result; + size_t result_len = sizeof result; + + if (0 <= sysctl (request, 2, &result, &result_len, NULL, 0)) + boot_time = result.tv_sec; + } +#endif + /* Loop through all the utmp entries we just read and count up the valid ones, also in the process possibly gleaning boottime. */ while (n--) |