From: Tom Hughes Date: Mon, 14 Jun 2004 12:33:43 +0000 (+0000) Subject: Fixed the sem test to work on systems with semtimedop. X-Git-Tag: svn/VALGRIND_2_1_2~93 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d9d4e91c04cf85fb4de056d0ec57b17e81560477;p=thirdparty%2Fvalgrind.git Fixed the sem test to work on systems with semtimedop. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2414 --- diff --git a/configure.in b/configure.in index e83ff8f8b2..fc4e7b01e4 100644 --- a/configure.in +++ b/configure.in @@ -345,7 +345,7 @@ AC_FUNC_MEMCMP AC_FUNC_MMAP AC_TYPE_SIGNAL -AC_CHECK_FUNCS([floor memchr memset mkdir strchr strdup strpbrk strrchr strstr]) +AC_CHECK_FUNCS([floor memchr memset mkdir strchr strdup strpbrk strrchr strstr semtimedop]) AC_OUTPUT( Makefile diff --git a/none/tests/sem.c b/none/tests/sem.c index 4e26b369f4..3eddaffda5 100644 --- a/none/tests/sem.c +++ b/none/tests/sem.c @@ -6,6 +6,56 @@ #include #include +#ifndef HAVE_SEMTIMEDOP + +#include +#include + +static int semtimedop(int semid, struct sembuf *sops, unsigned nsops, + struct timespec *timeout) +{ + struct sigaction act; + struct sigaction oldact; + struct itimerval itv; + int rv; + + act.sa_handler = SIG_IGN; + sigemptyset( &act.sa_mask ); + act.sa_flags = 0; + + if (sigaction(SIGALRM, &act, &oldact) < 0) + { + perror("sigaction"); + exit(1); + } + + itv.it_interval.tv_sec = 0; + itv.it_interval.tv_usec = 0; + itv.it_value.tv_sec = timeout->tv_sec; + itv.it_value.tv_usec = timeout->tv_nsec / 1000; + + if (setitimer(ITIMER_REAL, &itv, NULL) < 0) + { + perror("setitimer"); + exit(1); + } + + if ((rv = semop(semid, sops, nsops)) < 0 && errno == EINTR) + { + errno = EAGAIN; + } + + if (sigaction(SIGALRM, &oldact, NULL) < 0) + { + perror("sigaction"); + exit(1); + } + + return rv; +} + +#endif + int main(int argc, char **argv) { int semid;