--- rpl/src/interruptions.c 2011/08/09 11:31:36 1.60 +++ rpl/src/interruptions.c 2011/09/04 07:46:08 1.64 @@ -1991,20 +1991,12 @@ interruption2(SIGHANDLER_ARGS) void interruption3(SIGHANDLER_ARGS) { - pid_t pid; + pthread_t thread; struct_processus *s_etat_processus; - static int compteur = 0; - verrouillage_gestionnaire_signaux(); -# ifdef _BROKEN_SIGINFO - pid = origine_signal(signal); -# else - pid = (*siginfo).si_pid; -# endif - if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) { deverrouillage_gestionnaire_signaux(); @@ -2029,24 +2021,79 @@ interruption3(SIGHANDLER_ARGS) // Segfault dans une routine interne if (strncmp(getenv("LANG"), "fr", 2) == 0) { - printf("+++Système : Violation d'accès (dépassement de pile)\n"); + printf("+++Système : Violation d'accès\n"); } else { - printf("+++System : Access violation (stack overflow)\n"); + printf("+++System : Access violation\n"); } fflush(stdout); - compteur++; + (*s_etat_processus).compteur_violation_d_acces++; - if (compteur > 1) + if ((*s_etat_processus).compteur_violation_d_acces > 1) { + // On vient de récupérer plus d'une erreur de segmentation + // dans le même processus ou le même thread. L'erreur n'est pas + // récupérable et on sort autoritairement du programme. Il peut + // rester des processus orphelins en attente ! + + if (strncmp(getenv("LANG"), "fr", 2) == 0) + { + printf("+++Système : Violation d'accès, tentative de " + "terminaison de la tâche\n"); + printf(" (defauts multiples)\n"); + } + else + { + printf("+++System : Access violation, trying to kill task " + "(multiple defaults)\n"); + } + + fflush(stdout); + deverrouillage_gestionnaire_signaux(); exit(EXIT_FAILURE); } else { + // Première erreur de segmentation. On essaie de terminer + // proprement le thread ou le processus. Le signal ne peut être + // envoyé que depuis le même processus. + + if (recherche_thread_principal(getpid(), &thread) == d_vrai) + { + if (pthread_equal(thread, pthread_self()) != 0) + { + deverrouillage_gestionnaire_signaux(); + + if ((*s_etat_processus).pid_processus_pere != getpid()) + { + // On est dans le thread principal d'un processus. + + longjmp(contexte_processus, -1); + } + else + { + // On est dans le thread principal du processus + // père. + + longjmp(contexte_initial, -1); + } + } + else + { + // On est dans un thread fils d'un thread principal. + + deverrouillage_gestionnaire_signaux(); + longjmp(contexte_thread, -1); + } + } + + // Là, on ramasse les miettes puisque le thread n'existe plus + // dans la base (corruption de la mémoire). + deverrouillage_gestionnaire_signaux(); longjmp(contexte_initial, -1); } @@ -2059,18 +2106,10 @@ interruption3(SIGHANDLER_ARGS) void interruption4(SIGHANDLER_ARGS) { - pid_t pid; - struct_processus *s_etat_processus; verrouillage_gestionnaire_signaux(); -# ifdef _BROKEN_SIGINFO - pid = origine_signal(signal); -# else - pid = (*siginfo).si_pid; -# endif - if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) { deverrouillage_gestionnaire_signaux(); @@ -2167,18 +2206,10 @@ interruption5(SIGHANDLER_ARGS) void interruption6(SIGHANDLER_ARGS) { - pid_t pid; - struct_processus *s_etat_processus; verrouillage_gestionnaire_signaux(); -# ifdef _BROKEN_SIGINFO - pid = origine_signal(signal); -# else - pid = (*siginfo).si_pid; -# endif - if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) { deverrouillage_gestionnaire_signaux(); @@ -2199,18 +2230,10 @@ interruption6(SIGHANDLER_ARGS) void interruption7(SIGHANDLER_ARGS) { - pid_t pid; - struct_processus *s_etat_processus; verrouillage_gestionnaire_signaux(); -# ifdef _BROKEN_SIGINFO - pid = origine_signal(signal); -# else - pid = (*siginfo).si_pid; -# endif - if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) { deverrouillage_gestionnaire_signaux(); @@ -2286,18 +2309,10 @@ interruption8(SIGHANDLER_ARGS) void interruption9(SIGHANDLER_ARGS) { - pid_t pid; - struct_processus *s_etat_processus; verrouillage_gestionnaire_signaux(); -# ifdef _BROKEN_SIGINFO - pid = origine_signal(signal); -# else - pid = (*siginfo).si_pid; -# endif - if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) { deverrouillage_gestionnaire_signaux(); @@ -2331,20 +2346,12 @@ interruption10(SIGHANDLER_ARGS) { file *fichier; - pid_t pid; - struct_processus *s_etat_processus; unsigned char nom[8 + 64 + 1]; verrouillage_gestionnaire_signaux(); -# ifdef _BROKEN_SIGINFO - pid = origine_signal(signal); -# else - pid = (*siginfo).si_pid; -# endif - if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) { deverrouillage_gestionnaire_signaux();