]> granicus.if.org Git - strace/blob - tests/pause.c
77eeb6c8ff0858e67bc9e2905551eb19b07729b2
[strace] / tests / pause.c
1 /*
2  * Check decoding of pause syscall.
3  *
4  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
5  * Copyright (c) 2016 Fei Jie <feij.fnst@cn.fujitsu.com>
6  * All rights reserved.
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #include "tests.h"
12 #include <asm/unistd.h>
13
14 #ifdef __NR_pause
15
16 # include <errno.h>
17 # include <signal.h>
18 # include <stdio.h>
19 # include <sys/time.h>
20 # include <unistd.h>
21
22 static void
23 handler(int sig)
24 {
25 }
26
27 int
28 main(void)
29 {
30         const struct sigaction act = { .sa_handler = handler };
31         if (sigaction(SIGALRM, &act, NULL))
32                 perror_msg_and_fail("sigaction");
33
34         sigset_t mask;
35         sigemptyset(&mask);
36         sigaddset(&mask, SIGALRM);
37         if (sigprocmask(SIG_UNBLOCK, &mask, NULL))
38                 perror_msg_and_fail("sigprocmask");
39
40         const struct itimerval itv = { .it_value.tv_usec = 123456 };
41         if (setitimer(ITIMER_REAL, &itv, NULL))
42                 perror_msg_and_fail("setitimer");
43
44         syscall(__NR_pause);
45         if (errno == ENOSYS)
46                 printf("pause() = -1 ENOSYS (%m)\n");
47         else
48                 printf("pause() = ? ERESTARTNOHAND"
49                        " (To be restarted if no handler)\n");
50
51         puts("+++ exited with 0 +++");
52         return 0;
53 }
54
55 #else
56
57 SKIP_MAIN_UNDEFINED("__NR_pause")
58
59 #endif