Implemented last-chance recovery that saves the current and spare page. (issue 97)

Tested OK on Windows when crashing Contour (issue 119)
Doesn't handle frozen states (when killed in task manager), I'll have to look further.


git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@628 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud
2009-02-13 01:12:52 +00:00
parent 546dc6011f
commit d704c4f425
6 changed files with 164 additions and 14 deletions

59
init.c
View File

@@ -22,6 +22,11 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Signal handler: I activate it for the two platforms who certainly
// support them. Feel free to check with others.
#if defined(__WIN32__) || defined(__linux__)
#define GRAFX2_CATCHES_SIGNALS
#endif
#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
@@ -36,10 +41,12 @@
#if defined(__WIN32__)
#include <windows.h> // GetLogicalDrives(), GetDriveType(), DRIVE_*
#endif
#if defined(__amigaos4__) || defined(__AROS__) || defined(__MORPHOS__)
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/dos.h>
#endif
#ifdef GRAFX2_CATCHES_SIGNALS
#include <signal.h>
#endif
#include "const.h"
@@ -60,6 +67,7 @@
#include "windows.h"
#include "sdlscreen.h"
#include "mountlist.h" // read_file_system_list
#include "loadsave.h" // Image_emergency_backup
// Ajouter un lecteur à la liste de lecteurs
void Ajouter_lecteur(char Lettre, byte Type, char *Chemin)
@@ -72,7 +80,6 @@ void Ajouter_lecteur(char Lettre, byte Type, char *Chemin)
Nb_drives++;
}
// Rechercher la liste et le type des lecteurs de la machine
#if defined(__amigaos4__) || defined(__AROS__) || defined(__MORPHOS__)
@@ -2364,3 +2371,47 @@ void Config_par_defaut(void)
Snap_Decalage_X=Snap_Decalage_Y=0;
}
#ifdef GRAFX2_CATCHES_SIGNALS
// Memorize the signal handlers of SDL
__p_sig_fn_t Handler_TERM=SIG_DFL;
__p_sig_fn_t Handler_INT=SIG_DFL;
__p_sig_fn_t Handler_ABRT=SIG_DFL;
__p_sig_fn_t Handler_SEGV=SIG_DFL;
__p_sig_fn_t Handler_FPE=SIG_DFL;
void sig_handler(int sig)
{
// Restore default behaviour
signal(SIGTERM, Handler_TERM);
signal(SIGINT, Handler_INT);
signal(SIGABRT, Handler_ABRT);
signal(SIGSEGV, Handler_SEGV);
signal(SIGFPE, Handler_FPE);
switch(sig)
{
case SIGTERM:
case SIGINT:
case SIGABRT:
case SIGSEGV:
Image_emergency_backup();
default:
break;
}
}
#endif
void Initialiser_sighandler(void)
{
#ifdef GRAFX2_CATCHES_SIGNALS
Handler_TERM=signal(SIGTERM,sig_handler);
Handler_INT =signal(SIGINT,sig_handler);
Handler_ABRT=signal(SIGABRT,sig_handler);
Handler_SEGV=signal(SIGSEGV,sig_handler);
Handler_FPE =signal(SIGFPE,sig_handler);
#endif
}