src/SDL_fatal.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 01 Feb 2006 06:32:25 +0000
changeset 1312 c9b51268668f
parent 1152 51a8702d8ecd
child 1330 450721ad5436
permissions -rw-r--r--
Updated copyright information and removed rcs id lines (problematic in branch merges) I batch edited these files, so please let me know if I've accidentally removed anybody's credit here.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1152
diff changeset
     3
    Copyright (C) 1997-2006 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1152
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1152
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1152
diff changeset
    13
    Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1152
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1152
diff changeset
    16
    License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1152
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    19
    Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 1
diff changeset
    20
    slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    21
*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
1152
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 861
diff changeset
    23
#ifdef _WIN32_WCE
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 861
diff changeset
    24
#define NO_SIGNAL_H
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 861
diff changeset
    25
#endif
51a8702d8ecd Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents: 861
diff changeset
    26
 
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
/* General fatal signal handling code for SDL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    28
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    29
#ifdef NO_SIGNAL_H
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    30
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    31
/* No signals on this platform, nothing to do.. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    32
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    33
void SDL_InstallParachute(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    34
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    35
	return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    36
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    37
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    38
void SDL_UninstallParachute(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    39
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    40
	return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    41
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    42
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    43
#else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    44
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    45
#include <stdlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    46
#include <stdio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    47
#include <signal.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    48
#include <string.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    49
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    50
#include "SDL.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    51
#include "SDL_fatal.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    52
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    53
#ifdef __CYGWIN__
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    54
#define DISABLE_STDIO
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    55
#endif
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    56
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    57
/* This installs some signal handlers for the more common fatal signals,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    58
   so that if the programmer is lazy, the app doesn't die so horribly if
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    59
   the program crashes.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    60
*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    61
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    62
static void print_msg(const char *text)
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    63
{
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    64
#ifndef DISABLE_STDIO
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    65
	fprintf(stderr, "%s", text);
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    66
#endif
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    67
}
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    68
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    69
static void SDL_Parachute(int sig)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    70
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    71
	signal(sig, SIG_DFL);
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    72
	print_msg("Fatal signal: ");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    73
	switch (sig) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    74
		case SIGSEGV:
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    75
			print_msg("Segmentation Fault");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    76
			break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    77
#ifdef SIGBUS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    78
#if SIGBUS != SIGSEGV
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    79
		case SIGBUS:
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    80
			print_msg("Bus Error");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    81
			break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    82
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    83
#endif /* SIGBUS */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    84
#ifdef SIGFPE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    85
		case SIGFPE:
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    86
			print_msg("Floating Point Exception");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    87
			break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    88
#endif /* SIGFPE */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    89
#ifdef SIGQUIT
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    90
		case SIGQUIT:
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    91
			print_msg("Keyboard Quit");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    92
			break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    93
#endif /* SIGQUIT */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    94
#ifdef SIGPIPE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    95
		case SIGPIPE:
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
    96
			print_msg("Broken Pipe");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    97
			break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    98
#endif /* SIGPIPE */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    99
		default:
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   100
#ifndef DISABLE_STDIO
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   101
			fprintf(stderr, "# %d", sig);
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   102
#endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   103
			break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   104
	}
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   105
	print_msg(" (SDL Parachute Deployed)\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   106
	SDL_Quit();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   107
	exit(-sig);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   108
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   109
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   110
static int SDL_fatal_signals[] = {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   111
	SIGSEGV,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   112
#ifdef SIGBUS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   113
	SIGBUS,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   114
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   115
#ifdef SIGFPE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   116
	SIGFPE,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   117
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   118
#ifdef SIGQUIT
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   119
	SIGQUIT,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   120
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   121
	0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   122
};
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   123
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   124
void SDL_InstallParachute(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   125
{
814
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   126
	/* Set a handler for any fatal signal not already handled */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   127
	int i;
814
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   128
#ifdef HAVE_SIGACTION
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   129
	struct sigaction action;
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   130
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   131
	for ( i=0; SDL_fatal_signals[i]; ++i ) {
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   132
		sigaction(SDL_fatal_signals[i], NULL, &action);
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   133
		if ( action.sa_handler == SIG_DFL ) {
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   134
			action.sa_handler = SDL_Parachute;
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   135
			sigaction(SDL_fatal_signals[i], &action, NULL);
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   136
		}
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   137
	}
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   138
#ifdef SIGALRM
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   139
	/* Set SIGALRM to be ignored -- necessary on Solaris */
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   140
	sigaction(SIGALRM, NULL, &action);
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   141
	if ( action.sa_handler == SIG_DFL ) {
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   142
		action.sa_handler = SIG_IGN;
861
863da1c38c7e Oops, ignore SIGALRM, not 0
Sam Lantinga <slouken@libsdl.org>
parents: 822
diff changeset
   143
		sigaction(SIGALRM, &action, NULL);
814
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   144
	}
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   145
#endif
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   146
#else
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   147
	void (*ohandler)(int);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   148
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   149
	for ( i=0; SDL_fatal_signals[i]; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   150
		ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   151
		if ( ohandler != SIG_DFL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   152
			signal(SDL_fatal_signals[i], ohandler);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   153
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   154
	}
814
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   155
#endif /* HAVE_SIGACTION */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   156
	return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   157
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   158
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   159
void SDL_UninstallParachute(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   160
{
814
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   161
	/* Remove a handler for any fatal signal handled */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   162
	int i;
814
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   163
#ifdef HAVE_SIGACTION
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   164
	struct sigaction action;
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   165
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   166
	for ( i=0; SDL_fatal_signals[i]; ++i ) {
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   167
		sigaction(SDL_fatal_signals[i], NULL, &action);
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   168
		if ( action.sa_handler == SDL_Parachute ) {
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   169
			action.sa_handler = SIG_DFL;
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   170
			sigaction(SDL_fatal_signals[i], &action, NULL);
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   171
		}
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   172
	}
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   173
#else
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   174
	void (*ohandler)(int);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   175
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   176
	for ( i=0; SDL_fatal_signals[i]; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   177
		ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   178
		if ( ohandler != SDL_Parachute ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   179
			signal(SDL_fatal_signals[i], ohandler);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   180
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   181
	}
814
5a417d2a8603 Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   182
#endif /* HAVE_SIGACTION */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   183
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   184
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   185
#endif /* NO_SIGNAL_H */