From a24d64301f6ccdc04939bf8e42339f13a073f8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 14 May 2020 14:51:22 +0200 Subject: [PATCH] make finding libc platform independent and slower. and since we're making it slower, let's cache it, in case boottime gets called more than once. --- cloudinit/util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cloudinit/util.py b/cloudinit/util.py index 4cae7ec84d4..985e7d20b29 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -1866,6 +1866,7 @@ def time_rfc2822(): return ts +@lru_cache() def boottime(): """Use sysctlbyname(3) via ctypes to find kern.boottime @@ -1875,6 +1876,7 @@ def boottime(): @return boottime: float to be compatible with linux """ import ctypes + import ctypes.util NULL_BYTES = b"\x00" @@ -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()