sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 1 | #include <time.h> |
| 2 | #include <unistd.h> |
| 3 | #include <stdio.h> |
| 4 | #include <errno.h> |
| 5 | #include <signal.h> |
| 6 | |
| 7 | #include "../memcheck.h" |
| 8 | |
| 9 | /* Check that a syscall's POST function gets called if it completes |
| 10 | due to being interrupted. nanosleep is used here, because it |
| 11 | writes a result even if it fails. wait*() could also be used, |
florian | ad4e979 | 2015-07-05 21:53:33 +0000 | [diff] [blame] | 12 | because they successfully complete if interrupted by SIGCHLD. |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 13 | */ |
| 14 | static void handler(int s) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | int main() |
| 19 | { |
| 20 | struct timespec req, rem; |
| 21 | int ret; |
| 22 | |
| 23 | req.tv_sec = 2; |
| 24 | req.tv_nsec = 0; |
| 25 | |
| 26 | signal(SIGALRM, handler); |
| 27 | |
| 28 | alarm(1); |
| 29 | ret = nanosleep(&req, &rem); |
| 30 | |
| 31 | if (ret != -1 || errno != EINTR) { |
njn | 6cfb1df | 2009-05-04 01:17:56 +0000 | [diff] [blame] | 32 | fprintf(stderr, "FAILED: expected nanosleep to be interrupted\n"); |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 33 | } else { |
florian | 06bc722 | 2013-10-01 22:38:43 +0000 | [diff] [blame] | 34 | (void) VALGRIND_CHECK_VALUE_IS_DEFINED(rem); |
njn | 6cfb1df | 2009-05-04 01:17:56 +0000 | [diff] [blame] | 35 | fprintf(stderr, "PASSED\n"); /* assuming CHECK_VALUE_IS_DEFINED doesn't print anything */ |
sewardj | cbdddcf | 2005-03-10 23:23:45 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | return 0; |
| 39 | } |