Annotation of rpl/src/interruptions.c, revision 1.18

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

CVSweb interface <joel.bertrand@systella.fr>