[Mono-dev] use sysctl for get_boot_time() on *BSD systems and Mac OS X
Zoltan Varga
vargaz at gmail.com
Thu Apr 8 20:23:48 EDT 2010
Applied to SVN HEAD/2.6.
Zoltan
On Thu, Apr 8, 2010 at 5:28 PM, Robert Nagy <robert at openbsd.org> wrote:
> Tested on OpenBSD and FreeBSD.
>
> Index: mono/utils/mono-time.c
> ===================================================================
> --- mono/utils/mono-time.c (revision 155053)
> +++ mono/utils/mono-time.c (working copy)
> @@ -57,12 +57,32 @@
> #include <sys/time.h>
> #endif
>
> +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) ||
> defined(__NetBSD__)
> +#include <sys/param.h>
> +#include <sys/sysctl.h>
> +#endif
> +
> #include <time.h>
>
> static gint64
> get_boot_time (void)
> {
> - /* FIXME: use sysctl (kern.boottime) on OSX */
> +#if defined(PLATFORM_MACOSX) || defined(__FreeBSD__) ||
> defined(__OpenBSD__) || defined(__NetBSD__)
> + int mib [2];
> + size_t size;
> + time_t now;
> + struct timeval boottime;
> +
> + (void)time(&now);
> +
> + mib [0] = CTL_KERN;
> + mib [1] = KERN_BOOTTIME;
> +
> + size = sizeof(boottime);
> +
> + if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1)
> + return (gint64)((now - boottime.tv_sec) * MTICKS_PER_SEC);
> +#else
> FILE *uptime = fopen ("/proc/uptime", "r");
> if (uptime) {
> double upt;
> @@ -73,6 +93,7 @@
> }
> fclose (uptime);
> }
> +#endif
> /* a made up uptime of 300 seconds */
> return (gint64)300 * MTICKS_PER_SEC;
> }
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100409/3828fd20/attachment.html
More information about the Mono-devel-list
mailing list