relancer une application après une erreur critique
Le
Vincent Torri
Je voudrais connaître le moyen usuel pour relancer une application après
une erreur critique (comme un segmentation fault. Visual Studio, quand il
plante, se relance par exemple). Déjà, pour récupérer l'erreur, j'utilise
signal() ainsi :
[code]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
typedef void (*Es_Signal_Cb)(int);
static void
_es_signal_cb(int signal)
{
if (signal == SIGSEGV)
{
printf("access violation");
}
else if (signal == SIGILL)
{
printf("illegal instruction");
}
else if (signal == SIGFPE)
{
printf("floating point error");
}
else if (signal == SIGABRT)
{
printf("abnormal termination");
}
else
{
printf("unexpected signal (%d)", signal);
return;
}
}
int main()
{
Es_Signal_Cb previous_cb;
/* access violation (SIGSEGV) */
previous_cb = signal(SIGSEGV, _es_signal_segv_cb);
if (previous_cb == SIG_ERR)
{
printf("can not set up signal handler SIGSEGV (%s)", strerror
(errno));
printf("Exiting");
return -1;
}
/* illegal instruction (SIGILL) */
previous_cb = signal(SIGILL, _es_signal_ill_cb);
if (previous_cb == SIG_ERR)
{
printf("can not set up signal handler SIGILL (%s)", strerror
(errno));
printf("Exiting");
return -1;
}
/* floating point error (SIGFPE) */
previous_cb = signal(SIGFPE, _es_signal_fpe_cb);
if (previous_cb == SIG_ERR)
{
printf("can not set up signal handler SIGFPE (%s)", strerror
(errno));
printf("Exiting");
return -1;
}
/* abnormal termination (SIGABRT) */
previous_cb = signal(SIGABRT, _es_signal_abrt_cb);
if (previous_cb == SIG_ERR)
{
printf("can not set up signal handler SIGABRT (%s)", strerror
(errno));
printf("Exiting");
return -1;
}
abort();
return 0;
}
[/code]
(abort() est là pour faire un test). Donc il faut que je rajoute du code
dans _es_signal_cb() pour relancer l'application. Mais je n'ai pas trop
d'idées (je pourrais avec un execvp() relancer l'appli, peut-être)
Quelqu'un connaît-il le moyen standard pour faire ceci ?
Merci
une erreur critique (comme un segmentation fault. Visual Studio, quand il
plante, se relance par exemple). Déjà, pour récupérer l'erreur, j'utilise
signal() ainsi :
[code]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
typedef void (*Es_Signal_Cb)(int);
static void
_es_signal_cb(int signal)
{
if (signal == SIGSEGV)
{
printf("access violation");
}
else if (signal == SIGILL)
{
printf("illegal instruction");
}
else if (signal == SIGFPE)
{
printf("floating point error");
}
else if (signal == SIGABRT)
{
printf("abnormal termination");
}
else
{
printf("unexpected signal (%d)", signal);
return;
}
}
int main()
{
Es_Signal_Cb previous_cb;
/* access violation (SIGSEGV) */
previous_cb = signal(SIGSEGV, _es_signal_segv_cb);
if (previous_cb == SIG_ERR)
{
printf("can not set up signal handler SIGSEGV (%s)", strerror
(errno));
printf("Exiting");
return -1;
}
/* illegal instruction (SIGILL) */
previous_cb = signal(SIGILL, _es_signal_ill_cb);
if (previous_cb == SIG_ERR)
{
printf("can not set up signal handler SIGILL (%s)", strerror
(errno));
printf("Exiting");
return -1;
}
/* floating point error (SIGFPE) */
previous_cb = signal(SIGFPE, _es_signal_fpe_cb);
if (previous_cb == SIG_ERR)
{
printf("can not set up signal handler SIGFPE (%s)", strerror
(errno));
printf("Exiting");
return -1;
}
/* abnormal termination (SIGABRT) */
previous_cb = signal(SIGABRT, _es_signal_abrt_cb);
if (previous_cb == SIG_ERR)
{
printf("can not set up signal handler SIGABRT (%s)", strerror
(errno));
printf("Exiting");
return -1;
}
abort();
return 0;
}
[/code]
(abort() est là pour faire un test). Donc il faut que je rajoute du code
dans _es_signal_cb() pour relancer l'application. Mais je n'ai pas trop
d'idées (je pourrais avec un execvp() relancer l'appli, peut-être)
Quelqu'un connaît-il le moyen standard pour faire ceci ?
Merci

Poser une question


Sous Windows, c'est les SEH et depuis Vista, avec les apis genre
RegisterApplicationRestart
http://msdn.microsoft.com/en-us/lib...p/ee663265(v=VS.85).aspx
Je fais ça avec un simple programme à qui je passe en argument le nom de
l'appli à relancer avec ses arguments, après un délai permettant à
l'appelant de vider les lieux. Simple mais efficace.
news:4ef9afb5$0$5681$:
ok, merci. Avec execvp ou CreateProcess ?
J'utilise plutôt CreateProcess(), mais ça doit marcher aussi avec un
ShellExecute() ou autres.