Skip to content

Commit

Permalink
make finding libc platform independent
Browse files Browse the repository at this point in the history
and slower.
and since we're making it slower, let's cache it, in case boottime gets
called more than once.
  • Loading branch information
igalic committed May 14, 2020
1 parent 4261ae5 commit a24d643
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cloudinit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,7 @@ def time_rfc2822():
return ts


@lru_cache()
def boottime():
"""Use sysctlbyname(3) via ctypes to find kern.boottime
Expand All @@ -1875,6 +1876,7 @@ def boottime():
@return boottime: float to be compatible with linux
"""
import ctypes
import ctypes.util

NULL_BYTES = b"\x00"

Expand All @@ -1883,7 +1885,7 @@ class timeval(ctypes.Structure):
("tv_sec", ctypes.c_int64),
("tv_usec", ctypes.c_int64)
]
libc = ctypes.CDLL('libc.so')
libc = ctypes.CDLL(ctypes.util.find_library('c'))
size = ctypes.c_size_t()
size.value = ctypes.sizeof(timeval)
buf = timeval()
Expand Down

0 comments on commit a24d643

Please sign in to comment.