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  /* { dg-require-effective-target signal } */
       5  
       6  #include <stdio.h>
       7  #include <signal.h>
       8  
       9  extern void body_of_program(void);
      10  
      11  void custom_logger(const char *msg)
      12  {
      13    fprintf(stderr, "LOG: %s", msg); /* { dg-warning "call to 'fprintf' from within signal handler" } */
      14  }
      15  
      16  static void handler(int signum)
      17  {
      18    custom_logger("got signal");
      19  }
      20  
      21  int main(int argc, const char *argv)
      22  {
      23    custom_logger("started");
      24  
      25    signal(SIGINT, handler); /* { dg-message "registering 'handler' as signal handler" } */
      26  
      27    body_of_program();
      28  
      29    custom_logger("stopped");
      30  
      31    return 0;
      32  }