From 52b40984a2dc3289b40ceda1d4f797455092b9ba Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 15 Jul 2002 21:08:21 +0000 Subject: Include sys/sysctl.h. (print_uptime): Add support for determining the boot time on FreeBSD. --- src/uptime.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') 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 #include "system.h" +#if HAVE_SYSCTL && HAVE_SYS_SYSCTL_H +# include +#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--) -- cgit v1.2.3-54-g00ecf