Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(BSD) util.py:boottime: make finding libc platform independent #366

Merged
merged 2 commits into from
May 18, 2020

Conversation

igalic
Copy link
Collaborator

@igalic igalic commented May 14, 2020

and slower.
and since we're making it slower, let's cache it, in case boottime gets
called more than once.

this should fix boottime() (again).

@igalic
Copy link
Collaborator Author

igalic commented May 14, 2020

@goneri finally getting around to fixing this!

@OddBloke OddBloke self-assigned this May 14, 2020
and slower.
and since we're making it slower, let's cache it, in case boottime gets
called more than once.
@OddBloke
Copy link
Collaborator

I know it's not called on Linux (so I won't block merge on this at all, in particular because it's broken on Linux in master), but do we expect boottime() to work here?

I see:

In [2]: boottime()                                                                                                                                                                                                                                                                        
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-cc4cfa1f18c8> in <module>
----> 1 boottime()

~/dev/cloud-init/cloudinit/util.py in boottime()
   1889     size.value = ctypes.sizeof(timeval)
   1890     buf = timeval()
-> 1891     if libc.sysctlbyname(b"kern.boottime" + NULL_BYTES, ctypes.byref(buf),
   1892                          ctypes.byref(size), None, 0) != -1:
   1893         return buf.tv_sec + buf.tv_usec / 1000000.0

/usr/lib/python3.8/ctypes/__init__.py in __getattr__(self, name)
    384         if name.startswith('__') and name.endswith('__'):
    385             raise AttributeError(name)
--> 386         func = self.__getitem__(name)
    387         setattr(self, name, func)
    388         return func

/usr/lib/python3.8/ctypes/__init__.py in __getitem__(self, name_or_ordinal)
    389 
    390     def __getitem__(self, name_or_ordinal):
--> 391         func = self._FuncPtr((name_or_ordinal, self))
    392         if not isinstance(name_or_ordinal, int):
    393             func.__name__ = name_or_ordinal

AttributeError: /lib/x86_64-linux-gnu/libc.so.6: undefined symbol: sysctlbyname

Copy link
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Mina! This LGTM, but I'll wait for a +1 from @goneri (or I'll just go ahead without on Monday, in case they're busy) before I Approve and land it.

@igalic
Copy link
Collaborator Author

igalic commented May 15, 2020

sysctlbyname() exists on

anyone planning to make QNX available in their cloud?

but anyway, we should add a try around the call, until OpenBSD implements that function, or exclude it with util.is_OpenBSD()

Copy link
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's Monday, you know what that means.

@OddBloke OddBloke merged commit 904ad36 into canonical:master May 18, 2020
@igalic igalic deleted the fix/bsd-uptime branch May 18, 2020 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants