Gentoo Archives: gentoo-user

From: walt <w41ter@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] nanosleep broken on ~amd64?
Date: Sun, 03 May 2009 22:12:38
Message-Id: gtl1g1$8v9$1@ger.gmane.org
1 By accident I noticed that the configure script for one of the gentoo
2 packages (I think maybe it was coreutils but I can't remember) gives
3 different results on ~x86 and ~amd64.
4
5 The script uses a "test for working nanosleep" that I've included below.
6
7 Could someone else compile the test and confirm that it returns 119 on
8 ~amd64 instead of 0?
9
10 Here are the steps if you don't already know them:
11 1. Copy and paste the c code below into a new file named conftest.c
12 2. # gcc conftest.c
13 3. # ./a.out (don't forget that leading dot)
14 4. # echo $? (this should print either 0 or 119)
15
16 I get 119 on ~amd64, which implies the test for nanosleep fails.
17
18 Thanks!
19
20
21 Here are the contents of conftest.c:
22
23 #include <errno.h>
24 #include <limits.h>
25 #include <signal.h>
26 #include <sys/time.h>
27 #include <time.h>
28 #include <unistd.h>
29 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
30 #define TYPE_MAXIMUM(t) ((t) (! TYPE_SIGNED (t) ? (t) -1 : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
31
32 static void
33 check_for_SIGALRM (int sig)
34 {
35 if (sig != SIGALRM)
36 _exit (1);
37 }
38
39 int
40 main ()
41 {
42 static struct timespec ts_sleep;
43 static struct timespec ts_remaining;
44 static struct sigaction act;
45 if (! nanosleep)
46 return 1;
47 act.sa_handler = check_for_SIGALRM;
48 sigemptyset (&act.sa_mask);
49 sigaction (SIGALRM, &act, NULL);
50 ts_sleep.tv_sec = 0;
51 ts_sleep.tv_nsec = 1;
52 alarm (1);
53 if (nanosleep (&ts_sleep, NULL) != 0)
54 return 1;
55 ts_sleep.tv_sec = TYPE_MAXIMUM (time_t);
56 ts_sleep.tv_nsec = 999999999;
57 alarm (1);
58 if (nanosleep (&ts_sleep, &ts_remaining) == -1 && errno == EINTR
59 && TYPE_MAXIMUM (time_t) - 10 < ts_remaining.tv_sec)
60 return 0;
61 return 119;
62 }

Replies

Subject Author
Re: [gentoo-user] nanosleep broken on ~amd64? Peter Alfredsen <loki_val@g.o>
Re: [gentoo-user] nanosleep broken on ~amd64? "Arttu V." <arttuv69@×××××.com>
Re: [gentoo-user] nanosleep broken on ~amd64? Mike Kazantsev <mike_kazantsev@×××××××.net>