> This patch also checks the system platform as clock_gettime
> could exist on different platforms but with different values of
> CLOCK_MONOTONIC and different definitions of 'struct timespec'.
> In this case, the system call would be expected to catch the
> error, which is dangerous.
> 
> This patch ensures Linux, NetBSD and FreeBSD platforms use
> clock_gettime with their corresponding correct values and
> definitions. All other platforms use time.time().

thanks.

the following is incremental diff to fix NetBSD case.
please feel free to fold it into yours.

i haven't checked FreeBSD part.

YAMAMOTO Takashi

>From 71891a0fc4ba892e26fec8e704167ab8ccde408a Mon Sep 17 00:00:00 2001
From: YAMAMOTO Takashi <yamam...@valinux.co.jp>
Date: Tue, 3 Jun 2014 14:17:23 +0900
Subject: [PATCH] timeval: Fix NetBSD case

Signed-off-by: YAMAMOTO Takashi <yamam...@valinux.co.jp>
---
 python/ovs/timeval.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/python/ovs/timeval.py b/python/ovs/timeval.py
index 6f3cbb3..a34ef2b 100644
--- a/python/ovs/timeval.py
+++ b/python/ovs/timeval.py
@@ -16,6 +16,7 @@ import sys
 import time
 
 LIBRT = 'librt.so.1'
+clock_gettime_name = 'clock_gettime'
 
 try:
     import ctypes
@@ -24,6 +25,12 @@ try:
         CLOCK_MONOTONIC = 1
         time_t = ctypes.c_long
     elif sys.platform.startswith("netbsd"):
+        # NetBSD uses function renaming for ABI versioning.  While the proper
+        # way to get the appropriate version is of course "#include <time.h>",
+        # it is difficult with ctypes.  The following is appropriate for
+        # recent versions of NetBSD, including NetBSD-6.
+        LIBRT = 'libc.so.12'
+        clock_gettime_name = '__clock_gettime50'
         CLOCK_MONOTONIC = 3
         time_t = ctypes.c_int64
     elif sys.platform.startswith("freebsd"):
@@ -39,7 +46,7 @@ try:
         ]
 
     librt = ctypes.CDLL(LIBRT)
-    clock_gettime = librt.clock_gettime
+    clock_gettime = getattr(librt, clock_gettime_name)
     clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
 except:
     # Librt shared library could not be loaded
-- 
1.9.0
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to