Comment 1 for bug 1853160

Revision history for this message
Mina Galić (minagalic) wrote : Re: uptime code does not work on FreeBSD

my current attempt to bring this into the new millenium:

import ctypes
import time
import errno

class timeval(ctypes.Structure):
    _fields_ = [
        ("tv_sec", ctypes.c_int64),
        ("tv_usec", ctypes.c_int64)
    ]

libc = ctypes.CDLL('/lib/libc.so.7', use_errno=True)
boottime = timeval()
if libc.sysctlbyname("kern.boottime", ctypes.byref(boottime), ctypes.sizeof(timeval), None, 0) == -1:
    print(errno.errorcode[ctypes.get_errno()])
    exit(1)

which results in ENOENT

which is rather confusing, given that `sysctl kern.boottime` returns
kern.boottime: { sec = 1573656128, usec = 384300 } Wed Nov 13 14:42:08 2019