| 1 | #include <errno.h>
|
|---|
| 2 | #include <limits.h>
|
|---|
| 3 | #include <signal.h>
|
|---|
| 4 | #if HAVE_SYS_TIME_H
|
|---|
| 5 | #include <sys/time.h>
|
|---|
| 6 | #endif
|
|---|
| 7 | #include <time.h>
|
|---|
| 8 | #include <unistd.h>
|
|---|
| 9 | #include <stdio.h>
|
|---|
| 10 | static void
|
|---|
| 11 | check_for_SIGALRM (int sig)
|
|---|
| 12 | {
|
|---|
| 13 | if (sig != SIGALRM)
|
|---|
| 14 | _exit (1);
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | int
|
|---|
| 18 | main ()
|
|---|
| 19 | {
|
|---|
| 20 | static struct timespec ts_sleep;
|
|---|
| 21 | static struct timespec ts_remaining;
|
|---|
| 22 | static struct sigaction act;
|
|---|
| 23 | if (! nanosleep)
|
|---|
| 24 | return 2;
|
|---|
| 25 | act.sa_handler = check_for_SIGALRM;
|
|---|
| 26 | sigemptyset (&act.sa_mask);
|
|---|
| 27 | sigaction (SIGALRM, &act, NULL);
|
|---|
| 28 | ts_sleep.tv_sec=12; /* changed this to 2 secs (original test uses MAX_INT) */
|
|---|
| 29 | ts_sleep.tv_nsec = 999999999;
|
|---|
| 30 | alarm (1);
|
|---|
| 31 | if (nanosleep (&ts_sleep, &ts_remaining) != -1)
|
|---|
| 32 | {
|
|---|
| 33 | printf("\nAfter nanosleep, but no interrupt\n"); return 4;
|
|---|
| 34 | }
|
|---|
| 35 | else
|
|---|
| 36 | printf("\nAfter nanosleep and interrupted\n");
|
|---|
| 37 | if (errno != EINTR)
|
|---|
| 38 | return 5;
|
|---|
| 39 | if (ts_remaining.tv_sec <= ts_sleep.tv_sec - 10)
|
|---|
| 40 | return 6;
|
|---|
| 41 | return 0;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|