Annotation of rpl/src/instructions_w1.c, revision 1.98

1.1       bertrand    1: /*
                      2: ================================================================================
1.97      bertrand    3:   RPL/2 (R) version 4.1.22
1.92      bertrand    4:   Copyright (C) 1989-2015 Dr. BERTRAND Joël
1.1       bertrand    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: 
1.20      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   Fonction 'while'
                     29: ================================================================================
                     30:   Entrées :
                     31: --------------------------------------------------------------------------------
                     32:   Sorties :
                     33: --------------------------------------------------------------------------------
                     34:   Effets de bord : néant
                     35: ================================================================================
                     36: */
                     37: 
                     38: void
                     39: instruction_while(struct_processus *s_etat_processus)
                     40: {
                     41:    (*s_etat_processus).erreur_execution = d_ex;
                     42: 
                     43:    if ((*s_etat_processus).affichage_arguments == 'Y')
                     44:    {
                     45:        printf("\n  WHILE ");
                     46: 
                     47:        if ((*s_etat_processus).langue == 'F')
                     48:        {
                     49:            printf("(structure de contrôle)\n\n");
                     50:            printf("  Utilisation :\n\n");
                     51:        }
                     52:        else
                     53:        {
                     54:            printf("(control statement)\n\n");
                     55:            printf("  Usage:\n\n");
                     56:        }
                     57: 
                     58:        printf("    WHILE\n");
                     59:        printf("        (clause)\n");
                     60:        printf("    REPEAT\n");
                     61:        printf("        (expression 1)\n");
                     62:        printf("        EXIT\n");
                     63:        printf("        (expression 2)\n");
                     64:        printf("    END\n\n");
                     65: 
                     66:        printf("    WHILE\n");
                     67:        printf("        (clause)\n");
                     68:        printf("    REPEAT\n");
                     69:        printf("        (expression)\n");
                     70:        printf("    END\n");
                     71: 
                     72:        return;
                     73:    }
                     74:    else if ((*s_etat_processus).test_instruction == 'Y')
                     75:    {
                     76:        (*s_etat_processus).nombre_arguments = -1;
                     77:        return;
                     78:    }
                     79: 
                     80:    empilement_pile_systeme(s_etat_processus);
                     81: 
                     82:    if ((*s_etat_processus).erreur_systeme != d_es)
                     83:    {
                     84:        return;
                     85:    }
                     86: 
                     87:    (*(*s_etat_processus).l_base_pile_systeme).type_cloture = 'W';
                     88:    (*(*s_etat_processus).l_base_pile_systeme).clause = 'W';
                     89: 
                     90:    if ((*s_etat_processus).mode_execution_programme == 'Y')
                     91:    {
                     92:        (*(*s_etat_processus).l_base_pile_systeme).adresse_retour =
                     93:                (*s_etat_processus).position_courante;
                     94:    }
                     95:    else
                     96:    {
                     97:        if ((*s_etat_processus).expression_courante == NULL)
                     98:        {
                     99:            (*s_etat_processus).erreur_execution =
                    100:                    d_ex_erreur_traitement_boucle;
                    101:            return;
                    102:        }
                    103: 
                    104:        (*(*s_etat_processus).l_base_pile_systeme).pointeur_objet_retour =
                    105:                (*s_etat_processus).expression_courante;
                    106:    }
                    107: 
                    108:    return;
                    109: }
                    110: 
                    111: 
                    112: /*
                    113: ================================================================================
                    114:   Fonction 'warranty'
                    115: ================================================================================
                    116:   Entrées :
                    117: --------------------------------------------------------------------------------
                    118:   Sorties :
                    119: --------------------------------------------------------------------------------
                    120:   Effets de bord : néant
                    121: ================================================================================
                    122: */
                    123: 
                    124: void
                    125: instruction_warranty(struct_processus *s_etat_processus)
                    126: {
1.20      bertrand  127: #  include                 "garanties-conv.h"
1.1       bertrand  128: 
                    129:    (*s_etat_processus).erreur_execution = d_ex;
                    130: 
                    131:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    132:    {
                    133:        printf("\n  WARRANTY ");
                    134: 
                    135:        if ((*s_etat_processus).langue == 'F')
                    136:        {
                    137:            printf("(garantie)\n\n");
                    138:            printf("  Aucun argument\n");
                    139:        }
                    140:        else
                    141:        {
                    142:            printf("(warranty)\n\n");
                    143:            printf("  No argument\n");
                    144:        }
                    145: 
                    146:        return;
                    147:    }
                    148:    else if ((*s_etat_processus).test_instruction == 'Y')
                    149:    {
                    150:        (*s_etat_processus).nombre_arguments = -1;
                    151:        return;
                    152:    }
                    153: 
                    154:    printf("%s\n", warranty);
                    155: 
                    156:    if ((*s_etat_processus).hauteur_pile_operationnelle == 0)
                    157:    {
                    158:        printf("\n");
                    159:    }
                    160: 
                    161:    return;
                    162: }
                    163: 
                    164: 
                    165: /*
                    166: ================================================================================
                    167:   Fonction 'wait'
                    168: ================================================================================
                    169:   Entrées :
                    170: --------------------------------------------------------------------------------
                    171:   Sorties :
                    172: --------------------------------------------------------------------------------
                    173:   Effets de bord : néant
                    174: ================================================================================
                    175: */
                    176: 
                    177: void
                    178: instruction_wait(struct_processus *s_etat_processus)
                    179: {
                    180:    int                         code_retour;
                    181:    int                         erreur;
                    182: 
                    183:    real8                       attente;
                    184: 
                    185:    struct_objet                *s_objet;
                    186: 
                    187:    struct timespec             temporisation;
                    188: 
                    189:    (*s_etat_processus).erreur_execution = d_ex;
                    190: 
                    191:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    192:    {
                    193:        printf("\n  WAIT ");
                    194: 
                    195:        if ((*s_etat_processus).langue == 'F')
                    196:        {
                    197:            printf("(attente exprimée en secondes)\n\n");
                    198:        }
                    199:        else
                    200:        {
                    201:            printf("(wait a number of seconds)\n\n");
                    202:        }
                    203: 
                    204:        printf("    1: %s, %s\n", d_INT, d_REL);
                    205: 
                    206:        return;
                    207:    }
                    208:    else if ((*s_etat_processus).test_instruction == 'Y')
                    209:    {
                    210:        (*s_etat_processus).nombre_arguments = -1;
                    211:        return;
                    212:    }
                    213: 
                    214:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    215:    {
                    216:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    217:        {
                    218:            return;
                    219:        }
                    220:    }
                    221: 
                    222:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    223:            &s_objet) == d_erreur)
                    224:    {
                    225:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    226:        return;
                    227:    }
                    228:    
1.30      bertrand  229:    if (((*s_objet).type == INT) || ((*s_objet).type == REL))
1.1       bertrand  230:    {
                    231:        if ((*s_objet).type == INT)
                    232:        {
                    233:            attente = (real8) (*((integer8 *) (*s_objet).objet));
                    234:        }
                    235:        else
                    236:        {
                    237:            attente = (*((real8 *) (*s_objet).objet));
                    238:        }
                    239: 
                    240:        if (attente < 0)
                    241:        {
                    242:            liberation(s_etat_processus, s_objet);
                    243: 
                    244:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    245:            return;
                    246:        }
                    247: 
1.80      bertrand  248:        temporisation.tv_sec = (time_t) floor((double) attente);
1.79      bertrand  249:        temporisation.tv_nsec = (long) ((attente -
                    250:                ((real8) temporisation.tv_sec)) * (integer8) 1000000000);
1.1       bertrand  251: 
                    252:        if ((*s_etat_processus).profilage == d_vrai)
                    253:        {
                    254:            profilage(s_etat_processus, "Sleep function (WAIT)");
                    255: 
                    256:            if ((*s_etat_processus).erreur_systeme != d_es)
                    257:            {
                    258:                return;
                    259:            }
                    260:        }
                    261: 
                    262:        do
                    263:        {
1.51      bertrand  264: #          ifndef SEMAPHORES_NOMMES
                    265:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    266: #          else
                    267:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    268: #          endif
1.1       bertrand  269:            {
                    270:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    271:                return;
                    272:            }
                    273: 
                    274:            code_retour = nanosleep(&temporisation, &temporisation);
                    275:            erreur = errno;
                    276: 
1.51      bertrand  277: #          ifndef SEMAPHORES_NOMMES
                    278:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    279: #          else
                    280:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    281: #          endif
1.1       bertrand  282:            {
1.50      bertrand  283:                if (errno != EINTR)
                    284:                {
                    285:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    286:                    return;
                    287:                }
1.1       bertrand  288:            }
1.28      bertrand  289: 
                    290:            scrutation_injection(s_etat_processus);
                    291: 
1.84      bertrand  292:            if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions)
                    293:                    != 0)
1.83      bertrand  294:            {
                    295:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    296:                return;
                    297:            }
                    298: 
1.28      bertrand  299:            if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                    300:            {
                    301:                affectation_interruptions_logicielles(s_etat_processus);
                    302:            }
                    303: 
1.84      bertrand  304:            if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions)
                    305:                    != 0)
1.83      bertrand  306:            {
                    307:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    308:                return;
                    309:            }
                    310: 
1.28      bertrand  311:            if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                    312:            {
                    313:                traitement_interruptions_logicielles(s_etat_processus);
                    314:            }
1.1       bertrand  315:        } while(((code_retour == -1) && (erreur == EINTR))
                    316:                && ((*s_etat_processus).var_volatile_requete_arret == 0));
                    317: 
                    318:        if ((*s_etat_processus).profilage == d_vrai)
                    319:        {
                    320:            profilage(s_etat_processus, NULL);
                    321:        }
                    322:    }
                    323:    else
                    324:    {
                    325:        liberation(s_etat_processus, s_objet);
                    326: 
                    327:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    328:        return;
                    329:    }
                    330: 
                    331:    liberation(s_etat_processus, s_objet);
                    332: 
                    333:    return;
                    334: }
                    335: 
                    336: 
                    337: /*
                    338: ================================================================================
                    339:   Fonction 'wireframe' (passe en mode d'affichage échantillonné)
                    340: ================================================================================
                    341:   Entrées : structure processus
                    342: --------------------------------------------------------------------------------
                    343:   Sorties :
                    344: --------------------------------------------------------------------------------
                    345:   Effets de bord : néant
                    346: ================================================================================
                    347: */
                    348: 
                    349: void
                    350: instruction_wireframe(struct_processus *s_etat_processus)
                    351: {
                    352:    (*s_etat_processus).erreur_execution = d_ex;
                    353: 
                    354:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    355:    {
                    356:        printf("\n  WIREFRAME ");
                    357: 
                    358:        if ((*s_etat_processus).langue == 'F')
                    359:        {
                    360:            printf("(graphique tridimensionnel grillagé)\n\n");
                    361:            printf("  Aucun argument\n");
                    362:        }
                    363:        else
                    364:        {
                    365:            printf("(wireframe 3D graph)\n\n");
                    366:            printf("  No argument\n");
                    367:        }
                    368: 
                    369:        return;
                    370:    }
                    371:    else if ((*s_etat_processus).test_instruction == 'Y')
                    372:    {
                    373:        (*s_etat_processus).nombre_arguments = -1;
                    374:        return;
                    375:    }
                    376: 
                    377:    strcpy((*s_etat_processus).type_trace_eq, "GRILLE 3D");
                    378: 
                    379:    return;
                    380: }
                    381: 
                    382: 
                    383: /*
                    384: ================================================================================
                    385:   Fonction 'write'
                    386: ================================================================================
                    387:   Entrées : structure processus
                    388: --------------------------------------------------------------------------------
                    389:   Sorties :
                    390: --------------------------------------------------------------------------------
                    391:   Effets de bord : néant
                    392: ================================================================================
                    393: */
                    394: 
                    395: void
                    396: instruction_write(struct_processus *s_etat_processus)
                    397: {
1.6       bertrand  398:    const char                          *queue;
                    399: 
1.1       bertrand  400:    int                                 adresse[16];
                    401:    int                                 port;
1.70      bertrand  402:    int                                 sqlite_status;
1.1       bertrand  403: 
1.8       bertrand  404:    integer8                            clef;
                    405:    integer8                            compteur;
                    406:    integer8                            id;
1.79      bertrand  407:    integer8                            longueur;
1.78      bertrand  408:    integer8                            longueur_effective;
1.8       bertrand  409:    integer8                            ordre;
1.79      bertrand  410:    integer8                            recursivite;
1.8       bertrand  411: 
1.64      bertrand  412:    logical1                            format_degenere;
1.8       bertrand  413:    logical1                            mise_a_jour;
                    414: 
1.1       bertrand  415: 
1.6       bertrand  416:    sqlite3_stmt                        *ppStmt;
                    417: 
1.1       bertrand  418:    ssize_t                             ios;
                    419: 
1.5       bertrand  420:    struct_descripteur_fichier          *descripteur;
                    421: 
1.8       bertrand  422:    struct_liste_chainee                *l_element_courant;
                    423:    struct_liste_chainee                *l_element_courant_format;
                    424: 
                    425:    struct_objet                        *s_format;
                    426:    struct_objet                        *s_element;
1.6       bertrand  427:    struct_objet                        *s_objet_argument_1;
1.1       bertrand  428:    struct_objet                        *s_objet_argument_2;
1.6       bertrand  429:    struct_objet                        *s_objet_argument_3;
1.1       bertrand  430: 
                    431:    struct sigaction                    action;
                    432:    struct sigaction                    registre;
                    433: 
                    434:    struct sockaddr_in                  adresse_ipv4;
1.20      bertrand  435: #  ifdef IPV6
1.1       bertrand  436:    struct sockaddr_in6                 adresse_ipv6;
1.20      bertrand  437: #  endif
1.1       bertrand  438:    struct sockaddr_un                  adresse_unix;
                    439: 
                    440:    struct flock                        lock;
                    441: 
1.70      bertrand  442:    struct timespec                     attente;
                    443: 
1.1       bertrand  444:    uint32_t                            calcul_adresse;
                    445: 
                    446:    unsigned char                       *chaine;
1.5       bertrand  447:    unsigned char                       *chaine_utf8;
1.8       bertrand  448:    unsigned char                       *clef_utf8;
1.6       bertrand  449:    unsigned char                       *commande;
1.64      bertrand  450:    unsigned char                       *format_chaine;
1.1       bertrand  451: 
                    452:    unsigned long                       i;
                    453: 
                    454:    (*s_etat_processus).erreur_execution = d_ex;
                    455: 
                    456:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    457:    {
                    458:        printf("\n  WRITE ");
                    459: 
                    460:        if ((*s_etat_processus).langue == 'F')
                    461:        {
                    462:            printf("(écriture d'un enregistrement d'un fichier)\n\n");
                    463:        }
                    464:        else
                    465:        {
                    466:            printf("(write a record of a file)\n\n");
                    467:        }
                    468: 
                    469:        printf("    2: %s\n", d_LST);
1.6       bertrand  470:        printf("    1: %s, %s\n\n", d_FCH, d_SCK);
1.1       bertrand  471: 
1.6       bertrand  472:        printf("    3: %s\n", d_LST);
1.8       bertrand  473:        printf("    2: %s\n", d_INT);
1.6       bertrand  474:        printf("    1: %s\n", d_FCH);
1.1       bertrand  475:        return;
                    476:    }
                    477:    else if ((*s_etat_processus).test_instruction == 'Y')
                    478:    {
                    479:        (*s_etat_processus).nombre_arguments = -1;
                    480:        return;
                    481:    }
                    482: 
                    483:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    484:    {
1.6       bertrand  485:        if ((*s_etat_processus).l_base_pile == NULL)
1.1       bertrand  486:        {
1.6       bertrand  487:            (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1.1       bertrand  488:            return;
                    489:        }
1.6       bertrand  490: 
                    491:        if ((*(*(*s_etat_processus).l_base_pile).donnee).type == FCH)
                    492:        {
                    493:            if ((*((struct_fichier *) (*(*(*s_etat_processus).l_base_pile)
1.9       bertrand  494:                    .donnee).objet)).acces == 'D')
1.6       bertrand  495:            {
1.9       bertrand  496:                if (empilement_pile_last(s_etat_processus, 3) == d_erreur)
1.6       bertrand  497:                {
                    498:                    return;
                    499:                }
                    500:            }
                    501:            else
                    502:            {
1.9       bertrand  503:                if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
1.6       bertrand  504:                {
                    505:                    return;
                    506:                }
                    507:            }
                    508:        }
                    509:        else
                    510:        {
                    511:            if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    512:            {
                    513:                return;
                    514:            }
                    515:        }
1.1       bertrand  516:    }
                    517: 
                    518:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    519:            &s_objet_argument_1) == d_erreur)
                    520:    {
                    521:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    522:        return;
                    523:    }
                    524:    
                    525:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    526:            &s_objet_argument_2) == d_erreur)
                    527:    {
                    528:        liberation(s_etat_processus, s_objet_argument_1);
                    529: 
                    530:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    531:        return;
                    532:    }
                    533:    
1.6       bertrand  534:    if ((*s_objet_argument_1).type == FCH)
1.1       bertrand  535:    {
1.5       bertrand  536:        if ((descripteur = descripteur_fichier(s_etat_processus,
                    537:                (struct_fichier *) (*s_objet_argument_1).objet)) == NULL)
                    538:        {
                    539:            return;
                    540:        }
                    541: 
1.1       bertrand  542:        /*
                    543:         * Vérification des verrous
                    544:         */
                    545: 
                    546:        lock.l_type = F_WRLCK;
                    547:        lock.l_whence = SEEK_SET;
                    548:        lock.l_start = 0;
                    549:        lock.l_len = 0;
                    550:        lock.l_pid = getpid();
                    551:        recursivite = 0;
                    552: 
1.5       bertrand  553:        if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
                    554:                == -1)
1.1       bertrand  555:        {
                    556:            liberation(s_etat_processus, s_objet_argument_2);
                    557:            liberation(s_etat_processus, s_objet_argument_1);
                    558: 
                    559:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    560:            return;
                    561:        }
                    562: 
                    563:        if (lock.l_type != F_UNLCK)
                    564:        {
                    565:            liberation(s_etat_processus, s_objet_argument_2);
                    566:            liberation(s_etat_processus, s_objet_argument_1);
                    567: 
                    568:            (*s_etat_processus).erreur_execution =
                    569:                    d_ex_fichier_verrouille;
                    570:            return;
                    571:        }
                    572: 
                    573:        /*
                    574:         * Vérification de l'autorisation d'écriture
                    575:         */
                    576: 
                    577:        if ((*((struct_fichier *) (*s_objet_argument_1).objet))
                    578:                .protection == 'R')
                    579:        {
                    580:            liberation(s_etat_processus, s_objet_argument_2);
                    581:            liberation(s_etat_processus, s_objet_argument_1);
                    582: 
                    583:            (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
                    584:            return;
                    585:        }
                    586: 
                    587:        if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire == 'N')
                    588:        {
                    589:            /*
                    590:             * Fichiers formatés
                    591:             */
                    592: 
1.6       bertrand  593:            if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                    594:                    == 'S')
1.1       bertrand  595:            {
1.6       bertrand  596:                if ((*s_objet_argument_2).type != LST)
                    597:                {
                    598:                    liberation(s_etat_processus, s_objet_argument_2);
                    599:                    liberation(s_etat_processus, s_objet_argument_1);
                    600: 
                    601:                    (*s_etat_processus).erreur_execution =
                    602:                            d_ex_erreur_type_argument;
                    603:                    return;
                    604:                }
                    605: 
                    606:                if ((chaine = formateur_fichier(s_etat_processus,
                    607:                        s_objet_argument_2, (*((struct_fichier *)
                    608:                        (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
1.75      bertrand  609:                        &longueur_effective, &recursivite, d_vrai)) == NULL)
1.6       bertrand  610:                {
                    611:                    liberation(s_etat_processus, s_objet_argument_2);
                    612:                    liberation(s_etat_processus, s_objet_argument_1);
1.1       bertrand  613: 
1.6       bertrand  614:                    return;
                    615:                }
1.1       bertrand  616: 
1.5       bertrand  617:                BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
                    618: 
                    619:                if (fseek((*descripteur).descripteur_c, (long) 0, SEEK_END)
                    620:                        != 0)
1.1       bertrand  621:                {
                    622:                    liberation(s_etat_processus, s_objet_argument_2);
                    623:                    liberation(s_etat_processus, s_objet_argument_1);
                    624: 
                    625:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    626:                    return;
                    627:                }
                    628: 
1.5       bertrand  629:                if ((chaine_utf8 = transliteration(s_etat_processus,
                    630:                        chaine, d_locale, "UTF-8")) == NULL)
                    631:                {
1.6       bertrand  632:                    free(chaine);
                    633: 
1.5       bertrand  634:                    liberation(s_etat_processus, s_objet_argument_2);
                    635:                    liberation(s_etat_processus, s_objet_argument_1);
                    636: 
                    637:                    return;
                    638:                }
                    639: 
1.6       bertrand  640:                free(chaine);
                    641: 
1.7       bertrand  642:                if (fprintf((*descripteur).descripteur_c, "%s\n", chaine_utf8)
                    643:                        < 0)
1.1       bertrand  644:                {
1.5       bertrand  645:                    free(chaine_utf8);
                    646: 
1.1       bertrand  647:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    648:                    return;
                    649:                }
1.5       bertrand  650: 
                    651:                free(chaine_utf8);
1.1       bertrand  652:            }
                    653:            else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                    654:                    == 'D')
                    655:            {
1.6       bertrand  656:                BUG(((*descripteur).type != 'S'), uprintf("Bad filetype !\n"));
                    657: 
                    658:                if ((*s_objet_argument_2).type != INT)
                    659:                {
                    660:                    liberation(s_etat_processus, s_objet_argument_2);
                    661:                    liberation(s_etat_processus, s_objet_argument_1);
                    662: 
                    663:                    (*s_etat_processus).erreur_execution =
                    664:                            d_ex_erreur_type_argument;
                    665:                    return;
                    666:                }
                    667: 
                    668:                if (depilement(s_etat_processus, &((*s_etat_processus)
                    669:                        .l_base_pile), &s_objet_argument_3) == d_erreur)
                    670:                {
                    671:                    (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    672:                    return;
                    673:                }
                    674: 
                    675:                if ((*s_objet_argument_3).type != LST)
                    676:                {
                    677:                    liberation(s_etat_processus, s_objet_argument_3);
                    678:                    liberation(s_etat_processus, s_objet_argument_2);
                    679:                    liberation(s_etat_processus, s_objet_argument_1);
                    680: 
                    681:                    (*s_etat_processus).erreur_execution =
                    682:                            d_ex_erreur_type_argument;
                    683:                    return;
                    684:                }
                    685: 
1.8       bertrand  686:                // Modification ou création d'un nouvel enregistrement
                    687: 
                    688:                if ((chaine = formateur_fichier(s_etat_processus,
                    689:                        s_objet_argument_3, (*((struct_fichier *)
                    690:                        (*s_objet_argument_1).objet)).format, 0, 0, ' ',
1.75      bertrand  691:                        'F', &longueur_effective, &recursivite, d_vrai))
                    692:                        == NULL)
1.8       bertrand  693:                {
                    694:                    liberation(s_etat_processus, s_objet_argument_3);
                    695:                    liberation(s_etat_processus, s_objet_argument_2);
                    696:                    liberation(s_etat_processus, s_objet_argument_1);
                    697: 
                    698:                    return;
                    699:                }
                    700: 
                    701:                if ((chaine_utf8 = transliteration(s_etat_processus,
                    702:                        chaine, d_locale, "UTF-8")) == NULL)
                    703:                {
                    704:                    free(chaine);
                    705: 
                    706:                    liberation(s_etat_processus, s_objet_argument_3);
                    707:                    liberation(s_etat_processus, s_objet_argument_2);
                    708:                    liberation(s_etat_processus, s_objet_argument_1);
                    709: 
                    710:                    return;
                    711:                }
                    712: 
                    713:                free(chaine);
                    714: 
1.94      bertrand  715:                if (alsprintf(s_etat_processus, &commande,
                    716:                        "insert or replace into data "
1.8       bertrand  717:                        "(id, data) values (%lld, '%s')", (*((integer8 *)
                    718:                        (*s_objet_argument_2).objet)), chaine_utf8) < 0)
                    719:                {
1.9       bertrand  720:                    (*s_etat_processus).erreur_systeme =
                    721:                            d_es_allocation_memoire;
1.8       bertrand  722:                    return;
                    723:                }
                    724: 
                    725:                free(chaine_utf8);
                    726: 
                    727:                if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.79      bertrand  728:                        commande, (int) strlen(commande), &ppStmt, &queue)
1.8       bertrand  729:                        != SQLITE_OK)
                    730:                {
                    731:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    732:                    return;
                    733:                }
                    734: 
                    735:                if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    736:                {
                    737:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    738:                    return;
                    739:                }
                    740: 
                    741:                if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    742:                {
                    743:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    744:                    return;
                    745:                }
                    746: 
                    747:                liberation(s_etat_processus, s_objet_argument_3);
                    748:                free(commande);
                    749:            }
                    750:            else // Fichiers indexés
                    751:            {
                    752:                BUG(((*descripteur).type != 'S'), uprintf("Bad filetype !\n"));
                    753: 
                    754:                if ((*s_objet_argument_2).type != LST)
                    755:                {
                    756:                    liberation(s_etat_processus, s_objet_argument_2);
                    757:                    liberation(s_etat_processus, s_objet_argument_1);
                    758: 
                    759:                    (*s_etat_processus).erreur_execution =
                    760:                            d_ex_erreur_type_argument;
                    761:                    return;
                    762:                }
                    763: 
1.9       bertrand  764:                // Récupération de la position de la clef
1.8       bertrand  765: 
1.94      bertrand  766:                if (alsprintf(s_etat_processus, &commande,
                    767:                        "select key from control where id = 1") < 0)
1.8       bertrand  768:                {
1.9       bertrand  769:                    (*s_etat_processus).erreur_systeme =
                    770:                            d_es_allocation_memoire;
1.8       bertrand  771:                    return;
                    772:                }
                    773: 
                    774:                if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.79      bertrand  775:                        commande, (int) strlen(commande), &ppStmt, &queue)
1.8       bertrand  776:                        != SQLITE_OK)
                    777:                {
1.9       bertrand  778:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  779:                    return;
                    780:                }
                    781: 
1.70      bertrand  782:                attente.tv_sec = 0;
                    783:                attente.tv_nsec = GRANULARITE_us * 1000;
                    784: 
                    785:                do
1.8       bertrand  786:                {
1.70      bertrand  787:                    sqlite_status = sqlite3_step(ppStmt);
                    788: 
                    789:                    if (sqlite_status == SQLITE_ROW)
                    790:                    {
                    791:                        break;
                    792:                    }
                    793:                    else if ((sqlite_status == SQLITE_BUSY) ||
                    794:                            (sqlite_status == SQLITE_LOCKED))
                    795:                    {
                    796:                        nanosleep(&attente, NULL);
                    797:                        INCR_GRANULARITE(attente.tv_nsec);
                    798:                    }
                    799:                    else
                    800:                    {
                    801:                        (*s_etat_processus).erreur_systeme =
                    802:                                d_es_erreur_fichier;
                    803:                        return;
                    804:                    }
                    805:                } while(sqlite_status != SQLITE_ROW);
1.8       bertrand  806: 
                    807:                if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
                    808:                {
1.9       bertrand  809:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  810:                    return;
                    811:                }
                    812: 
                    813:                clef = sqlite3_column_int64(ppStmt, 0);
                    814: 
                    815:                if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    816:                {
1.9       bertrand  817:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  818:                    return;
                    819:                }
                    820: 
                    821:                if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    822:                {
1.9       bertrand  823:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  824:                    return;
                    825:                }
                    826: 
                    827:                free(commande);
                    828: 
                    829:                l_element_courant = (struct_liste_chainee *)
                    830:                        (*s_objet_argument_2).objet;
                    831:                l_element_courant_format = (struct_liste_chainee *)
                    832:                        (*(*((struct_fichier *) (*s_objet_argument_1).objet))
                    833:                        .format).objet;
                    834:                compteur = 1;
                    835: 
                    836:                while((l_element_courant != NULL) &&
                    837:                        (l_element_courant_format != NULL))
                    838:                {
                    839:                    if (compteur == clef)
                    840:                    {
                    841:                        break;
                    842:                    }
                    843: 
                    844:                    l_element_courant = (*l_element_courant).suivant;
                    845:                    l_element_courant_format = (*l_element_courant_format)
                    846:                            .suivant;
                    847:                    compteur++;
                    848:                }
                    849: 
                    850:                if ((l_element_courant == NULL) ||
                    851:                        (l_element_courant_format == NULL))
                    852:                {
                    853:                    (*s_etat_processus).erreur_execution =
                    854:                            d_ex_clef_inexistante;
                    855:                        
                    856:                    liberation(s_etat_processus, s_objet_argument_2);
                    857:                    liberation(s_etat_processus, s_objet_argument_1);
                    858: 
                    859:                    return;
                    860:                }
                    861: 
                    862:                if ((s_element = allocation(s_etat_processus, LST)) == NULL)
                    863:                {
                    864:                    (*s_etat_processus).erreur_systeme =
                    865:                            d_es_allocation_memoire;
                    866:                    return;
                    867:                }
                    868: 
                    869:                if (((*s_element).objet = allocation_maillon(s_etat_processus))
                    870:                        == NULL)
                    871:                {
                    872:                    (*s_etat_processus).erreur_systeme =
                    873:                            d_es_allocation_memoire;
                    874:                    return;
                    875:                }
                    876: 
                    877:                (*((struct_liste_chainee *) (*s_element).objet)).suivant = NULL;
                    878: 
                    879:                if (((*((struct_liste_chainee *) (*s_element).objet))
                    880:                        .donnee = copie_objet(s_etat_processus,
                    881:                        (*l_element_courant).donnee, 'N')) == NULL)
                    882:                {
                    883:                    (*s_etat_processus).erreur_systeme =
                    884:                            d_es_allocation_memoire;
                    885:                    return;
                    886:                }
                    887: 
                    888:                if ((s_format = allocation(s_etat_processus, LST)) == NULL)
                    889:                {
                    890:                    (*s_etat_processus).erreur_systeme =
                    891:                            d_es_allocation_memoire;
                    892:                    return;
                    893:                }
                    894: 
                    895:                if (((*s_format).objet = allocation_maillon(s_etat_processus))
                    896:                        == NULL)
                    897:                {
                    898:                    (*s_etat_processus).erreur_systeme =
                    899:                            d_es_allocation_memoire;
                    900:                    return;
                    901:                }
                    902: 
                    903:                (*((struct_liste_chainee *) (*s_format).objet)).suivant = NULL;
                    904: 
                    905:                if (((*((struct_liste_chainee *) (*s_format).objet))
                    906:                        .donnee = copie_objet(s_etat_processus,
                    907:                        (*l_element_courant_format).donnee, 'N')) == NULL)
                    908:                {
                    909:                    (*s_etat_processus).erreur_systeme =
                    910:                            d_es_allocation_memoire;
                    911:                    return;
                    912:                }
                    913: 
                    914:                if ((chaine = formateur_fichier(s_etat_processus,
                    915:                        s_element, s_format, 0, 0, ' ',
1.75      bertrand  916:                        'F', &longueur_effective, &recursivite, d_vrai))
                    917:                        == NULL)
1.8       bertrand  918:                {
                    919:                    liberation(s_etat_processus, s_element);
                    920:                    liberation(s_etat_processus, s_format);
                    921:                    liberation(s_etat_processus, s_objet_argument_2);
                    922:                    liberation(s_etat_processus, s_objet_argument_1);
                    923: 
                    924:                    return;
                    925:                }
                    926: 
                    927:                liberation(s_etat_processus, s_element);
                    928:                liberation(s_etat_processus, s_format);
                    929: 
                    930:                if ((clef_utf8 = transliteration(s_etat_processus,
                    931:                        chaine, d_locale, "UTF-8")) == NULL)
                    932:                {
                    933:                    liberation(s_etat_processus, s_objet_argument_2);
                    934:                    liberation(s_etat_processus, s_objet_argument_1);
                    935: 
                    936:                    return;
                    937:                }
                    938: 
                    939:                free(chaine);
                    940: 
                    941:                // Récupération de l'identifiant de la clef
                    942: 
1.94      bertrand  943:                if (alsprintf(s_etat_processus, &commande,
                    944:                        "select id from key where key = '%s'", clef_utf8) < 0)
1.8       bertrand  945:                {
1.9       bertrand  946:                    (*s_etat_processus).erreur_systeme =
                    947:                            d_es_allocation_memoire;
1.8       bertrand  948:                    return;
                    949:                }
                    950: 
                    951:                if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.79      bertrand  952:                        commande, (int) strlen(commande), &ppStmt, &queue)
1.8       bertrand  953:                        != SQLITE_OK)
                    954:                {
1.9       bertrand  955:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand  956:                    return;
                    957:                }
                    958: 
1.70      bertrand  959:                attente.tv_sec = 0;
                    960:                attente.tv_nsec = GRANULARITE_us * 1000;
                    961: 
                    962:                do
1.8       bertrand  963:                {
1.70      bertrand  964:                    switch(sqlite_status = sqlite3_step(ppStmt))
1.8       bertrand  965:                    {
1.70      bertrand  966:                        case SQLITE_ROW:
                    967:                        {
                    968:                            // Une clef existe.
                    969: 
                    970:                            mise_a_jour = d_vrai;
                    971:                            break;
                    972:                        }
1.8       bertrand  973: 
1.70      bertrand  974:                        case SQLITE_DONE:
                    975:                        {
                    976:                            // Aucune clef n'existe.
                    977: 
                    978:                            mise_a_jour = d_faux;
1.8       bertrand  979: 
1.70      bertrand  980:                            if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    981:                            {
                    982:                                (*s_etat_processus).erreur_systeme =
                    983:                                        d_es_erreur_fichier;
                    984:                                return;
                    985:                            }
1.8       bertrand  986: 
1.70      bertrand  987:                            free(commande);
1.8       bertrand  988: 
1.94      bertrand  989:                            if (alsprintf(s_etat_processus, &commande,
                    990:                                    "insert into key (key) values ('%s')",
                    991:                                    clef_utf8) < 0)
1.70      bertrand  992:                            {
                    993:                                (*s_etat_processus).erreur_systeme =
                    994:                                        d_es_allocation_memoire;
                    995:                                return;
                    996:                            }
1.8       bertrand  997: 
1.70      bertrand  998:                            if (sqlite3_prepare_v2((*descripteur)
1.79      bertrand  999:                                    .descripteur_sqlite, commande,
                   1000:                                    (int) strlen(commande), &ppStmt, &queue)
1.70      bertrand 1001:                                    != SQLITE_OK)
                   1002:                            {
                   1003:                                (*s_etat_processus).erreur_systeme =
                   1004:                                        d_es_erreur_fichier;
                   1005:                                return;
                   1006:                            }
1.8       bertrand 1007: 
1.70      bertrand 1008:                            if (sqlite3_step(ppStmt) != SQLITE_DONE)
                   1009:                            {
                   1010:                                (*s_etat_processus).erreur_systeme =
                   1011:                                        d_es_erreur_fichier;
                   1012:                                return;
                   1013:                            }
1.8       bertrand 1014: 
1.70      bertrand 1015:                            if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1016:                            {
                   1017:                                (*s_etat_processus).erreur_systeme =
                   1018:                                        d_es_erreur_fichier;
                   1019:                                return;
                   1020:                            }
1.8       bertrand 1021: 
1.70      bertrand 1022:                            free(commande);
1.8       bertrand 1023: 
1.94      bertrand 1024:                            if (alsprintf(s_etat_processus, &commande,
                   1025:                                    "select id from key where key = '%s'",
                   1026:                                    clef_utf8) < 0)
1.70      bertrand 1027:                            {
                   1028:                                (*s_etat_processus).erreur_systeme =
                   1029:                                        d_es_allocation_memoire;
                   1030:                                return;
                   1031:                            }
1.8       bertrand 1032: 
1.70      bertrand 1033:                            if (sqlite3_prepare_v2((*descripteur)
1.79      bertrand 1034:                                    .descripteur_sqlite, commande,
                   1035:                                    (int) strlen(commande), &ppStmt, &queue)
1.70      bertrand 1036:                                    != SQLITE_OK)
                   1037:                            {
                   1038:                                (*s_etat_processus).erreur_systeme =
                   1039:                                        d_es_erreur_fichier;
                   1040:                                return;
                   1041:                            }
1.8       bertrand 1042: 
1.70      bertrand 1043:                            break;
1.8       bertrand 1044:                        }
                   1045: 
1.70      bertrand 1046:                        case SQLITE_BUSY:
                   1047:                        case SQLITE_LOCKED:
1.8       bertrand 1048:                        {
1.70      bertrand 1049:                            nanosleep(&attente, NULL);
                   1050:                            INCR_GRANULARITE(attente.tv_nsec);
                   1051:                            break;
1.8       bertrand 1052:                        }
                   1053: 
1.70      bertrand 1054:                        default:
1.8       bertrand 1055:                        {
                   1056:                            (*s_etat_processus).erreur_systeme =
                   1057:                                    d_es_erreur_fichier;
                   1058:                            return;
                   1059:                        }
                   1060:                    }
1.70      bertrand 1061:                } while(sqlite_status != SQLITE_ROW);
1.8       bertrand 1062: 
                   1063:                if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER)
                   1064:                {
1.9       bertrand 1065:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1066:                    return;
                   1067:                }
                   1068: 
                   1069:                id = sqlite3_column_int64(ppStmt, 0);
                   1070: 
                   1071:                if (sqlite3_step(ppStmt) != SQLITE_DONE)
1.6       bertrand 1072:                {
1.9       bertrand 1073:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1074:                    return;
                   1075:                }
1.6       bertrand 1076: 
1.8       bertrand 1077:                if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1078:                {
1.9       bertrand 1079:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1080:                    return;
                   1081:                }
                   1082: 
                   1083:                free(commande);
                   1084: 
                   1085:                // Modification de la clef
                   1086: 
                   1087:                if (mise_a_jour == d_vrai)
                   1088:                {
1.94      bertrand 1089:                    if (alsprintf(s_etat_processus, &commande,
                   1090:                            "update key set key = '%s' where id = %lld",
                   1091:                            clef_utf8, id) < 0)
1.6       bertrand 1092:                    {
1.9       bertrand 1093:                        (*s_etat_processus).erreur_systeme =
                   1094:                                d_es_allocation_memoire;
1.6       bertrand 1095:                        return;
                   1096:                    }
1.8       bertrand 1097: 
                   1098:                    if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.79      bertrand 1099:                            commande, (int) strlen(commande), &ppStmt, &queue)
1.8       bertrand 1100:                            != SQLITE_OK)
                   1101:                    {
                   1102:                        (*s_etat_processus).erreur_systeme =
                   1103:                                d_es_erreur_fichier;
                   1104:                        return;
                   1105:                    }
                   1106: 
                   1107:                    if (sqlite3_step(ppStmt) != SQLITE_DONE)
                   1108:                    {
                   1109:                        (*s_etat_processus).erreur_systeme =
                   1110:                                d_es_erreur_fichier;
                   1111:                        return;
                   1112:                    }
                   1113: 
                   1114:                    if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1115:                    {
                   1116:                        (*s_etat_processus).erreur_systeme =
                   1117:                                d_es_erreur_fichier;
                   1118:                        return;
                   1119:                    }
                   1120: 
                   1121:                    free(commande);
1.6       bertrand 1122:                }
1.8       bertrand 1123: 
                   1124:                // Effacement de l'enregistrement existant
                   1125: 
1.94      bertrand 1126:                if (alsprintf(s_etat_processus, &commande,
                   1127:                        "delete from data where key_id = %lld", id) < 0)
1.8       bertrand 1128:                {
1.9       bertrand 1129:                    (*s_etat_processus).erreur_systeme =
                   1130:                            d_es_allocation_memoire;
1.8       bertrand 1131:                    return;
                   1132:                }
                   1133: 
                   1134:                if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.79      bertrand 1135:                        commande, (int) strlen(commande), &ppStmt, &queue)
1.8       bertrand 1136:                        != SQLITE_OK)
                   1137:                {
1.9       bertrand 1138:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1139:                    return;
                   1140:                }
                   1141: 
                   1142:                if (sqlite3_step(ppStmt) != SQLITE_DONE)
                   1143:                {
1.9       bertrand 1144:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1145:                    return;
                   1146:                }
                   1147: 
                   1148:                if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1149:                {
1.9       bertrand 1150:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.8       bertrand 1151:                    return;
                   1152:                }
                   1153: 
                   1154:                free(commande);
                   1155: 
                   1156:                // Modification ou création d'un nouvel enregistrement
                   1157: 
                   1158:                l_element_courant = (struct_liste_chainee *)
                   1159:                        (*s_objet_argument_2).objet;
                   1160:                l_element_courant_format = (struct_liste_chainee *)
                   1161:                        (*(*((struct_fichier *) (*s_objet_argument_1).objet))
                   1162:                        .format).objet;
                   1163:                compteur = 1;
                   1164:                ordre = 1;
                   1165: 
                   1166:                while((l_element_courant != NULL) &&
                   1167:                        (l_element_courant_format != NULL))
1.6       bertrand 1168:                {
1.8       bertrand 1169:                    if (compteur == clef)
                   1170:                    {
                   1171:                        l_element_courant = (*l_element_courant).suivant;
                   1172:                        l_element_courant_format = (*l_element_courant_format)
                   1173:                                .suivant;
                   1174:                        compteur++;
                   1175:                        continue;
                   1176:                    }
                   1177: 
                   1178:                    if ((s_element = allocation(s_etat_processus, LST)) == NULL)
                   1179:                    {
                   1180:                        (*s_etat_processus).erreur_systeme =
                   1181:                                d_es_allocation_memoire;
                   1182:                        return;
                   1183:                    }
                   1184: 
                   1185:                    if (((*s_element).objet =
                   1186:                            allocation_maillon(s_etat_processus)) == NULL)
                   1187:                    {
                   1188:                        (*s_etat_processus).erreur_systeme =
                   1189:                                d_es_allocation_memoire;
                   1190:                        return;
                   1191:                    }
                   1192: 
                   1193:                    (*((struct_liste_chainee *) (*s_element).objet)).suivant
                   1194:                            = NULL;
                   1195: 
                   1196:                    if ((s_format = allocation(s_etat_processus, LST)) == NULL)
                   1197:                    {
                   1198:                        (*s_etat_processus).erreur_systeme =
                   1199:                                d_es_allocation_memoire;
                   1200:                        return;
                   1201:                    }
                   1202: 
                   1203:                    if (((*s_format).objet =
                   1204:                            allocation_maillon(s_etat_processus)) == NULL)
                   1205:                    {
                   1206:                        (*s_etat_processus).erreur_systeme =
                   1207:                                d_es_allocation_memoire;
                   1208:                        return;
                   1209:                    }
                   1210: 
                   1211:                    (*((struct_liste_chainee *) (*s_format).objet)).suivant
                   1212:                            = NULL;
                   1213: 
                   1214:                    if (((*((struct_liste_chainee *) (*s_element).objet))
                   1215:                            .donnee = copie_objet(s_etat_processus,
                   1216:                            (*l_element_courant).donnee, 'N')) == NULL)
                   1217:                    {
                   1218:                        (*s_etat_processus).erreur_systeme =
                   1219:                                d_es_allocation_memoire;
                   1220:                        return;
                   1221:                    }
                   1222: 
                   1223:                    if (((*((struct_liste_chainee *) (*s_format).objet))
                   1224:                            .donnee = copie_objet(s_etat_processus,
                   1225:                            (*l_element_courant_format).donnee, 'N')) == NULL)
                   1226:                    {
                   1227:                        (*s_etat_processus).erreur_systeme =
                   1228:                                d_es_allocation_memoire;
                   1229:                        return;
                   1230:                    }
1.6       bertrand 1231: 
                   1232:                    if ((chaine = formateur_fichier(s_etat_processus,
1.8       bertrand 1233:                            s_element, s_format, 0, 0, ' ',
1.75      bertrand 1234:                            'F', &longueur_effective, &recursivite, d_vrai))
                   1235:                            == NULL)
1.6       bertrand 1236:                    {
1.8       bertrand 1237:                        free(clef_utf8);
1.9       bertrand 1238: 
1.8       bertrand 1239:                        liberation(s_etat_processus, s_element);
                   1240:                        liberation(s_etat_processus, s_format);
1.6       bertrand 1241:                        liberation(s_etat_processus, s_objet_argument_2);
                   1242:                        liberation(s_etat_processus, s_objet_argument_1);
                   1243: 
                   1244:                        return;
                   1245:                    }
                   1246: 
                   1247:                    if ((chaine_utf8 = transliteration(s_etat_processus,
                   1248:                            chaine, d_locale, "UTF-8")) == NULL)
                   1249:                    {
1.8       bertrand 1250:                        free(clef_utf8);
1.6       bertrand 1251:                        free(chaine);
                   1252: 
                   1253:                        liberation(s_etat_processus, s_objet_argument_2);
                   1254:                        liberation(s_etat_processus, s_objet_argument_1);
                   1255: 
                   1256:                        return;
                   1257:                    }
                   1258: 
                   1259:                    free(chaine);
                   1260: 
1.94      bertrand 1261:                    if (alsprintf(s_etat_processus, &commande,
                   1262:                            "insert into data (data, key_id, sequence) values "
1.8       bertrand 1263:                            "('%s', %lld, %lld)", chaine_utf8, id, ordre) < 0)
1.6       bertrand 1264:                    {
1.9       bertrand 1265:                        (*s_etat_processus).erreur_systeme =
                   1266:                                d_es_allocation_memoire;
1.6       bertrand 1267:                        return;
                   1268:                    }
                   1269: 
1.8       bertrand 1270:                    if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
1.79      bertrand 1271:                            commande, (int) strlen(commande), &ppStmt, &queue)
1.8       bertrand 1272:                            != SQLITE_OK)
                   1273:                    {
                   1274:                        (*s_etat_processus).erreur_systeme =
                   1275:                                d_es_erreur_fichier;
                   1276:                        return;
                   1277:                    }
                   1278: 
                   1279:                    if (sqlite3_step(ppStmt) != SQLITE_DONE)
                   1280:                    {
                   1281:                        (*s_etat_processus).erreur_systeme =
                   1282:                                d_es_erreur_fichier;
                   1283:                        return;
                   1284:                    }
                   1285: 
                   1286:                    if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                   1287:                    {
                   1288:                        (*s_etat_processus).erreur_systeme =
                   1289:                                d_es_erreur_fichier;
                   1290:                        return;
                   1291:                    }
                   1292: 
                   1293:                    free(commande);
1.6       bertrand 1294:                    free(chaine_utf8);
1.8       bertrand 1295: 
                   1296:                    liberation(s_etat_processus, s_element);
                   1297:                    liberation(s_etat_processus, s_format);
                   1298: 
                   1299:                    l_element_courant = (*l_element_courant).suivant;
                   1300:                    l_element_courant_format = (*l_element_courant_format)
                   1301:                            .suivant;
                   1302: 
                   1303:                    compteur++;
                   1304:                    ordre++;
1.6       bertrand 1305:                }
                   1306: 
1.8       bertrand 1307:                free(clef_utf8);
1.6       bertrand 1308: 
1.8       bertrand 1309:                if ((l_element_courant != NULL) ||
                   1310:                        (l_element_courant_format != NULL))
1.6       bertrand 1311:                {
1.8       bertrand 1312:                    liberation(s_etat_processus, s_objet_argument_1);
                   1313:                    liberation(s_etat_processus, s_objet_argument_2);
1.6       bertrand 1314: 
1.8       bertrand 1315:                    (*s_etat_processus).erreur_execution =
                   1316:                            d_ex_erreur_format_fichier;
1.6       bertrand 1317:                    return;
                   1318:                }
1.1       bertrand 1319:            }
                   1320:        }
                   1321:        else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire
                   1322:                == 'Y')
                   1323:        {
                   1324:            /*
                   1325:             * Fichiers non formatés
                   1326:             */
                   1327: 
1.75      bertrand 1328:            if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                   1329:                    == 'S')
1.1       bertrand 1330:            {
1.76      bertrand 1331:                if ((*s_objet_argument_2).type != LST)
                   1332:                {
                   1333:                    liberation(s_etat_processus, s_objet_argument_2);
                   1334:                    liberation(s_etat_processus, s_objet_argument_1);
                   1335: 
                   1336:                    (*s_etat_processus).erreur_execution =
                   1337:                            d_ex_erreur_type_argument;
                   1338:                    return;
                   1339:                }
                   1340: 
1.75      bertrand 1341:                if ((chaine = formateur_fichier(s_etat_processus,
                   1342:                        s_objet_argument_2, (*((struct_fichier *)
                   1343:                        (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
                   1344:                        &longueur_effective, &recursivite, d_vrai)) == NULL)
                   1345:                {
                   1346:                    liberation(s_etat_processus, s_objet_argument_2);
                   1347:                    liberation(s_etat_processus, s_objet_argument_1);
1.1       bertrand 1348: 
1.75      bertrand 1349:                    return;
                   1350:                }
1.1       bertrand 1351: 
1.5       bertrand 1352:                BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
                   1353: 
                   1354:                if (fseek((*descripteur).descripteur_c, (long) 0, SEEK_END)
                   1355:                        != 0)
1.1       bertrand 1356:                {
                   1357:                    liberation(s_etat_processus, s_objet_argument_2);
                   1358:                    liberation(s_etat_processus, s_objet_argument_1);
                   1359: 
                   1360:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                   1361:                    return;
                   1362:                }
                   1363: 
1.79      bertrand 1364:                if (fwrite(chaine, sizeof(unsigned char),
                   1365:                        (size_t) longueur_effective,
1.5       bertrand 1366:                        (*descripteur).descripteur_c) !=
                   1367:                        (size_t) longueur_effective)
1.1       bertrand 1368:                {
                   1369:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                   1370:                    return;
                   1371:                }
                   1372:            }
                   1373:            else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                   1374:                    == 'D')
                   1375:            {
1.76      bertrand 1376:                if ((*s_objet_argument_2).type != INT)
                   1377:                {
                   1378:                    liberation(s_etat_processus, s_objet_argument_2);
                   1379:                    liberation(s_etat_processus, s_objet_argument_1);
                   1380: 
                   1381:                    (*s_etat_processus).erreur_execution =
                   1382:                            d_ex_erreur_type_argument;
                   1383:                    return;
                   1384:                }
                   1385: 
                   1386:                if (depilement(s_etat_processus, &((*s_etat_processus)
                   1387:                        .l_base_pile), &s_objet_argument_3) == d_erreur)
                   1388:                {
                   1389:                    (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1390:                    return;
                   1391:                }
                   1392: 
                   1393:                if ((*s_objet_argument_3).type != LST)
                   1394:                {
                   1395:                    liberation(s_etat_processus, s_objet_argument_3);
                   1396:                    liberation(s_etat_processus, s_objet_argument_2);
                   1397:                    liberation(s_etat_processus, s_objet_argument_1);
                   1398: 
                   1399:                    (*s_etat_processus).erreur_execution =
                   1400:                            d_ex_erreur_type_argument;
                   1401:                    return;
                   1402:                }
                   1403: 
1.75      bertrand 1404:                if ((chaine = formateur_fichier(s_etat_processus,
                   1405:                        s_objet_argument_2, (*((struct_fichier *)
                   1406:                        (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
                   1407:                        &longueur_effective, &recursivite, d_faux)) == NULL)
                   1408:                {
                   1409:                    liberation(s_etat_processus, s_objet_argument_2);
                   1410:                    liberation(s_etat_processus, s_objet_argument_1);
                   1411: 
                   1412:                    return;
                   1413:                }
1.1       bertrand 1414:            }
1.75      bertrand 1415:            else // Fichiers indexés
1.1       bertrand 1416:            {
1.76      bertrand 1417:                if ((*s_objet_argument_2).type != LST)
                   1418:                {
                   1419:                    liberation(s_etat_processus, s_objet_argument_2);
                   1420:                    liberation(s_etat_processus, s_objet_argument_1);
                   1421: 
                   1422:                    (*s_etat_processus).erreur_execution =
                   1423:                            d_ex_erreur_type_argument;
                   1424:                    return;
                   1425:                }
                   1426: 
1.75      bertrand 1427:                if ((chaine = formateur_fichier(s_etat_processus,
                   1428:                        s_objet_argument_2, (*((struct_fichier *)
                   1429:                        (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
                   1430:                        &longueur_effective, &recursivite, d_faux)) == NULL)
                   1431:                {
                   1432:                    liberation(s_etat_processus, s_objet_argument_2);
                   1433:                    liberation(s_etat_processus, s_objet_argument_1);
                   1434: 
                   1435:                    return;
                   1436:                }
1.1       bertrand 1437:            }
                   1438: 
                   1439:            free(chaine);
                   1440:        }
                   1441:        else
                   1442:        {
                   1443:            /*
                   1444:             * Fichiers de type FLOW
                   1445:             */
1.33      bertrand 1446: 
                   1447:            if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                   1448:                    == 'S')
                   1449:            {
                   1450:                BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
                   1451: 
1.56      bertrand 1452:                if ((*s_objet_argument_2).type != LST)
                   1453:                {
                   1454:                    liberation(s_etat_processus, s_objet_argument_2);
                   1455:                    liberation(s_etat_processus, s_objet_argument_1);
                   1456: 
                   1457:                    (*s_etat_processus).erreur_execution =
                   1458:                            d_ex_erreur_type_argument;
                   1459:                    return;
                   1460:                }
                   1461: 
                   1462:                if ((*((struct_liste_chainee *) (*s_objet_argument_2).objet))
                   1463:                        .donnee == NULL)
                   1464:                {
                   1465:                    liberation(s_etat_processus, s_objet_argument_2);
                   1466:                    liberation(s_etat_processus, s_objet_argument_1);
                   1467: 
                   1468:                    (*s_etat_processus).erreur_execution =
                   1469:                            d_ex_erreur_type_argument;
                   1470:                    return;
                   1471:                }
                   1472: 
1.64      bertrand 1473:                l_element_courant = (*s_objet_argument_2).objet;
                   1474:                l_element_courant_format = (struct_liste_chainee *)
                   1475:                        (*(*((struct_fichier *) (*s_objet_argument_1).objet))
                   1476:                        .format).objet;
                   1477: 
                   1478:                while((l_element_courant != NULL) &&
                   1479:                        (l_element_courant_format != NULL))
1.33      bertrand 1480:                {
1.64      bertrand 1481:                    if ((*(*l_element_courant).donnee).type != CHN)
                   1482:                    {
                   1483:                        liberation(s_etat_processus, s_objet_argument_2);
                   1484:                        liberation(s_etat_processus, s_objet_argument_1);
                   1485: 
                   1486:                        (*s_etat_processus).erreur_execution =
                   1487:                                d_ex_erreur_type_argument;
                   1488:                        return;
                   1489:                    }
                   1490: 
                   1491:                    if ((*(*l_element_courant_format).donnee).type != CHN)
                   1492:                    {
                   1493:                        liberation(s_etat_processus, s_objet_argument_2);
                   1494:                        liberation(s_etat_processus, s_objet_argument_1);
                   1495: 
                   1496:                        (*s_etat_processus).erreur_execution =
                   1497:                                d_ex_erreur_type_argument;
                   1498:                        return;
                   1499:                    }
                   1500: 
1.94      bertrand 1501:                    if ((format_chaine = conversion_majuscule(s_etat_processus,
                   1502:                            (unsigned char *) (*(*l_element_courant_format)
                   1503:                            .donnee).objet)) == NULL)
1.64      bertrand 1504:                    {
                   1505:                        (*s_etat_processus).erreur_systeme =
                   1506:                                d_es_allocation_memoire;
                   1507:                        return;
                   1508:                    }
                   1509: 
                   1510:                    if (strncmp("LENGTH*(", format_chaine, 8) != 0)
                   1511:                    {
                   1512:                        free(format_chaine);
                   1513: 
                   1514:                        liberation(s_etat_processus, s_objet_argument_2);
                   1515:                        liberation(s_etat_processus, s_objet_argument_1);
                   1516: 
                   1517:                        (*s_etat_processus).erreur_execution =
                   1518:                                d_ex_erreur_format_fichier;
                   1519:                        return;
                   1520:                    }
                   1521: 
1.79      bertrand 1522:                    longueur = (integer8) strlen(format_chaine);
1.64      bertrand 1523: 
1.65      bertrand 1524:                    if (format_chaine[longueur - 1] != ')')
1.64      bertrand 1525:                    {
                   1526:                        free(format_chaine);
                   1527: 
                   1528:                        liberation(s_etat_processus, s_objet_argument_2);
                   1529:                        liberation(s_etat_processus, s_objet_argument_1);
                   1530: 
                   1531:                        (*s_etat_processus).erreur_execution =
                   1532:                                d_ex_erreur_format_fichier;
                   1533:                        return;
                   1534:                    }
                   1535: 
                   1536:                    format_chaine[longueur] = d_code_fin_chaine;
                   1537: 
                   1538:                    if (format_chaine[8] == '*')
                   1539:                    {
                   1540:                        format_degenere = d_vrai;
                   1541:                    }
                   1542:                    else
                   1543:                    {
                   1544:                        // Détermination de la longueur
                   1545:                        format_degenere = d_faux;
                   1546: 
1.79      bertrand 1547:                        if (sscanf(&(format_chaine[8]), "%lld", &longueur) != 1)
1.64      bertrand 1548:                        {
                   1549:                            free(format_chaine);
                   1550: 
                   1551:                            liberation(s_etat_processus, s_objet_argument_2);
                   1552:                            liberation(s_etat_processus, s_objet_argument_1);
1.33      bertrand 1553: 
1.64      bertrand 1554:                            (*s_etat_processus).erreur_execution =
                   1555:                                    d_ex_erreur_format_fichier;
                   1556:                            return;
                   1557:                        }
                   1558:                    }
1.33      bertrand 1559: 
1.64      bertrand 1560:                    free(format_chaine);
1.33      bertrand 1561: 
1.64      bertrand 1562:                    if ((chaine = formateur_flux(s_etat_processus,
                   1563:                            (unsigned char *) (*(*l_element_courant).donnee)
                   1564:                            .objet, &longueur_effective)) == NULL)
                   1565:                    {
                   1566:                        (*s_etat_processus).erreur_systeme =
                   1567:                                d_es_allocation_memoire;
                   1568:                        return;
                   1569:                    }
1.33      bertrand 1570: 
1.64      bertrand 1571:                    if ((format_degenere == d_vrai) ||
                   1572:                            (longueur_effective < longueur))
                   1573:                    {
                   1574:                        if (fwrite(chaine, sizeof(unsigned char),
1.79      bertrand 1575:                                (size_t) longueur_effective,
1.64      bertrand 1576:                                (*descripteur).descripteur_c) !=
                   1577:                                (size_t) longueur_effective)
                   1578:                        {
                   1579:                            (*s_etat_processus).erreur_systeme =
                   1580:                                    d_es_erreur_fichier;
                   1581:                            return;
                   1582:                        }
                   1583:                    }
                   1584:                    else
                   1585:                    {
                   1586:                        if (fwrite(chaine, sizeof(unsigned char),
1.79      bertrand 1587:                                (size_t) longueur_effective,
1.64      bertrand 1588:                                (*descripteur).descripteur_c) !=
                   1589:                                (size_t) longueur)
                   1590:                        {
                   1591:                            (*s_etat_processus).erreur_systeme =
                   1592:                                    d_es_erreur_fichier;
                   1593:                            return;
                   1594:                        }
                   1595:                    }
1.63      bertrand 1596: 
1.64      bertrand 1597:                    free(chaine);
1.63      bertrand 1598: 
1.64      bertrand 1599:                    l_element_courant = (*l_element_courant).suivant;
                   1600:                    l_element_courant_format = (*l_element_courant_format)
                   1601:                            .suivant;
                   1602:                }
1.63      bertrand 1603: 
1.64      bertrand 1604:                if ((l_element_courant_format != NULL) ||
                   1605:                        (l_element_courant != NULL))
1.63      bertrand 1606:                {
1.64      bertrand 1607:                    liberation(s_etat_processus, s_objet_argument_2);
                   1608:                    liberation(s_etat_processus, s_objet_argument_1);
                   1609: 
                   1610:                    (*s_etat_processus).erreur_execution =
                   1611:                            d_ex_erreur_format_fichier;
1.63      bertrand 1612:                    return;
                   1613:                }
1.33      bertrand 1614:            }
                   1615:            else
                   1616:            {
                   1617:                liberation(s_etat_processus, s_objet_argument_1);
                   1618:                liberation(s_etat_processus, s_objet_argument_2);
                   1619: 
                   1620:                (*s_etat_processus).erreur_execution =
                   1621:                        d_ex_erreur_type_fichier;
                   1622:                return;
                   1623:            }
1.1       bertrand 1624:        }
                   1625:    }
                   1626:    else if (((*s_objet_argument_2).type == LST) &&
                   1627:            ((*s_objet_argument_1).type == SCK))
                   1628:    {
                   1629:        /*
                   1630:         * Vérification de l'autorisation d'écriture
                   1631:         */
                   1632: 
                   1633:        if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1634:                .protection == 'R')
                   1635:        {
                   1636:            liberation(s_etat_processus, s_objet_argument_2);
                   1637:            liberation(s_etat_processus, s_objet_argument_1);
                   1638: 
                   1639:            (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
                   1640:            return;
                   1641:        }
                   1642: 
                   1643:        if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire == 'N')
                   1644:        {
                   1645:            /*
                   1646:             * Sockets formatées
                   1647:             */
                   1648: 
                   1649:            if ((chaine = formateur_fichier(s_etat_processus,
                   1650:                    s_objet_argument_2, (*((struct_socket *)
                   1651:                    (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
1.75      bertrand 1652:                    &longueur_effective, &recursivite, d_faux)) == NULL)
1.1       bertrand 1653:            {
                   1654:                liberation(s_etat_processus, s_objet_argument_2);
                   1655:                liberation(s_etat_processus, s_objet_argument_1);
                   1656: 
                   1657:                return;
                   1658:            }
1.33      bertrand 1659:        }
                   1660:        else if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire
                   1661:                == 'Y')
                   1662:        {
                   1663:            /*
                   1664:             * Sockets non formatées
                   1665:             */
1.38      bertrand 1666: 
1.77      bertrand 1667:            if ((chaine = formateur_fichier(s_etat_processus,
                   1668:                    s_objet_argument_2, (*((struct_socket *)
                   1669:                    (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
                   1670:                    &longueur_effective, &recursivite, d_faux)) == NULL)
                   1671:            {
                   1672:                liberation(s_etat_processus, s_objet_argument_2);
                   1673:                liberation(s_etat_processus, s_objet_argument_1);
                   1674: 
                   1675:                return;
                   1676:            }
1.33      bertrand 1677:        }
                   1678:        else
                   1679:        {
                   1680:            /*
                   1681:             *  Sockets de type FLOW
                   1682:             */
                   1683: 
                   1684:            if ((*((*((struct_liste_chainee *) (*s_objet_argument_2).objet))
                   1685:                    .donnee)).type != CHN)
                   1686:            {
                   1687:                liberation(s_etat_processus, s_objet_argument_2);
                   1688:                liberation(s_etat_processus, s_objet_argument_1);
                   1689: 
                   1690:                (*s_etat_processus).erreur_execution =
                   1691:                        d_ex_erreur_type_argument;
                   1692:                return;
                   1693:            }
                   1694: 
                   1695:            if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
                   1696:                    (*((*((struct_liste_chainee *) (*s_objet_argument_2)
                   1697:                    .objet)).donnee)).objet, &longueur_effective)) == NULL)
                   1698:            {
                   1699:                liberation(s_etat_processus, s_objet_argument_2);
                   1700:                liberation(s_etat_processus, s_objet_argument_1);
                   1701: 
                   1702:                return;
                   1703:            }
                   1704:        }
1.1       bertrand 1705: 
1.33      bertrand 1706:        if ((strcmp((*((struct_socket *) (*s_objet_argument_1).objet)).type,
                   1707:                "STREAM") == 0) || (strcmp((*((struct_socket *)
                   1708:                (*s_objet_argument_1).objet)).type,
                   1709:                "SEQUENTIAL DATAGRAM") == 0))
                   1710:        { // Sockets connectées
                   1711: 
                   1712:            action.sa_handler = SIG_IGN;
                   1713:            action.sa_flags = SA_ONSTACK;
                   1714: 
                   1715:            if (sigaction(SIGPIPE, &action, &registre) != 0)
                   1716:            {
                   1717:                (*s_etat_processus).erreur_systeme = d_es_signal;
                   1718:                return;
                   1719:            }
                   1720: 
1.51      bertrand 1721: #          ifndef SEMAPHORES_NOMMES
                   1722:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1723: #          else
                   1724:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1725: #          endif
1.33      bertrand 1726:            {
                   1727:                if (sigaction(SIGPIPE, &registre, NULL) != 0)
                   1728:                {
                   1729:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                   1730:                    return;
                   1731:                }
                   1732: 
                   1733:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1734:                return;
                   1735:            }
1.1       bertrand 1736: 
1.33      bertrand 1737:            if (send((*((struct_socket *) (*s_objet_argument_1).objet))
1.79      bertrand 1738:                    .socket, chaine, (size_t) longueur_effective, 0) < 0)
1.33      bertrand 1739:            {
                   1740:                ios = errno;
1.1       bertrand 1741: 
1.33      bertrand 1742:                if (sigaction(SIGPIPE, &registre, NULL) != 0)
1.1       bertrand 1743:                {
                   1744:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                   1745:                    return;
                   1746:                }
                   1747: 
1.51      bertrand 1748: #              ifndef SEMAPHORES_NOMMES
                   1749:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1750: #              else
                   1751:                    while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1752: #              endif
1.1       bertrand 1753:                {
1.50      bertrand 1754:                    if (errno != EINTR)
                   1755:                    {
                   1756:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1757:                        return;
                   1758:                    }
1.33      bertrand 1759:                }
1.1       bertrand 1760: 
1.33      bertrand 1761:                if ((ios == EPIPE) || (ios == ECONNRESET))
                   1762:                {
                   1763:                    (*s_etat_processus).erreur_execution =
                   1764:                            d_ex_erreur_acces_fichier;
1.1       bertrand 1765:                    return;
                   1766:                }
                   1767: 
1.33      bertrand 1768:                (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                   1769:                return;
                   1770:            }
                   1771: 
1.51      bertrand 1772: #          ifndef SEMAPHORES_NOMMES
                   1773:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1774: #          else
                   1775:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1776: #          endif
1.33      bertrand 1777:            {
                   1778:                if (errno != EINTR)
1.1       bertrand 1779:                {
                   1780:                    if (sigaction(SIGPIPE, &registre, NULL) != 0)
                   1781:                    {
                   1782:                        (*s_etat_processus).erreur_systeme = d_es_signal;
                   1783:                        return;
                   1784:                    }
                   1785: 
1.33      bertrand 1786:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1787:                    return;
                   1788:                }
                   1789:            }
                   1790: 
                   1791:            if (sigaction(SIGPIPE, &registre, NULL) != 0)
                   1792:            {
                   1793:                (*s_etat_processus).erreur_systeme = d_es_signal;
                   1794:                return;
                   1795:            }
                   1796:        }
                   1797:        else
                   1798:        { // Sockets non connectées
                   1799: 
                   1800:            /*
                   1801:             * Vérification de l'adresse distante
                   1802:             */
                   1803: 
                   1804:            if (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
                   1805:                    .adresse_distante, "") == 0)
                   1806:            {
                   1807:                liberation(s_etat_processus, s_objet_argument_1);
                   1808:                liberation(s_etat_processus, s_objet_argument_2);
                   1809: 
                   1810:                (*s_etat_processus).erreur_execution =
                   1811:                        d_ex_erreur_acces_fichier;
                   1812:                return;
                   1813:            }
                   1814: 
                   1815:            /*
                   1816:             * Création de l'adresse logique
                   1817:             */
                   1818: 
                   1819:            if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1820:                    .domaine == PF_UNIX)
                   1821:            {
                   1822:                adresse_unix.sun_family = AF_UNIX;
                   1823:                strncpy(adresse_unix.sun_path, (*((struct_socket *)
                   1824:                        (*s_objet_argument_1).objet)).adresse_distante,
                   1825:                        UNIX_PATH_MAX);
                   1826:                adresse_unix.sun_path[UNIX_PATH_MAX - 1] =
                   1827:                        d_code_fin_chaine;
                   1828: 
1.51      bertrand 1829: #              ifndef SEMAPHORES_NOMMES
                   1830:                    if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1831: #              else
                   1832:                    if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1833: #              endif
1.33      bertrand 1834:                {
                   1835:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1836:                    return;
                   1837:                }
                   1838: 
                   1839:                if (sendto((*((struct_socket *)
                   1840:                        (*s_objet_argument_1).objet)).socket, chaine,
1.79      bertrand 1841:                        (size_t) longueur_effective, 0, (struct sockaddr *)
1.33      bertrand 1842:                        &adresse_unix, sizeof(adresse_unix)) < 0)
                   1843:                {
1.38      bertrand 1844:                    ios = errno;
                   1845: 
1.51      bertrand 1846: #                  ifndef SEMAPHORES_NOMMES
                   1847:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   1848:                                != 0)
                   1849: #                  else
                   1850:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1851: #                  endif
1.1       bertrand 1852:                    {
1.50      bertrand 1853:                        if (errno != EINTR)
                   1854:                        {
                   1855:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1856:                            return;
                   1857:                        }
1.1       bertrand 1858:                    }
                   1859: 
1.34      bertrand 1860:                    if ((ios == EPIPE) || (ios == ECONNRESET))
                   1861:                    {
                   1862:                        (*s_etat_processus).erreur_execution =
                   1863:                                d_ex_erreur_acces_fichier;
                   1864:                        return;
                   1865:                    }
                   1866: 
1.73      bertrand 1867:                    if (ios == EMSGSIZE)
                   1868:                    {
                   1869:                        (*s_etat_processus).erreur_execution =
                   1870:                                d_ex_taille_message;
1.74      bertrand 1871:                        return;
1.73      bertrand 1872:                    }
1.34      bertrand 1873: 
                   1874:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.1       bertrand 1875:                    return;
                   1876:                }
                   1877: 
1.51      bertrand 1878: #              ifndef SEMAPHORES_NOMMES
                   1879:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1880: #              else
                   1881:                    while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1882: #              endif
1.1       bertrand 1883:                {
1.50      bertrand 1884:                    if (errno != EINTR)
                   1885:                    {
                   1886:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1887:                        return;
                   1888:                    }
1.1       bertrand 1889:                }
                   1890:            }
1.33      bertrand 1891:            else if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1892:                    .domaine == PF_INET)
                   1893:            {
                   1894:                if (sscanf((*((struct_socket *)
                   1895:                        (*s_objet_argument_1).objet))
                   1896:                        .adresse_distante, "%d.%d.%d.%d(%d)",
                   1897:                        &(adresse[0]), &(adresse[1]), &(adresse[2]),
                   1898:                        &(adresse[3]), &port) == 5)
                   1899:                { // Adresse IPv4
                   1900:                    calcul_adresse = 0;
                   1901:                    for(i = 0; i < 4; calcul_adresse =
1.79      bertrand 1902:                            (256 * calcul_adresse) +
                   1903:                            ((unsigned char) adresse[i++]));
1.33      bertrand 1904: 
                   1905:                    memset(&adresse_ipv4, 0, sizeof(adresse_ipv4));
                   1906:                    adresse_ipv4.sin_family = AF_INET;
1.81      bertrand 1907:                    adresse_ipv4.sin_port = htons((uint16_t) port);
1.33      bertrand 1908:                    adresse_ipv4.sin_addr.s_addr = htonl(calcul_adresse);
1.1       bertrand 1909: 
1.51      bertrand 1910: #                  ifndef SEMAPHORES_NOMMES
                   1911:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   1912:                                != 0)
                   1913: #                  else
                   1914:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1915: #                  endif
1.1       bertrand 1916:                    {
                   1917:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1918:                        return;
                   1919:                    }
                   1920: 
                   1921:                    if (sendto((*((struct_socket *)
                   1922:                            (*s_objet_argument_1).objet)).socket, chaine,
1.79      bertrand 1923:                            (size_t) longueur_effective, 0, (struct sockaddr *)
1.33      bertrand 1924:                            &adresse_ipv4, sizeof(adresse_ipv4)) < 0)
1.1       bertrand 1925:                    {
1.74      bertrand 1926:                        ios = errno;
                   1927: 
1.51      bertrand 1928: #                      ifndef SEMAPHORES_NOMMES
                   1929:                            while(sem_wait(&((*s_etat_processus)
                   1930:                                    .semaphore_fork)) != 0)
                   1931: #                      else
                   1932:                            while(sem_wait((*s_etat_processus)
                   1933:                                    .semaphore_fork) != 0)
                   1934: #                      endif
1.1       bertrand 1935:                        {
1.50      bertrand 1936:                            if (errno != EINTR)
                   1937:                            {
                   1938:                                (*s_etat_processus).erreur_systeme =
                   1939:                                        d_es_processus;
                   1940:                                return;
                   1941:                            }
1.1       bertrand 1942:                        }
                   1943: 
1.74      bertrand 1944:                        if ((ios == EPIPE) || (ios == ECONNRESET))
                   1945:                        {
                   1946:                            (*s_etat_processus).erreur_execution =
                   1947:                                    d_ex_erreur_acces_fichier;
                   1948:                            return;
                   1949:                        }
                   1950: 
                   1951:                        if (ios == EMSGSIZE)
                   1952:                        {
                   1953:                            (*s_etat_processus).erreur_execution =
                   1954:                                    d_ex_taille_message;
                   1955:                            return;
                   1956:                        }
                   1957: 
1.1       bertrand 1958:                        (*s_etat_processus).erreur_systeme =
                   1959:                                d_es_erreur_fichier;
                   1960:                        return;
                   1961:                    }
                   1962: 
1.51      bertrand 1963: #                  ifndef SEMAPHORES_NOMMES
                   1964:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   1965:                                != 0)
                   1966: #                  else
                   1967:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1968: #                  endif
1.1       bertrand 1969:                    {
1.50      bertrand 1970:                        if (errno != EINTR)
                   1971:                        {
                   1972:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1973:                            return;
                   1974:                        }
1.1       bertrand 1975:                    }
                   1976:                }
1.33      bertrand 1977:                else
1.1       bertrand 1978:                {
1.33      bertrand 1979:                    liberation(s_etat_processus, s_objet_argument_1);
                   1980:                    liberation(s_etat_processus, s_objet_argument_2);
1.1       bertrand 1981: 
1.33      bertrand 1982:                    (*s_etat_processus).erreur_execution =
                   1983:                            d_ex_erreur_parametre_fichier;
                   1984:                    return;
                   1985:                }
                   1986:            }
                   1987:            else if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1988:                    .domaine == PF_INET6)
                   1989:            {
                   1990:                if (sscanf((*((struct_socket *) (*s_objet_argument_1)
                   1991:                        .objet)).adresse_distante, "%X:%X:%X:%X:%X:"
                   1992:                        "%X:%X:%X:%X:%X:%X:%X:%X:%X:%X:%X(%d)",
                   1993:                        &(adresse[0]), &(adresse[1]), &(adresse[2]),
                   1994:                        &(adresse[3]), &(adresse[4]), &(adresse[5]),
                   1995:                        &(adresse[6]), &(adresse[7]), &(adresse[8]),
                   1996:                        &(adresse[9]), &(adresse[10]), &(adresse[11]),
                   1997:                        &(adresse[12]), &(adresse[13]), &(adresse[14]),
                   1998:                        &(adresse[15]), &port)== 17)
                   1999:                { // Adresse IPv6
                   2000: #                  ifdef IPV6
                   2001:                    memset(&adresse_ipv6, 0, sizeof(adresse_ipv6));
                   2002:                    adresse_ipv6.sin6_family = AF_INET6;
                   2003:                    adresse_ipv6.sin6_port = htons((uint16_t) port);
                   2004: 
                   2005:                    for(i = 0; i < 16;
                   2006:                            adresse_ipv6.sin6_addr.s6_addr[i] =
1.79      bertrand 2007:                            (unsigned char) adresse[i], i++);
1.1       bertrand 2008: 
1.51      bertrand 2009: #                  ifndef SEMAPHORES_NOMMES
                   2010:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   2011:                                != 0)
                   2012: #                  else
                   2013:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   2014: #                  endif
1.33      bertrand 2015:                    {
                   2016:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2017:                        return;
                   2018:                    }
1.1       bertrand 2019: 
1.33      bertrand 2020:                    if (sendto((*((struct_socket *)
                   2021:                            (*s_objet_argument_1).objet)).socket, chaine,
1.79      bertrand 2022:                            (size_t) longueur_effective, 0, (struct sockaddr *)
1.33      bertrand 2023:                            &adresse_ipv6, sizeof(adresse_ipv6)) < 0)
                   2024:                    {
1.74      bertrand 2025:                        ios = errno;
                   2026: 
1.51      bertrand 2027: #                      ifndef SEMAPHORES_NOMMES
                   2028:                            while(sem_wait(&((*s_etat_processus)
                   2029:                                    .semaphore_fork)) != 0)
                   2030: #                      else
                   2031:                            while(sem_wait((*s_etat_processus)
                   2032:                                    .semaphore_fork) != 0)
                   2033: #                      endif
1.1       bertrand 2034:                        {
1.50      bertrand 2035:                            if (errno != EINTR)
                   2036:                            {
                   2037:                                (*s_etat_processus).erreur_systeme =
                   2038:                                        d_es_processus;
                   2039:                                return;
                   2040:                            }
1.1       bertrand 2041:                        }
                   2042: 
1.74      bertrand 2043:                        if ((ios == EPIPE) || (ios == ECONNRESET))
                   2044:                        {
                   2045:                            (*s_etat_processus).erreur_execution =
                   2046:                                    d_ex_erreur_acces_fichier;
                   2047:                            return;
                   2048:                        }
                   2049: 
                   2050:                        if (ios == EMSGSIZE)
                   2051:                        {
                   2052:                            (*s_etat_processus).erreur_execution =
                   2053:                                    d_ex_taille_message;
                   2054:                            return;
                   2055:                        }
                   2056: 
1.33      bertrand 2057:                        (*s_etat_processus).erreur_systeme =
                   2058:                                d_es_erreur_fichier;
1.1       bertrand 2059:                        return;
                   2060:                    }
                   2061: 
1.51      bertrand 2062: #                  ifndef SEMAPHORES_NOMMES
                   2063:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   2064:                                != 0)
                   2065: #                  else
                   2066:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   2067: #                  endif
1.33      bertrand 2068:                    {
1.50      bertrand 2069:                        if (errno != EINTR)
                   2070:                        {
                   2071:                            (*s_etat_processus).erreur_systeme =
                   2072:                                    d_es_processus;
                   2073:                            return;
                   2074:                        }
1.33      bertrand 2075:                    }
                   2076: #                  else
                   2077:                    if ((*s_etat_processus).langue == 'F')
                   2078:                    {
                   2079:                        printf("+++Attention : Support du protocole"
                   2080:                                " IPv6 indisponible\n");
1.1       bertrand 2081:                    }
                   2082:                    else
                   2083:                    {
1.33      bertrand 2084:                        printf("+++Warning : IPv6 support "
                   2085:                                "unavailable\n");
1.1       bertrand 2086:                    }
1.33      bertrand 2087: #                  endif
1.1       bertrand 2088:                }
1.33      bertrand 2089:                else
1.1       bertrand 2090:                {
                   2091:                    liberation(s_etat_processus, s_objet_argument_1);
                   2092:                    liberation(s_etat_processus, s_objet_argument_2);
                   2093: 
                   2094:                    (*s_etat_processus).erreur_execution =
                   2095:                            d_ex_erreur_parametre_fichier;
                   2096:                    return;
                   2097:                }
                   2098:            }
1.33      bertrand 2099:            else 
                   2100:            {
                   2101:                liberation(s_etat_processus, s_objet_argument_1);
                   2102:                liberation(s_etat_processus, s_objet_argument_2);
1.1       bertrand 2103: 
1.33      bertrand 2104:                (*s_etat_processus).erreur_execution =
                   2105:                        d_ex_erreur_parametre_fichier;
                   2106:                return;
                   2107:            }
1.1       bertrand 2108:        }
1.33      bertrand 2109: 
                   2110:        free(chaine);
1.1       bertrand 2111:    }
                   2112:    else
                   2113:    {
                   2114:        liberation(s_etat_processus, s_objet_argument_2);
                   2115:        liberation(s_etat_processus, s_objet_argument_1);
                   2116: 
                   2117:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2118:        return;
                   2119:    }
                   2120: 
                   2121:    liberation(s_etat_processus, s_objet_argument_2);
                   2122:    liberation(s_etat_processus, s_objet_argument_1);
                   2123: 
                   2124:    return;
                   2125: }
                   2126: 
                   2127: 
                   2128: /*
                   2129: ================================================================================
                   2130:   Fonction 'wflock'
                   2131: ================================================================================
                   2132:   Entrées : pointeur sur une structure struct_processus
                   2133: --------------------------------------------------------------------------------
                   2134:   Sorties :
                   2135: --------------------------------------------------------------------------------
                   2136:   Effets de bord : néant
                   2137: ================================================================================
                   2138: */
                   2139: 
                   2140: void
                   2141: instruction_wflock(struct_processus *s_etat_processus)
                   2142: {
                   2143:    logical1                    drapeau;
                   2144: 
                   2145:    struct flock                lock;
                   2146: 
                   2147:    struct timespec             attente;
                   2148: 
1.5       bertrand 2149:    struct_descripteur_fichier  *descripteur;
                   2150: 
1.1       bertrand 2151:    struct_objet                *s_objet_argument_1;
                   2152:    struct_objet                *s_objet_argument_2;
                   2153: 
                   2154:    unsigned char               *chaine;
                   2155:    unsigned char               registre_instruction_valide;
                   2156: 
                   2157:    attente.tv_sec = 0;
                   2158:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2159: 
                   2160:    (*s_etat_processus).erreur_execution = d_ex;
                   2161: 
                   2162:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2163:    {
                   2164:        printf("\n  WFLOCK ");
                   2165:        
                   2166:        if ((*s_etat_processus).langue == 'F')
                   2167:        {
                   2168:            printf("(attente du positionnement d'un verrou sur un fichier)"
                   2169:                    "\n\n");
                   2170:        }
                   2171:        else
                   2172:        {
                   2173:            printf("(wait for file lock)\n\n");
                   2174:        }
                   2175: 
                   2176:        printf("    2: %s\n", d_FCH);
                   2177:        printf("    1: %s (READ/WRITE/NONE)\n", d_CHN);
                   2178: 
                   2179:        return;
                   2180:    }
                   2181:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2182:    {
                   2183:        (*s_etat_processus).nombre_arguments = -1;
                   2184:        return;
                   2185:    }
                   2186: 
                   2187:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2188:    {
                   2189:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                   2190:        {
                   2191:            return;
                   2192:        }
                   2193:    }
                   2194: 
                   2195:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2196:            &s_objet_argument_1) == d_erreur)
                   2197:    {
                   2198:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2199:        return;
                   2200:    }
                   2201: 
                   2202:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2203:            &s_objet_argument_2) == d_erreur)
                   2204:    {
                   2205:        liberation(s_etat_processus, s_objet_argument_1);
                   2206: 
                   2207:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2208:        return;
                   2209:    }
                   2210: 
                   2211:    if (((*s_objet_argument_2).type == FCH) &&
                   2212:            ((*s_objet_argument_1).type == CHN))
                   2213:    {
                   2214:        drapeau = d_faux;
                   2215: 
                   2216:        do
                   2217:        {
1.94      bertrand 2218:            if ((chaine = conversion_majuscule(s_etat_processus,
                   2219:                    (unsigned char *) (*s_objet_argument_1).objet)) == NULL)
1.1       bertrand 2220:            {
                   2221:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2222:                return;
                   2223:            }
                   2224: 
                   2225:            if (strcmp(chaine, "WRITE") == 0)
                   2226:            {
                   2227:                lock.l_type = F_WRLCK;
                   2228:            }
                   2229:            else if (strcmp(chaine, "READ") == 0)
                   2230:            {
                   2231:                lock.l_type = F_RDLCK;
                   2232:            }
                   2233:            else if (strcmp(chaine, "NONE") == 0)
                   2234:            {
                   2235:                lock.l_type = F_UNLCK;
                   2236:            }
                   2237:            else
                   2238:            {
                   2239:                free(chaine);
                   2240: 
                   2241:                liberation(s_etat_processus, s_objet_argument_1);
                   2242:                liberation(s_etat_processus, s_objet_argument_2);
                   2243: 
                   2244:                (*s_etat_processus).erreur_execution = d_ex_verrou_indefini;
                   2245:                return;
                   2246:            }
                   2247: 
                   2248:            free(chaine);
                   2249: 
                   2250:            lock.l_whence = SEEK_SET;
                   2251:            lock.l_start = 0;
                   2252:            lock.l_len = 0;
                   2253:            lock.l_pid = getpid();
                   2254: 
                   2255:            if ((descripteur = descripteur_fichier(s_etat_processus,
                   2256:                    (struct_fichier *) (*s_objet_argument_2).objet)) == NULL)
                   2257:            {
                   2258:                return;
                   2259:            }
                   2260: 
1.5       bertrand 2261:            if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
                   2262:                    == -1)
1.1       bertrand 2263:            {
                   2264:                liberation(s_etat_processus, s_objet_argument_1);
                   2265:                liberation(s_etat_processus, s_objet_argument_2);
                   2266: 
                   2267:                (*s_etat_processus).erreur_execution = d_ex_fichier_verrouille;
                   2268:                return;
                   2269:            }
                   2270: 
1.51      bertrand 2271: #          ifndef SEMAPHORES_NOMMES
                   2272:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2273: #          else
                   2274:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   2275: #          endif
1.1       bertrand 2276:            {
                   2277:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   2278:                return;
                   2279:            }
1.47      bertrand 2280: 
1.51      bertrand 2281: #          ifndef SEMAPHORES_NOMMES
                   2282:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   2283: #          else
                   2284:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   2285: #          endif
1.12      bertrand 2286:            {
1.50      bertrand 2287:                if (errno != EINTR)
                   2288:                {
                   2289:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2290:                    return;
                   2291:                }
1.12      bertrand 2292:            }
1.1       bertrand 2293: 
                   2294:            if (lock.l_type == F_UNLCK)
                   2295:            {
                   2296:                drapeau = d_vrai;
                   2297:            }
                   2298:            else
                   2299:            {
1.84      bertrand 2300:                if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions)
                   2301:                        != 0)
1.83      bertrand 2302:                {
                   2303:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2304:                    return;
                   2305:                }
                   2306: 
1.1       bertrand 2307:                if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   2308:                {
                   2309:                    affectation_interruptions_logicielles(s_etat_processus);
                   2310:                }
                   2311: 
1.84      bertrand 2312:                if (pthread_mutex_unlock(&(*s_etat_processus)
                   2313:                        .mutex_interruptions) != 0)
1.83      bertrand 2314:                {
                   2315:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2316:                    return;
                   2317:                }
                   2318: 
                   2319:                if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
1.1       bertrand 2320:                {
                   2321:                    registre_instruction_valide =
                   2322:                            (*s_etat_processus).instruction_valide;
                   2323:                    traitement_interruptions_logicielles(
                   2324:                            s_etat_processus);
                   2325:                    (*s_etat_processus).instruction_valide =
                   2326:                            registre_instruction_valide;
                   2327:                }
                   2328: 
                   2329:                nanosleep(&attente, NULL);
                   2330:                scrutation_injection(s_etat_processus);
                   2331: 
                   2332:                INCR_GRANULARITE(attente.tv_nsec);
                   2333:            }
                   2334:        } while((drapeau == d_faux) && ((*s_etat_processus)
                   2335:                .var_volatile_requete_arret != -1));
                   2336:    }
                   2337:    else
                   2338:    {
                   2339:        liberation(s_etat_processus, s_objet_argument_1);
                   2340:        liberation(s_etat_processus, s_objet_argument_2);
                   2341: 
                   2342:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2343:        return;
                   2344:    }
                   2345: 
                   2346:    return;
                   2347: }
                   2348: 
                   2349: 
                   2350: /*
                   2351: ================================================================================
                   2352:   Fonction 'wfproc'
                   2353: ================================================================================
                   2354:   Entrées : pointeur sur une structure struct_processus
                   2355: --------------------------------------------------------------------------------
                   2356:   Sorties :
                   2357: --------------------------------------------------------------------------------
                   2358:   Effets de bord : néant
                   2359: ================================================================================
                   2360: */
                   2361: 
                   2362: void
                   2363: instruction_wfproc(struct_processus *s_etat_processus)
                   2364: {
                   2365:    logical1                    drapeau_fin;
                   2366: 
                   2367:    struct_liste_chainee        *l_element_courant;
                   2368: 
                   2369:    struct_objet                *s_objet_argument;
                   2370: 
                   2371:    struct timespec             attente;
                   2372: 
                   2373:    unsigned char               registre_instruction_valide;
                   2374: 
                   2375:    (*s_etat_processus).erreur_execution = d_ex;
                   2376: 
                   2377:    attente.tv_sec = 0;
                   2378:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2379: 
                   2380:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2381:    {
                   2382:        printf("\n  WFPROC ");
                   2383: 
                   2384:        if ((*s_etat_processus).langue == 'F')
                   2385:        {
                   2386:            printf("(attente de la fin d'un processus fils)\n\n");
                   2387:        }
                   2388:        else
                   2389:        {
                   2390:            printf("(wait for child process end)\n\n");
                   2391:        }
                   2392: 
                   2393:        printf("    1: %s\n", d_PRC);
                   2394: 
                   2395:        return;
                   2396:    }
                   2397:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2398:    {
                   2399:        (*s_etat_processus).nombre_arguments = -1;
                   2400:        return;
                   2401:    }
                   2402: 
                   2403:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2404:    {
                   2405:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2406:        {
                   2407:            return;
                   2408:        }
                   2409:    }
                   2410: 
                   2411:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2412:            &s_objet_argument) == d_erreur)
                   2413:    {
                   2414:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2415:        return;
                   2416:    }
                   2417: 
                   2418:    if ((*s_objet_argument).type == PRC)
                   2419:    {
                   2420:        drapeau_fin = d_faux;
                   2421: 
                   2422:        if ((*s_etat_processus).profilage == d_vrai)
                   2423:        {
                   2424:            profilage(s_etat_processus, "Interprocess or interthread "
                   2425:                    "communications (WFPROC)");
                   2426: 
                   2427:            if ((*s_etat_processus).erreur_systeme != d_es)
                   2428:            {
                   2429:                return;
                   2430:            }
                   2431:        }
                   2432: 
1.85      bertrand 2433:        if (pthread_mutex_lock(&((*s_etat_processus).mutex_pile_processus))
                   2434:                != 0)
1.1       bertrand 2435:        {
                   2436:            if ((*s_etat_processus).profilage == d_vrai)
                   2437:            {
                   2438:                profilage(s_etat_processus, NULL);
                   2439:            }
                   2440: 
                   2441:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2442:            return;
                   2443:        }
                   2444: 
                   2445:        while(drapeau_fin == d_faux)
                   2446:        {
                   2447:            l_element_courant = (struct_liste_chainee *)
                   2448:                    (*s_etat_processus).l_base_pile_processus;
                   2449: 
                   2450:            while(l_element_courant != NULL)
                   2451:            {
                   2452:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2453:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   2454:                {
                   2455:                    if ((*(*((struct_processus_fils *)
                   2456:                            (*s_objet_argument).objet)).thread)
                   2457:                            .processus_detache == d_vrai)
                   2458:                    {
                   2459:                        if ((*(*((struct_processus_fils *)
                   2460:                                (*(*l_element_courant)
                   2461:                                .donnee).objet)).thread).pid ==
                   2462:                                (*(*((struct_processus_fils *)
                   2463:                                (*s_objet_argument).objet)).thread).pid)
                   2464:                        {
                   2465:                            break;
                   2466:                        }
                   2467:                    }
                   2468:                }
                   2469:                else
                   2470:                {
                   2471:                    if ((*(*((struct_processus_fils *)
                   2472:                            (*s_objet_argument).objet)).thread)
                   2473:                            .processus_detache == d_faux)
                   2474:                    {
                   2475:                        if ((pthread_equal((*(*((struct_processus_fils *)
                   2476:                                (*(*l_element_courant).donnee).objet)).thread)
                   2477:                                .tid, (*(*((struct_processus_fils *)
                   2478:                                (*s_objet_argument).objet)).thread).tid) != 0)
                   2479:                                && ((*(*((struct_processus_fils *)
                   2480:                                (*(*l_element_courant).donnee).objet)).thread)
                   2481:                                .pid == (*(*((struct_processus_fils *)
                   2482:                                (*s_objet_argument).objet)).thread).pid))
                   2483:                        {
                   2484:                            break;
                   2485:                        }
                   2486:                    }
                   2487:                }
                   2488: 
                   2489:                l_element_courant = (*l_element_courant).suivant;
                   2490:            }
                   2491: 
                   2492:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2493:            {
                   2494:                if ((*s_etat_processus).profilage == d_vrai)
                   2495:                {
                   2496:                    profilage(s_etat_processus, NULL);
                   2497:                }
                   2498: 
1.85      bertrand 2499:                if (pthread_mutex_unlock(&((*s_etat_processus)
                   2500:                        .mutex_pile_processus)) != 0)
1.1       bertrand 2501:                {
                   2502:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2503:                    return;
                   2504:                }
                   2505: 
                   2506:                liberation(s_etat_processus, s_objet_argument);
                   2507:                return;
                   2508:            }
                   2509: 
                   2510:            if (l_element_courant == NULL)
                   2511:            {
                   2512:                /*
                   2513:                 * Si l_element_courant vaut NULL, le processus n'existe plus.
                   2514:                 */
                   2515: 
                   2516:                drapeau_fin = d_vrai;
                   2517:            }
                   2518:            else
                   2519:            {
                   2520:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2521:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   2522:                {
1.48      bertrand 2523:                    if (envoi_signal_processus((*(*((struct_processus_fils *)
1.1       bertrand 2524:                            (*(*l_element_courant).donnee).objet)).thread).pid,
1.48      bertrand 2525:                            rpl_signull) != 0)
1.1       bertrand 2526:                    {
                   2527:                        drapeau_fin = d_vrai;
                   2528:                    }
                   2529:                    else
                   2530:                    {
                   2531:                        drapeau_fin = d_faux;
                   2532:                    }
                   2533:                }
                   2534:                else
                   2535:                {
                   2536:                    if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
                   2537:                            (*(*l_element_courant).donnee).objet)).thread)
                   2538:                            .mutex)) != 0)
                   2539:                    {
                   2540:                        if ((*s_etat_processus).profilage == d_vrai)
                   2541:                        {
                   2542:                            profilage(s_etat_processus, NULL);
                   2543:                        }
                   2544: 
                   2545:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2546:                        return;
                   2547:                    }
                   2548: 
                   2549:                    if ((*(*((struct_processus_fils *)
                   2550:                            (*(*l_element_courant).donnee).objet)).thread)
                   2551:                            .thread_actif == d_faux)
                   2552:                    {
                   2553:                        drapeau_fin = d_vrai;
                   2554:                    }
                   2555:                    else
                   2556:                    {
                   2557:                        drapeau_fin = d_faux;
                   2558:                    }
                   2559: 
                   2560:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   2561:                            (*(*l_element_courant).donnee).objet)).thread)
                   2562:                            .mutex)) != 0)
                   2563:                    {
                   2564:                        if ((*s_etat_processus).profilage == d_vrai)
                   2565:                        {
                   2566:                            profilage(s_etat_processus, NULL);
                   2567:                        }
                   2568: 
                   2569:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2570:                        return;
                   2571:                    }
                   2572:                }
                   2573: 
                   2574:                if (drapeau_fin == d_faux)
                   2575:                {
                   2576:                    /*
                   2577:                     * Le processus n'est pas terminé
                   2578:                     */
                   2579: 
1.84      bertrand 2580:                    if (pthread_mutex_lock(&((*s_etat_processus)
                   2581:                            .mutex_interruptions)) != 0)
                   2582:                    {
1.85      bertrand 2583:                        pthread_mutex_unlock(&((*s_etat_processus)
                   2584:                                .mutex_pile_processus));
1.84      bertrand 2585: 
                   2586:                        if ((*s_etat_processus).profilage == d_vrai)
                   2587:                        {
                   2588:                            profilage(s_etat_processus, NULL);
                   2589:                        }
                   2590: 
                   2591:                        (*s_etat_processus).erreur_systeme =
                   2592:                                d_es_processus;
                   2593:                        return;
                   2594:                    }
                   2595: 
1.83      bertrand 2596:                    if ((*s_etat_processus).nombre_interruptions_non_affectees
                   2597:                            != 0)
                   2598:                    {
                   2599:                        affectation_interruptions_logicielles(s_etat_processus);
                   2600:                    }
                   2601: 
1.84      bertrand 2602:                    if (pthread_mutex_unlock(&((*s_etat_processus)
                   2603:                            .mutex_interruptions)) != 0)
                   2604:                    {
1.85      bertrand 2605:                        pthread_mutex_unlock(&((*s_etat_processus)
                   2606:                                .mutex_pile_processus));
1.84      bertrand 2607: 
                   2608:                        if ((*s_etat_processus).profilage == d_vrai)
                   2609:                        {
                   2610:                            profilage(s_etat_processus, NULL);
                   2611:                        }
                   2612: 
                   2613:                        (*s_etat_processus).erreur_systeme =
                   2614:                                d_es_processus;
                   2615:                        return;
                   2616:                    }
                   2617: 
1.85      bertrand 2618:                    if (pthread_mutex_unlock(&((*s_etat_processus)
                   2619:                            .mutex_pile_processus)) != 0)
1.1       bertrand 2620:                    {
                   2621:                        if ((*s_etat_processus).profilage == d_vrai)
                   2622:                        {
                   2623:                            profilage(s_etat_processus, NULL);
                   2624:                        }
                   2625: 
                   2626:                        (*s_etat_processus).erreur_systeme =
                   2627:                                d_es_processus;
                   2628:                        return;
                   2629:                    }
                   2630: 
1.83      bertrand 2631:                    if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
1.1       bertrand 2632:                    {
                   2633:                        registre_instruction_valide =
                   2634:                                (*s_etat_processus).instruction_valide;
                   2635:                        traitement_interruptions_logicielles(
                   2636:                                s_etat_processus);
                   2637:                        (*s_etat_processus).instruction_valide =
                   2638:                                registre_instruction_valide;
                   2639:                    }
                   2640: 
1.51      bertrand 2641: #                  ifndef SEMAPHORES_NOMMES
                   2642:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   2643:                                != 0)
                   2644: #                  else
                   2645:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   2646: #                  endif
1.1       bertrand 2647:                    {
                   2648:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2649:                        return;
                   2650:                    }
                   2651: 
                   2652:                    nanosleep(&attente, NULL);
                   2653: 
1.51      bertrand 2654: #                  ifndef SEMAPHORES_NOMMES
                   2655:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   2656:                                != 0)
                   2657: #                  else
                   2658:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   2659: #                  endif
1.1       bertrand 2660:                    {
1.50      bertrand 2661:                        if (errno != EINTR)
                   2662:                        {
                   2663:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2664:                            return;
                   2665:                        }
1.1       bertrand 2666:                    }
                   2667: 
                   2668:                    scrutation_injection(s_etat_processus);
                   2669: 
1.85      bertrand 2670:                    if (pthread_mutex_lock(&((*s_etat_processus)
                   2671:                            .mutex_pile_processus)) != 0)
1.1       bertrand 2672:                    {
                   2673:                        if ((*s_etat_processus).profilage == d_vrai)
                   2674:                        {
                   2675:                            profilage(s_etat_processus, NULL);
                   2676:                        }
                   2677: 
                   2678:                        (*s_etat_processus).erreur_systeme =
                   2679:                                d_es_processus;
                   2680:                        return;
                   2681:                    }
                   2682:                }
                   2683:            }
                   2684: 
                   2685:            INCR_GRANULARITE(attente.tv_nsec);
                   2686:        }
                   2687: 
                   2688:        if ((*s_etat_processus).profilage == d_vrai)
                   2689:        {
                   2690:            profilage(s_etat_processus, NULL);
                   2691:        }
                   2692: 
1.85      bertrand 2693:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex_pile_processus))
                   2694:                != 0)
1.1       bertrand 2695:        {
                   2696:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2697:            return;
                   2698:        }
                   2699:    }
                   2700:    else
                   2701:    {
                   2702:        liberation(s_etat_processus, s_objet_argument);
                   2703: 
                   2704:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2705:        return;
                   2706:    }
                   2707: 
                   2708:    liberation(s_etat_processus, s_objet_argument);
                   2709: 
                   2710:    return;
                   2711: }
                   2712: 
                   2713: 
                   2714: /*
                   2715: ================================================================================
                   2716:   Fonction 'wfdata'
                   2717: ================================================================================
                   2718:   Entrées : pointeur sur une structure struct_processus
                   2719: --------------------------------------------------------------------------------
                   2720:   Sorties :
                   2721: --------------------------------------------------------------------------------
                   2722:   Effets de bord : néant
                   2723: ================================================================================
                   2724: */
                   2725: 
                   2726: void
                   2727: instruction_wfdata(struct_processus *s_etat_processus)
                   2728: {
                   2729:    logical1                    drapeau_fin;
                   2730: 
                   2731:    struct_liste_chainee        *l_element_courant;
                   2732: 
                   2733:    struct_objet                *s_objet_argument;
                   2734: 
                   2735:    struct timespec             attente;
                   2736: 
                   2737:    unsigned char               registre_instruction_valide;
                   2738: 
                   2739:    (*s_etat_processus).erreur_execution = d_ex;
                   2740: 
                   2741:    attente.tv_sec = 0;
                   2742:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2743: 
                   2744:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2745:    {
                   2746:        printf("\n  WFDATA ");
                   2747: 
                   2748:        if ((*s_etat_processus).langue == 'F')
                   2749:        {
                   2750:            printf("(attente de données d'un processus fils)\n\n");
                   2751:        }
                   2752:        else
                   2753:        {
                   2754:            printf("(wait for data from child process)\n\n");
                   2755:        }
                   2756: 
                   2757:        printf("    1: %s\n", d_PRC);
                   2758: 
                   2759:        return;
                   2760:    }
                   2761:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2762:    {
                   2763:        (*s_etat_processus).nombre_arguments = -1;
                   2764:        return;
                   2765:    }
                   2766: 
                   2767:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2768:    {
                   2769:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2770:        {
                   2771:            return;
                   2772:        }
                   2773:    }
                   2774: 
                   2775:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2776:            &s_objet_argument) == d_erreur)
                   2777:    {
                   2778:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2779:        return;
                   2780:    }
                   2781: 
                   2782:    if ((*s_objet_argument).type == PRC)
                   2783:    {
                   2784:        drapeau_fin = d_faux;
                   2785: 
                   2786:        if ((*s_etat_processus).profilage == d_vrai)
                   2787:        {
                   2788:            profilage(s_etat_processus, "Interprocess or interthread "
                   2789:                    "communications (WFDATA)");
                   2790: 
                   2791:            if ((*s_etat_processus).erreur_systeme != d_es)
                   2792:            {
                   2793:                return;
                   2794:            }
                   2795:        }
                   2796: 
1.85      bertrand 2797:        if (pthread_mutex_lock(&((*s_etat_processus).mutex_pile_processus))
                   2798:                != 0)
1.1       bertrand 2799:        {
                   2800:            if ((*s_etat_processus).profilage == d_vrai)
                   2801:            {
                   2802:                profilage(s_etat_processus, NULL);
                   2803:            }
                   2804: 
                   2805:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2806:            return;
                   2807:        }
                   2808: 
                   2809:        while(drapeau_fin == d_faux)
                   2810:        {
                   2811:            l_element_courant = (struct_liste_chainee *)
                   2812:                    (*s_etat_processus).l_base_pile_processus;
                   2813: 
                   2814:            while(l_element_courant != NULL)
                   2815:            {
                   2816:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2817:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   2818:                {
                   2819:                    if (((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2820:                            .donnee).objet)).thread).pid ==
                   2821:                            (*(*((struct_processus_fils *)
                   2822:                            (*s_objet_argument).objet)).thread).pid)
                   2823:                            && ((*(*((struct_processus_fils *)
                   2824:                            (*s_objet_argument).objet)).thread)
                   2825:                            .processus_detache == d_vrai))
                   2826:                    {
                   2827:                        break;
                   2828:                    }
                   2829:                }
                   2830:                else
                   2831:                {
                   2832:                    if ((pthread_equal((*(*((struct_processus_fils *)
                   2833:                            (*(*l_element_courant).donnee).objet)).thread).tid,
                   2834:                            (*(*((struct_processus_fils *) (*s_objet_argument)
                   2835:                            .objet)).thread).tid) != 0) &&
                   2836:                            ((*(*((struct_processus_fils *)
                   2837:                            (*(*l_element_courant).donnee).objet)).thread).pid
                   2838:                            == (*(*((struct_processus_fils *)
                   2839:                            (*s_objet_argument).objet)).thread).pid) &&
                   2840:                            ((*(*((struct_processus_fils *)
                   2841:                            (*s_objet_argument).objet)).thread)
                   2842:                            .processus_detache == d_faux))
                   2843:                    {
                   2844:                        break;
                   2845:                    }
                   2846:                }
                   2847: 
                   2848:                l_element_courant = (*l_element_courant).suivant;
                   2849:            }
                   2850: 
                   2851:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2852:            {
                   2853:                if ((*s_etat_processus).profilage == d_vrai)
                   2854:                {
                   2855:                    profilage(s_etat_processus, NULL);
                   2856:                }
                   2857: 
1.85      bertrand 2858:                if (pthread_mutex_unlock(&((*s_etat_processus)
                   2859:                        .mutex_pile_processus)) != 0)
1.1       bertrand 2860:                {
                   2861:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2862:                    return;
                   2863:                }
                   2864: 
                   2865:                liberation(s_etat_processus, s_objet_argument);
                   2866:                return;
                   2867:            }
                   2868: 
                   2869:            if (l_element_courant != NULL)
                   2870:            {
                   2871:                if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
                   2872:                        (*(*l_element_courant).donnee).objet)).thread).mutex))
                   2873:                        != 0)
                   2874:                {
                   2875:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2876:                    return;
                   2877:                }
                   2878: 
                   2879:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2880:                        .donnee).objet)).thread).nombre_objets_dans_pipe != 0)
                   2881:                {
                   2882:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   2883:                            (*(*l_element_courant).donnee).objet)).thread)
                   2884:                            .mutex)) != 0)
                   2885:                    {
                   2886:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2887:                        return;
                   2888:                    }
                   2889: 
                   2890:                    drapeau_fin = d_vrai;
                   2891:                }
                   2892:                else
                   2893:                {
                   2894:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   2895:                            (*(*l_element_courant).donnee).objet)).thread)
                   2896:                            .mutex)) != 0)
                   2897:                    {
                   2898:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2899:                        return;
                   2900:                    }
                   2901: 
1.85      bertrand 2902:                    if (pthread_mutex_unlock(&((*s_etat_processus)
                   2903:                            .mutex_pile_processus)) != 0)
1.1       bertrand 2904:                    {
                   2905:                        if ((*s_etat_processus).profilage == d_vrai)
                   2906:                        {
                   2907:                            profilage(s_etat_processus, NULL);
                   2908:                        }
                   2909: 
                   2910:                        (*s_etat_processus).erreur_systeme =
                   2911:                                d_es_processus;
                   2912:                        return;
                   2913:                    }
                   2914: 
1.51      bertrand 2915: #                  ifndef SEMAPHORES_NOMMES
                   2916:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   2917:                                != 0)
                   2918: #                  else
                   2919:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   2920: #                  endif
1.12      bertrand 2921:                    {
                   2922:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2923:                        return;
                   2924:                    }
1.1       bertrand 2925: 
                   2926:                    nanosleep(&attente, NULL);
                   2927: 
1.51      bertrand 2928: #                  ifndef SEMAPHORES_NOMMES
                   2929:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   2930:                                != 0)
                   2931: #                  else
                   2932:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   2933: #                  endif
1.1       bertrand 2934:                    {
1.50      bertrand 2935:                        if (errno != EINTR)
                   2936:                        {
                   2937:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2938:                            return;
                   2939:                        }
1.1       bertrand 2940:                    }
                   2941: 
                   2942:                    scrutation_injection(s_etat_processus);
                   2943: 
1.84      bertrand 2944:                    if (pthread_mutex_lock(&(*s_etat_processus)
                   2945:                            .mutex_interruptions) != 0)
1.83      bertrand 2946:                    {
                   2947:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2948:                        return;
                   2949:                    }
                   2950: 
1.1       bertrand 2951:                    if ((*s_etat_processus).nombre_interruptions_non_affectees
                   2952:                            != 0)
                   2953:                    {
                   2954:                        affectation_interruptions_logicielles(s_etat_processus);
                   2955:                    }
                   2956: 
1.84      bertrand 2957:                    if (pthread_mutex_unlock(&(*s_etat_processus)
                   2958:                            .mutex_interruptions) != 0)
1.83      bertrand 2959:                    {
                   2960:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2961:                        return;
                   2962:                    }
                   2963: 
1.1       bertrand 2964:                    if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   2965:                    {
                   2966:                        registre_instruction_valide =
                   2967:                                (*s_etat_processus).instruction_valide;
                   2968:                        traitement_interruptions_logicielles(s_etat_processus);
                   2969:                        (*s_etat_processus).instruction_valide =
                   2970:                                registre_instruction_valide;
                   2971:                    }
                   2972: 
                   2973:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2974:                    {
                   2975:                        if ((*s_etat_processus).profilage == d_vrai)
                   2976:                        {
                   2977:                            profilage(s_etat_processus, NULL);
                   2978:                        }
                   2979: 
                   2980:                        return;
                   2981:                    }
                   2982: 
1.85      bertrand 2983:                    if (pthread_mutex_lock(&((*s_etat_processus)
                   2984:                            .mutex_pile_processus)) != 0)
1.1       bertrand 2985:                    {
                   2986:                        if ((*s_etat_processus).profilage == d_vrai)
                   2987:                        {
                   2988:                            profilage(s_etat_processus, NULL);
                   2989:                        }
                   2990: 
                   2991:                        (*s_etat_processus).erreur_systeme =
                   2992:                                d_es_processus;
                   2993:                        return;
                   2994:                    }
                   2995:                }
                   2996:            }
                   2997:            else
                   2998:            {
                   2999:                drapeau_fin = d_vrai;
                   3000:                (*s_etat_processus).erreur_execution = d_ex_processus;
                   3001:            }
                   3002: 
                   3003:            INCR_GRANULARITE(attente.tv_nsec);
                   3004:        }
                   3005: 
                   3006:        if ((*s_etat_processus).profilage == d_vrai)
                   3007:        {
                   3008:            profilage(s_etat_processus, NULL);
                   3009:        }
                   3010: 
1.85      bertrand 3011:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex_pile_processus))
                   3012:                != 0)
1.1       bertrand 3013:        {
                   3014:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   3015:            return;
                   3016:        }
                   3017:    }
                   3018:    else
                   3019:    {
                   3020:        liberation(s_etat_processus, s_objet_argument);
                   3021: 
                   3022:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   3023:        return;
                   3024:    }
                   3025: 
                   3026:    liberation(s_etat_processus, s_objet_argument);
                   3027: 
                   3028:    return;
                   3029: }
                   3030: 
                   3031: 
                   3032: /*
                   3033: ================================================================================
                   3034:   Fonction 'wfsock'
                   3035: ================================================================================
                   3036:   Entrées : pointeur sur une structure struct_processus
                   3037: --------------------------------------------------------------------------------
                   3038:   Sorties :
                   3039: --------------------------------------------------------------------------------
                   3040:   Effets de bord : néant
                   3041: ================================================================================
                   3042: */
                   3043: 
1.98    ! bertrand 3044: static inline logical1
        !          3045: options_sockets(struct_processus *s_etat_processus, struct_socket *s_socket)
        !          3046: {
        !          3047:    int                         drapeau;
        !          3048: 
        !          3049:    if (((*s_socket).options & (1 << d_BROADCAST)) != 0)
        !          3050:    {
        !          3051:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_BROADCAST, &drapeau,
        !          3052:                sizeof(drapeau)) != 0)
        !          3053:        {
        !          3054:            return(d_erreur);
        !          3055:        }
        !          3056:    }
        !          3057: 
        !          3058:    if (((*s_socket).options & (1 << d_DONT_ROUTE)) != 0)
        !          3059:    {
        !          3060:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_DONTROUTE, &drapeau,
        !          3061:                sizeof(drapeau)) != 0)
        !          3062:        {
        !          3063:            return(d_erreur);
        !          3064:        }
        !          3065:    }
        !          3066: 
        !          3067:    if (((*s_socket).options & (1 << d_KEEP_ALIVE)) != 0)
        !          3068:    {
        !          3069:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_KEEPALIVE, &drapeau,
        !          3070:                sizeof(drapeau)) != 0)
        !          3071:        {
        !          3072:            return(d_erreur);
        !          3073:        }
        !          3074:    }
        !          3075: 
        !          3076:    if (((*s_socket).options & (1 << d_PRIORITY)) != 0)
        !          3077:    {
        !          3078:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_PRIORITY,
        !          3079:                &((*s_socket).priorite), sizeof((*s_socket).priorite)) != 0)
        !          3080:        {
        !          3081:            return(d_erreur);
        !          3082:        }
        !          3083:    }
        !          3084: 
        !          3085:    // Les deux options suivantes ne peuvent être positionnées simultanément.
        !          3086: 
        !          3087:    if (((*s_socket).options & (1 << d_RECEIVE_BUFFER)) != 0)
        !          3088:    {
        !          3089:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVBUF,
        !          3090:                &((*s_socket).buffer_reception),
        !          3091:                sizeof((*s_socket).buffer_reception)) != 0)
        !          3092:        {
        !          3093:            return(d_erreur);
        !          3094:        }
        !          3095:    }
        !          3096: 
        !          3097:    if (((*s_socket).options & (1 << d_FORCE_RECEIVE_BUFFER)) != 0)
        !          3098:    {
        !          3099:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVBUFFORCE,
        !          3100:                &((*s_socket).buffer_reception),
        !          3101:                sizeof((*s_socket).buffer_reception)) != 0)
        !          3102:        {
        !          3103:            return(d_erreur);
        !          3104:        }
        !          3105:    }
        !          3106: 
        !          3107:    // Même remarque
        !          3108: 
        !          3109:    if (((*s_socket).options & (1 << d_SEND_BUFFER)) != 0)
        !          3110:    {
        !          3111:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDBUF,
        !          3112:                &((*s_socket).buffer_emission),
        !          3113:                sizeof((*s_socket).buffer_emission)) != 0)
        !          3114:        {
        !          3115:            return(d_erreur);
        !          3116:        }
        !          3117:    }
        !          3118: 
        !          3119:    if (((*s_socket).options & (1 << d_FORCE_SEND_BUFFER)) != 0)
        !          3120:    {
        !          3121:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDBUFFORCE,
        !          3122:                &((*s_socket).buffer_emission),
        !          3123:                sizeof((*s_socket).buffer_emission)) != 0)
        !          3124:        {
        !          3125:            return(d_erreur);
        !          3126:        }
        !          3127:    }
        !          3128: 
        !          3129:    if (((*s_socket).options & (1 << d_RECEIVING_TIMEOUT)) != 0)
        !          3130:    {
        !          3131:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVTIMEO,
        !          3132:                &((*s_socket).timeout_emission),
        !          3133:                sizeof((*s_socket).timeout_emission)) != 0)
        !          3134:        {
        !          3135:            return(d_erreur);
        !          3136:        }
        !          3137:    }
        !          3138: 
        !          3139:    if (((*s_socket).options & (1 << d_SENDING_TIMEOUT)) != 0)
        !          3140:    {
        !          3141:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDTIMEO,
        !          3142:                &((*s_socket).timeout_emission),
        !          3143:                sizeof((*s_socket).timeout_emission)) != 0)
        !          3144:        {
        !          3145:            return(d_erreur);
        !          3146:        }
        !          3147:    }
        !          3148: 
        !          3149:    return(d_absence_erreur);;
        !          3150: }
        !          3151: 
        !          3152: 
1.1       bertrand 3153: void
                   3154: instruction_wfsock(struct_processus *s_etat_processus)
                   3155: {
                   3156:    int                     erreur;
                   3157: 
                   3158:    logical1                drapeau;
                   3159: 
                   3160:    socklen_t               longueur;
                   3161: 
                   3162:    struct_liste_chainee    *l_element_courant;
                   3163: 
                   3164:    struct_objet            *s_objet_argument;
                   3165:    struct_objet            *s_objet_resultat;
                   3166: 
1.54      bertrand 3167:    struct pollfd           s_poll;
                   3168: 
1.1       bertrand 3169:    struct sockaddr_in      adresse_ipv4;
1.20      bertrand 3170: #  ifdef IPV6
1.1       bertrand 3171:    struct sockaddr_in6     adresse_ipv6;
1.20      bertrand 3172: #  endif
1.1       bertrand 3173: 
                   3174:    unsigned long           i;
                   3175: 
                   3176:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   3177:    {
                   3178:        printf("\n  WFSOCK ");
                   3179: 
                   3180:        if ((*s_etat_processus).langue == 'F')
                   3181:        {
                   3182:            printf("(attente d'une connexion sur une socket)\n\n");
                   3183:        }
                   3184:        else
                   3185:        {
                   3186:            printf("(wait for connection on a socket)\n\n");
                   3187:        }
                   3188: 
                   3189:        printf("    1: %s\n", d_SCK);
                   3190:        printf("->  2: %s\n", d_SCK);
                   3191:        printf("    1: %s\n", d_SCK);
                   3192: 
                   3193:        return;
                   3194:    }
                   3195:    else if ((*s_etat_processus).test_instruction == 'Y')
                   3196:    {
                   3197:        (*s_etat_processus).nombre_arguments = -1;
                   3198:        return;
                   3199:    }
                   3200: 
                   3201:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   3202:    {
                   3203:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   3204:        {
                   3205:            return;
                   3206:        }
                   3207:    }
                   3208: 
                   3209:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3210:            &s_objet_argument) == d_erreur)
                   3211:    {
                   3212:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   3213:        return;
                   3214:    }
                   3215: 
                   3216:    if ((*s_objet_argument).type == SCK)
                   3217:    {
                   3218:        if ((strcmp((*((struct_socket *) (*s_objet_argument).objet)).type,
                   3219:                "STREAM") != 0) && (strcmp((*((struct_socket *)
                   3220:                (*s_objet_argument).objet)).type, "SEQUENTIAL DATAGRAM") != 0))
                   3221:        {
1.54      bertrand 3222:            // Mode non connecté : l'attente se fait sur un poll()
                   3223: 
                   3224:            if ((s_objet_resultat = copie_objet(s_etat_processus,
                   3225:                    s_objet_argument, 'P')) == NULL)
                   3226:            {
                   3227:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3228:                return;
                   3229:            }
                   3230: 
                   3231:            s_poll.fd = (*((struct_socket *) (*s_objet_argument).objet)).socket;
                   3232:            s_poll.events = POLLIN;
                   3233:            s_poll.revents = 0;
                   3234: 
1.55      bertrand 3235:            do
1.54      bertrand 3236:            {
1.55      bertrand 3237:                drapeau = d_vrai;
                   3238: 
                   3239: #              ifndef SEMAPHORES_NOMMES
                   3240:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   3241: #              else
                   3242:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   3243: #              endif
                   3244:                {
                   3245:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   3246:                    return;
                   3247:                }
                   3248: 
                   3249:                if (poll(&s_poll, 1, -1) < 0)
                   3250:                {
                   3251:                    erreur = errno;
                   3252: 
                   3253: #                  ifndef SEMAPHORES_NOMMES
                   3254:                    while(sem_wait(&((*s_etat_processus)
                   3255:                            .semaphore_fork)) != 0)
                   3256: #                  else
                   3257:                    while(sem_wait((*s_etat_processus).semaphore_fork)
                   3258:                            != 0)
                   3259: #                  endif
                   3260: 
                   3261:                    if (erreur != EINTR)
                   3262:                    {
                   3263:                        liberation(s_etat_processus, s_objet_argument);
                   3264:                        liberation(s_etat_processus, s_objet_resultat);
                   3265: 
                   3266:                        (*s_etat_processus).erreur_execution =
                   3267:                                d_ex_erreur_acces_fichier;
                   3268:                        return;
                   3269:                    }
                   3270: 
                   3271:                    scrutation_injection(s_etat_processus);
                   3272: 
                   3273:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3274:                    {
                   3275:                        drapeau = d_vrai;
                   3276:                    }
                   3277:                    else
                   3278:                    {
                   3279:                        drapeau = d_faux;
                   3280:                    }
                   3281:                }
                   3282:                else
1.54      bertrand 3283:                {
1.55      bertrand 3284: #                  ifndef SEMAPHORES_NOMMES
                   3285:                        while(sem_wait(&((*s_etat_processus)
                   3286:                                .semaphore_fork)) != 0)
                   3287: #                  else
                   3288:                        while(sem_wait((*s_etat_processus).semaphore_fork)
                   3289:                                != 0)
                   3290: #                  endif
                   3291:                    {
                   3292:                        if (errno != EINTR)
                   3293:                        {
                   3294:                            (*s_etat_processus).erreur_systeme =
                   3295:                                    d_es_processus;
                   3296:                            return;
                   3297:                        }
                   3298:                    }
1.54      bertrand 3299:                }
1.55      bertrand 3300:            } while(drapeau == d_faux);
1.54      bertrand 3301: 
                   3302:            if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3303:                    s_objet_argument) == d_erreur)
                   3304:            {
                   3305:                return;
                   3306:            }
1.1       bertrand 3307: 
1.54      bertrand 3308:            if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3309:                    s_objet_resultat) == d_erreur)
                   3310:            {
                   3311:                return;
                   3312:            }
1.1       bertrand 3313:        }
1.54      bertrand 3314:        else
1.1       bertrand 3315:        {
1.54      bertrand 3316:            // Mode connecté
1.1       bertrand 3317: 
1.54      bertrand 3318:            if ((s_objet_resultat = copie_objet(s_etat_processus,
                   3319:                    s_objet_argument, 'O')) == NULL)
                   3320:            {
                   3321:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3322:                return;
                   3323:            }
1.1       bertrand 3324: 
1.54      bertrand 3325:            (*((struct_socket *) (*s_objet_resultat).objet)).effacement = 'N';
                   3326:            (*((struct_socket *) (*s_objet_resultat).objet)).socket_en_ecoute
                   3327:                    = 'N';
1.1       bertrand 3328: 
1.54      bertrand 3329:            if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
                   3330:                    PF_INET)
1.1       bertrand 3331:            {
1.54      bertrand 3332:                longueur = sizeof(adresse_ipv4);
                   3333: 
                   3334:                do
                   3335:                {
                   3336:                    drapeau = d_vrai;
1.1       bertrand 3337: 
1.98    ! bertrand 3338: #                  ifndef SEMAPHORES_NOMMES
1.54      bertrand 3339:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   3340:                                != 0)
1.98    ! bertrand 3341: #                  else
1.54      bertrand 3342:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1.98    ! bertrand 3343: #                  endif
1.54      bertrand 3344:                    {
                   3345:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   3346:                        return;
                   3347:                    }
1.1       bertrand 3348: 
1.54      bertrand 3349:                    if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3350:                            .socket = accept((*((struct_socket *)
                   3351:                            (*s_objet_argument).objet)).socket,
                   3352:                            (struct sockaddr *) &adresse_ipv4, &longueur))
                   3353:                            < 0)
                   3354:                    {
                   3355:                        erreur = errno;
1.1       bertrand 3356: 
1.55      bertrand 3357: #                      ifndef SEMAPHORES_NOMMES
1.98    ! bertrand 3358:                            while(sem_wait(&((*s_etat_processus)
        !          3359:                                    .semaphore_fork)) != 0)
1.55      bertrand 3360: #                      else
1.98    ! bertrand 3361:                            while(sem_wait((*s_etat_processus).semaphore_fork)
        !          3362:                                    != 0)
1.55      bertrand 3363: #                      endif
1.50      bertrand 3364:                        {
1.54      bertrand 3365:                            if (errno != EINTR)
                   3366:                            {
                   3367:                                (*s_etat_processus).erreur_systeme =
                   3368:                                        d_es_processus;
                   3369:                                return;
                   3370:                            }
1.50      bertrand 3371:                        }
1.1       bertrand 3372: 
1.54      bertrand 3373:                        if (erreur != EINTR)
                   3374:                        {
                   3375:                            liberation(s_etat_processus, s_objet_argument);
                   3376:                            liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3377: 
1.54      bertrand 3378:                            (*s_etat_processus).erreur_execution =
                   3379:                                    d_ex_erreur_acces_fichier;
                   3380:                            return;
                   3381:                        }
1.1       bertrand 3382: 
1.54      bertrand 3383:                        scrutation_injection(s_etat_processus);
1.1       bertrand 3384: 
1.54      bertrand 3385:                        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3386:                        {
                   3387:                            drapeau = d_vrai;
                   3388:                        }
                   3389:                        else
                   3390:                        {
                   3391:                            drapeau = d_faux;
                   3392:                        }
1.1       bertrand 3393:                    }
                   3394:                    else
                   3395:                    {
1.98    ! bertrand 3396: #                      ifndef SEMAPHORES_NOMMES
1.54      bertrand 3397:                            while(sem_wait(&((*s_etat_processus)
                   3398:                                    .semaphore_fork)) != 0)
1.98    ! bertrand 3399: #                      else
1.54      bertrand 3400:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3401:                                    != 0)
1.98    ! bertrand 3402: #                      endif
1.50      bertrand 3403:                        {
1.54      bertrand 3404:                            if (errno != EINTR)
                   3405:                            {
                   3406:                                (*s_etat_processus).erreur_systeme =
                   3407:                                        d_es_processus;
                   3408:                                return;
                   3409:                            }
1.50      bertrand 3410:                        }
1.98    ! bertrand 3411: 
        !          3412:                        if (options_sockets(s_etat_processus,
        !          3413:                                (*s_objet_resultat).objet) != d_absence_erreur)
        !          3414:                        {
        !          3415:                            liberation(s_etat_processus, s_objet_argument);
        !          3416:                            liberation(s_etat_processus, s_objet_resultat);
        !          3417: 
        !          3418:                            (*s_etat_processus).erreur_execution =
        !          3419:                                    d_ex_erreur_parametre_fichier;
        !          3420:                            return;
        !          3421:                        }
1.1       bertrand 3422:                    }
1.54      bertrand 3423:                } while(drapeau == d_faux);
                   3424: 
                   3425:                if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3426:                        .adresse_distante = malloc(22 *
                   3427:                        sizeof(unsigned char))) == NULL)
                   3428:                {
                   3429:                    (*s_etat_processus).erreur_systeme =
                   3430:                            d_es_allocation_memoire;
                   3431:                    return;
1.1       bertrand 3432:                }
                   3433: 
1.54      bertrand 3434:                sprintf((*((struct_socket *) (*s_objet_resultat).objet))
                   3435:                        .adresse_distante, "%d.%d.%d.%d(%d)",
                   3436:                        (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF,
                   3437:                        (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF,
                   3438:                        (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF,
                   3439:                        ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF,
                   3440:                        ntohs(adresse_ipv4.sin_port));
                   3441:            }
                   3442:            else if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
                   3443:                    PF_INET6)
1.1       bertrand 3444:            {
1.20      bertrand 3445: #          ifdef IPV6
1.54      bertrand 3446:                longueur = sizeof(adresse_ipv6);
1.1       bertrand 3447: 
1.54      bertrand 3448:                do
                   3449:                {
                   3450:                    drapeau = d_vrai;
1.1       bertrand 3451: 
1.98    ! bertrand 3452: #                  ifndef SEMAPHORES_NOMMES
1.54      bertrand 3453:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   3454:                                != 0)
1.98    ! bertrand 3455: #                  else
1.54      bertrand 3456:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1.98    ! bertrand 3457: #                  endif
1.54      bertrand 3458:                    {
                   3459:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   3460:                        return;
                   3461:                    }
1.1       bertrand 3462: 
1.54      bertrand 3463:                    if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3464:                            .socket = accept((*((struct_socket *)
                   3465:                            (*s_objet_argument).objet)).socket,
                   3466:                            (struct sockaddr *) &adresse_ipv6, &longueur)) < 0)
                   3467:                    {
                   3468:                        erreur = errno;
1.1       bertrand 3469: 
1.98    ! bertrand 3470: #                      ifndef SEMAPHORES_NOMMES
1.54      bertrand 3471:                            while(sem_wait(&((*s_etat_processus)
                   3472:                                    .semaphore_fork)) != 0)
1.98    ! bertrand 3473: #                      else
1.54      bertrand 3474:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3475:                                    != 0)
1.98    ! bertrand 3476: #                      endif
1.50      bertrand 3477:                        {
1.54      bertrand 3478:                            if (errno != EINTR)
                   3479:                            {
                   3480:                                (*s_etat_processus).erreur_systeme =
                   3481:                                        d_es_processus;
                   3482:                                return;
                   3483:                            }
1.50      bertrand 3484:                        }
1.1       bertrand 3485: 
1.54      bertrand 3486:                        if (erreur != EINTR)
                   3487:                        {
                   3488:                            liberation(s_etat_processus, s_objet_argument);
                   3489:                            liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3490: 
1.54      bertrand 3491:                            (*s_etat_processus).erreur_execution =
                   3492:                                    d_ex_erreur_acces_fichier;
                   3493:                            return;
                   3494:                        }
1.1       bertrand 3495: 
1.54      bertrand 3496:                        scrutation_injection(s_etat_processus);
1.1       bertrand 3497: 
1.54      bertrand 3498:                        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3499:                        {
                   3500:                            drapeau = d_vrai;
                   3501:                        }
                   3502:                        else
                   3503:                        {
                   3504:                            drapeau = d_faux;
                   3505:                        }
1.1       bertrand 3506:                    }
                   3507:                    else
                   3508:                    {
1.98    ! bertrand 3509: #                      ifndef SEMAPHORES_NOMMES
1.54      bertrand 3510:                            while(sem_wait(&((*s_etat_processus)
                   3511:                                    .semaphore_fork)) != 0)
1.98    ! bertrand 3512: #                      else
1.54      bertrand 3513:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3514:                                    != 0)
1.98    ! bertrand 3515: #                      endif
1.50      bertrand 3516:                        {
1.54      bertrand 3517:                            if (errno != EINTR)
                   3518:                            {
                   3519:                                (*s_etat_processus).erreur_systeme =
                   3520:                                        d_es_processus;
                   3521:                                return;
                   3522:                            }
1.50      bertrand 3523:                        }
1.98    ! bertrand 3524: 
        !          3525:                        if (options_sockets(s_etat_processus,
        !          3526:                                (*s_objet_resultat).objet) != d_absence_erreur)
        !          3527:                        {
        !          3528:                            liberation(s_etat_processus, s_objet_argument);
        !          3529:                            liberation(s_etat_processus, s_objet_resultat);
        !          3530: 
        !          3531:                            (*s_etat_processus).erreur_execution =
        !          3532:                                    d_ex_erreur_parametre_fichier;
        !          3533:                            return;
        !          3534:                        }
1.1       bertrand 3535:                    }
1.54      bertrand 3536:                } while(drapeau == d_faux);
                   3537: 
                   3538:                if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3539:                        .adresse_distante = malloc(55 *
                   3540:                        sizeof(unsigned char))) == NULL)
                   3541:                {
                   3542:                    (*s_etat_processus).erreur_systeme =
                   3543:                            d_es_allocation_memoire;
                   3544:                    return;
1.1       bertrand 3545:                }
                   3546: 
1.54      bertrand 3547:                (*((struct_socket *) (*s_objet_resultat).objet))
                   3548:                        .adresse_distante = d_code_fin_chaine;
1.1       bertrand 3549: 
1.54      bertrand 3550:                for(i = 0; i < 16; i++)
                   3551:                {
                   3552:                    sprintf((*((struct_socket *) (*s_objet_resultat)
                   3553:                            .objet)).adresse_distante, (i == 0) ? "%s%X"
                   3554:                            : "%s:%X", (*((struct_socket *) (*s_objet_resultat)
                   3555:                            .objet)).adresse_distante,
                   3556:                            adresse_ipv6.sin6_addr.s6_addr[i]);
                   3557:                }
1.1       bertrand 3558: 
                   3559:                sprintf((*((struct_socket *) (*s_objet_resultat)
1.54      bertrand 3560:                        .objet)).adresse_distante, "%s(%u)",
1.1       bertrand 3561:                        (*((struct_socket *) (*s_objet_resultat)
                   3562:                        .objet)).adresse_distante,
1.54      bertrand 3563:                        ntohs(adresse_ipv6.sin6_port));
1.20      bertrand 3564: #          else
1.54      bertrand 3565:                if ((*s_etat_processus).langue == 'F')
                   3566:                {
                   3567:                    printf("+++Attention : Support du protocole"
                   3568:                            " IPv6 indisponible\n");
                   3569:                }
                   3570:                else
                   3571:                {
                   3572:                    printf("+++Warning : IPv6 support "
                   3573:                            "unavailable\n");
                   3574:                }
                   3575: #          endif
1.22      bertrand 3576:            }
                   3577:            else
                   3578:            {
1.54      bertrand 3579:                longueur = 0;
1.1       bertrand 3580: 
1.54      bertrand 3581:                do
                   3582:                {
                   3583:                    drapeau = d_vrai;
1.1       bertrand 3584: 
1.98    ! bertrand 3585: #                  ifndef SEMAPHORES_NOMMES
1.54      bertrand 3586:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   3587:                                != 0)
1.98    ! bertrand 3588: #                  else
1.54      bertrand 3589:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1.98    ! bertrand 3590: #                  endif
1.54      bertrand 3591:                    {
                   3592:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   3593:                        return;
                   3594:                    }
1.1       bertrand 3595: 
1.54      bertrand 3596:                    if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3597:                            .socket = accept((*((struct_socket *)
                   3598:                            (*s_objet_argument).objet)).socket, NULL,
                   3599:                            &longueur)) < 0)
                   3600:                    {
                   3601:                        erreur = errno;
1.1       bertrand 3602: 
1.98    ! bertrand 3603: #                      ifndef SEMAPHORES_NOMMES
1.54      bertrand 3604:                            while(sem_wait(&((*s_etat_processus)
                   3605:                                    .semaphore_fork)) != 0)
1.98    ! bertrand 3606: #                      else
1.54      bertrand 3607:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3608:                                    != 0)
1.98    ! bertrand 3609: #                      endif
1.50      bertrand 3610:                        {
1.54      bertrand 3611:                            if (errno != EINTR)
                   3612:                            {
                   3613:                                (*s_etat_processus).erreur_systeme =
                   3614:                                        d_es_processus;
                   3615:                                return;
                   3616:                            }
1.50      bertrand 3617:                        }
1.1       bertrand 3618: 
1.54      bertrand 3619:                        if (erreur != EINTR)
                   3620:                        {
                   3621:                            liberation(s_etat_processus, s_objet_argument);
                   3622:                            liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3623: 
1.54      bertrand 3624:                            (*s_etat_processus).erreur_execution =
                   3625:                                    d_ex_erreur_acces_fichier;
                   3626:                            return;
                   3627:                        }
1.1       bertrand 3628: 
1.54      bertrand 3629:                        scrutation_injection(s_etat_processus);
1.1       bertrand 3630: 
1.54      bertrand 3631:                        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3632:                        {
                   3633:                            drapeau = d_vrai;
                   3634:                        }
                   3635:                        else
                   3636:                        {
                   3637:                            drapeau = d_faux;
                   3638:                        }
1.1       bertrand 3639:                    }
                   3640:                    else
                   3641:                    {
1.98    ! bertrand 3642: #                      ifndef SEMAPHORES_NOMMES
1.54      bertrand 3643:                            while(sem_wait(&((*s_etat_processus)
                   3644:                                    .semaphore_fork)) != 0)
1.98    ! bertrand 3645: #                      else
1.54      bertrand 3646:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3647:                                    != 0)
1.98    ! bertrand 3648: #                      endif
1.50      bertrand 3649:                        {
1.54      bertrand 3650:                            if (errno != EINTR)
                   3651:                            {
                   3652:                                (*s_etat_processus).erreur_systeme =
                   3653:                                        d_es_processus;
                   3654:                                return;
                   3655:                            }
1.50      bertrand 3656:                        }
1.98    ! bertrand 3657: 
        !          3658:                        if (options_sockets(s_etat_processus,
        !          3659:                                (*s_objet_resultat).objet) != d_absence_erreur)
        !          3660:                        {
        !          3661:                            liberation(s_etat_processus, s_objet_argument);
        !          3662:                            liberation(s_etat_processus, s_objet_resultat);
        !          3663: 
        !          3664:                            (*s_etat_processus).erreur_execution =
        !          3665:                                    d_ex_erreur_parametre_fichier;
        !          3666:                            return;
        !          3667:                        }
1.1       bertrand 3668:                    }
1.54      bertrand 3669:                } while(drapeau == d_faux);
                   3670:            }
1.1       bertrand 3671: 
1.54      bertrand 3672:            // Si accept() renvoie une erreur non récupérée, il ne peut s'agir
                   3673:            // que de EINTR sachant qu'une requête d'arrêt est en court de
                   3674:            // traitement.
1.1       bertrand 3675: 
1.54      bertrand 3676:            if ((*((struct_socket *) (*s_objet_resultat).objet)).socket >= 0)
                   3677:            {
                   3678:                l_element_courant = (*s_etat_processus).s_sockets;
1.1       bertrand 3679: 
1.54      bertrand 3680:                if (l_element_courant == NULL)
1.1       bertrand 3681:                {
1.54      bertrand 3682:                    if (((*s_etat_processus).s_sockets =
                   3683:                            allocation_maillon(s_etat_processus)) == NULL)
                   3684:                    {
                   3685:                        (*s_etat_processus).erreur_systeme =
                   3686:                                d_es_allocation_memoire;
                   3687:                        return;
                   3688:                    }
                   3689: 
                   3690:                    (*(*s_etat_processus).s_sockets).suivant = NULL;
                   3691:                    l_element_courant = (*s_etat_processus).s_sockets;
1.1       bertrand 3692:                }
1.54      bertrand 3693:                else
                   3694:                {
                   3695:                    /*
                   3696:                     * Ajout d'un élément à la fin de la liste chaînée
                   3697:                     */
1.1       bertrand 3698: 
1.54      bertrand 3699:                    while((*l_element_courant).suivant != NULL)
                   3700:                    {
                   3701:                        l_element_courant = (*l_element_courant).suivant;
                   3702:                    }
                   3703: 
                   3704:                    if (((*l_element_courant).suivant =
                   3705:                            allocation_maillon(s_etat_processus)) == NULL)
                   3706:                    {
                   3707:                        (*s_etat_processus).erreur_systeme =
                   3708:                                d_es_allocation_memoire;
                   3709:                        return;
                   3710:                    }
1.1       bertrand 3711: 
                   3712:                    l_element_courant = (*l_element_courant).suivant;
1.54      bertrand 3713:                    (*l_element_courant).suivant = NULL;
1.1       bertrand 3714:                }
                   3715: 
1.54      bertrand 3716:                if (((*l_element_courant).donnee = copie_objet(s_etat_processus,
                   3717:                        s_objet_resultat, 'O')) == NULL)
1.1       bertrand 3718:                {
                   3719:                    (*s_etat_processus).erreur_systeme =
                   3720:                            d_es_allocation_memoire;
                   3721:                    return;
                   3722:                }
1.54      bertrand 3723:            }
1.1       bertrand 3724: 
1.54      bertrand 3725:            if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3726:                    s_objet_argument) == d_erreur)
                   3727:            {
                   3728:                return;
1.1       bertrand 3729:            }
                   3730: 
1.54      bertrand 3731:            if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3732:                    s_objet_resultat) == d_erreur)
1.1       bertrand 3733:            {
                   3734:                return;
                   3735:            }
                   3736:        }
                   3737:    }
                   3738:    else
                   3739:    {
                   3740:        liberation(s_etat_processus, s_objet_argument);
                   3741: 
                   3742:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   3743:        return;
                   3744:    }
                   3745: 
                   3746:    return;
                   3747: }
                   3748: 
                   3749: 
                   3750: /*
                   3751: ================================================================================
                   3752:   Fonction 'wfswi'
                   3753: ================================================================================
                   3754:   Entrées : pointeur sur une structure struct_processus
                   3755: --------------------------------------------------------------------------------
                   3756:   Sorties :
                   3757: --------------------------------------------------------------------------------
                   3758:   Effets de bord : néant
                   3759: ================================================================================
                   3760: */
                   3761: 
                   3762: void
                   3763: instruction_wfswi(struct_processus *s_etat_processus)
                   3764: {
                   3765:    integer8                    interruption;
                   3766: 
                   3767:    logical1                    drapeau_fin;
                   3768: 
                   3769:    struct_objet                *s_objet_argument;
                   3770: 
                   3771:    struct timespec             attente;
                   3772: 
                   3773:    (*s_etat_processus).erreur_execution = d_ex;
                   3774: 
                   3775:    attente.tv_sec = 0;
                   3776:    attente.tv_nsec = GRANULARITE_us * 1000;
                   3777: 
                   3778:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   3779:    {
                   3780:        printf("\n  WFSWI ");
                   3781: 
                   3782:        if ((*s_etat_processus).langue == 'F')
                   3783:        {
                   3784:            printf("(attente d'une interruption)\n\n");
                   3785:        }
                   3786:        else
                   3787:        {
                   3788:            printf("(wait for interrupt)\n\n");
                   3789:        }
                   3790: 
                   3791:        printf("    1: %s\n", d_INT);
                   3792: 
                   3793:        return;
                   3794:    }
                   3795:    else if ((*s_etat_processus).test_instruction == 'Y')
                   3796:    {
                   3797:        (*s_etat_processus).nombre_arguments = -1;
                   3798:        return;
                   3799:    }
                   3800: 
                   3801:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   3802:    {
                   3803:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   3804:        {
                   3805:            return;
                   3806:        }
                   3807:    }
                   3808: 
                   3809:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3810:            &s_objet_argument) == d_erreur)
                   3811:    {
                   3812:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   3813:        return;
                   3814:    }
                   3815: 
                   3816:    if ((*s_objet_argument).type == INT)
                   3817:    {
                   3818:        drapeau_fin = d_faux;
                   3819: 
                   3820:        interruption = (*((integer8 *) (*s_objet_argument).objet));
                   3821: 
                   3822:        if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
                   3823:        {
                   3824:            liberation(s_etat_processus, s_objet_argument);
                   3825: 
                   3826:            (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
                   3827:            return;
                   3828:        }
                   3829: 
                   3830:        while(drapeau_fin == d_faux)
                   3831:        {
                   3832:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3833:            {
                   3834:                liberation(s_etat_processus, s_objet_argument);
                   3835:                return;
                   3836:            }
                   3837: 
1.84      bertrand 3838:            if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions)
                   3839:                    != 0)
1.83      bertrand 3840:            {
                   3841:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3842:                return;
                   3843:            }
                   3844: 
1.1       bertrand 3845:            if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   3846:            {
                   3847:                affectation_interruptions_logicielles(s_etat_processus);
                   3848:            }
                   3849: 
1.84      bertrand 3850:            if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions)
                   3851:                    != 0)
1.83      bertrand 3852:            {
                   3853:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3854:                return;
                   3855:            }
                   3856: 
1.1       bertrand 3857:            if ((*s_etat_processus).queue_interruptions[interruption - 1] > 0)
                   3858:            {
                   3859:                drapeau_fin = d_vrai;
                   3860:            }
                   3861:            else
                   3862:            {
                   3863:                nanosleep(&attente, NULL);
                   3864:                scrutation_injection(s_etat_processus);
                   3865:                INCR_GRANULARITE(attente.tv_nsec);
                   3866:            }
                   3867:        }
                   3868:    }
                   3869:    else
                   3870:    {
                   3871:        liberation(s_etat_processus, s_objet_argument);
                   3872: 
                   3873:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   3874:        return;
                   3875:    }
                   3876: 
                   3877:    liberation(s_etat_processus, s_objet_argument);
                   3878: 
                   3879:    return;
                   3880: }
                   3881: 
                   3882: 
                   3883: /*
                   3884: ================================================================================
                   3885:   Fonction 'wfpoke'
                   3886: ================================================================================
                   3887:   Entrées : pointeur sur une structure struct_processus
                   3888: --------------------------------------------------------------------------------
                   3889:   Sorties :
                   3890: --------------------------------------------------------------------------------
                   3891:   Effets de bord : néant
                   3892: ================================================================================
                   3893: */
                   3894: 
                   3895: void
                   3896: instruction_wfpoke(struct_processus *s_etat_processus)
                   3897: {
                   3898:    struct timespec             attente;
                   3899: 
                   3900:    unsigned char               registre_instruction_valide;
                   3901: 
                   3902:    (*s_etat_processus).erreur_execution = d_ex;
                   3903: 
                   3904:    attente.tv_sec = 0;
                   3905:    attente.tv_nsec = GRANULARITE_us * 1000;
                   3906: 
                   3907:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   3908:    {
                   3909:        printf("\n  WFPOKE ");
                   3910: 
                   3911:        if ((*s_etat_processus).langue == 'F')
                   3912:        {
                   3913:            printf("(attente de données en provenance du processus père)\n\n");
                   3914:            printf("  Aucun argument\n");
                   3915:        }
                   3916:        else
                   3917:        {
                   3918:            printf("(wait for data from parent process)\n\n");
                   3919:            printf("  No argument\n");
                   3920:        }
                   3921: 
                   3922:        return;
                   3923:    }
                   3924:    else if ((*s_etat_processus).test_instruction == 'Y')
                   3925:    {
                   3926:        (*s_etat_processus).nombre_arguments = -1;
                   3927:        return;
                   3928:    }
                   3929: 
                   3930:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   3931:    {
                   3932:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                   3933:        {
                   3934:            return;
                   3935:        }
                   3936:    }
                   3937: 
                   3938:    if ((*s_etat_processus).presence_pipes == d_faux)
                   3939:    {
                   3940:        (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
                   3941:        return;
                   3942:    }
                   3943: 
                   3944:    if ((*s_etat_processus).nombre_objets_injectes > 0)
                   3945:    {
                   3946:        return;
                   3947:    }
                   3948: 
                   3949:    if ((*s_etat_processus).profilage == d_vrai)
                   3950:    {
                   3951:        profilage(s_etat_processus, "Interprocess or interthread "
                   3952:                "communications (WFPOKE)");
                   3953: 
                   3954:        if ((*s_etat_processus).erreur_systeme != d_es)
                   3955:        {
                   3956:            return;
                   3957:        }
                   3958:    }
                   3959: 
                   3960:    do
                   3961:    {
1.51      bertrand 3962: #      ifndef SEMAPHORES_NOMMES
                   3963:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   3964: #      else
                   3965:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   3966: #      endif
1.1       bertrand 3967:        {
                   3968:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   3969:            return;
                   3970:        }
                   3971: 
                   3972:        nanosleep(&attente, NULL);
                   3973: 
1.51      bertrand 3974: #      ifndef SEMAPHORES_NOMMES
                   3975:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   3976: #      else
                   3977:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   3978: #      endif
1.1       bertrand 3979:        {
1.50      bertrand 3980:            if (errno != EINTR)
                   3981:            {
                   3982:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3983:                return;
                   3984:            }
1.1       bertrand 3985:        }
                   3986: 
                   3987:        scrutation_injection(s_etat_processus);
                   3988: 
1.84      bertrand 3989:        if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) != 0)
1.83      bertrand 3990:        {
                   3991:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   3992:            return;
                   3993:        }
                   3994: 
1.1       bertrand 3995:        if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   3996:        {
                   3997:            affectation_interruptions_logicielles(s_etat_processus);
                   3998:        }
                   3999: 
1.84      bertrand 4000:        if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) != 0)
1.83      bertrand 4001:        {
                   4002:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   4003:            return;
                   4004:        }
                   4005: 
1.1       bertrand 4006:        if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   4007:        {
                   4008:            registre_instruction_valide =
                   4009:                    (*s_etat_processus).instruction_valide;
                   4010:            traitement_interruptions_logicielles(s_etat_processus);
                   4011:            (*s_etat_processus).instruction_valide =
                   4012:                    registre_instruction_valide;
                   4013:        }
                   4014: 
                   4015:        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   4016:        {
                   4017:            if ((*s_etat_processus).profilage == d_vrai)
                   4018:            {
                   4019:                profilage(s_etat_processus, NULL);
                   4020:            }
                   4021: 
                   4022:            return;
                   4023:        }
                   4024: 
                   4025:        INCR_GRANULARITE(attente.tv_nsec);
                   4026:    } while((*s_etat_processus).nombre_objets_injectes == 0);
                   4027: 
                   4028:    return;
                   4029: }
                   4030: 
                   4031: 
                   4032: /*
                   4033: ================================================================================
                   4034:   Fonction 'wfack'
                   4035: ================================================================================
                   4036:   Entrées : pointeur sur une structure struct_processus
                   4037: --------------------------------------------------------------------------------
                   4038:   Sorties :
                   4039: --------------------------------------------------------------------------------
                   4040:   Effets de bord : néant
                   4041: ================================================================================
                   4042: */
                   4043: 
                   4044: void
                   4045: instruction_wfack(struct_processus *s_etat_processus)
                   4046: {
                   4047:    struct timespec             attente;
                   4048: 
                   4049:    unsigned char               registre_instruction_valide;
                   4050: 
                   4051:    (*s_etat_processus).erreur_execution = d_ex;
                   4052: 
                   4053:    attente.tv_sec = 0;
                   4054:    attente.tv_nsec = GRANULARITE_us * 1000;
                   4055: 
                   4056:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   4057:    {
                   4058:        printf("\n  WFACK ");
                   4059: 
                   4060:        if ((*s_etat_processus).langue == 'F')
                   4061:        {
                   4062:            printf("(attente des acquittements de lecture)\n\n");
                   4063:            printf("  Aucun argument\n");
                   4064:        }
                   4065:        else
                   4066:        {
                   4067:            printf("(wait for reading of data acknowledgement)\n\n");
                   4068:            printf("  No argument\n");
                   4069:        }
                   4070: 
                   4071:        return;
                   4072:    }
                   4073:    else if ((*s_etat_processus).test_instruction == 'Y')
                   4074:    {
                   4075:        (*s_etat_processus).nombre_arguments = -1;
                   4076:        return;
                   4077:    }
                   4078: 
                   4079:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   4080:    {
                   4081:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                   4082:        {
                   4083:            return;
                   4084:        }
                   4085:    }
                   4086: 
                   4087:    if ((*s_etat_processus).presence_pipes == d_faux)
                   4088:    {
                   4089:        (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
                   4090:        return;
                   4091:    }
                   4092: 
                   4093:    if ((*s_etat_processus).profilage == d_vrai)
                   4094:    {
                   4095:        profilage(s_etat_processus, "Interprocess or interthread communications"
                   4096:                " (WFACK)");
                   4097: 
                   4098:        if ((*s_etat_processus).erreur_systeme != d_es)
                   4099:        {
                   4100:            return;
                   4101:        }
                   4102:    }
                   4103: 
                   4104:    while((*s_etat_processus).nombre_objets_envoyes_non_lus != 0)
                   4105:    {
                   4106:        scrutation_injection(s_etat_processus);
                   4107: 
1.84      bertrand 4108:        if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) != 0)
1.83      bertrand 4109:        {
                   4110:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   4111:            return;
                   4112:        }
                   4113: 
1.1       bertrand 4114:        if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   4115:        {
                   4116:            affectation_interruptions_logicielles(s_etat_processus);
                   4117:        }
                   4118: 
1.84      bertrand 4119:        if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) != 0)
1.83      bertrand 4120:        {
                   4121:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   4122:            return;
                   4123:        }
                   4124: 
1.1       bertrand 4125:        if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   4126:        {
                   4127:            registre_instruction_valide =
                   4128:                    (*s_etat_processus).instruction_valide;
                   4129:            traitement_interruptions_logicielles(s_etat_processus);
                   4130:            (*s_etat_processus).instruction_valide =
                   4131:                    registre_instruction_valide;
                   4132:        }
                   4133: 
                   4134:        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   4135:        {
                   4136:            if ((*s_etat_processus).profilage == d_vrai)
                   4137:            {
                   4138:                profilage(s_etat_processus, NULL);
                   4139:            }
                   4140: 
                   4141:            return;
                   4142:        }
                   4143: 
1.51      bertrand 4144: #      ifndef SEMAPHORES_NOMMES
                   4145:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   4146: #      else
                   4147:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   4148: #      endif
1.12      bertrand 4149:        {
                   4150:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   4151:            return;
                   4152:        }
1.1       bertrand 4153: 
                   4154:        nanosleep(&attente, NULL);
                   4155:        INCR_GRANULARITE(attente.tv_nsec);
                   4156: 
1.51      bertrand 4157: #      ifndef SEMAPHORES_NOMMES
                   4158:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   4159: #      else
                   4160:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   4161: #      endif
1.1       bertrand 4162:        {
1.50      bertrand 4163:            if (errno != EINTR)
                   4164:            {
                   4165:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   4166:                return;
                   4167:            }
1.1       bertrand 4168:        }
                   4169:    }
                   4170: 
                   4171:    if ((*s_etat_processus).profilage == d_vrai)
                   4172:    {
                   4173:        profilage(s_etat_processus, NULL);
                   4174:    }
                   4175: 
                   4176:    return;
                   4177: }
                   4178: 
                   4179: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>