]> git.decadent.org.uk Git - ion3.git/blobdiff - libmainloop/signal.c
[svn-upgrade] Integrating new upstream version, ion3 (20070708)
[ion3.git] / libmainloop / signal.c
index f09d1db1a1b55c22037a981736c06cd1ca987cbb..37ee995f507da6818d8b0c622d9a9782ef12a0c4 100644 (file)
@@ -14,6 +14,7 @@
 #include <signal.h>
 #include <string.h>
 #include <stdlib.h>
+#include <errno.h>
 
 #include <libtu/objp.h>
 #include <libtu/types.h>
@@ -44,19 +45,29 @@ static WTimer *queue=NULL;
 
 int mainloop_gettime(struct timeval *val)
 {
-#ifdef _POSIX_MONOTONIC_CLOCK
+#if defined(_POSIX_MONOTONIC_CLOCK) && (_POSIX_MONOTONIC_CLOCK>=0)
     struct timespec spec;
     int ret;
+    static int checked=0;
     
-    ret=clock_gettime(CLOCK_MONOTONIC, &spec);
+    if(checked>=0){
+        ret=clock_gettime(CLOCK_MONOTONIC, &spec);
     
-    val->tv_sec=spec.tv_sec;
-    val->tv_usec=spec.tv_nsec/1000;
-    
-    return ret;
+        if(ret==-1 && errno==EINVAL && checked==0){
+            checked=-1;
+        }else{
+            checked=1;
+            
+            val->tv_sec=spec.tv_sec;
+            val->tv_usec=spec.tv_nsec/1000;
+        
+            return ret;
+        }
+    }
 #else
-    return gettimeofday(&val, NULL);
+    #warning "Monotonic clock unavailable; please fix your operating system."
 #endif
+    return gettimeofday(val, NULL);
 }