]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Include sys/sysctl.h.
authorJim Meyering <jim@meyering.net>
Mon, 15 Jul 2002 21:08:21 +0000 (21:08 +0000)
committerJim Meyering <jim@meyering.net>
Mon, 15 Jul 2002 21:08:21 +0000 (21:08 +0000)
(print_uptime): Add support for determining the boot time on FreeBSD.

src/uptime.c

index b3351ef354aa956833d012cf2b06753eadf48716..9d6df3514f36ca9ef2e2ee197d0a6c702b9211c2 100644 (file)
 #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--)