#4942: GHC.ConsoleHandler does not call back application when Close button is
pressed
------------------------+---------------------------------------------------
    Reporter:  Amatic   |        Owner:                             
        Type:  bug      |       Status:  new                        
    Priority:  normal   |    Milestone:  7.4.1                      
   Component:  GHC API  |      Version:  6.12.3                     
    Keywords:           |     Testcase:                             
   Blockedby:           |   Difficulty:                             
          Os:  Windows  |     Blocking:                             
Architecture:  x86      |      Failure:  Incorrect result at runtime
------------------------+---------------------------------------------------

Comment(by fryguybob):

 It looks like this behavior is by design, looking in
 rts/win32/ConsoleHandler.c:

 {{{
 #!C
 static BOOL WINAPI generic_handler(DWORD dwCtrlType)
 {
     /* Ultra-simple -- up the counter + signal a switch. */
     switch(dwCtrlType) {
     case CTRL_CLOSE_EVENT:
         /* Don't support the delivery of this event; if we
          * indicate that we've handled it here and the Haskell handler
          * doesn't take proper action (e.g., terminate the OS process),
          * the user of the app will be unable to kill/close it. Not
          * good, so disable the delivery for now.
          */
         return FALSE;
     default:
         if (!deliver_event) return TRUE;

 #if defined(THREADED_RTS)
         sendIOManagerEvent((StgWord8) ((dwCtrlType<<1) | 1));
 #else
         if ( stg_pending_events < N_PENDING_EVENTS ) {
             stg_pending_buf[stg_pending_events] = dwCtrlType;
             stg_pending_events++;
         }

         // we need to wake up awaitEvent()
         abandonRequestWait();
 #endif
         return TRUE;
     }
 }
 }}}

 To get the behavior desired `CTRL_CLOSE_EVENT` would have to be handled
 before `generic_handler` returns and have it return `FALSE` to which
 windows responds by terminating the process or never return and ensure
 that `rts_ConsoleHandlerDone`  terminates the process in the cases of
 `CTRL_CLOSE_EVENT`, `CTRL_LOGOFF_EVENT`, or `CTRL_SHUTDOWN_EVENT`.  I
 suppose there could be situations where returning `TRUE` could be desired
 but the API given in `GHC.ConsoleHandler` doesn't provide for that and I'm
 not sure it is particularly friendly to users (see remarks in the
 [http://msdn.microsoft.com/en-us/library/ms683242(VS.85).aspx MSDN docs]).

 I don't know enough about the implications of not returning from
 `generic_handler` and having `rts_ConsoleHandlerDone` terminate the
 process, but I think I will experiment a little and see what happens.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4942#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to