title: libsigsegv and responding to a stack overflow
body: <p>We are attempting to test student code, and in an effort to automate the process, we'd like to detect if a student's code overflows the stack.</p>
  
  <p>I've met with some success using the libsigsegv library and its corresponding stackoverflow_install_handler. It works brilliantly, until the student's code blows the stack twice.</p>
  
  <p>For example, here's some sample output:</p>
  
  <pre><code>[# ~]$ ledit ./interpreter
  -&gt; (use solution)
  -&gt; (fun 1 2)
  
  *** Stack overflow detected ***
  -&gt; (fun 1 2)
  Signal -10
  [# ~]
  </code></pre>
  
  <p>The initial "<strong>* Stack overflow detected *</strong>" is the desirable output. After blowing the stack for the second time, all I get is an unhelpful "Signal -10" and the program stops execution. I'd like to see the stack overflow detected message again, and let the code continue execution.</p>
  
  <p>In my stack overflow handler, I'm just printing the overflow detection message to stderr and long jumping back to an "awaiting input state" in the interpreter.</p>
  
  <p>Thanks for any help!</p>
  
  <p><em>EDIT</em></p>
  
  <p>As per caf's suggestion below, we've added a call to sigsegv_leave_handler() like so:</p>
  
  <pre><code>static void continuation(void *arg1, void *arg2, void *arg3) {                  
    (void)(arg1);                                                                 
    (void)(arg2);                                                                 
    (void)(arg3);                                                                 
    siglongjmp(errorjmp, 1);                                                      
  }                                                                               
  
  static void handler(int emergency, stackoverflow_context_t context) {           
   (void)emergency;                                                               
   (void)context;                                                                 
   fprintf(stderr, "\n*** Stack overflow detected ***\n");                        
   fflush(stderr);                                                                
   sigsegv_leave_handler(continuation, NULL, NULL, NULL);                         
  }  
  </code></pre>
  
  <p>However, the output is still the same.</p>