]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix compilation on older Linux distros (Bart Van Assche)
authorJulian Seward <jseward@acm.org>
Tue, 27 Nov 2007 23:39:13 +0000 (23:39 +0000)
committerJulian Seward <jseward@acm.org>
Tue, 27 Nov 2007 23:39:13 +0000 (23:39 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7244

exp-drd/tests/sigalrm.c

index e5d986849acb0bda1c4e54a0622ba50b3285d899..76b094bc5c59783f7f63f47ec18641332dbb807f 100644 (file)
@@ -16,7 +16,11 @@ static int s_debug = 0;
 
 static int getktid()
 {
+#ifdef __NR_gettid
   return syscall(__NR_gettid);
+#else
+  return -1;
+#endif
 }
 
 static int getvgtid()
@@ -26,31 +30,28 @@ static int getvgtid()
   return res;
 }
 
-static void SignalHandler(const int iSignal)
+static void print_thread_id(const char* const label)
 {
   if (s_debug)
   {
     char msg[256];
-    snprintf(msg, sizeof(msg), "Signal %d was delivered to kernel thread ID %d"
-           " / Valgrind thread ID %d\n",
-             iSignal, getktid(), getvgtid());
+    snprintf(msg, sizeof(msg),
+             "%spid %d / kernel thread ID %d / Valgrind thread ID %d\n",
+             label, getpid(), getktid(), getvgtid());
     write(STDOUT_FILENO, msg, strlen(msg));
   }
 }
 
-void* thread_func(void* thread_arg)
+static void SignalHandler(const int iSignal)
 {
-  struct timespec tsRemain, tsDelay;
+  print_thread_id("Signal was delivered to ");
+}
 
-  if (s_debug)
-  {
-    printf("thread: kernel thread ID %d  / Valgrind thread ID %d\n",
-          getktid(), getvgtid());
-  }
+void* thread_func(void* thread_arg)
+{
+  print_thread_id("thread: ");
 
-  tsDelay.tv_sec = 10;
-  tsDelay.tv_nsec = 0;
-  clock_nanosleep(CLOCK_MONOTONIC, 0, &tsDelay, &tsRemain);
+  sleep(10);
   //assert(result < 0 && errno == EINTR);
 
   return 0;
@@ -68,11 +69,7 @@ int main(int argc, char** argv)
 
   vgthreadid = getvgtid();
 
-  if (s_debug)
-  {
-    printf("main: kernel thread ID %d / Valgrind thread ID %d\n",
-          getktid(), vgthreadid);
-  }
+  print_thread_id("main: ");
 
   {
     struct sigaction sa;
@@ -86,7 +83,7 @@ int main(int argc, char** argv)
   // Wait until the thread is inside clock_nanosleep().
   tsDelay.tv_sec = 0;
   tsDelay.tv_nsec = 20 * 1000 * 1000;
-  clock_nanosleep(CLOCK_MONOTONIC, 0, &tsDelay, 0);
+  nanosleep(&tsDelay, 0);
   // And send SIGALRM to the thread.
   pthread_kill(threadid, SIGALRM);
   pthread_join(threadid, 0);