File:  [local] / rpl / src / interruptions.c
Revision 1.46.2.3: download - view: text, annotated - select for diffs - revision graph
Mon May 9 13:52:23 2011 UTC (12 years, 11 months ago) by bertrand
Branches: rpl-4_0
Diff to: branchpoint 1.46: preferred, colored
En route pour la 4.0.24...

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.0.24
    4:   Copyright (C) 1989-2011 Dr. BERTRAND Joël
    5: 
    6:   This file is part of RPL/2.
    7: 
    8:   RPL/2 is free software; you can redistribute it and/or modify it
    9:   under the terms of the CeCILL V2 License as published by the french
   10:   CEA, CNRS and INRIA.
   11:  
   12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
   13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
   15:   for more details.
   16:  
   17:   You should have received a copy of the CeCILL License
   18:   along with RPL/2. If not, write to info@cecill.info.
   19: ================================================================================
   20: */
   21: 
   22: 
   23: #include "rpl-conv.h"
   24: 
   25: 
   26: /*
   27: ================================================================================
   28:   Procédures de gestion par thread des variables issues des gestionnaires
   29:   de signaux
   30: ================================================================================
   31:   Entrée : variable globale
   32: --------------------------------------------------------------------------------
   33:   Sortie : variable globale modifiée
   34: --------------------------------------------------------------------------------
   35:   Effets de bord : néant
   36: ================================================================================
   37: */
   38: 
   39: typedef struct thread
   40: {
   41:     pid_t               pid;
   42:     pthread_t           tid;
   43: 
   44:     logical1            thread_principal;
   45: 
   46:     struct_processus    *s_etat_processus;
   47: } struct_thread;
   48: 
   49: typedef struct liste_chainee_volatile
   50: {
   51:     volatile struct liste_chainee_volatile  *suivant;
   52:     volatile void                           *donnee;
   53: } struct_liste_chainee_volatile;
   54: 
   55: 
   56: static volatile struct_liste_chainee_volatile   *liste_threads
   57:         = NULL;
   58: static volatile struct_liste_chainee_volatile   *liste_threads_surveillance
   59:         = NULL;
   60: 
   61: void
   62: modification_pid_thread_pere(struct_processus *s_etat_processus)
   63: {
   64:     // La variable existe toujours et aucun thread concurrent ne peut
   65:     // la modifier puisque cette routine ne peut être appelée que depuis
   66:     // DAEMON.
   67: 
   68:     (*((struct_thread *) (*liste_threads).donnee)).pid =
   69:             (*s_etat_processus).pid_processus_pere;
   70: 
   71:     return;
   72: }
   73: 
   74: void
   75: insertion_thread(struct_processus *s_etat_processus, logical1 thread_principal)
   76: {
   77:     sigset_t                                    oldset;
   78:     sigset_t                                    set;
   79: 
   80:     volatile struct_liste_chainee_volatile      *l_nouvel_objet;
   81: 
   82:     sigfillset(&set);
   83:     pthread_sigmask(SIG_BLOCK, &set, &oldset);
   84: 
   85:     if ((l_nouvel_objet = malloc(sizeof(struct_liste_chainee_volatile)))
   86:             == NULL)
   87:     {
   88:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
   89:         sigpending(&set);
   90: 
   91:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
   92:         return;
   93:     }
   94: 
   95:     if (((*l_nouvel_objet).donnee = malloc(sizeof(struct_thread))) == NULL)
   96:     {
   97:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
   98:         sigpending(&set);
   99: 
  100:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  101:         return;
  102:     }
  103: 
  104:     (*((struct_thread *) (*l_nouvel_objet).donnee)).pid = getpid();
  105:     (*((struct_thread *) (*l_nouvel_objet).donnee)).tid = pthread_self();
  106:     (*((struct_thread *) (*l_nouvel_objet).donnee)).thread_principal =
  107:             thread_principal;
  108:     (*((struct_thread *) (*l_nouvel_objet).donnee)).s_etat_processus =
  109:             s_etat_processus;
  110: 
  111: #   ifndef SEMAPHORES_NOMMES
  112:     while(sem_wait(&semaphore_liste_threads) == -1)
  113: #   else
  114:     while(sem_wait(semaphore_liste_threads) == -1)
  115: #   endif
  116:     {
  117:         if (errno != EINTR)
  118:         {
  119:             pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  120:             sigpending(&set);
  121: 
  122:             (*s_etat_processus).erreur_systeme = d_es_processus;
  123:             return;
  124:         }
  125:     }
  126: 
  127:     (*l_nouvel_objet).suivant = liste_threads;
  128:     liste_threads = l_nouvel_objet;
  129: 
  130: #   ifndef SEMAPHORES_NOMMES
  131:     if (sem_post(&semaphore_liste_threads) != 0)
  132: #   else
  133:     if (sem_post(semaphore_liste_threads) != 0)
  134: #   endif
  135:     {
  136:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  137:         sigpending(&set);
  138: 
  139:         (*s_etat_processus).erreur_systeme = d_es_processus;
  140:         return;
  141:     }
  142: 
  143:     pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  144:     sigpending(&set);
  145:     return;
  146: }
  147: 
  148: void
  149: insertion_thread_surveillance(struct_processus *s_etat_processus,
  150:         struct_descripteur_thread *s_argument_thread)
  151: {
  152:     sigset_t                                    oldset;
  153:     sigset_t                                    set;
  154: 
  155:     volatile struct_liste_chainee_volatile      *l_nouvel_objet;
  156: 
  157:     sigfillset(&set);
  158:     pthread_sigmask(SIG_BLOCK, &set, &oldset);
  159: 
  160:     if ((l_nouvel_objet = malloc(sizeof(struct_liste_chainee_volatile)))
  161:             == NULL)
  162:     {
  163:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  164:         sigpending(&set);
  165: 
  166:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  167:         return;
  168:     }
  169: 
  170: #   ifndef SEMAPHORES_NOMMES
  171:     while(sem_wait(&semaphore_liste_threads) == -1)
  172: #   else
  173:     while(sem_wait(semaphore_liste_threads) == -1)
  174: #   endif
  175:     {
  176:         if (errno != EINTR)
  177:         {
  178:             pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  179:             sigpending(&set);
  180: 
  181:             (*s_etat_processus).erreur_systeme = d_es_processus;
  182:             return;
  183:         }
  184:     }
  185: 
  186:     pthread_mutex_lock(&((*s_argument_thread).mutex_nombre_references));
  187:     (*s_argument_thread).nombre_references++;
  188:     pthread_mutex_unlock(&((*s_argument_thread).mutex_nombre_references));
  189: 
  190:     (*l_nouvel_objet).suivant = liste_threads_surveillance;
  191:     (*l_nouvel_objet).donnee = (void *) s_argument_thread;
  192: 
  193:     liste_threads_surveillance = l_nouvel_objet;
  194: 
  195: #   ifndef SEMAPHORES_NOMMES
  196:     if (sem_post(&semaphore_liste_threads) != 0)
  197: #   else
  198:     if (sem_post(semaphore_liste_threads) != 0)
  199: #   endif
  200:     {
  201:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  202:         sigpending(&set);
  203: 
  204:         (*s_etat_processus).erreur_systeme = d_es_processus;
  205:         return;
  206:     }
  207: 
  208:     pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  209:     sigpending(&set);
  210:     return;
  211: }
  212: 
  213: void
  214: retrait_thread(struct_processus *s_etat_processus)
  215: {
  216:     sigset_t                                oldset;
  217:     sigset_t                                set;
  218: 
  219:     volatile struct_liste_chainee_volatile  *l_element_precedent;
  220:     volatile struct_liste_chainee_volatile  *l_element_courant;
  221: 
  222:     sigfillset(&set);
  223:     pthread_sigmask(SIG_BLOCK, &set, &oldset);
  224: 
  225: #   ifndef SEMAPHORES_NOMMES
  226:     while(sem_wait(&semaphore_liste_threads) == -1)
  227: #   else
  228:     while(sem_wait(semaphore_liste_threads) == -1)
  229: #   endif
  230:     {
  231:         if (errno != EINTR)
  232:         {
  233:             pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  234:             sigpending(&set);
  235: 
  236:             (*s_etat_processus).erreur_systeme = d_es_processus;
  237:             return;
  238:         }
  239:     }
  240: 
  241:     l_element_precedent = NULL;
  242:     l_element_courant = liste_threads;
  243: 
  244:     while(l_element_courant != NULL)
  245:     {
  246:         if (((*((struct_thread *) (*l_element_courant).donnee)).pid
  247:                 == getpid()) && (pthread_equal((*((struct_thread *)
  248:                 (*l_element_courant).donnee)).tid, pthread_self()) != 0))
  249:         {
  250:             break;
  251:         }
  252: 
  253:         l_element_precedent = l_element_courant;
  254:         l_element_courant = (*l_element_courant).suivant;
  255:     }
  256: 
  257:     if (l_element_courant == NULL)
  258:     {
  259: #       ifndef SEMAPHORES_NOMMES
  260:         sem_post(&semaphore_liste_threads);
  261: #       else
  262:         sem_post(semaphore_liste_threads);
  263: #       endif
  264:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  265:         sigpending(&set);
  266: 
  267:         (*s_etat_processus).erreur_systeme = d_es_processus;
  268:         return;
  269:     }
  270: 
  271:     if (l_element_precedent == NULL)
  272:     {
  273:         liste_threads = (*l_element_courant).suivant;
  274:     }
  275:     else
  276:     {
  277:         (*l_element_precedent).suivant = (*l_element_courant).suivant;
  278:     }
  279: 
  280:     if (pthread_setspecific(semaphore_fork_processus_courant, NULL) != 0)
  281:     {
  282:         (*s_etat_processus).erreur_systeme = d_es_processus;
  283: 
  284: #       ifndef SEMAPHORES_NOMMES
  285:         sem_post(&semaphore_liste_threads);
  286: #       else
  287:         sem_post(semaphore_liste_threads);
  288: #       endif
  289:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  290:         sigpending(&set);
  291:         return;
  292:     }
  293: 
  294: #   ifndef SEMAPHORES_NOMMES
  295:     if (sem_post(&semaphore_liste_threads) != 0)
  296: #   else
  297:     if (sem_post(semaphore_liste_threads) != 0)
  298: #   endif
  299:     {
  300:         (*s_etat_processus).erreur_systeme = d_es_processus;
  301: 
  302:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  303:         sigpending(&set);
  304:         return;
  305:     }
  306: 
  307:     free((void *) (*l_element_courant).donnee);
  308:     free((struct_liste_chainee_volatile *) l_element_courant);
  309: 
  310:     pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  311:     sigpending(&set);
  312:     return;
  313: }
  314: 
  315: void
  316: retrait_thread_surveillance(struct_processus *s_etat_processus,
  317:         struct_descripteur_thread *s_argument_thread)
  318: {
  319:     sigset_t                                set;
  320:     sigset_t                                oldset;
  321: 
  322:     volatile struct_liste_chainee_volatile  *l_element_precedent;
  323:     volatile struct_liste_chainee_volatile  *l_element_courant;
  324: 
  325:     sigfillset(&set);
  326:     pthread_sigmask(SIG_BLOCK, &set, &oldset);
  327: 
  328: #   ifndef SEMAPHORES_NOMMES
  329:     while(sem_wait(&semaphore_liste_threads) == -1)
  330: #   else
  331:     while(sem_wait(semaphore_liste_threads) == -1)
  332: #   endif
  333:     {
  334:         if (errno != EINTR)
  335:         {
  336:             pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  337:             sigpending(&set);
  338: 
  339:             (*s_etat_processus).erreur_systeme = d_es_processus;
  340:             return;
  341:         }
  342:     }
  343: 
  344:     l_element_precedent = NULL;
  345:     l_element_courant = liste_threads_surveillance;
  346: 
  347:     while(l_element_courant != NULL)
  348:     {
  349:         if ((*l_element_courant).donnee == (void *) s_argument_thread)
  350:         {
  351:             break;
  352:         }
  353: 
  354:         l_element_precedent = l_element_courant;
  355:         l_element_courant = (*l_element_courant).suivant;
  356:     }
  357: 
  358:     if (l_element_courant == NULL)
  359:     {
  360: #       ifndef SEMAPHORES_NOMMES
  361:         sem_post(&semaphore_liste_threads);
  362: #       else
  363:         sem_post(semaphore_liste_threads);
  364: #       endif
  365:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  366:         sigpending(&set);
  367: 
  368:         (*s_etat_processus).erreur_systeme = d_es_processus;
  369:         return;
  370:     }
  371: 
  372:     if (l_element_precedent == NULL)
  373:     {
  374:         liste_threads_surveillance = (*l_element_courant).suivant;
  375:     }
  376:     else
  377:     {
  378:         (*l_element_precedent).suivant = (*l_element_courant).suivant;
  379:     }
  380: 
  381:     if (pthread_mutex_lock(&((*s_argument_thread).mutex_nombre_references))
  382:             != 0)
  383:     {
  384: #       ifndef SEMAPHORES_NOMMES
  385:         sem_post(&semaphore_liste_threads);
  386: #       else
  387:         sem_post(semaphore_liste_threads);
  388: #       endif
  389:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  390:         sigpending(&set);
  391: 
  392:         (*s_etat_processus).erreur_systeme = d_es_processus;
  393:         return;
  394:     }
  395: 
  396:     (*s_argument_thread).nombre_references--;
  397: 
  398:     BUG((*s_argument_thread).nombre_references < 0,
  399:             printf("(*s_argument_thread).nombre_references = %d\n",
  400:             (int) (*s_argument_thread).nombre_references));
  401: 
  402:     if ((*s_argument_thread).nombre_references == 0)
  403:     {
  404:         if (pthread_mutex_unlock(&((*s_argument_thread)
  405:                 .mutex_nombre_references)) != 0)
  406:         {
  407: #           ifndef SEMAPHORES_NOMMES
  408:             sem_post(&semaphore_liste_threads);
  409: #           else
  410:             sem_post(semaphore_liste_threads);
  411: #           endif
  412:             pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  413:             sigpending(&set);
  414: 
  415:             (*s_etat_processus).erreur_systeme = d_es_processus;
  416:             return;
  417:         }
  418: 
  419:         pthread_mutex_destroy(&((*s_argument_thread).mutex));
  420:         pthread_mutex_destroy(&((*s_argument_thread).mutex_nombre_references));
  421:         free(s_argument_thread);
  422:     }
  423:     else
  424:     {
  425:         if (pthread_mutex_unlock(&((*s_argument_thread)
  426:                 .mutex_nombre_references)) != 0)
  427:         {
  428: #           ifndef SEMAPHORES_NOMMES
  429:             sem_post(&semaphore_liste_threads);
  430: #           else
  431:             sem_post(semaphore_liste_threads);
  432: #           endif
  433:             pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  434:             sigpending(&set);
  435: 
  436:             (*s_etat_processus).erreur_systeme = d_es_processus;
  437:             return;
  438:         }
  439:     }
  440: 
  441: #   ifndef SEMAPHORES_NOMMES
  442:     if (sem_post(&semaphore_liste_threads) != 0)
  443: #   else
  444:     if (sem_post(semaphore_liste_threads) != 0)
  445: #   endif
  446:     {
  447:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  448:         sigpending(&set);
  449: 
  450:         (*s_etat_processus).erreur_systeme = d_es_processus;
  451:         return;
  452:     }
  453: 
  454:     free((struct_liste_chainee_volatile *) l_element_courant);
  455: 
  456:     pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  457:     sigpending(&set);
  458: 
  459:     return;
  460: }
  461: 
  462: void
  463: verrouillage_threads_concurrents(struct_processus *s_etat_processus)
  464: {
  465:     volatile struct_liste_chainee_volatile  *l_element_courant;
  466: 
  467: #   ifndef SEMAPHORES_NOMMES
  468:     while(sem_wait(&semaphore_liste_threads) == -1)
  469: #   else
  470:     while(sem_wait(semaphore_liste_threads) == -1)
  471: #   endif
  472:     {
  473:         if (errno != EINTR)
  474:         {
  475:             (*s_etat_processus).erreur_systeme = d_es_processus;
  476:             return;
  477:         }
  478:     }
  479: 
  480:     l_element_courant = liste_threads;
  481: 
  482:     while(l_element_courant != NULL)
  483:     {
  484:         if (((*((struct_thread *) (*l_element_courant).donnee)).pid
  485:                 == getpid()) && (pthread_equal((*((struct_thread *)
  486:                 (*l_element_courant).donnee)).tid, pthread_self()) == 0))
  487:         {
  488: #           ifndef SEMAPHORES_NOMMES
  489:             while(sem_wait(&((*(*((struct_thread *) (*l_element_courant)
  490:                     .donnee)).s_etat_processus).semaphore_fork)) == -1)
  491: #           else
  492:             while(sem_wait((*(*((struct_thread *) (*l_element_courant)
  493:                     .donnee)).s_etat_processus).semaphore_fork) == -1)
  494: #           endif
  495:             {
  496:                 if (errno != EINTR)
  497:                 {
  498:                     (*s_etat_processus).erreur_systeme = d_es_processus;
  499:                     return;
  500:                 }
  501:             }
  502:         }
  503: 
  504:         l_element_courant = (*l_element_courant).suivant;
  505:     }
  506: 
  507:     return;
  508: }
  509: 
  510: void
  511: deverrouillage_threads_concurrents(struct_processus *s_etat_processus)
  512: {
  513:     volatile struct_liste_chainee_volatile  *l_element_courant;
  514: 
  515:     l_element_courant = liste_threads;
  516: 
  517:     while(l_element_courant != NULL)
  518:     {
  519:         if (((*((struct_thread *) (*l_element_courant).donnee)).pid
  520:                 == getpid()) && (pthread_equal((*((struct_thread *)
  521:                 (*l_element_courant).donnee)).tid, pthread_self()) == 0))
  522:         {
  523: #           ifndef SEMAPHORES_NOMMES
  524:             if (sem_post(&((*(*((struct_thread *)
  525:                     (*l_element_courant).donnee)).s_etat_processus)
  526:                     .semaphore_fork)) != 0)
  527: #           else
  528:             if (sem_post((*(*((struct_thread *)
  529:                     (*l_element_courant).donnee)).s_etat_processus)
  530:                     .semaphore_fork) != 0)
  531: #           endif
  532:             {
  533: #               ifndef SEMAPHORES_NOMMES
  534:                 if (sem_post(&semaphore_liste_threads) != 0)
  535:                 {
  536:                     (*s_etat_processus).erreur_systeme = d_es_processus;
  537:                     return;
  538:                 }
  539: #               else
  540:                 if (sem_post(semaphore_liste_threads) != 0)
  541:                 {
  542:                     (*s_etat_processus).erreur_systeme = d_es_processus;
  543:                     return;
  544:                 }
  545: #               endif
  546: 
  547:                 (*s_etat_processus).erreur_systeme = d_es_processus;
  548:                 return;
  549:             }
  550:         }
  551: 
  552:         l_element_courant = (*l_element_courant).suivant;
  553:     }
  554: 
  555: #   ifndef SEMAPHORES_NOMMES
  556:     if (sem_post(&semaphore_liste_threads) != 0)
  557: #   else
  558:     if (sem_post(semaphore_liste_threads) != 0)
  559: #   endif
  560:     {
  561:         (*s_etat_processus).erreur_systeme = d_es_processus;
  562:         return;
  563:     }
  564: 
  565:     return;
  566: }
  567: 
  568: void
  569: liberation_threads(struct_processus *s_etat_processus)
  570: {
  571:     logical1                                    suppression_variables_partagees;
  572: 
  573:     sigset_t                                    oldset;
  574:     sigset_t                                    set;
  575: 
  576:     struct_descripteur_thread                   *s_argument_thread;
  577: 
  578:     struct_processus                            *candidat;
  579: 
  580:     unsigned long                               i;
  581: 
  582:     void                                        *element_candidat;
  583:     void                                        *element_courant;
  584:     void                                        *element_suivant;
  585: 
  586:     volatile struct_liste_chainee_volatile      *l_element_courant;
  587:     volatile struct_liste_chainee_volatile      *l_element_suivant;
  588: 
  589:     sigfillset(&set);
  590:     pthread_sigmask(SIG_BLOCK, &set, &oldset);
  591: 
  592: #   ifndef SEMAPHORES_NOMMES
  593:     while(sem_wait(&semaphore_liste_threads) == -1)
  594: #   else
  595:     while(sem_wait(semaphore_liste_threads) == -1)
  596: #   endif
  597:     {
  598:         if (errno != EINTR)
  599:         {
  600:             pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  601:             (*s_etat_processus).erreur_systeme = d_es_processus;
  602:             return;
  603:         }
  604:     }
  605: 
  606:     l_element_courant = liste_threads;
  607:     suppression_variables_partagees = d_faux;
  608: 
  609:     while(l_element_courant != NULL)
  610:     {
  611:         if ((*((struct_thread *) (*l_element_courant).donnee)).s_etat_processus
  612:                 != s_etat_processus)
  613:         {
  614:             candidat = s_etat_processus;
  615:             s_etat_processus = (*((struct_thread *)
  616:                     (*l_element_courant).donnee)).s_etat_processus;
  617:             free((*s_etat_processus).localisation);
  618: 
  619:             // (*s_etat_processus).instruction_courante peut pointer sur
  620:             // n'importe quoi (une instruction courante ou un champ d'une
  621:             // structure objet). On ne le libère pas quitte à avoir une
  622:             // petite fuite mémoire dans le processus fils.
  623: 
  624:             if ((*s_etat_processus).instruction_courante != NULL)
  625:             {
  626:                 //free((*s_etat_processus).instruction_courante);
  627:             }
  628: 
  629:             close((*s_etat_processus).pipe_acquittement);
  630:             close((*s_etat_processus).pipe_donnees);
  631:             close((*s_etat_processus).pipe_injections);
  632:             close((*s_etat_processus).pipe_nombre_injections);
  633:             close((*s_etat_processus).pipe_interruptions);
  634:             close((*s_etat_processus).pipe_nombre_objets_attente);
  635:             close((*s_etat_processus).pipe_nombre_interruptions_attente);
  636: 
  637:             liberation(s_etat_processus, (*s_etat_processus).at_exit);
  638: 
  639:             if ((*s_etat_processus).nom_fichier_impression != NULL)
  640:             {
  641:                 free((*s_etat_processus).nom_fichier_impression);
  642:             }
  643: 
  644:             while((*s_etat_processus).fichiers_graphiques != NULL)
  645:             {
  646:                 free((*(*s_etat_processus).fichiers_graphiques).nom);
  647: 
  648:                 if ((*(*s_etat_processus).fichiers_graphiques).legende != NULL)
  649:                 {
  650:                     free((*(*s_etat_processus).fichiers_graphiques).legende);
  651:                 }
  652: 
  653:                 element_courant = (*s_etat_processus).fichiers_graphiques;
  654:                 (*s_etat_processus).fichiers_graphiques =
  655:                         (*(*s_etat_processus).fichiers_graphiques).suivant;
  656: 
  657:                 free(element_courant);
  658:             }
  659: 
  660:             if ((*s_etat_processus).entree_standard != NULL)
  661:             {
  662:                 pclose((*s_etat_processus).entree_standard);
  663:             }
  664: 
  665:             if ((*s_etat_processus).generateur_aleatoire != NULL)
  666:             {
  667:                 liberation_generateur_aleatoire(s_etat_processus);
  668:             }
  669: 
  670:             if ((*s_etat_processus).instruction_derniere_erreur != NULL)
  671:             {
  672:                 free((*s_etat_processus).instruction_derniere_erreur);
  673:                 (*s_etat_processus).instruction_derniere_erreur = NULL;
  674:             }
  675: 
  676:             element_courant = (void *) (*s_etat_processus)
  677:                     .l_base_pile_processus;
  678:             while(element_courant != NULL)
  679:             {
  680:                 s_argument_thread = (struct_descripteur_thread *)
  681:                         (*((struct_liste_chainee *) element_courant)).donnee;
  682: 
  683:                 if (pthread_mutex_lock(&((*s_argument_thread)
  684:                         .mutex_nombre_references)) != 0)
  685:                 {
  686:                     (*s_etat_processus).erreur_systeme = d_es_processus;
  687:                     sem_post(&semaphore_liste_threads);
  688:                     return;
  689:                 }
  690: 
  691:                 (*s_argument_thread).nombre_references--;
  692: 
  693:                 BUG((*s_argument_thread).nombre_references < 0,
  694:                         printf("(*s_argument_thread).nombre_references = %d\n",
  695:                         (int) (*s_argument_thread).nombre_references));
  696: 
  697:                 if ((*s_argument_thread).nombre_references == 0)
  698:                 {
  699:                     close((*s_argument_thread).pipe_objets[0]);
  700:                     close((*s_argument_thread).pipe_acquittement[1]);
  701:                     close((*s_argument_thread).pipe_injections[1]);
  702:                     close((*s_argument_thread).pipe_nombre_injections[1]);
  703:                     close((*s_argument_thread).pipe_nombre_objets_attente[0]);
  704:                     close((*s_argument_thread).pipe_interruptions[0]);
  705:                     close((*s_argument_thread)
  706:                             .pipe_nombre_interruptions_attente[0]);
  707: 
  708:                     if (pthread_mutex_unlock(&((*s_argument_thread)
  709:                             .mutex_nombre_references)) != 0)
  710:                     {
  711:                         (*s_etat_processus).erreur_systeme = d_es_processus;
  712:                         sem_post(&semaphore_liste_threads);
  713:                         return;
  714:                     }
  715: 
  716:                     pthread_mutex_destroy(&((*s_argument_thread).mutex));
  717:                     pthread_mutex_destroy(&((*s_argument_thread)
  718:                             .mutex_nombre_references));
  719: 
  720:                     if ((*s_argument_thread).processus_detache == d_faux)
  721:                     {
  722:                         if ((*s_argument_thread).destruction_objet == d_vrai)
  723:                         {
  724:                             liberation(s_etat_processus, (*s_argument_thread)
  725:                                     .argument);
  726:                         }
  727:                     }
  728: 
  729:                     free(s_argument_thread);
  730:                 }
  731:                 else
  732:                 {
  733:                     if (pthread_mutex_unlock(&((*s_argument_thread)
  734:                             .mutex_nombre_references)) != 0)
  735:                     {
  736:                         (*s_etat_processus).erreur_systeme = d_es_processus;
  737:                         sem_post(&semaphore_liste_threads);
  738:                         return;
  739:                     }
  740:                 }
  741: 
  742:                 element_suivant = (*((struct_liste_chainee *) element_courant))
  743:                         .suivant;
  744:                 free(element_courant);
  745:                 element_courant = element_suivant;
  746:             }
  747: 
  748:             (*s_etat_processus).l_base_pile_processus = NULL;
  749: 
  750:             pthread_mutex_trylock(&((*(*s_etat_processus).indep).mutex));
  751:             pthread_mutex_unlock(&((*(*s_etat_processus).indep).mutex));
  752:             liberation(s_etat_processus, (*s_etat_processus).indep);
  753: 
  754:             pthread_mutex_trylock(&((*(*s_etat_processus).depend).mutex));
  755:             pthread_mutex_unlock(&((*(*s_etat_processus).depend).mutex));
  756:             liberation(s_etat_processus, (*s_etat_processus).depend);
  757: 
  758:             free((*s_etat_processus).label_x);
  759:             free((*s_etat_processus).label_y);
  760:             free((*s_etat_processus).label_z);
  761:             free((*s_etat_processus).titre);
  762:             free((*s_etat_processus).legende);
  763: 
  764:             pthread_mutex_trylock(&((*(*s_etat_processus)
  765:                     .parametres_courbes_de_niveau).mutex));
  766:             pthread_mutex_unlock(&((*(*s_etat_processus)
  767:                     .parametres_courbes_de_niveau).mutex));
  768:             liberation(s_etat_processus, (*s_etat_processus)
  769:                     .parametres_courbes_de_niveau);
  770: 
  771:             for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
  772:             {
  773:                 if ((*s_etat_processus).corps_interruptions[i] != NULL)
  774:                 {
  775:                     pthread_mutex_trylock(&((*(*s_etat_processus)
  776:                             .corps_interruptions[i]).mutex));
  777:                     pthread_mutex_unlock(&((*(*s_etat_processus)
  778:                             .corps_interruptions[i]).mutex));
  779: 
  780:                     liberation(s_etat_processus,
  781:                             (*s_etat_processus).corps_interruptions[i]);
  782:                 }
  783: 
  784:                 element_courant = (*s_etat_processus)
  785:                         .pile_origine_interruptions[i];
  786: 
  787:                 while(element_courant != NULL)
  788:                 {
  789:                     element_suivant = (*((struct_liste_chainee *)
  790:                             element_courant)).suivant;
  791: 
  792:                     pthread_mutex_trylock(&((*(*((struct_liste_chainee *)
  793:                             element_courant)).donnee).mutex));
  794:                     pthread_mutex_unlock(&((*(*((struct_liste_chainee *)
  795:                             element_courant)).donnee).mutex));
  796: 
  797:                     liberation(s_etat_processus,
  798:                             (*((struct_liste_chainee *) element_courant))
  799:                             .donnee);
  800:                     free(element_courant);
  801: 
  802:                     element_courant = element_suivant;
  803:                 }
  804:             }
  805: 
  806:             for(i = 0; i < (*s_etat_processus).nombre_variables; i++)
  807:             {
  808:                 pthread_mutex_trylock(&((*(*s_etat_processus)
  809:                         .s_liste_variables[i].objet).mutex));
  810:                 pthread_mutex_unlock(&((*(*s_etat_processus)
  811:                         .s_liste_variables[i].objet).mutex));
  812: 
  813:                 // Les variables de niveau 0 sont des définitions qui
  814:                 // ne sont pas copiées entre threads.
  815:                 if ((*s_etat_processus).s_liste_variables[i].niveau > 0)
  816:                 {
  817:                     liberation(s_etat_processus,
  818:                             (*s_etat_processus).s_liste_variables[i].objet);
  819:                 }
  820: 
  821:                 free((*s_etat_processus).s_liste_variables[i].nom);
  822:             }
  823: 
  824:             free((*s_etat_processus).s_liste_variables);
  825: 
  826:             for(i = 0; i < (*s_etat_processus).nombre_variables_statiques; i++)
  827:             {
  828:                 pthread_mutex_trylock(&((*(*s_etat_processus)
  829:                         .s_liste_variables_statiques[i].objet).mutex));
  830:                 pthread_mutex_unlock(&((*(*s_etat_processus)
  831:                         .s_liste_variables_statiques[i].objet).mutex));
  832: 
  833:                 liberation(s_etat_processus, (*s_etat_processus)
  834:                         .s_liste_variables_statiques[i].objet);
  835:                 free((*s_etat_processus).s_liste_variables_statiques[i].nom);
  836:             }
  837: 
  838:             free((*s_etat_processus).s_liste_variables_statiques);
  839: 
  840:             // Ne peut être effacé qu'une seule fois
  841:             if (suppression_variables_partagees == d_faux)
  842:             {
  843:                 suppression_variables_partagees = d_vrai;
  844: 
  845:                 for(i = 0; i < (*(*s_etat_processus)
  846:                         .s_liste_variables_partagees).nombre_variables; i++)
  847:                 {
  848:                     pthread_mutex_trylock(&((*(*(*s_etat_processus)
  849:                             .s_liste_variables_partagees).table[i].objet)
  850:                             .mutex));
  851:                     pthread_mutex_unlock(&((*(*(*s_etat_processus)
  852:                             .s_liste_variables_partagees).table[i].objet)
  853:                             .mutex));
  854: 
  855:                     liberation(s_etat_processus, (*(*s_etat_processus)
  856:                             .s_liste_variables_partagees).table[i].objet);
  857:                     free((*(*s_etat_processus).s_liste_variables_partagees)
  858:                             .table[i].nom);
  859:                 }
  860: 
  861:                 if ((*(*s_etat_processus).s_liste_variables_partagees).table
  862:                         != NULL)
  863:                 {
  864:                     free((struct_variable_partagee *) (*(*s_etat_processus)
  865:                             .s_liste_variables_partagees).table);
  866:                 }
  867: 
  868:                 pthread_mutex_trylock(&((*(*s_etat_processus)
  869:                         .s_liste_variables_partagees).mutex));
  870:                 pthread_mutex_unlock(&((*(*s_etat_processus)
  871:                         .s_liste_variables_partagees).mutex));
  872:             }
  873: 
  874:             element_courant = (*s_etat_processus).l_base_pile;
  875:             while(element_courant != NULL)
  876:             {
  877:                 element_suivant = (*((struct_liste_chainee *)
  878:                         element_courant)).suivant;
  879: 
  880:                 pthread_mutex_trylock(&((*(*((struct_liste_chainee *)
  881:                         element_courant)).donnee).mutex));
  882:                 pthread_mutex_unlock(&((*(*((struct_liste_chainee *)
  883:                         element_courant)).donnee).mutex));
  884: 
  885:                 liberation(s_etat_processus,
  886:                         (*((struct_liste_chainee *)
  887:                         element_courant)).donnee);
  888:                 free((struct_liste_chainee *) element_courant);
  889: 
  890:                 element_courant = element_suivant;
  891:             }
  892: 
  893:             element_courant = (*s_etat_processus).l_base_pile_contextes;
  894:             while(element_courant != NULL)
  895:             {
  896:                 element_suivant = (*((struct_liste_chainee *)
  897:                         element_courant)).suivant;
  898: 
  899:                 pthread_mutex_trylock(&((*(*((struct_liste_chainee *)
  900:                         element_courant)).donnee).mutex));
  901:                 pthread_mutex_unlock(&((*(*((struct_liste_chainee *)
  902:                         element_courant)).donnee).mutex));
  903:                 liberation(s_etat_processus, (*((struct_liste_chainee *)
  904:                         element_courant)).donnee);
  905:                 free((struct_liste_chainee *) element_courant);
  906: 
  907:                 element_courant = element_suivant;
  908:             }
  909: 
  910:             element_courant = (*s_etat_processus).l_base_pile_taille_contextes;
  911:             while(element_courant != NULL)
  912:             {
  913:                 element_suivant = (*((struct_liste_chainee *)
  914:                         element_courant)).suivant;
  915: 
  916:                 pthread_mutex_trylock(&((*(*((struct_liste_chainee *)
  917:                         element_courant)).donnee).mutex));
  918:                 pthread_mutex_unlock(&((*(*((struct_liste_chainee *)
  919:                         element_courant)).donnee).mutex));
  920:                 liberation(s_etat_processus,
  921:                         (*((struct_liste_chainee *)
  922:                         element_courant)).donnee);
  923:                 free((struct_liste_chainee *) element_courant);
  924: 
  925:                 element_courant = element_suivant;
  926:             }
  927: 
  928:             for(i = 0; i < (*s_etat_processus).nombre_instructions_externes;
  929:                     i++)
  930:             {
  931:                 free((*s_etat_processus).s_instructions_externes[i].nom);
  932:                 free((*s_etat_processus).s_instructions_externes[i]
  933:                         .nom_bibliotheque);
  934:             }
  935: 
  936:             if ((*s_etat_processus).nombre_instructions_externes != 0)
  937:             {
  938:                 free((*s_etat_processus).s_instructions_externes);
  939:             }
  940: 
  941:             element_courant = (*s_etat_processus).s_bibliotheques;
  942:             while(element_courant != NULL)
  943:             {
  944:                 element_suivant = (*((struct_liste_chainee *)
  945:                         element_courant)).suivant;
  946: 
  947:                 element_candidat = (*candidat).s_bibliotheques;
  948:                 while(element_candidat != NULL)
  949:                 {
  950:                     if (((*((struct_bibliotheque *) (*((struct_liste_chainee *)
  951:                             element_courant)).donnee))
  952:                             .descripteur == (*((struct_bibliotheque *)
  953:                             (*((struct_liste_chainee *) element_candidat))
  954:                             .donnee)).descripteur) &&
  955:                             ((*((struct_bibliotheque *)
  956:                             (*((struct_liste_chainee *) element_courant))
  957:                             .donnee)).pid == (*((struct_bibliotheque *)
  958:                             (*((struct_liste_chainee *) element_candidat))
  959:                             .donnee)).pid) && (pthread_equal(
  960:                             (*((struct_bibliotheque *)
  961:                             (*((struct_liste_chainee *) element_courant))
  962:                             .donnee)).tid, (*((struct_bibliotheque *)
  963:                             (*((struct_liste_chainee *) element_candidat))
  964:                             .donnee)).tid) != 0))
  965:                     {
  966:                         break;
  967:                     }
  968: 
  969:                     element_candidat = (*((struct_liste_chainee *)
  970:                             element_candidat)).suivant;
  971:                 }
  972: 
  973:                 if (element_candidat == NULL)
  974:                 {
  975:                     dlclose((*((struct_bibliotheque *)
  976:                             (*((struct_liste_chainee *) element_courant))
  977:                             .donnee)).descripteur);
  978:                 }
  979: 
  980:                 free((*((struct_bibliotheque *)
  981:                         (*((struct_liste_chainee *)
  982:                         element_courant)).donnee)).nom);
  983:                 free((*((struct_liste_chainee *) element_courant)).donnee);
  984:                 free(element_courant);
  985: 
  986:                 element_courant = element_suivant;
  987:             }
  988: 
  989:             element_courant = (*s_etat_processus).l_base_pile_last;
  990:             while(element_courant != NULL)
  991:             {
  992:                 element_suivant = (*((struct_liste_chainee *)
  993:                         element_courant)).suivant;
  994: 
  995:                 pthread_mutex_trylock(&((*(*((struct_liste_chainee *)
  996:                         element_courant)).donnee).mutex));
  997:                 pthread_mutex_unlock(&((*(*((struct_liste_chainee *)
  998:                         element_courant)).donnee).mutex));
  999:                 liberation(s_etat_processus,
 1000:                         (*((struct_liste_chainee *) element_courant)).donnee);
 1001:                 free(element_courant);
 1002: 
 1003:                 element_courant = element_suivant;
 1004:             }
 1005: 
 1006:             element_courant = (*s_etat_processus).l_base_pile_systeme;
 1007:             while(element_courant != NULL)
 1008:             {
 1009:                 element_suivant = (*((struct_liste_pile_systeme *)
 1010:                         element_courant)).suivant;
 1011: 
 1012:                 if ((*((struct_liste_pile_systeme *)
 1013:                         element_courant)).indice_boucle != NULL)
 1014:                 {
 1015:                     pthread_mutex_trylock(&((*(*((struct_liste_pile_systeme *)
 1016:                             element_courant)).indice_boucle).mutex));
 1017:                     pthread_mutex_unlock(&((*(*((struct_liste_pile_systeme *)
 1018:                             element_courant)).indice_boucle).mutex));
 1019:                 }
 1020: 
 1021:                 liberation(s_etat_processus,
 1022:                         (*((struct_liste_pile_systeme *)
 1023:                         element_courant)).indice_boucle);
 1024: 
 1025:                 if ((*((struct_liste_pile_systeme *)
 1026:                         element_courant)).limite_indice_boucle != NULL)
 1027:                 {
 1028:                     pthread_mutex_trylock(&((*(*((struct_liste_pile_systeme *)
 1029:                             element_courant)).limite_indice_boucle).mutex));
 1030:                     pthread_mutex_unlock(&((*(*((struct_liste_pile_systeme *)
 1031:                             element_courant)).limite_indice_boucle).mutex));
 1032:                 }
 1033: 
 1034:                 liberation(s_etat_processus,
 1035:                         (*((struct_liste_pile_systeme *)
 1036:                         element_courant)).limite_indice_boucle);
 1037: 
 1038:                 if ((*((struct_liste_pile_systeme *)
 1039:                         element_courant)).objet_de_test != NULL)
 1040:                 {
 1041:                     pthread_mutex_trylock(&((*(*((struct_liste_pile_systeme *)
 1042:                             element_courant)).objet_de_test).mutex));
 1043:                     pthread_mutex_unlock(&((*(*((struct_liste_pile_systeme *)
 1044:                             element_courant)).objet_de_test).mutex));
 1045:                 }
 1046: 
 1047:                 liberation(s_etat_processus,
 1048:                         (*((struct_liste_pile_systeme *)
 1049:                         element_courant)).objet_de_test);
 1050: 
 1051:                 if ((*((struct_liste_pile_systeme *)
 1052:                         element_courant)).nom_variable != NULL)
 1053:                 {
 1054:                     free((*((struct_liste_pile_systeme *)
 1055:                             element_courant)).nom_variable);
 1056:                 }
 1057: 
 1058:                 free(element_courant);
 1059: 
 1060:                 element_courant = element_suivant;
 1061:             }
 1062: 
 1063:             element_courant = (*s_etat_processus).s_fichiers;
 1064:             while(element_courant != NULL)
 1065:             {
 1066:                 element_suivant = (*((struct_liste_chainee *)
 1067:                         element_courant)).suivant;
 1068: 
 1069:                 element_candidat = (*candidat).s_fichiers;
 1070:                 while(element_candidat != NULL)
 1071:                 {
 1072:                     if (((*((struct_descripteur_fichier *)
 1073:                             (*((struct_liste_chainee *) element_courant))
 1074:                             .donnee)).pid ==
 1075:                             (*((struct_descripteur_fichier *)
 1076:                             (*((struct_liste_chainee *) element_candidat))
 1077:                             .donnee)).pid) && (pthread_equal(
 1078:                             (*((struct_descripteur_fichier *)
 1079:                             (*((struct_liste_chainee *) element_courant))
 1080:                             .donnee)).tid, (*((struct_descripteur_fichier *)
 1081:                             (*((struct_liste_chainee *) element_candidat))
 1082:                             .donnee)).tid) != 0))
 1083:                     {
 1084:                         if ((*((struct_descripteur_fichier *)
 1085:                                 (*((struct_liste_chainee *) element_courant))
 1086:                                 .donnee)).type ==
 1087:                                 (*((struct_descripteur_fichier *)
 1088:                                 (*((struct_liste_chainee *) element_candidat))
 1089:                                 .donnee)).type)
 1090:                         {
 1091:                             if ((*((struct_descripteur_fichier *)
 1092:                                     (*((struct_liste_chainee *)
 1093:                                     element_candidat)).donnee)).type == 'C')
 1094:                             {
 1095:                                 if ((*((struct_descripteur_fichier *)
 1096:                                         (*((struct_liste_chainee *)
 1097:                                         element_courant)).donnee))
 1098:                                         .descripteur_c ==
 1099:                                         (*((struct_descripteur_fichier *)
 1100:                                         (*((struct_liste_chainee *)
 1101:                                         element_candidat)).donnee))
 1102:                                         .descripteur_c)
 1103:                                 {
 1104:                                     break;
 1105:                                 }
 1106:                             }
 1107:                             else
 1108:                             {
 1109:                                 if (((*((struct_descripteur_fichier *)
 1110:                                         (*((struct_liste_chainee *)
 1111:                                         element_courant)).donnee))
 1112:                                         .descripteur_sqlite ==
 1113:                                         (*((struct_descripteur_fichier *)
 1114:                                         (*((struct_liste_chainee *)
 1115:                                         element_candidat)).donnee))
 1116:                                         .descripteur_sqlite) &&
 1117:                                         ((*((struct_descripteur_fichier *)
 1118:                                         (*((struct_liste_chainee *)
 1119:                                         element_courant)).donnee))
 1120:                                         .descripteur_c ==
 1121:                                         (*((struct_descripteur_fichier *)
 1122:                                         (*((struct_liste_chainee *)
 1123:                                         element_candidat)).donnee))
 1124:                                         .descripteur_c))
 1125:                                 {
 1126:                                     break;
 1127:                                 }
 1128:                             }
 1129:                         }
 1130:                     }
 1131: 
 1132:                     element_candidat = (*((struct_liste_chainee *)
 1133:                             element_candidat)).suivant;
 1134:                 }
 1135: 
 1136:                 if (element_candidat == NULL)
 1137:                 {
 1138:                     fclose((*((struct_descripteur_fichier *)
 1139:                             (*((struct_liste_chainee *) element_courant))
 1140:                             .donnee)).descripteur_c);
 1141: 
 1142:                     if ((*((struct_descripteur_fichier *)
 1143:                             (*((struct_liste_chainee *) element_courant))
 1144:                             .donnee)).type != 'C')
 1145:                     {
 1146:                         sqlite3_close((*((struct_descripteur_fichier *)
 1147:                                 (*((struct_liste_chainee *) element_courant))
 1148:                                 .donnee)).descripteur_sqlite);
 1149:                     }
 1150:                 }
 1151: 
 1152:                 free((*((struct_descripteur_fichier *)
 1153:                         (*((struct_liste_chainee *)
 1154:                         element_courant)).donnee)).nom);
 1155:                 free((struct_descripteur_fichier *)
 1156:                         (*((struct_liste_chainee *)
 1157:                         element_courant)).donnee);
 1158:                 free(element_courant);
 1159: 
 1160:                 element_courant = element_suivant;
 1161:             }
 1162: 
 1163:             element_courant = (*s_etat_processus).s_sockets;
 1164:             while(element_courant != NULL)
 1165:             {
 1166:                 element_suivant = (*((struct_liste_chainee *)
 1167:                         element_courant)).suivant;
 1168: 
 1169:                 element_candidat = (*candidat).s_sockets;
 1170:                 while(element_candidat != NULL)
 1171:                 {
 1172:                     if (((*((struct_socket *)
 1173:                             (*((struct_liste_chainee *) element_courant))
 1174:                             .donnee)).socket == (*((struct_socket *)
 1175:                             (*((struct_liste_chainee *) element_candidat))
 1176:                             .donnee)).socket) &&
 1177:                             ((*((struct_socket *)
 1178:                             (*((struct_liste_chainee *) element_courant))
 1179:                             .donnee)).pid == (*((struct_socket *)
 1180:                             (*((struct_liste_chainee *) element_candidat))
 1181:                             .donnee)).pid) && (pthread_equal(
 1182:                             (*((struct_socket *)
 1183:                             (*((struct_liste_chainee *) element_courant))
 1184:                             .donnee)).tid, (*((struct_socket *)
 1185:                             (*((struct_liste_chainee *) element_candidat))
 1186:                             .donnee)).tid) != 0))
 1187:                     {
 1188:                         break;
 1189:                     }
 1190: 
 1191:                     element_candidat = (*((struct_liste_chainee *)
 1192:                             element_candidat)).suivant;
 1193:                 }
 1194: 
 1195:                 if (element_candidat == NULL)
 1196:                 {
 1197:                     if ((*((struct_socket *) (*((struct_liste_chainee *)
 1198:                             element_courant)).donnee)).socket_connectee
 1199:                             == d_vrai)
 1200:                     {
 1201:                         shutdown((*((struct_socket *)
 1202:                                 (*((struct_liste_chainee *) element_courant))
 1203:                                 .donnee)).socket, SHUT_RDWR);
 1204:                     }
 1205: 
 1206:                     close((*((struct_socket *)
 1207:                             (*((struct_liste_chainee *) element_courant))
 1208:                             .donnee)).socket);
 1209:                 }
 1210: 
 1211:                 pthread_mutex_trylock(&((*(*((struct_liste_chainee *)
 1212:                         element_courant)).donnee).mutex));
 1213:                 pthread_mutex_unlock(&((*(*((struct_liste_chainee *)
 1214:                         element_courant)).donnee).mutex));
 1215: 
 1216:                 liberation(s_etat_processus,
 1217:                         (*((struct_liste_chainee *)
 1218:                         element_courant)).donnee);
 1219:                 free(element_courant);
 1220: 
 1221:                 element_courant = element_suivant;
 1222:             }
 1223: 
 1224: /*
 1225: ================================================================================
 1226:   À noter : on ne ferme pas la connexion car la conséquence immédiate est
 1227:   une destruction de l'objet pour le processus père.
 1228: ================================================================================
 1229: 
 1230:             element_courant = (*s_etat_processus).s_connecteurs_sql;
 1231:             while(element_courant != NULL)
 1232:             {
 1233:                 element_suivant = (*((struct_liste_chainee *)
 1234:                         element_courant)).suivant;
 1235: 
 1236:                 element_candidat = (*candidat).s_connecteurs_sql;
 1237:                 while(element_candidat != NULL)
 1238:                 {
 1239:                     if (((
 1240: #ifdef MYSQL_SUPPORT
 1241:                             ((*((struct_connecteur_sql *)
 1242:                             (*((struct_liste_chainee *) element_courant))
 1243:                             .donnee)).descripteur.mysql ==
 1244:                             (*((struct_connecteur_sql *)
 1245:                             (*((struct_liste_chainee *) element_candidat))
 1246:                             .donnee)).descripteur.mysql)
 1247:                             &&
 1248:                             (strcmp((*((struct_connecteur_sql *)
 1249:                             (*((struct_liste_chainee *) element_courant))
 1250:                             .donnee)).type, "MYSQL") == 0)
 1251:                             &&
 1252:                             (strcmp((*((struct_connecteur_sql *)
 1253:                             (*((struct_liste_chainee *) element_candidat))
 1254:                             .donnee)).type, "MYSQL") == 0)
 1255: #else
 1256:                             0
 1257: #endif
 1258:                             ) || (
 1259: #ifdef POSTGRESQL_SUPPORT
 1260:                             ((*((struct_connecteur_sql *)
 1261:                             (*((struct_liste_chainee *) element_courant))
 1262:                             .donnee)).descripteur.postgresql ==
 1263:                             (*((struct_connecteur_sql *)
 1264:                             (*((struct_liste_chainee *) element_candidat))
 1265:                             .donnee)).descripteur.postgresql)
 1266:                             &&
 1267:                             (strcmp((*((struct_connecteur_sql *)
 1268:                             (*((struct_liste_chainee *) element_courant))
 1269:                             .donnee)).type, "POSTGRESQL") == 0)
 1270:                             &&
 1271:                             (strcmp((*((struct_connecteur_sql *)
 1272:                             (*((struct_liste_chainee *) element_candidat))
 1273:                             .donnee)).type, "POSTGRESQL") == 0)
 1274: #else
 1275:                             0
 1276: #endif
 1277:                             )) &&
 1278:                             ((*((struct_connecteur_sql *)
 1279:                             (*((struct_liste_chainee *) element_courant))
 1280:                             .donnee)).pid == (*((struct_connecteur_sql *)
 1281:                             (*((struct_liste_chainee *) element_candidat))
 1282:                             .donnee)).pid) && (pthread_equal(
 1283:                             (*((struct_connecteur_sql *)
 1284:                             (*((struct_liste_chainee *) element_courant))
 1285:                             .donnee)).tid, (*((struct_connecteur_sql *)
 1286:                             (*((struct_liste_chainee *) element_candidat))
 1287:                             .donnee)).tid) != 0))
 1288:                     {
 1289:                         break;
 1290:                     }
 1291: 
 1292:                     element_candidat = (*((struct_liste_chainee *)
 1293:                             element_candidat)).suivant;
 1294:                 }
 1295: 
 1296:                 if (element_candidat == NULL)
 1297:                 {
 1298:                     sqlclose((*((struct_liste_chainee *) element_courant))
 1299:                             .donnee);
 1300:                 }
 1301: 
 1302:                 pthread_mutex_trylock(&((*(*((struct_liste_chainee *)
 1303:                         element_courant)).donnee).mutex));
 1304:                 pthread_mutex_unlock(&((*(*((struct_liste_chainee *)
 1305:                         element_courant)).donnee).mutex));
 1306: 
 1307:                 liberation(s_etat_processus, (*((struct_liste_chainee *)
 1308:                         element_courant)).donnee);
 1309:                 free(element_courant);
 1310: 
 1311:                 element_courant = element_suivant;
 1312:             }
 1313: */
 1314: 
 1315:             (*s_etat_processus).s_connecteurs_sql = NULL;
 1316: 
 1317:             element_courant = (*s_etat_processus).s_marques;
 1318:             while(element_courant != NULL)
 1319:             {
 1320:                 free((*((struct_marque *) element_courant)).label);
 1321:                 free((*((struct_marque *) element_courant)).position);
 1322:                 element_suivant = (*((struct_marque *) element_courant))
 1323:                         .suivant;
 1324:                 free(element_courant);
 1325:                 element_courant = element_suivant;
 1326:             }
 1327: 
 1328:             liberation_allocateur(s_etat_processus);
 1329: 
 1330: #           ifndef SEMAPHORES_NOMMES
 1331:             sem_post(&((*s_etat_processus).semaphore_fork));
 1332:             sem_destroy(&((*s_etat_processus).semaphore_fork));
 1333: #           else
 1334:             sem_post((*s_etat_processus).semaphore_fork);
 1335:             sem_destroy2((*s_etat_processus).semaphore_fork, sem_fork);
 1336: #           endif
 1337: 
 1338:             free(s_etat_processus);
 1339: 
 1340:             s_etat_processus = candidat;
 1341:         }
 1342: 
 1343:         l_element_suivant = (*l_element_courant).suivant;
 1344: 
 1345:         free((struct_thread *) (*l_element_courant).donnee);
 1346:         free((struct_liste_chainee *) l_element_courant);
 1347: 
 1348:         l_element_courant = l_element_suivant;
 1349:     }
 1350: 
 1351:     liste_threads = NULL;
 1352: 
 1353:     l_element_courant = liste_threads_surveillance;
 1354: 
 1355:     while(l_element_courant != NULL)
 1356:     {
 1357:         s_argument_thread = (struct_descripteur_thread *)
 1358:                 (*l_element_courant).donnee;
 1359: 
 1360:         if (pthread_mutex_lock(&((*s_argument_thread).mutex_nombre_references))
 1361:                 != 0)
 1362:         {
 1363:             (*s_etat_processus).erreur_systeme = d_es_processus;
 1364:             sem_post(&semaphore_liste_threads);
 1365:             return;
 1366:         }
 1367: 
 1368:         (*s_argument_thread).nombre_references--;
 1369: 
 1370:         BUG((*s_argument_thread).nombre_references < 0,
 1371:                 printf("(*s_argument_thread).nombre_references = %d\n",
 1372:                 (int) (*s_argument_thread).nombre_references));
 1373: 
 1374:         if ((*s_argument_thread).nombre_references == 0)
 1375:         {
 1376:             close((*s_argument_thread).pipe_objets[0]);
 1377:             close((*s_argument_thread).pipe_acquittement[1]);
 1378:             close((*s_argument_thread).pipe_injections[1]);
 1379:             close((*s_argument_thread).pipe_nombre_injections[1]);
 1380:             close((*s_argument_thread).pipe_nombre_objets_attente[0]);
 1381:             close((*s_argument_thread).pipe_interruptions[0]);
 1382:             close((*s_argument_thread).pipe_nombre_interruptions_attente[0]);
 1383: 
 1384:             if (pthread_mutex_unlock(&((*s_argument_thread)
 1385:                     .mutex_nombre_references)) != 0)
 1386:             {
 1387:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1388:                 sem_post(&semaphore_liste_threads);
 1389:                 return;
 1390:             }
 1391: 
 1392:             pthread_mutex_destroy(&((*s_argument_thread).mutex));
 1393:             pthread_mutex_destroy(&((*s_argument_thread)
 1394:                     .mutex_nombre_references));
 1395: 
 1396:             if ((*s_argument_thread).processus_detache == d_faux)
 1397:             {
 1398:                 if ((*s_argument_thread).destruction_objet == d_vrai)
 1399:                 {
 1400:                     liberation(s_etat_processus, (*s_argument_thread).argument);
 1401:                 }
 1402:             }
 1403: 
 1404:             free(s_argument_thread);
 1405:         }
 1406:         else
 1407:         {
 1408:             if (pthread_mutex_unlock(&((*s_argument_thread)
 1409:                     .mutex_nombre_references)) != 0)
 1410:             {
 1411:                 (*s_etat_processus).erreur_systeme = d_es_processus;
 1412:                 sem_post(&semaphore_liste_threads);
 1413:                 return;
 1414:             }
 1415:         }
 1416: 
 1417:         l_element_suivant = (*l_element_courant).suivant;
 1418:         free((struct_liste_chainee *) l_element_courant);
 1419:         l_element_courant = l_element_suivant;
 1420:     }
 1421: 
 1422:     liste_threads_surveillance = NULL;
 1423: 
 1424: #   ifndef SEMAPHORES_NOMMES
 1425:     if (sem_post(&semaphore_liste_threads) != 0)
 1426: #   else
 1427:     if (sem_post(semaphore_liste_threads) != 0)
 1428: #   endif
 1429:     {
 1430:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1431:         (*s_etat_processus).erreur_systeme = d_es_processus;
 1432:         return;
 1433:     }
 1434: 
 1435:     pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1436:     sigpending(&set);
 1437:     return;
 1438: }
 1439: 
 1440: static struct_processus *
 1441: recherche_thread(pid_t pid, pthread_t tid)
 1442: {
 1443:     volatile struct_liste_chainee_volatile      *l_element_courant;
 1444: 
 1445:     struct_processus                            *s_etat_processus;
 1446: 
 1447:     l_element_courant = liste_threads;
 1448: 
 1449:     while(l_element_courant != NULL)
 1450:     {
 1451:         if ((pthread_equal((*((struct_thread *) (*l_element_courant).donnee))
 1452:                 .tid, tid) != 0) && ((*((struct_thread *)
 1453:                 (*l_element_courant).donnee)).pid == pid))
 1454:         {
 1455:             break;
 1456:         }
 1457: 
 1458:         l_element_courant = (*l_element_courant).suivant;
 1459:     }
 1460: 
 1461:     if (l_element_courant == NULL)
 1462:     {
 1463:         /*
 1464:          * Le processus n'existe plus. On ne distribue aucun signal.
 1465:          */
 1466: 
 1467:         return(NULL);
 1468:     }
 1469: 
 1470:     s_etat_processus = (*((struct_thread *)
 1471:             (*l_element_courant).donnee)).s_etat_processus;
 1472: 
 1473:     return(s_etat_processus);
 1474: }
 1475: 
 1476: static logical1
 1477: recherche_thread_principal(pid_t pid, pthread_t *thread)
 1478: {
 1479:     volatile struct_liste_chainee_volatile      *l_element_courant;
 1480: 
 1481:     l_element_courant = liste_threads;
 1482: 
 1483:     while(l_element_courant != NULL)
 1484:     {
 1485:         if (((*((struct_thread *) (*l_element_courant).donnee)).thread_principal
 1486:                 == d_vrai) && ((*((struct_thread *)
 1487:                 (*l_element_courant).donnee)).pid == pid))
 1488:         {
 1489:             break;
 1490:         }
 1491: 
 1492:         l_element_courant = (*l_element_courant).suivant;
 1493:     }
 1494: 
 1495:     if (l_element_courant == NULL)
 1496:     {
 1497:         /*
 1498:          * Le processus n'existe plus. On ne distribue aucun signal.
 1499:          */
 1500: 
 1501:         return(d_faux);
 1502:     }
 1503: 
 1504:     (*thread) = (*((struct_thread *) (*l_element_courant).donnee)).tid;
 1505: 
 1506:     return(d_vrai);
 1507: }
 1508: 
 1509: 
 1510: /*
 1511: ================================================================================
 1512:   Procédures de gestion des signaux d'interruption
 1513: ================================================================================
 1514:   Entrée : variable globale
 1515: --------------------------------------------------------------------------------
 1516:   Sortie : variable globale modifiée
 1517: --------------------------------------------------------------------------------
 1518:   Effets de bord : néant
 1519: ================================================================================
 1520: */
 1521: 
 1522: // Les routines suivantes sont uniquement appelées depuis les gestionnaires
 1523: // des signaux asynchrones. Elles ne doivent pas bloquer dans le cas où
 1524: // les sémaphores sont déjà bloqués par un gestionnaire de signal.
 1525: 
 1526: static inline void
 1527: verrouillage_gestionnaire_signaux()
 1528: {
 1529:     int         semaphore;
 1530: 
 1531:     sigset_t    oldset;
 1532:     sigset_t    set;
 1533: 
 1534:     sem_t       *sem;
 1535: 
 1536:     if ((sem = pthread_getspecific(semaphore_fork_processus_courant))
 1537:             != NULL)
 1538:     {
 1539:         if (sem_post(sem) != 0)
 1540:         {
 1541:             BUG(1, uprintf("Lock error !\n"));
 1542:             return;
 1543:         }
 1544:     }
 1545: 
 1546:     // Il faut respecteur l'atomicité des deux opérations suivantes !
 1547: 
 1548:     sigfillset(&set);
 1549:     pthread_sigmask(SIG_BLOCK, &set, &oldset);
 1550: 
 1551: #   ifndef SEMAPHORES_NOMMES
 1552:     while(sem_wait(&semaphore_gestionnaires_signaux_atomique) == -1)
 1553: #   else
 1554:     while(sem_wait(semaphore_gestionnaires_signaux_atomique) == -1)
 1555: #   endif
 1556:     {
 1557:         if (errno != EINTR)
 1558:         {
 1559:             pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1560:             BUG(1, uprintf("Unlock error !\n"));
 1561:             return;
 1562:         }
 1563:     }
 1564: 
 1565: #   ifndef SEMAPHORES_NOMMES
 1566:     if (sem_post(&semaphore_gestionnaires_signaux) == -1)
 1567: #   else
 1568:     if (sem_post(semaphore_gestionnaires_signaux) == -1)
 1569: #   endif
 1570:     {
 1571:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1572:         BUG(1, uprintf("Lock error !\n"));
 1573:         return;
 1574:     }
 1575: 
 1576: #   ifndef SEMAPHORES_NOMMES
 1577:     if (sem_getvalue(&semaphore_gestionnaires_signaux, &semaphore) != 0)
 1578: #   else
 1579:     if (sem_getvalue(semaphore_gestionnaires_signaux, &semaphore) != 0)
 1580: #   endif
 1581:     {
 1582:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1583:         BUG(1, uprintf("Lock error !\n"));
 1584:         return;
 1585:     }
 1586: 
 1587: #   ifndef SEMAPHORES_NOMMES
 1588:     if (sem_post(&semaphore_gestionnaires_signaux_atomique) != 0)
 1589: #   else
 1590:     if (sem_post(semaphore_gestionnaires_signaux_atomique) != 0)
 1591: #   endif
 1592:     {
 1593:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1594:         BUG(1, uprintf("Unlock error !\n"));
 1595:         return;
 1596:     }
 1597: 
 1598:     if (semaphore == 1)
 1599:     {
 1600:         // Le semaphore ne peut être pris par le thread qui a appelé
 1601:         // le gestionnaire de signal car le signal est bloqué par ce thread
 1602:         // dans les zones critiques. Ce sémaphore ne peut donc être bloqué que
 1603:         // par un thread concurrent. On essaye donc de le bloquer jusqu'à
 1604:         // ce que ce soit possible.
 1605: 
 1606: #       ifndef SEMAPHORES_NOMMES
 1607:         while(sem_wait(&semaphore_liste_threads) == -1)
 1608: #       else
 1609:         while(sem_wait(semaphore_liste_threads) == -1)
 1610: #       endif
 1611:         {
 1612:             if (errno != EINTR)
 1613:             {
 1614:                 pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1615: 
 1616:                 while(sem_wait(sem) == -1)
 1617:                 {
 1618:                     if (errno != EINTR)
 1619:                     {
 1620:                         BUG(1, uprintf("Lock error !\n"));
 1621:                         return;
 1622:                     }
 1623:                 }
 1624: 
 1625:                 BUG(1, uprintf("Lock error !\n"));
 1626:                 return;
 1627:             }
 1628:         }
 1629:     }
 1630: 
 1631:     pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1632:     sigpending(&set);
 1633: 
 1634:     return;
 1635: }
 1636: 
 1637: static inline void
 1638: deverrouillage_gestionnaire_signaux()
 1639: {
 1640:     int         semaphore;
 1641: 
 1642:     sem_t       *sem;
 1643: 
 1644:     sigset_t    oldset;
 1645:     sigset_t    set;
 1646: 
 1647:     // Il faut respecteur l'atomicité des deux opérations suivantes !
 1648: 
 1649:     sigfillset(&set);
 1650:     pthread_sigmask(SIG_BLOCK, &set, &oldset);
 1651: 
 1652: #   ifndef SEMAPHORES_NOMMES
 1653:     while(sem_wait(&semaphore_gestionnaires_signaux_atomique) == -1)
 1654: #   else
 1655:     while(sem_wait(semaphore_gestionnaires_signaux_atomique) == -1)
 1656: #   endif
 1657:     {
 1658:         if (errno != EINTR)
 1659:         {
 1660:             pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1661:             BUG(1, uprintf("Unlock error !\n"));
 1662:             return;
 1663:         }
 1664:     }
 1665: 
 1666: #   ifndef SEMAPHORES_NOMMES
 1667:     if (sem_getvalue(&semaphore_gestionnaires_signaux, &semaphore) != 0)
 1668: #   else
 1669:     if (sem_getvalue(semaphore_gestionnaires_signaux, &semaphore) != 0)
 1670: #   endif
 1671:     {
 1672:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1673:         BUG(1, uprintf("Unlock error !\n"));
 1674:         return;
 1675:     }
 1676: 
 1677: #   ifndef SEMAPHORES_NOMMES
 1678:     while(sem_wait(&semaphore_gestionnaires_signaux) == -1)
 1679: #   else
 1680:     while(sem_wait(semaphore_gestionnaires_signaux) == -1)
 1681: #   endif
 1682:     {
 1683:         if (errno != EINTR)
 1684:         {
 1685:             pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1686:             BUG(1, uprintf("Unlock error !\n"));
 1687:             return;
 1688:         }
 1689:     }
 1690: 
 1691: #   ifndef SEMAPHORES_NOMMES
 1692:     if (sem_post(&semaphore_gestionnaires_signaux_atomique) != 0)
 1693: #   else
 1694:     if (sem_post(semaphore_gestionnaires_signaux_atomique) != 0)
 1695: #   endif
 1696:     {
 1697:         pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1698:         BUG(1, uprintf("Unlock error !\n"));
 1699:         return;
 1700:     }
 1701: 
 1702:     if ((sem = pthread_getspecific(semaphore_fork_processus_courant))
 1703:             != NULL)
 1704:     {
 1705:         while(sem_wait(sem) == -1)
 1706:         {
 1707:             if (errno != EINTR)
 1708:             {
 1709:                 pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1710:                 BUG(1, uprintf("Unlock error !\n"));
 1711:                 return;
 1712:             }
 1713:         }
 1714:     }
 1715: 
 1716:     if (semaphore == 1)
 1717:     {
 1718: #       ifndef SEMAPHORES_NOMMES
 1719:         if (sem_post(&semaphore_liste_threads) != 0)
 1720: #       else
 1721:         if (sem_post(semaphore_liste_threads) != 0)
 1722: #       endif
 1723:         {
 1724:             pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1725: 
 1726:             BUG(1, uprintf("Unlock error !\n"));
 1727:             return;
 1728:         }
 1729:     }
 1730: 
 1731:     pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 1732:     sigpending(&set);
 1733: 
 1734:     return;
 1735: }
 1736: 
 1737: void
 1738: interruption1(SIGHANDLER_ARGS)
 1739: {
 1740:     pid_t                   pid;
 1741: 
 1742:     pthread_t               thread;
 1743: 
 1744:     struct_processus        *s_etat_processus;
 1745: 
 1746:     volatile sig_atomic_t   exclusion = 0;
 1747: 
 1748:     verrouillage_gestionnaire_signaux();
 1749: 
 1750: #   ifdef _BROKEN_SIGINFO
 1751:     if ((signal == SIGINT) || (signal == SIGTERM))
 1752:     {
 1753:         // Si l'interruption provient du clavier, il n'y a pas eu d'appel
 1754:         // à queue_in().
 1755: 
 1756:         pid = getpid();
 1757:     }
 1758:     else
 1759:     {
 1760:         pid = origine_signal(signal);
 1761:     }
 1762: #   else
 1763:     if (siginfo != NULL)
 1764:     {
 1765:         pid = (*siginfo).si_pid;
 1766:     }
 1767:     else
 1768:     {
 1769:         pid = getpid();
 1770:     }
 1771: #   endif
 1772: 
 1773:     switch(signal)
 1774:     {
 1775:         case SIGALRM :
 1776:         {
 1777:             if (pid == getpid())
 1778:             {
 1779:                 if ((s_etat_processus = recherche_thread(getpid(),
 1780:                         pthread_self())) == NULL)
 1781:                 {
 1782:                     deverrouillage_gestionnaire_signaux();
 1783:                      return;
 1784:                 }
 1785: 
 1786:                 if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)
 1787:                 {
 1788:                     printf("[%d] SIGALRM (thread %llu)\n", (int) getpid(),
 1789:                             (unsigned long long) pthread_self());
 1790:                     fflush(stdout);
 1791:                 }
 1792: 
 1793:                 if ((*s_etat_processus).pid_processus_pere != getpid())
 1794:                 {
 1795:                     kill((*s_etat_processus).pid_processus_pere, signal);
 1796:                 }
 1797:                 else
 1798:                 {
 1799:                     (*s_etat_processus).var_volatile_alarme = -1;
 1800:                     (*s_etat_processus).var_volatile_requete_arret = -1;
 1801:                 }
 1802:             }
 1803:             else
 1804:             {
 1805:                 if (recherche_thread_principal(getpid(), &thread) == d_vrai)
 1806:                 {
 1807:                     pthread_kill(thread, signal);
 1808:                 }
 1809:             }
 1810: 
 1811:             break;
 1812:         }
 1813: 
 1814:         case SIGINT :
 1815:         case SIGTERM :
 1816:         {
 1817:             /*
 1818:              * Une vieille spécification POSIX permet au pointeur siginfo
 1819:              * d'être nul dans le cas d'un ^C envoyé depuis le clavier.
 1820:              * Solaris suit en particulier cette spécification.
 1821:              */
 1822: 
 1823: #           ifndef _BROKEN_SIGINFO
 1824:             if (siginfo == NULL)
 1825:             {
 1826:                 kill(getpid(), signal);
 1827:             }
 1828:             else
 1829: #           endif
 1830:             if (pid == getpid())
 1831:             {
 1832:                 if ((s_etat_processus = recherche_thread(getpid(),
 1833:                         pthread_self())) == NULL)
 1834:                 {
 1835:                     deverrouillage_gestionnaire_signaux();
 1836:                     return;
 1837:                 }
 1838: 
 1839:                 if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)
 1840:                 {
 1841:                     if (signal == SIGINT)
 1842:                     {
 1843:                         printf("[%d] SIGINT (thread %llu)\n", (int) getpid(),
 1844:                                 (unsigned long long) pthread_self());
 1845:                     }
 1846:                     else
 1847:                     {
 1848:                         printf("[%d] SIGTERM (thread %llu)\n", (int) getpid(),
 1849:                                 (unsigned long long) pthread_self());
 1850:                     }
 1851: 
 1852:                     fflush(stdout);
 1853:                 }
 1854: 
 1855:                 if ((*s_etat_processus).pid_processus_pere != getpid())
 1856:                 {
 1857:                     kill((*s_etat_processus).pid_processus_pere, signal);
 1858:                 }
 1859:                 else
 1860:                 {
 1861:                     (*s_etat_processus).var_volatile_traitement_sigint = -1;
 1862: 
 1863:                     while(exclusion == 1);
 1864:                     exclusion = 1;
 1865: 
 1866:                     if ((*s_etat_processus).var_volatile_requete_arret == -1)
 1867:                     {
 1868:                         deverrouillage_gestionnaire_signaux();
 1869:                         exclusion = 0;
 1870:                         return;
 1871:                     }
 1872: 
 1873:                     if (signal == SIGINT)
 1874:                     {
 1875:                         if (strncmp(getenv("LANG"), "fr", 2) == 0)
 1876:                         {
 1877:                             printf("+++Interruption\n");
 1878:                         }
 1879:                         else
 1880:                         {
 1881:                             printf("+++Interrupt\n");
 1882:                         }
 1883: 
 1884:                         fflush(stdout);
 1885:                     }
 1886: 
 1887:                     (*s_etat_processus).var_volatile_requete_arret = -1;
 1888:                     (*s_etat_processus).var_volatile_alarme = -1;
 1889: 
 1890:                     exclusion = 0;
 1891:                 }
 1892:             }
 1893:             else
 1894:             {
 1895:                 if (recherche_thread_principal(getpid(), &thread) == d_vrai)
 1896:                 {
 1897:                     pthread_kill(thread, signal);
 1898:                 }
 1899:             }
 1900: 
 1901:             break;
 1902:         }
 1903: 
 1904:         default :
 1905:         {
 1906:             BUG(1, uprintf("[%d] Unknown signal %d in this context\n",
 1907:                     (int) getpid(), signal));
 1908:             break;
 1909:         }
 1910:     }
 1911: 
 1912:     deverrouillage_gestionnaire_signaux();
 1913:     return;
 1914: }
 1915: 
 1916: void
 1917: interruption2(SIGHANDLER_ARGS)
 1918: {
 1919:     pid_t                   pid;
 1920: 
 1921:     pthread_t               thread;
 1922: 
 1923:     struct_processus        *s_etat_processus;
 1924: 
 1925:     verrouillage_gestionnaire_signaux();
 1926: 
 1927: #   ifdef _BROKEN_SIGINFO
 1928:     pid = origine_signal(signal);
 1929: #   else
 1930:     if (siginfo != NULL)
 1931:     {
 1932:         pid = (*siginfo).si_pid;
 1933:     }
 1934:     else
 1935:     {
 1936:         pid = getpid();
 1937:     }
 1938: #   endif
 1939: 
 1940: #   ifndef _BROKEN_SIGINFO
 1941:     if (siginfo == NULL)
 1942:     {
 1943:         /*
 1944:          * Le signal SIGFSTP provient de la mort du processus de contrôle.
 1945:          * Sous certains systèmes (Linux...), la mort du terminal de contrôle
 1946:          * se traduit par l'envoi d'un SIGHUP au processus. Sur d'autres
 1947:          * (SunOS), le processus reçoit un SIGFSTP avec une structure siginfo
 1948:          * non initialisée (pointeur NULL) issue de TERMIO.
 1949:          */
 1950: 
 1951:         if (recherche_thread_principal(getpid(), &thread) == d_vrai)
 1952:         {
 1953:             pthread_kill(thread, SIGHUP);
 1954:             deverrouillage_gestionnaire_signaux();
 1955:             return;
 1956:         }
 1957:     }
 1958:     else
 1959: #   endif
 1960:     if (pid == getpid())
 1961:     {
 1962:         if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))
 1963:                 == NULL)
 1964:         {
 1965:             deverrouillage_gestionnaire_signaux();
 1966:             return;
 1967:         }
 1968: 
 1969:         /*
 1970:          *  0 => fonctionnement normal
 1971:          * -1 => requête
 1972:          *  1 => requête acceptée en attente de traitement
 1973:          */
 1974: 
 1975:         if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)
 1976:         {
 1977:             printf("[%d] SIGTSTP (thread %llu)\n", (int) getpid(),
 1978:                     (unsigned long long) pthread_self());
 1979:             fflush(stdout);
 1980:         }
 1981: 
 1982:         if ((*s_etat_processus).var_volatile_processus_pere == 0)
 1983:         {
 1984:             kill((*s_etat_processus).pid_processus_pere, signal);
 1985:         }
 1986:         else
 1987:         {
 1988:             (*s_etat_processus).var_volatile_requete_arret2 = -1;
 1989:         }
 1990:     }
 1991:     else
 1992:     {
 1993:         // Envoi d'un signal au thread maître du groupe.
 1994: 
 1995:         if (recherche_thread_principal(getpid(), &thread) == d_vrai)
 1996:         {
 1997:             pthread_kill(thread, SIGTSTP);
 1998:             deverrouillage_gestionnaire_signaux();
 1999:             return;
 2000:         }
 2001:     }
 2002: 
 2003:     deverrouillage_gestionnaire_signaux();
 2004:     return;
 2005: }
 2006: 
 2007: void
 2008: interruption3(SIGHANDLER_ARGS)
 2009: {
 2010:     pid_t                   pid;
 2011: 
 2012:     struct_processus        *s_etat_processus;
 2013: 
 2014:     static int              compteur = 0;
 2015: 
 2016:     verrouillage_gestionnaire_signaux();
 2017: 
 2018: #   ifdef _BROKEN_SIGINFO
 2019:     pid = origine_signal(signal);
 2020: #   else
 2021:     pid = (*siginfo).si_pid;
 2022: #   endif
 2023: 
 2024:     if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)
 2025:     {
 2026:         deverrouillage_gestionnaire_signaux();
 2027:         return;
 2028:     }
 2029: 
 2030:     if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)
 2031:     {
 2032:         printf("[%d] SIGSEGV (thread %llu)\n", (int) getpid(),
 2033:                 (unsigned long long) pthread_self());
 2034:         fflush(stdout);
 2035:     }
 2036: 
 2037:     if ((*s_etat_processus).var_volatile_recursivite == -1)
 2038:     {
 2039:         // Segfault dans un appel de fonction récursive
 2040:         deverrouillage_gestionnaire_signaux();
 2041:         longjmp(contexte, -1);
 2042:     }
 2043:     else
 2044:     {
 2045:         // Segfault dans une routine interne
 2046:         if (strncmp(getenv("LANG"), "fr", 2) == 0)
 2047:         {
 2048:             printf("+++Système : Violation d'accès (dépassement de pile)\n");
 2049:         }
 2050:         else
 2051:         {
 2052:             printf("+++System : Access violation (stack overflow)\n");
 2053:         }
 2054: 
 2055:         fflush(stdout);
 2056: 
 2057:         compteur++;
 2058: 
 2059:         if (compteur > 1)
 2060:         {
 2061:             deverrouillage_gestionnaire_signaux();
 2062:             exit(EXIT_FAILURE);
 2063:         }
 2064:         else
 2065:         {
 2066:             deverrouillage_gestionnaire_signaux();
 2067:             longjmp(contexte_initial, -1);
 2068:         }
 2069:     }
 2070: 
 2071:     deverrouillage_gestionnaire_signaux();
 2072:     return;
 2073: }
 2074: 
 2075: void
 2076: interruption4(SIGHANDLER_ARGS)
 2077: {
 2078:     pid_t                   pid;
 2079: 
 2080:     struct_processus        *s_etat_processus;
 2081: 
 2082:     verrouillage_gestionnaire_signaux();
 2083: 
 2084: #   ifdef _BROKEN_SIGINFO
 2085:     pid = origine_signal(signal);
 2086: #   else
 2087:     pid = (*siginfo).si_pid;
 2088: #   endif
 2089: 
 2090:     if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)
 2091:     {
 2092:         deverrouillage_gestionnaire_signaux();
 2093:         return;
 2094:     }
 2095: 
 2096:     /*
 2097:      * Démarrage d'un processus fils ou gestion de SIGCONT (SUSPEND)
 2098:      */
 2099: 
 2100:     if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)
 2101:     {
 2102:         printf("[%d] SIGSTART/SIGCONT (thread %llu)\n", (int) getpid(),
 2103:                 (unsigned long long) pthread_self());
 2104:         fflush(stdout);
 2105:     }
 2106: 
 2107:     deverrouillage_gestionnaire_signaux();
 2108:     return;
 2109: }
 2110: 
 2111: void
 2112: interruption5(SIGHANDLER_ARGS)
 2113: {
 2114:     pid_t                   pid;
 2115: 
 2116:     pthread_t               thread;
 2117: 
 2118:     struct_processus        *s_etat_processus;
 2119: 
 2120:     verrouillage_gestionnaire_signaux();
 2121: 
 2122: #   ifdef _BROKEN_SIGINFO
 2123:     pid = origine_signal(signal);
 2124: #   else
 2125:     pid = (*siginfo).si_pid;
 2126: #   endif
 2127: 
 2128:     if (pid == getpid())
 2129:     {
 2130:         if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))
 2131:                 == NULL)
 2132:         {
 2133:             deverrouillage_gestionnaire_signaux();
 2134:             return;
 2135:         }
 2136: 
 2137:         if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)
 2138:         {
 2139:             printf("[%d] SIGFSTOP (thread %llu)\n", (int) getpid(),
 2140:                     (unsigned long long) pthread_self());
 2141:             fflush(stdout);
 2142:         }
 2143: 
 2144:         /*
 2145:          * var_globale_traitement_retarde_stop :
 2146:          *  0 -> traitement immédiat
 2147:          *  1 -> traitement retardé (aucun signal reçu)
 2148:          * -1 -> traitement retardé (un ou plusieurs signaux stop reçus)
 2149:          */
 2150: 
 2151:         if ((*s_etat_processus).var_volatile_traitement_retarde_stop == 0)
 2152:         {
 2153:             (*s_etat_processus).var_volatile_requete_arret = -1;
 2154:         }
 2155:         else
 2156:         {
 2157:             (*s_etat_processus).var_volatile_traitement_retarde_stop = -1;
 2158:         }
 2159:     }
 2160:     else
 2161:     {
 2162:         if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))
 2163:                 == NULL)
 2164:         {
 2165:             deverrouillage_gestionnaire_signaux();
 2166:             return;
 2167:         }
 2168: 
 2169:         // Envoi d'un signal au thread maître du groupe.
 2170: 
 2171:         if (recherche_thread_principal(getpid(), &thread) == d_vrai)
 2172:         {
 2173:             pthread_kill(thread, signal);
 2174:             deverrouillage_gestionnaire_signaux();
 2175:             return;
 2176:         }
 2177:     }
 2178: 
 2179:     deverrouillage_gestionnaire_signaux();
 2180:     return;
 2181: }
 2182: 
 2183: void
 2184: interruption6(SIGHANDLER_ARGS)
 2185: {
 2186:     pid_t                   pid;
 2187: 
 2188:     struct_processus        *s_etat_processus;
 2189: 
 2190:     verrouillage_gestionnaire_signaux();
 2191: 
 2192: #   ifdef _BROKEN_SIGINFO
 2193:     pid = origine_signal(signal);
 2194: #   else
 2195:     pid = (*siginfo).si_pid;
 2196: #   endif
 2197: 
 2198:     if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)
 2199:     {
 2200:         deverrouillage_gestionnaire_signaux();
 2201:         return;
 2202:     }
 2203: 
 2204:     if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)
 2205:     {
 2206:         printf("[%d] SIGINJECT/SIGQUIT (thread %llu)\n", (int) getpid(),
 2207:                 (unsigned long long) pthread_self());
 2208:         fflush(stdout);
 2209:     }
 2210: 
 2211:     deverrouillage_gestionnaire_signaux();
 2212:     return;
 2213: }
 2214: 
 2215: void
 2216: interruption7(SIGHANDLER_ARGS)
 2217: {
 2218:     pid_t                   pid;
 2219: 
 2220:     struct_processus        *s_etat_processus;
 2221: 
 2222:     verrouillage_gestionnaire_signaux();
 2223: 
 2224: #   ifdef _BROKEN_SIGINFO
 2225:     pid = origine_signal(signal);
 2226: #   else
 2227:     pid = (*siginfo).si_pid;
 2228: #   endif
 2229: 
 2230:     if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)
 2231:     {
 2232:         deverrouillage_gestionnaire_signaux();
 2233:         return;
 2234:     }
 2235: 
 2236:     if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)
 2237:     {
 2238:         printf("[%d] SIGPIPE (thread %llu)\n", (int) getpid(),
 2239:                 (unsigned long long) pthread_self());
 2240:         fflush(stdout);
 2241:     }
 2242: 
 2243:     (*s_etat_processus).var_volatile_requete_arret = -1;
 2244:     deverrouillage_gestionnaire_signaux();
 2245: 
 2246:     BUG(1, printf("[%d] SIGPIPE\n", (int) getpid()));
 2247:     return;
 2248: }
 2249: 
 2250: void
 2251: interruption8(SIGHANDLER_ARGS)
 2252: {
 2253:     pid_t                   pid;
 2254: 
 2255:     pthread_t               thread;
 2256: 
 2257:     struct_processus        *s_etat_processus;
 2258: 
 2259:     verrouillage_gestionnaire_signaux();
 2260: 
 2261: #   ifdef _BROKEN_SIGINFO
 2262:     pid = origine_signal(signal);
 2263: #   else
 2264:     pid = (*siginfo).si_pid;
 2265: #   endif
 2266: 
 2267:     if (pid == getpid())
 2268:     {
 2269:         if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))
 2270:                 == NULL)
 2271:         {
 2272:             deverrouillage_gestionnaire_signaux();
 2273:             return;
 2274:         }
 2275: 
 2276:         if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)
 2277:         {
 2278:             printf("[%d] SIGURG (thread %llu)\n", (int) getpid(),
 2279:                     (unsigned long long) pthread_self());
 2280:             fflush(stdout);
 2281:         }
 2282: 
 2283:         (*s_etat_processus).var_volatile_alarme = -1;
 2284:         (*s_etat_processus).var_volatile_requete_arret = -1;
 2285:     }
 2286:     else
 2287:     {
 2288:         // Envoi d'un signal au thread maître du groupe.
 2289: 
 2290:         if (recherche_thread_principal(getpid(), &thread) == d_vrai)
 2291:         {
 2292:             pthread_kill(thread, SIGURG);
 2293:             deverrouillage_gestionnaire_signaux();
 2294:             return;
 2295:         }
 2296:     }
 2297: 
 2298:     deverrouillage_gestionnaire_signaux();
 2299:     return;
 2300: }
 2301: 
 2302: void
 2303: interruption9(SIGHANDLER_ARGS)
 2304: {
 2305:     pid_t                   pid;
 2306: 
 2307:     struct_processus        *s_etat_processus;
 2308: 
 2309:     verrouillage_gestionnaire_signaux();
 2310: 
 2311: #   ifdef _BROKEN_SIGINFO
 2312:     pid = origine_signal(signal);
 2313: #   else
 2314:     pid = (*siginfo).si_pid;
 2315: #   endif
 2316: 
 2317:     if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)
 2318:     {
 2319:         deverrouillage_gestionnaire_signaux();
 2320:         return;
 2321:     }
 2322: 
 2323:     if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)
 2324:     {
 2325:         printf("[%d] SIGABORT/SIGPROF (thread %llu)\n", (int) getpid(),
 2326:                 (unsigned long long) pthread_self());
 2327:         fflush(stdout);
 2328:     }
 2329: 
 2330: #   ifdef _BROKEN_SIGINFO
 2331:     if (queue_in(getpid(), signal) != 0)
 2332:     {
 2333:         return;
 2334:     }
 2335: 
 2336:     deverrouillage_gestionnaire_signaux();
 2337:     interruption11(signal);
 2338: #   else
 2339:     deverrouillage_gestionnaire_signaux();
 2340:     interruption11(signal, siginfo, context);
 2341: #   endif
 2342:     return;
 2343: }
 2344: 
 2345: void
 2346: interruption10(SIGHANDLER_ARGS)
 2347: {
 2348:     file                    *fichier;
 2349: 
 2350:     pid_t                   pid;
 2351: 
 2352:     struct_processus        *s_etat_processus;
 2353: 
 2354:     unsigned char           nom[8 + 64 + 1];
 2355: 
 2356:     verrouillage_gestionnaire_signaux();
 2357: 
 2358: #   ifdef _BROKEN_SIGINFO
 2359:     pid = origine_signal(signal);
 2360: #   else
 2361:     pid = (*siginfo).si_pid;
 2362: #   endif
 2363: 
 2364:     if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)
 2365:     {
 2366:         deverrouillage_gestionnaire_signaux();
 2367:         return;
 2368:     }
 2369: 
 2370:     snprintf(nom, 8 + 64 + 1, "rpl-out-%lu-%lu", (unsigned long) getpid(),
 2371:             (unsigned long) pthread_self());
 2372: 
 2373:     if ((fichier = fopen(nom, "w+")) != NULL)
 2374:     {
 2375:         fclose(fichier);
 2376: 
 2377:         freopen(nom, "w", stdout);
 2378:         freopen(nom, "w", stderr);
 2379:     }
 2380: 
 2381:     freopen("/dev/null", "r", stdin);
 2382: 
 2383:     if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)
 2384:     {
 2385:         printf("[%d] SIGHUP (thread %llu)\n", (int) getpid(),
 2386:                 (unsigned long long) pthread_self());
 2387:         fflush(stdout);
 2388:     }
 2389: 
 2390:     deverrouillage_gestionnaire_signaux();
 2391:     return;
 2392: }
 2393: 
 2394: void
 2395: interruption11(SIGHANDLER_ARGS)
 2396: {
 2397:     pid_t                   pid;
 2398: 
 2399:     pthread_t               thread;
 2400: 
 2401:     struct_processus        *s_etat_processus;
 2402: 
 2403:     verrouillage_gestionnaire_signaux();
 2404: 
 2405: #   ifdef _BROKEN_SIGINFO
 2406:     pid = origine_signal(signal);
 2407: #   else
 2408:     pid = (*siginfo).si_pid;
 2409: #   endif
 2410: 
 2411:     if (pid == getpid())
 2412:     {
 2413:         if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))
 2414:                 == NULL)
 2415:         {
 2416:             deverrouillage_gestionnaire_signaux();
 2417:             return;
 2418:         }
 2419: 
 2420:         (*s_etat_processus).arret_depuis_abort = -1;
 2421: 
 2422:         if (((*s_etat_processus).type_debug & d_debug_signaux) != 0)
 2423:         {
 2424:             printf("[%d] SIGFABORT (thread %llu)\n", (int) getpid(),
 2425:                     (unsigned long long) pthread_self());
 2426:             fflush(stdout);
 2427:         }
 2428: 
 2429:         /*
 2430:          * var_globale_traitement_retarde_stop :
 2431:          *  0 -> traitement immédiat
 2432:          *  1 -> traitement retardé (aucun signal reçu)
 2433:          * -1 -> traitement retardé (un ou plusieurs signaux stop reçus)
 2434:          */
 2435: 
 2436:         if ((*s_etat_processus).var_volatile_traitement_retarde_stop == 0)
 2437:         {
 2438:             (*s_etat_processus).var_volatile_requete_arret = -1;
 2439:         }
 2440:         else
 2441:         {
 2442:             (*s_etat_processus).var_volatile_traitement_retarde_stop = -1;
 2443:         }
 2444:     }
 2445:     else
 2446:     {
 2447:         if ((s_etat_processus = recherche_thread(getpid(), pthread_self()))
 2448:                 == NULL)
 2449:         {
 2450:             deverrouillage_gestionnaire_signaux();
 2451:             return;
 2452:         }
 2453: 
 2454:         (*s_etat_processus).arret_depuis_abort = -1;
 2455: 
 2456:         // Envoi d'un signal au thread maître du groupe.
 2457: 
 2458:         if (recherche_thread_principal(getpid(), &thread) == d_vrai)
 2459:         {
 2460:             pthread_kill(thread, signal);
 2461:             deverrouillage_gestionnaire_signaux();
 2462:             return;
 2463:         }
 2464:     }
 2465: 
 2466:     deverrouillage_gestionnaire_signaux();
 2467:     return;
 2468: }
 2469: 
 2470: void
 2471: traitement_exceptions_gsl(const char *reason, const char *file,
 2472:         int line, int gsl_errno)
 2473: {
 2474:     struct_processus        *s_etat_processus;
 2475: 
 2476:     verrouillage_gestionnaire_signaux();
 2477: 
 2478:     if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL)
 2479:     {
 2480:         deverrouillage_gestionnaire_signaux();
 2481:         return;
 2482:     }
 2483: 
 2484:     (*s_etat_processus).var_volatile_exception_gsl = gsl_errno;
 2485:     deverrouillage_gestionnaire_signaux();
 2486:     return;
 2487: }
 2488: 
 2489: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>