X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=libmainloop%2Fsignal.c;h=877e3ec808665b5a5b7a44a8d928eafb5ebfcae7;hb=df57861c962a50bfbf57f276d288395fe0c6a4b6;hp=f09d1db1a1b55c22037a981736c06cd1ca987cbb;hpb=1cd244db6df1337d594b9e2456c735cbc28aea6c;p=ion3.git diff --git a/libmainloop/signal.c b/libmainloop/signal.c index f09d1db..877e3ec 100644 --- a/libmainloop/signal.c +++ b/libmainloop/signal.c @@ -1,7 +1,7 @@ /* * ion/libmainloop/signal.c * - * Copyright (c) Tuomo Valkonen 1999-2007. + * Copyright (c) Tuomo Valkonen 1999-2008. * * See the included file LICENSE for details. */ @@ -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); }