uptime code does not work on FreeBSD with python 3
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
cloud-init |
Fix Released
|
Medium
|
Mina Galić |
Bug Description
The uptime code in cloudinit/util.py does not work for FreeBSD (any more)
https:/
root@container-
Python 3.6.9 (default, Oct 24 2019, 01:18:01)
[GCC 4.2.1 Compatible FreeBSD Clang 6.0.1 (tags/RELEASE_
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> libc = ctypes.
>>> import time
>>> size = ctypes.c_size_t()
>>> buf = ctypes.c_int()
>>> size.value = ctypes.sizeof(buf)
>>> libc.sysctlbyna
-1
>>>
root@container-
and here's what happens when we ask for kern.boottime via sysctl(8):
root@container-
kern.boottime: { sec = 1573656128, usec = 384300 } Wed Nov 13 14:42:08 2019
root@container-
tags: | added: freebsd |
summary: |
- uptime code does not work on FreeBSD + uptime code does not work on FreeBSD with python 3 |
Changed in cloud-init: | |
importance: | Undecided → Medium |
status: | New → In Progress |
Changed in cloud-init: | |
status: | Fix Committed → Fix Released |
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) me("kern. boottime" , ctypes. byref(boottime) , ctypes. sizeof( timeval) , None, 0) == -1: errno.errorcode [ctypes. get_errno( )])
boottime = timeval()
if libc.sysctlbyna
print(
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