]> granicus.if.org Git - strace/blob - tests/erestartsys.c
Update copyright headers
[strace] / tests / erestartsys.c
1 /*
2  * Check decoding of ERESTARTSYS error code.
3  *
4  * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@altlinux.org>
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9
10 #include "tests.h"
11
12 #include <signal.h>
13 #include <stdio.h>
14 #include <sys/time.h>
15 #include <sys/socket.h>
16 #include <unistd.h>
17
18 static int sv[2];
19
20 static void
21 handler(int sig)
22 {
23         close(sv[1]);
24         sv[1] = -1;
25 }
26
27 int
28 main(void)
29 {
30         if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv))
31                 perror_msg_and_skip("socketpair");
32
33         const struct sigaction act = {
34                 .sa_handler = handler,
35                 .sa_flags = SA_RESTART
36         };
37         if (sigaction(SIGALRM, &act, NULL))
38                 perror_msg_and_fail("sigaction");
39
40         sigset_t mask;
41         sigemptyset(&mask);
42         sigaddset(&mask, SIGALRM);
43         if (sigprocmask(SIG_UNBLOCK, &mask, NULL))
44                 perror_msg_and_fail("sigprocmask");
45
46         const struct itimerval itv = { .it_value.tv_usec = 123456 };
47         if (setitimer(ITIMER_REAL, &itv, NULL))
48                 perror_msg_and_fail("setitimer");
49
50         if (recvfrom(sv[0], &sv[1], sizeof(sv[1]), 0, NULL, NULL))
51                 perror_msg_and_fail("recvfrom");
52
53         printf("recvfrom(%d, %p, %d, 0, NULL, NULL) = ? ERESTARTSYS"
54                " (To be restarted if SA_RESTART is set)\n",
55                sv[0], &sv[1], (int) sizeof(sv[1]));
56         printf("recvfrom(%d, \"\", %d, 0, NULL, NULL) = 0\n",
57                sv[0], (int) sizeof(sv[1]));
58
59         puts("+++ exited with 0 +++");
60         return 0;
61 }