src/events/SDL_quit.c
branchSDL-1.2
changeset 5492 b214b7ce9b00
parent 4159 a1b03ba2fcd0
child 5500 27348c0ae529
equal deleted inserted replaced
5394:67d3be4ec9f2 5492:b214b7ce9b00
    43 #endif /* HAVE_SIGNAL_H */
    43 #endif /* HAVE_SIGNAL_H */
    44 
    44 
    45 /* Public functions */
    45 /* Public functions */
    46 int SDL_QuitInit(void)
    46 int SDL_QuitInit(void)
    47 {
    47 {
    48 #ifdef HAVE_SIGNAL_H
    48 #ifdef HAVE_SIGACTION
       
    49 	struct sigaction action;
       
    50 	sigaction(SIGINT, NULL, &action);
       
    51 	if ( action.sa_handler == SIG_DFL && action.sa_sigaction == SIG_DFL ) {
       
    52 		action.sa_handler = SDL_HandleSIG;
       
    53 		sigaction(SIGINT, &action, NULL);
       
    54 	}
       
    55 	sigaction(SIGTERM, NULL, &action);
       
    56 	if ( action.sa_handler == SIG_DFL && action.sa_sigaction == SIG_DFL ) {
       
    57 		action.sa_handler = SDL_HandleSIG;
       
    58 		sigaction(SIGTERM, &action, NULL);
       
    59 	}
       
    60 #elif HAVE_SIGNAL_H
    49 	void (*ohandler)(int);
    61 	void (*ohandler)(int);
    50 
    62 
    51 	/* Both SIGINT and SIGTERM are translated into quit interrupts */
    63 	/* Both SIGINT and SIGTERM are translated into quit interrupts */
    52 	ohandler = signal(SIGINT, SDL_HandleSIG);
    64 	ohandler = signal(SIGINT, SDL_HandleSIG);
    53 	if ( ohandler != SIG_DFL )
    65 	if ( ohandler != SIG_DFL )
    60 	/* That's it! */
    72 	/* That's it! */
    61 	return(0);
    73 	return(0);
    62 }
    74 }
    63 void SDL_QuitQuit(void)
    75 void SDL_QuitQuit(void)
    64 {
    76 {
    65 #ifdef HAVE_SIGNAL_H
    77 #ifdef HAVE_SIGACTION
       
    78 	struct sigaction action;
       
    79 	sigaction(SIGINT, NULL, &action);
       
    80 	if ( action.sa_handler == SDL_HandleSIG ) {
       
    81 		action.sa_handler = SIG_DFL;
       
    82 		sigaction(SIGINT, &action, NULL);
       
    83 	}
       
    84 	sigaction(SIGTERM, NULL, &action);
       
    85 	if ( action.sa_handler == SDL_HandleSIG ) {
       
    86 		action.sa_handler = SIG_DFL;
       
    87 		sigaction(SIGTERM, &action, NULL);
       
    88 	}
       
    89 #elif HAVE_SIGNAL_H
    66 	void (*ohandler)(int);
    90 	void (*ohandler)(int);
    67 
    91 
    68 	ohandler = signal(SIGINT, SIG_DFL);
    92 	ohandler = signal(SIGINT, SIG_DFL);
    69 	if ( ohandler != SDL_HandleSIG )
    93 	if ( ohandler != SDL_HandleSIG )
    70 		signal(SIGINT, ohandler);
    94 		signal(SIGINT, ohandler);