#define _GNU_SOURCE #include #include #include #include #include #include #include static int value = -1; #define FUTEX_WAIT 0 #define FUTEX_WAKE 1 static int futex(int32_t *uaddr, int op, int32_t val, const struct timespec *timeout, int32_t *uaddr2, int32_t val3) { return syscall(__NR_futex, uaddr, op, val, timeout, uaddr2, val3); } static void sighandler(int signo, siginfo_t *siginfo, void *context) { fprintf(stderr, "[OK] Test program with pid: %d SIGUSR1 handler\n", getpid()); } int main(int argc, char **argv) { struct sigaction act; pid_t pid, wait_pid; int ret; fprintf(stderr, "Testing futex sigrestart. Stop with CTRL-c.\n", getpid()); act.sa_sigaction = sighandler; act.sa_flags = SA_SIGINFO | SA_RESTART; //act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); ret = sigaction(SIGUSR1, &act, NULL); if (ret) abort(); pid = fork(); if (pid > 0) { /* parent */ for (;;) { ret = kill(pid, SIGUSR1); if (ret) { perror("kill"); abort(); } sleep(1); } } else { if (pid < 0) { abort(); } /* child */ for (;;) { ret = futex(&value, FUTEX_WAIT, -1, NULL, NULL, 0); if (ret < 0) { fprintf(stderr, "[FAIL] futex returns %d, %s\n", ret, strerror(errno)); } else { fprintf(stderr, "[FAIL] futex returns %d (unexpected)\n", ret); } } } return 0; }