]>
Commit | Line | Data |
---|---|---|
581c785b | 1 | /* Copyright (C) 2003-2022 Free Software Foundation, Inc. |
71028edd | 2 | This file is part of the GNU C Library. |
71028edd UD |
3 | |
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 | 15 | License along with the GNU C Library; if not, see |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
71028edd UD |
17 | |
18 | #include <pthread.h> | |
19 | #include <signal.h> | |
20 | #include <unistd.h> | |
ce5b73a7 MC |
21 | #include <support/xthread.h> |
22 | #include <support/xsignal.h> | |
23 | #include <support/xthread.h> | |
71028edd UD |
24 | |
25 | ||
26 | static int the_sig; | |
27 | ||
28 | ||
29 | static void | |
30 | eintr_handler (int sig) | |
31 | { | |
32 | if (sig != the_sig) | |
33 | { | |
34 | write (STDOUT_FILENO, "eintr_handler: signal number wrong\n", 35); | |
35 | _exit (1); | |
36 | } | |
37 | write (STDOUT_FILENO, ".", 1); | |
38 | } | |
39 | ||
40 | ||
41 | static void * | |
42 | eintr_source (void *arg) | |
43 | { | |
44 | struct timespec ts = { .tv_sec = 0, .tv_nsec = 500000 }; | |
45 | ||
33ebea17 UD |
46 | if (arg == NULL) |
47 | { | |
48 | sigset_t ss; | |
49 | sigemptyset (&ss); | |
50 | sigaddset (&ss, the_sig); | |
ce5b73a7 | 51 | xpthread_sigmask (SIG_BLOCK, &ss, NULL); |
33ebea17 UD |
52 | } |
53 | ||
71028edd UD |
54 | while (1) |
55 | { | |
4efdd8d3 UD |
56 | if (arg != NULL) |
57 | pthread_kill (*(pthread_t *) arg, the_sig); | |
58 | else | |
59 | kill (getpid (), the_sig); | |
71028edd UD |
60 | |
61 | nanosleep (&ts, NULL); | |
62 | } | |
757f9fcb UD |
63 | |
64 | /* NOTREACHED */ | |
65 | return NULL; | |
71028edd UD |
66 | } |
67 | ||
68 | ||
69 | static void | |
4efdd8d3 | 70 | setup_eintr (int sig, pthread_t *thp) |
71028edd UD |
71 | { |
72 | struct sigaction sa; | |
73 | sigemptyset (&sa.sa_mask); | |
74 | sa.sa_flags = 0; | |
75 | sa.sa_handler = eintr_handler; | |
76 | if (sigaction (sig, &sa, NULL) != 0) | |
77 | { | |
78 | puts ("setup_eintr: sigaction failed"); | |
79 | exit (1); | |
80 | } | |
81 | the_sig = sig; | |
82 | ||
83 | /* Create the thread which will fire off the signals. */ | |
ce5b73a7 | 84 | xpthread_create (NULL, eintr_source, thp); |
71028edd | 85 | } |