X-Git-Url: https://git.decadent.org.uk/gitweb/?p=ion3.git;a=blobdiff_plain;f=libmainloop%2Fsignal.c;fp=libmainloop%2Fsignal.c;h=37ee995f507da6818d8b0c622d9a9782ef12a0c4;hp=f09d1db1a1b55c22037a981736c06cd1ca987cbb;hb=214381793227e299ae1e72caa24ad2cfde029ef1;hpb=1cd244db6df1337d594b9e2456c735cbc28aea6c diff --git a/libmainloop/signal.c b/libmainloop/signal.c index f09d1db..37ee995 100644 --- a/libmainloop/signal.c +++ b/libmainloop/signal.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -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); }