145
|
1 /* Example of a bad call within a signal handler.
|
|
2 'handler' calls 'custom_logger' which calls 'fprintf', and 'fprintf' is
|
|
3 not allowed from a signal handler. */
|
|
4
|
|
5 #include <stdio.h>
|
|
6 #include <signal.h>
|
|
7
|
|
8 extern void body_of_program(void);
|
|
9
|
|
10 void custom_logger(const char *msg)
|
|
11 {
|
|
12 fprintf(stderr, "LOG: %s", msg); /* { dg-warning "call to 'fprintf' from within signal handler" } */
|
|
13 }
|
|
14
|
|
15 static void handler(int signum)
|
|
16 {
|
|
17 custom_logger("got signal");
|
|
18 }
|
|
19
|
|
20 int main(int argc, const char *argv)
|
|
21 {
|
|
22 custom_logger("started");
|
|
23
|
|
24 signal(SIGINT, handler); /* { dg-message "registering 'handler' as signal handler" } */
|
|
25
|
|
26 body_of_program();
|
|
27
|
|
28 custom_logger("stopped");
|
|
29
|
|
30 return 0;
|
|
31 }
|