| 1 |
/* Example of a bad call within a signal handler with replacement |
| 2 |
alternative. 'handler' calls 'exit', and 'exit' is not allowed |
| 3 |
from a signal handler. But '_exit' is allowed. */ |
| 4 |
/* { dg-require-effective-target signal } */ |
| 5 |
|
| 6 |
#include <signal.h> |
| 7 |
#include <stdlib.h> |
| 8 |
|
| 9 |
extern void body_of_program(void); |
| 10 |
|
| 11 |
static void handler(int signum) |
| 12 |
{ |
| 13 |
exit(1); /* { dg-warning "call to 'exit' from within signal handler" "warning" } */ |
| 14 |
/* { dg-message "note: '_exit' is a possible signal-safe alternative for 'exit'" "replacement note" { target *-*-* } .-1 } */ |
| 15 |
} |
| 16 |
|
| 17 |
int main(int argc, const char *argv) |
| 18 |
{ |
| 19 |
signal(SIGINT, handler); /* { dg-message "registering 'handler' as signal handler" } */ |
| 20 |
|
| 21 |
body_of_program(); |
| 22 |
|
| 23 |
return 0; |
| 24 |
} |