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

1.1       bertrand    1: /*
                      2: ================================================================================
1.109     bertrand    3:   RPL/2 (R) version 4.1.29
                      4:   Copyright (C) 1989-2018 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.110     bertrand  413:    logical1                            format_oriente_ligne;
1.8       bertrand  414:    logical1                            mise_a_jour;
                    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: 
1.110     bertrand 1510:                    if (strcmp("LINE*(*)", format_chaine) == 0)
1.64      bertrand 1511:                    {
1.110     bertrand 1512:                        format_oriente_ligne = d_vrai;
                   1513:                        format_degenere = d_vrai;
1.64      bertrand 1514:                    }
1.110     bertrand 1515:                    else
1.64      bertrand 1516:                    {
1.110     bertrand 1517:                        format_oriente_ligne = d_faux;
                   1518:                        
                   1519:                        if (strncmp("LENGTH*(", format_chaine, 8) != 0)
                   1520:                        {
                   1521:                            free(format_chaine);
1.64      bertrand 1522: 
1.110     bertrand 1523:                            liberation(s_etat_processus, s_objet_argument_2);
                   1524:                            liberation(s_etat_processus, s_objet_argument_1);
1.64      bertrand 1525: 
1.110     bertrand 1526:                            (*s_etat_processus).erreur_execution =
                   1527:                                    d_ex_erreur_format_fichier;
                   1528:                            return;
                   1529:                        }
1.64      bertrand 1530: 
1.110     bertrand 1531:                        longueur = (integer8) strlen(format_chaine);
1.64      bertrand 1532: 
1.110     bertrand 1533:                        if (format_chaine[longueur - 1] != ')')
1.64      bertrand 1534:                        {
                   1535:                            free(format_chaine);
                   1536: 
                   1537:                            liberation(s_etat_processus, s_objet_argument_2);
                   1538:                            liberation(s_etat_processus, s_objet_argument_1);
1.33      bertrand 1539: 
1.64      bertrand 1540:                            (*s_etat_processus).erreur_execution =
                   1541:                                    d_ex_erreur_format_fichier;
                   1542:                            return;
                   1543:                        }
1.110     bertrand 1544: 
                   1545:                        format_chaine[longueur] = d_code_fin_chaine;
                   1546: 
                   1547:                        if (format_chaine[8] == '*')
                   1548:                        {
                   1549:                            format_degenere = d_vrai;
                   1550:                        }
                   1551:                        else
                   1552:                        {
                   1553:                            // Détermination de la longueur
                   1554:                            format_degenere = d_faux;
                   1555: 
                   1556:                            if (sscanf(&(format_chaine[8]), "%lld", &longueur)
                   1557:                                    != 1)
                   1558:                            {
                   1559:                                free(format_chaine);
                   1560: 
                   1561:                                liberation(s_etat_processus,
                   1562:                                        s_objet_argument_2);
                   1563:                                liberation(s_etat_processus,
                   1564:                                        s_objet_argument_1);
                   1565: 
                   1566:                                (*s_etat_processus).erreur_execution =
                   1567:                                        d_ex_erreur_format_fichier;
                   1568:                                return;
                   1569:                            }
                   1570:                        }
1.64      bertrand 1571:                    }
1.33      bertrand 1572: 
1.64      bertrand 1573:                    free(format_chaine);
1.33      bertrand 1574: 
1.64      bertrand 1575:                    if ((chaine = formateur_flux(s_etat_processus,
                   1576:                            (unsigned char *) (*(*l_element_courant).donnee)
                   1577:                            .objet, &longueur_effective)) == NULL)
                   1578:                    {
                   1579:                        (*s_etat_processus).erreur_systeme =
                   1580:                                d_es_allocation_memoire;
                   1581:                        return;
                   1582:                    }
1.33      bertrand 1583: 
1.64      bertrand 1584:                    if ((format_degenere == d_vrai) ||
                   1585:                            (longueur_effective < longueur))
                   1586:                    {
                   1587:                        if (fwrite(chaine, sizeof(unsigned char),
1.79      bertrand 1588:                                (size_t) longueur_effective,
1.64      bertrand 1589:                                (*descripteur).descripteur_c) !=
                   1590:                                (size_t) longueur_effective)
                   1591:                        {
                   1592:                            (*s_etat_processus).erreur_systeme =
                   1593:                                    d_es_erreur_fichier;
                   1594:                            return;
                   1595:                        }
                   1596:                    }
                   1597:                    else
                   1598:                    {
                   1599:                        if (fwrite(chaine, sizeof(unsigned char),
1.79      bertrand 1600:                                (size_t) longueur_effective,
1.64      bertrand 1601:                                (*descripteur).descripteur_c) !=
                   1602:                                (size_t) longueur)
                   1603:                        {
                   1604:                            (*s_etat_processus).erreur_systeme =
                   1605:                                    d_es_erreur_fichier;
                   1606:                            return;
                   1607:                        }
                   1608:                    }
1.63      bertrand 1609: 
1.64      bertrand 1610:                    free(chaine);
1.63      bertrand 1611: 
1.110     bertrand 1612:                    if (format_oriente_ligne == d_vrai)
                   1613:                    {
                   1614:                        if (fwrite("\n", 1, 1, (*descripteur).descripteur_c)
                   1615:                                != 1)
                   1616:                        {
                   1617:                            (*s_etat_processus).erreur_systeme =
                   1618:                                    d_es_erreur_fichier;
                   1619:                            return;
                   1620:                        }
                   1621:                    }
                   1622: 
1.64      bertrand 1623:                    l_element_courant = (*l_element_courant).suivant;
                   1624:                    l_element_courant_format = (*l_element_courant_format)
                   1625:                            .suivant;
                   1626:                }
1.63      bertrand 1627: 
1.64      bertrand 1628:                if ((l_element_courant_format != NULL) ||
                   1629:                        (l_element_courant != NULL))
1.63      bertrand 1630:                {
1.64      bertrand 1631:                    liberation(s_etat_processus, s_objet_argument_2);
                   1632:                    liberation(s_etat_processus, s_objet_argument_1);
                   1633: 
                   1634:                    (*s_etat_processus).erreur_execution =
                   1635:                            d_ex_erreur_format_fichier;
1.63      bertrand 1636:                    return;
                   1637:                }
1.33      bertrand 1638:            }
                   1639:            else
                   1640:            {
                   1641:                liberation(s_etat_processus, s_objet_argument_1);
                   1642:                liberation(s_etat_processus, s_objet_argument_2);
                   1643: 
                   1644:                (*s_etat_processus).erreur_execution =
                   1645:                        d_ex_erreur_type_fichier;
                   1646:                return;
                   1647:            }
1.1       bertrand 1648:        }
                   1649:    }
                   1650:    else if (((*s_objet_argument_2).type == LST) &&
                   1651:            ((*s_objet_argument_1).type == SCK))
                   1652:    {
                   1653:        /*
                   1654:         * Vérification de l'autorisation d'écriture
                   1655:         */
                   1656: 
                   1657:        if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1658:                .protection == 'R')
                   1659:        {
                   1660:            liberation(s_etat_processus, s_objet_argument_2);
                   1661:            liberation(s_etat_processus, s_objet_argument_1);
                   1662: 
                   1663:            (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
                   1664:            return;
                   1665:        }
                   1666: 
                   1667:        if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire == 'N')
                   1668:        {
                   1669:            /*
                   1670:             * Sockets formatées
                   1671:             */
                   1672: 
                   1673:            if ((chaine = formateur_fichier(s_etat_processus,
                   1674:                    s_objet_argument_2, (*((struct_socket *)
                   1675:                    (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
1.75      bertrand 1676:                    &longueur_effective, &recursivite, d_faux)) == NULL)
1.1       bertrand 1677:            {
                   1678:                liberation(s_etat_processus, s_objet_argument_2);
                   1679:                liberation(s_etat_processus, s_objet_argument_1);
                   1680: 
                   1681:                return;
                   1682:            }
1.33      bertrand 1683:        }
                   1684:        else if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire
                   1685:                == 'Y')
                   1686:        {
                   1687:            /*
                   1688:             * Sockets non formatées
                   1689:             */
1.38      bertrand 1690: 
1.77      bertrand 1691:            if ((chaine = formateur_fichier(s_etat_processus,
                   1692:                    s_objet_argument_2, (*((struct_socket *)
                   1693:                    (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
                   1694:                    &longueur_effective, &recursivite, d_faux)) == NULL)
                   1695:            {
                   1696:                liberation(s_etat_processus, s_objet_argument_2);
                   1697:                liberation(s_etat_processus, s_objet_argument_1);
                   1698: 
                   1699:                return;
                   1700:            }
1.33      bertrand 1701:        }
                   1702:        else
                   1703:        {
                   1704:            /*
                   1705:             *  Sockets de type FLOW
                   1706:             */
                   1707: 
                   1708:            if ((*((*((struct_liste_chainee *) (*s_objet_argument_2).objet))
                   1709:                    .donnee)).type != CHN)
                   1710:            {
                   1711:                liberation(s_etat_processus, s_objet_argument_2);
                   1712:                liberation(s_etat_processus, s_objet_argument_1);
                   1713: 
                   1714:                (*s_etat_processus).erreur_execution =
                   1715:                        d_ex_erreur_type_argument;
                   1716:                return;
                   1717:            }
                   1718: 
                   1719:            if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
                   1720:                    (*((*((struct_liste_chainee *) (*s_objet_argument_2)
                   1721:                    .objet)).donnee)).objet, &longueur_effective)) == NULL)
                   1722:            {
                   1723:                liberation(s_etat_processus, s_objet_argument_2);
                   1724:                liberation(s_etat_processus, s_objet_argument_1);
                   1725: 
                   1726:                return;
                   1727:            }
                   1728:        }
1.1       bertrand 1729: 
1.33      bertrand 1730:        if ((strcmp((*((struct_socket *) (*s_objet_argument_1).objet)).type,
                   1731:                "STREAM") == 0) || (strcmp((*((struct_socket *)
                   1732:                (*s_objet_argument_1).objet)).type,
                   1733:                "SEQUENTIAL DATAGRAM") == 0))
                   1734:        { // Sockets connectées
                   1735: 
                   1736:            action.sa_handler = SIG_IGN;
                   1737:            action.sa_flags = SA_ONSTACK;
                   1738: 
                   1739:            if (sigaction(SIGPIPE, &action, &registre) != 0)
                   1740:            {
                   1741:                (*s_etat_processus).erreur_systeme = d_es_signal;
                   1742:                return;
                   1743:            }
                   1744: 
1.51      bertrand 1745: #          ifndef SEMAPHORES_NOMMES
                   1746:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1747: #          else
                   1748:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1749: #          endif
1.33      bertrand 1750:            {
                   1751:                if (sigaction(SIGPIPE, &registre, NULL) != 0)
                   1752:                {
                   1753:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                   1754:                    return;
                   1755:                }
                   1756: 
                   1757:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1758:                return;
                   1759:            }
1.1       bertrand 1760: 
1.33      bertrand 1761:            if (send((*((struct_socket *) (*s_objet_argument_1).objet))
1.79      bertrand 1762:                    .socket, chaine, (size_t) longueur_effective, 0) < 0)
1.33      bertrand 1763:            {
                   1764:                ios = errno;
1.1       bertrand 1765: 
1.33      bertrand 1766:                if (sigaction(SIGPIPE, &registre, NULL) != 0)
1.1       bertrand 1767:                {
                   1768:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                   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.1       bertrand 1777:                {
1.50      bertrand 1778:                    if (errno != EINTR)
                   1779:                    {
                   1780:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1781:                        return;
                   1782:                    }
1.33      bertrand 1783:                }
1.1       bertrand 1784: 
1.33      bertrand 1785:                if ((ios == EPIPE) || (ios == ECONNRESET))
                   1786:                {
                   1787:                    (*s_etat_processus).erreur_execution =
                   1788:                            d_ex_erreur_acces_fichier;
1.1       bertrand 1789:                    return;
                   1790:                }
                   1791: 
1.33      bertrand 1792:                (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                   1793:                return;
                   1794:            }
                   1795: 
1.51      bertrand 1796: #          ifndef SEMAPHORES_NOMMES
                   1797:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1798: #          else
                   1799:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1800: #          endif
1.33      bertrand 1801:            {
                   1802:                if (errno != EINTR)
1.1       bertrand 1803:                {
                   1804:                    if (sigaction(SIGPIPE, &registre, NULL) != 0)
                   1805:                    {
                   1806:                        (*s_etat_processus).erreur_systeme = d_es_signal;
                   1807:                        return;
                   1808:                    }
                   1809: 
1.33      bertrand 1810:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1811:                    return;
                   1812:                }
                   1813:            }
                   1814: 
                   1815:            if (sigaction(SIGPIPE, &registre, NULL) != 0)
                   1816:            {
                   1817:                (*s_etat_processus).erreur_systeme = d_es_signal;
                   1818:                return;
                   1819:            }
                   1820:        }
                   1821:        else
                   1822:        { // Sockets non connectées
                   1823: 
                   1824:            /*
                   1825:             * Vérification de l'adresse distante
                   1826:             */
                   1827: 
                   1828:            if (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
                   1829:                    .adresse_distante, "") == 0)
                   1830:            {
                   1831:                liberation(s_etat_processus, s_objet_argument_1);
                   1832:                liberation(s_etat_processus, s_objet_argument_2);
                   1833: 
                   1834:                (*s_etat_processus).erreur_execution =
                   1835:                        d_ex_erreur_acces_fichier;
                   1836:                return;
                   1837:            }
                   1838: 
                   1839:            /*
                   1840:             * Création de l'adresse logique
                   1841:             */
                   1842: 
                   1843:            if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1844:                    .domaine == PF_UNIX)
                   1845:            {
                   1846:                adresse_unix.sun_family = AF_UNIX;
                   1847:                strncpy(adresse_unix.sun_path, (*((struct_socket *)
                   1848:                        (*s_objet_argument_1).objet)).adresse_distante,
                   1849:                        UNIX_PATH_MAX);
                   1850:                adresse_unix.sun_path[UNIX_PATH_MAX - 1] =
                   1851:                        d_code_fin_chaine;
                   1852: 
1.51      bertrand 1853: #              ifndef SEMAPHORES_NOMMES
                   1854:                    if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1855: #              else
                   1856:                    if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1857: #              endif
1.33      bertrand 1858:                {
                   1859:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1860:                    return;
                   1861:                }
                   1862: 
                   1863:                if (sendto((*((struct_socket *)
                   1864:                        (*s_objet_argument_1).objet)).socket, chaine,
1.79      bertrand 1865:                        (size_t) longueur_effective, 0, (struct sockaddr *)
1.33      bertrand 1866:                        &adresse_unix, sizeof(adresse_unix)) < 0)
                   1867:                {
1.38      bertrand 1868:                    ios = errno;
                   1869: 
1.51      bertrand 1870: #                  ifndef SEMAPHORES_NOMMES
                   1871:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   1872:                                != 0)
                   1873: #                  else
                   1874:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1875: #                  endif
1.1       bertrand 1876:                    {
1.50      bertrand 1877:                        if (errno != EINTR)
                   1878:                        {
                   1879:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1880:                            return;
                   1881:                        }
1.1       bertrand 1882:                    }
                   1883: 
1.34      bertrand 1884:                    if ((ios == EPIPE) || (ios == ECONNRESET))
                   1885:                    {
                   1886:                        (*s_etat_processus).erreur_execution =
                   1887:                                d_ex_erreur_acces_fichier;
                   1888:                        return;
                   1889:                    }
                   1890: 
1.73      bertrand 1891:                    if (ios == EMSGSIZE)
                   1892:                    {
                   1893:                        (*s_etat_processus).erreur_execution =
                   1894:                                d_ex_taille_message;
1.74      bertrand 1895:                        return;
1.73      bertrand 1896:                    }
1.34      bertrand 1897: 
                   1898:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1.1       bertrand 1899:                    return;
                   1900:                }
                   1901: 
1.51      bertrand 1902: #              ifndef SEMAPHORES_NOMMES
                   1903:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   1904: #              else
                   1905:                    while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1906: #              endif
1.1       bertrand 1907:                {
1.50      bertrand 1908:                    if (errno != EINTR)
                   1909:                    {
                   1910:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1911:                        return;
                   1912:                    }
1.1       bertrand 1913:                }
                   1914:            }
1.33      bertrand 1915:            else if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1916:                    .domaine == PF_INET)
                   1917:            {
                   1918:                if (sscanf((*((struct_socket *)
                   1919:                        (*s_objet_argument_1).objet))
                   1920:                        .adresse_distante, "%d.%d.%d.%d(%d)",
                   1921:                        &(adresse[0]), &(adresse[1]), &(adresse[2]),
                   1922:                        &(adresse[3]), &port) == 5)
                   1923:                { // Adresse IPv4
                   1924:                    calcul_adresse = 0;
                   1925:                    for(i = 0; i < 4; calcul_adresse =
1.79      bertrand 1926:                            (256 * calcul_adresse) +
                   1927:                            ((unsigned char) adresse[i++]));
1.33      bertrand 1928: 
                   1929:                    memset(&adresse_ipv4, 0, sizeof(adresse_ipv4));
                   1930:                    adresse_ipv4.sin_family = AF_INET;
1.81      bertrand 1931:                    adresse_ipv4.sin_port = htons((uint16_t) port);
1.33      bertrand 1932:                    adresse_ipv4.sin_addr.s_addr = htonl(calcul_adresse);
1.1       bertrand 1933: 
1.51      bertrand 1934: #                  ifndef SEMAPHORES_NOMMES
                   1935:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   1936:                                != 0)
                   1937: #                  else
                   1938:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   1939: #                  endif
1.1       bertrand 1940:                    {
                   1941:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1942:                        return;
                   1943:                    }
                   1944: 
                   1945:                    if (sendto((*((struct_socket *)
                   1946:                            (*s_objet_argument_1).objet)).socket, chaine,
1.79      bertrand 1947:                            (size_t) longueur_effective, 0, (struct sockaddr *)
1.33      bertrand 1948:                            &adresse_ipv4, sizeof(adresse_ipv4)) < 0)
1.1       bertrand 1949:                    {
1.74      bertrand 1950:                        ios = errno;
                   1951: 
1.51      bertrand 1952: #                      ifndef SEMAPHORES_NOMMES
                   1953:                            while(sem_wait(&((*s_etat_processus)
                   1954:                                    .semaphore_fork)) != 0)
                   1955: #                      else
                   1956:                            while(sem_wait((*s_etat_processus)
                   1957:                                    .semaphore_fork) != 0)
                   1958: #                      endif
1.1       bertrand 1959:                        {
1.50      bertrand 1960:                            if (errno != EINTR)
                   1961:                            {
                   1962:                                (*s_etat_processus).erreur_systeme =
                   1963:                                        d_es_processus;
                   1964:                                return;
                   1965:                            }
1.1       bertrand 1966:                        }
                   1967: 
1.74      bertrand 1968:                        if ((ios == EPIPE) || (ios == ECONNRESET))
                   1969:                        {
                   1970:                            (*s_etat_processus).erreur_execution =
                   1971:                                    d_ex_erreur_acces_fichier;
                   1972:                            return;
                   1973:                        }
                   1974: 
                   1975:                        if (ios == EMSGSIZE)
                   1976:                        {
                   1977:                            (*s_etat_processus).erreur_execution =
                   1978:                                    d_ex_taille_message;
                   1979:                            return;
                   1980:                        }
                   1981: 
1.1       bertrand 1982:                        (*s_etat_processus).erreur_systeme =
                   1983:                                d_es_erreur_fichier;
                   1984:                        return;
                   1985:                    }
                   1986: 
1.51      bertrand 1987: #                  ifndef SEMAPHORES_NOMMES
                   1988:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   1989:                                != 0)
                   1990: #                  else
                   1991:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   1992: #                  endif
1.1       bertrand 1993:                    {
1.50      bertrand 1994:                        if (errno != EINTR)
                   1995:                        {
                   1996:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1997:                            return;
                   1998:                        }
1.1       bertrand 1999:                    }
                   2000:                }
1.33      bertrand 2001:                else
1.1       bertrand 2002:                {
1.33      bertrand 2003:                    liberation(s_etat_processus, s_objet_argument_1);
                   2004:                    liberation(s_etat_processus, s_objet_argument_2);
1.1       bertrand 2005: 
1.33      bertrand 2006:                    (*s_etat_processus).erreur_execution =
                   2007:                            d_ex_erreur_parametre_fichier;
                   2008:                    return;
                   2009:                }
                   2010:            }
                   2011:            else if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   2012:                    .domaine == PF_INET6)
                   2013:            {
                   2014:                if (sscanf((*((struct_socket *) (*s_objet_argument_1)
                   2015:                        .objet)).adresse_distante, "%X:%X:%X:%X:%X:"
                   2016:                        "%X:%X:%X:%X:%X:%X:%X:%X:%X:%X:%X(%d)",
                   2017:                        &(adresse[0]), &(adresse[1]), &(adresse[2]),
                   2018:                        &(adresse[3]), &(adresse[4]), &(adresse[5]),
                   2019:                        &(adresse[6]), &(adresse[7]), &(adresse[8]),
                   2020:                        &(adresse[9]), &(adresse[10]), &(adresse[11]),
                   2021:                        &(adresse[12]), &(adresse[13]), &(adresse[14]),
                   2022:                        &(adresse[15]), &port)== 17)
                   2023:                { // Adresse IPv6
                   2024: #                  ifdef IPV6
                   2025:                    memset(&adresse_ipv6, 0, sizeof(adresse_ipv6));
                   2026:                    adresse_ipv6.sin6_family = AF_INET6;
                   2027:                    adresse_ipv6.sin6_port = htons((uint16_t) port);
                   2028: 
                   2029:                    for(i = 0; i < 16;
                   2030:                            adresse_ipv6.sin6_addr.s6_addr[i] =
1.79      bertrand 2031:                            (unsigned char) adresse[i], i++);
1.1       bertrand 2032: 
1.51      bertrand 2033: #                  ifndef SEMAPHORES_NOMMES
                   2034:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   2035:                                != 0)
                   2036: #                  else
                   2037:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   2038: #                  endif
1.33      bertrand 2039:                    {
                   2040:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2041:                        return;
                   2042:                    }
1.1       bertrand 2043: 
1.33      bertrand 2044:                    if (sendto((*((struct_socket *)
                   2045:                            (*s_objet_argument_1).objet)).socket, chaine,
1.79      bertrand 2046:                            (size_t) longueur_effective, 0, (struct sockaddr *)
1.33      bertrand 2047:                            &adresse_ipv6, sizeof(adresse_ipv6)) < 0)
                   2048:                    {
1.74      bertrand 2049:                        ios = errno;
                   2050: 
1.51      bertrand 2051: #                      ifndef SEMAPHORES_NOMMES
                   2052:                            while(sem_wait(&((*s_etat_processus)
                   2053:                                    .semaphore_fork)) != 0)
                   2054: #                      else
                   2055:                            while(sem_wait((*s_etat_processus)
                   2056:                                    .semaphore_fork) != 0)
                   2057: #                      endif
1.1       bertrand 2058:                        {
1.50      bertrand 2059:                            if (errno != EINTR)
                   2060:                            {
                   2061:                                (*s_etat_processus).erreur_systeme =
                   2062:                                        d_es_processus;
                   2063:                                return;
                   2064:                            }
1.1       bertrand 2065:                        }
                   2066: 
1.74      bertrand 2067:                        if ((ios == EPIPE) || (ios == ECONNRESET))
                   2068:                        {
                   2069:                            (*s_etat_processus).erreur_execution =
                   2070:                                    d_ex_erreur_acces_fichier;
                   2071:                            return;
                   2072:                        }
                   2073: 
                   2074:                        if (ios == EMSGSIZE)
                   2075:                        {
                   2076:                            (*s_etat_processus).erreur_execution =
                   2077:                                    d_ex_taille_message;
                   2078:                            return;
                   2079:                        }
                   2080: 
1.33      bertrand 2081:                        (*s_etat_processus).erreur_systeme =
                   2082:                                d_es_erreur_fichier;
1.1       bertrand 2083:                        return;
                   2084:                    }
                   2085: 
1.51      bertrand 2086: #                  ifndef SEMAPHORES_NOMMES
                   2087:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   2088:                                != 0)
                   2089: #                  else
                   2090:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   2091: #                  endif
1.33      bertrand 2092:                    {
1.50      bertrand 2093:                        if (errno != EINTR)
                   2094:                        {
                   2095:                            (*s_etat_processus).erreur_systeme =
                   2096:                                    d_es_processus;
                   2097:                            return;
                   2098:                        }
1.33      bertrand 2099:                    }
                   2100: #                  else
                   2101:                    if ((*s_etat_processus).langue == 'F')
                   2102:                    {
                   2103:                        printf("+++Attention : Support du protocole"
                   2104:                                " IPv6 indisponible\n");
1.1       bertrand 2105:                    }
                   2106:                    else
                   2107:                    {
1.33      bertrand 2108:                        printf("+++Warning : IPv6 support "
                   2109:                                "unavailable\n");
1.1       bertrand 2110:                    }
1.33      bertrand 2111: #                  endif
1.1       bertrand 2112:                }
1.33      bertrand 2113:                else
1.1       bertrand 2114:                {
                   2115:                    liberation(s_etat_processus, s_objet_argument_1);
                   2116:                    liberation(s_etat_processus, s_objet_argument_2);
                   2117: 
                   2118:                    (*s_etat_processus).erreur_execution =
                   2119:                            d_ex_erreur_parametre_fichier;
                   2120:                    return;
                   2121:                }
                   2122:            }
1.33      bertrand 2123:            else 
                   2124:            {
                   2125:                liberation(s_etat_processus, s_objet_argument_1);
                   2126:                liberation(s_etat_processus, s_objet_argument_2);
1.1       bertrand 2127: 
1.33      bertrand 2128:                (*s_etat_processus).erreur_execution =
                   2129:                        d_ex_erreur_parametre_fichier;
                   2130:                return;
                   2131:            }
1.1       bertrand 2132:        }
1.33      bertrand 2133: 
                   2134:        free(chaine);
1.1       bertrand 2135:    }
                   2136:    else
                   2137:    {
                   2138:        liberation(s_etat_processus, s_objet_argument_2);
                   2139:        liberation(s_etat_processus, s_objet_argument_1);
                   2140: 
                   2141:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2142:        return;
                   2143:    }
                   2144: 
                   2145:    liberation(s_etat_processus, s_objet_argument_2);
                   2146:    liberation(s_etat_processus, s_objet_argument_1);
                   2147: 
                   2148:    return;
                   2149: }
                   2150: 
                   2151: 
                   2152: /*
                   2153: ================================================================================
                   2154:   Fonction 'wflock'
                   2155: ================================================================================
                   2156:   Entrées : pointeur sur une structure struct_processus
                   2157: --------------------------------------------------------------------------------
                   2158:   Sorties :
                   2159: --------------------------------------------------------------------------------
                   2160:   Effets de bord : néant
                   2161: ================================================================================
                   2162: */
                   2163: 
                   2164: void
                   2165: instruction_wflock(struct_processus *s_etat_processus)
                   2166: {
                   2167:    logical1                    drapeau;
                   2168: 
                   2169:    struct flock                lock;
                   2170: 
                   2171:    struct timespec             attente;
                   2172: 
1.5       bertrand 2173:    struct_descripteur_fichier  *descripteur;
                   2174: 
1.1       bertrand 2175:    struct_objet                *s_objet_argument_1;
                   2176:    struct_objet                *s_objet_argument_2;
                   2177: 
                   2178:    unsigned char               *chaine;
                   2179:    unsigned char               registre_instruction_valide;
                   2180: 
                   2181:    attente.tv_sec = 0;
                   2182:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2183: 
                   2184:    (*s_etat_processus).erreur_execution = d_ex;
                   2185: 
                   2186:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2187:    {
                   2188:        printf("\n  WFLOCK ");
                   2189:        
                   2190:        if ((*s_etat_processus).langue == 'F')
                   2191:        {
                   2192:            printf("(attente du positionnement d'un verrou sur un fichier)"
                   2193:                    "\n\n");
                   2194:        }
                   2195:        else
                   2196:        {
                   2197:            printf("(wait for file lock)\n\n");
                   2198:        }
                   2199: 
                   2200:        printf("    2: %s\n", d_FCH);
                   2201:        printf("    1: %s (READ/WRITE/NONE)\n", d_CHN);
                   2202: 
                   2203:        return;
                   2204:    }
                   2205:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2206:    {
                   2207:        (*s_etat_processus).nombre_arguments = -1;
                   2208:        return;
                   2209:    }
                   2210: 
                   2211:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2212:    {
                   2213:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                   2214:        {
                   2215:            return;
                   2216:        }
                   2217:    }
                   2218: 
                   2219:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2220:            &s_objet_argument_1) == d_erreur)
                   2221:    {
                   2222:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2223:        return;
                   2224:    }
                   2225: 
                   2226:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2227:            &s_objet_argument_2) == d_erreur)
                   2228:    {
                   2229:        liberation(s_etat_processus, s_objet_argument_1);
                   2230: 
                   2231:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2232:        return;
                   2233:    }
                   2234: 
                   2235:    if (((*s_objet_argument_2).type == FCH) &&
                   2236:            ((*s_objet_argument_1).type == CHN))
                   2237:    {
                   2238:        drapeau = d_faux;
                   2239: 
                   2240:        do
                   2241:        {
1.94      bertrand 2242:            if ((chaine = conversion_majuscule(s_etat_processus,
                   2243:                    (unsigned char *) (*s_objet_argument_1).objet)) == NULL)
1.1       bertrand 2244:            {
                   2245:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2246:                return;
                   2247:            }
                   2248: 
                   2249:            if (strcmp(chaine, "WRITE") == 0)
                   2250:            {
                   2251:                lock.l_type = F_WRLCK;
                   2252:            }
                   2253:            else if (strcmp(chaine, "READ") == 0)
                   2254:            {
                   2255:                lock.l_type = F_RDLCK;
                   2256:            }
                   2257:            else if (strcmp(chaine, "NONE") == 0)
                   2258:            {
                   2259:                lock.l_type = F_UNLCK;
                   2260:            }
                   2261:            else
                   2262:            {
                   2263:                free(chaine);
                   2264: 
                   2265:                liberation(s_etat_processus, s_objet_argument_1);
                   2266:                liberation(s_etat_processus, s_objet_argument_2);
                   2267: 
                   2268:                (*s_etat_processus).erreur_execution = d_ex_verrou_indefini;
                   2269:                return;
                   2270:            }
                   2271: 
                   2272:            free(chaine);
                   2273: 
                   2274:            lock.l_whence = SEEK_SET;
                   2275:            lock.l_start = 0;
                   2276:            lock.l_len = 0;
                   2277:            lock.l_pid = getpid();
                   2278: 
                   2279:            if ((descripteur = descripteur_fichier(s_etat_processus,
                   2280:                    (struct_fichier *) (*s_objet_argument_2).objet)) == NULL)
                   2281:            {
                   2282:                return;
                   2283:            }
                   2284: 
1.5       bertrand 2285:            if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
                   2286:                    == -1)
1.1       bertrand 2287:            {
                   2288:                liberation(s_etat_processus, s_objet_argument_1);
                   2289:                liberation(s_etat_processus, s_objet_argument_2);
                   2290: 
                   2291:                (*s_etat_processus).erreur_execution = d_ex_fichier_verrouille;
                   2292:                return;
                   2293:            }
                   2294: 
1.51      bertrand 2295: #          ifndef SEMAPHORES_NOMMES
                   2296:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2297: #          else
                   2298:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   2299: #          endif
1.1       bertrand 2300:            {
                   2301:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   2302:                return;
                   2303:            }
1.47      bertrand 2304: 
1.51      bertrand 2305: #          ifndef SEMAPHORES_NOMMES
                   2306:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   2307: #          else
                   2308:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   2309: #          endif
1.12      bertrand 2310:            {
1.50      bertrand 2311:                if (errno != EINTR)
                   2312:                {
                   2313:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2314:                    return;
                   2315:                }
1.12      bertrand 2316:            }
1.1       bertrand 2317: 
                   2318:            if (lock.l_type == F_UNLCK)
                   2319:            {
                   2320:                drapeau = d_vrai;
                   2321:            }
                   2322:            else
                   2323:            {
1.84      bertrand 2324:                if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions)
                   2325:                        != 0)
1.83      bertrand 2326:                {
                   2327:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2328:                    return;
                   2329:                }
                   2330: 
1.1       bertrand 2331:                if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   2332:                {
                   2333:                    affectation_interruptions_logicielles(s_etat_processus);
                   2334:                }
                   2335: 
1.84      bertrand 2336:                if (pthread_mutex_unlock(&(*s_etat_processus)
                   2337:                        .mutex_interruptions) != 0)
1.83      bertrand 2338:                {
                   2339:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2340:                    return;
                   2341:                }
                   2342: 
                   2343:                if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
1.1       bertrand 2344:                {
                   2345:                    registre_instruction_valide =
                   2346:                            (*s_etat_processus).instruction_valide;
                   2347:                    traitement_interruptions_logicielles(
                   2348:                            s_etat_processus);
                   2349:                    (*s_etat_processus).instruction_valide =
                   2350:                            registre_instruction_valide;
                   2351:                }
                   2352: 
                   2353:                nanosleep(&attente, NULL);
                   2354:                scrutation_injection(s_etat_processus);
                   2355: 
                   2356:                INCR_GRANULARITE(attente.tv_nsec);
                   2357:            }
                   2358:        } while((drapeau == d_faux) && ((*s_etat_processus)
                   2359:                .var_volatile_requete_arret != -1));
                   2360:    }
                   2361:    else
                   2362:    {
                   2363:        liberation(s_etat_processus, s_objet_argument_1);
                   2364:        liberation(s_etat_processus, s_objet_argument_2);
                   2365: 
                   2366:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2367:        return;
                   2368:    }
                   2369: 
                   2370:    return;
                   2371: }
                   2372: 
                   2373: 
                   2374: /*
                   2375: ================================================================================
                   2376:   Fonction 'wfproc'
                   2377: ================================================================================
                   2378:   Entrées : pointeur sur une structure struct_processus
                   2379: --------------------------------------------------------------------------------
                   2380:   Sorties :
                   2381: --------------------------------------------------------------------------------
                   2382:   Effets de bord : néant
                   2383: ================================================================================
                   2384: */
                   2385: 
                   2386: void
                   2387: instruction_wfproc(struct_processus *s_etat_processus)
                   2388: {
                   2389:    logical1                    drapeau_fin;
                   2390: 
                   2391:    struct_liste_chainee        *l_element_courant;
                   2392: 
                   2393:    struct_objet                *s_objet_argument;
                   2394: 
                   2395:    struct timespec             attente;
                   2396: 
                   2397:    unsigned char               registre_instruction_valide;
                   2398: 
                   2399:    (*s_etat_processus).erreur_execution = d_ex;
                   2400: 
                   2401:    attente.tv_sec = 0;
                   2402:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2403: 
                   2404:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2405:    {
                   2406:        printf("\n  WFPROC ");
                   2407: 
                   2408:        if ((*s_etat_processus).langue == 'F')
                   2409:        {
                   2410:            printf("(attente de la fin d'un processus fils)\n\n");
                   2411:        }
                   2412:        else
                   2413:        {
                   2414:            printf("(wait for child process end)\n\n");
                   2415:        }
                   2416: 
                   2417:        printf("    1: %s\n", d_PRC);
                   2418: 
                   2419:        return;
                   2420:    }
                   2421:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2422:    {
                   2423:        (*s_etat_processus).nombre_arguments = -1;
                   2424:        return;
                   2425:    }
                   2426: 
                   2427:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2428:    {
                   2429:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2430:        {
                   2431:            return;
                   2432:        }
                   2433:    }
                   2434: 
                   2435:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2436:            &s_objet_argument) == d_erreur)
                   2437:    {
                   2438:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2439:        return;
                   2440:    }
                   2441: 
                   2442:    if ((*s_objet_argument).type == PRC)
                   2443:    {
                   2444:        drapeau_fin = d_faux;
                   2445: 
                   2446:        if ((*s_etat_processus).profilage == d_vrai)
                   2447:        {
                   2448:            profilage(s_etat_processus, "Interprocess or interthread "
                   2449:                    "communications (WFPROC)");
                   2450: 
                   2451:            if ((*s_etat_processus).erreur_systeme != d_es)
                   2452:            {
                   2453:                return;
                   2454:            }
                   2455:        }
                   2456: 
1.85      bertrand 2457:        if (pthread_mutex_lock(&((*s_etat_processus).mutex_pile_processus))
                   2458:                != 0)
1.1       bertrand 2459:        {
                   2460:            if ((*s_etat_processus).profilage == d_vrai)
                   2461:            {
                   2462:                profilage(s_etat_processus, NULL);
                   2463:            }
                   2464: 
                   2465:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2466:            return;
                   2467:        }
                   2468: 
                   2469:        while(drapeau_fin == d_faux)
                   2470:        {
                   2471:            l_element_courant = (struct_liste_chainee *)
                   2472:                    (*s_etat_processus).l_base_pile_processus;
                   2473: 
                   2474:            while(l_element_courant != NULL)
                   2475:            {
                   2476:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2477:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   2478:                {
                   2479:                    if ((*(*((struct_processus_fils *)
                   2480:                            (*s_objet_argument).objet)).thread)
                   2481:                            .processus_detache == d_vrai)
                   2482:                    {
                   2483:                        if ((*(*((struct_processus_fils *)
                   2484:                                (*(*l_element_courant)
                   2485:                                .donnee).objet)).thread).pid ==
                   2486:                                (*(*((struct_processus_fils *)
                   2487:                                (*s_objet_argument).objet)).thread).pid)
                   2488:                        {
                   2489:                            break;
                   2490:                        }
                   2491:                    }
                   2492:                }
                   2493:                else
                   2494:                {
                   2495:                    if ((*(*((struct_processus_fils *)
                   2496:                            (*s_objet_argument).objet)).thread)
                   2497:                            .processus_detache == d_faux)
                   2498:                    {
                   2499:                        if ((pthread_equal((*(*((struct_processus_fils *)
                   2500:                                (*(*l_element_courant).donnee).objet)).thread)
                   2501:                                .tid, (*(*((struct_processus_fils *)
                   2502:                                (*s_objet_argument).objet)).thread).tid) != 0)
                   2503:                                && ((*(*((struct_processus_fils *)
                   2504:                                (*(*l_element_courant).donnee).objet)).thread)
                   2505:                                .pid == (*(*((struct_processus_fils *)
                   2506:                                (*s_objet_argument).objet)).thread).pid))
                   2507:                        {
                   2508:                            break;
                   2509:                        }
                   2510:                    }
                   2511:                }
                   2512: 
                   2513:                l_element_courant = (*l_element_courant).suivant;
                   2514:            }
                   2515: 
                   2516:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2517:            {
                   2518:                if ((*s_etat_processus).profilage == d_vrai)
                   2519:                {
                   2520:                    profilage(s_etat_processus, NULL);
                   2521:                }
                   2522: 
1.85      bertrand 2523:                if (pthread_mutex_unlock(&((*s_etat_processus)
                   2524:                        .mutex_pile_processus)) != 0)
1.1       bertrand 2525:                {
                   2526:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2527:                    return;
                   2528:                }
                   2529: 
                   2530:                liberation(s_etat_processus, s_objet_argument);
                   2531:                return;
                   2532:            }
                   2533: 
                   2534:            if (l_element_courant == NULL)
                   2535:            {
                   2536:                /*
                   2537:                 * Si l_element_courant vaut NULL, le processus n'existe plus.
                   2538:                 */
                   2539: 
                   2540:                drapeau_fin = d_vrai;
                   2541:            }
                   2542:            else
                   2543:            {
                   2544:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2545:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   2546:                {
1.48      bertrand 2547:                    if (envoi_signal_processus((*(*((struct_processus_fils *)
1.1       bertrand 2548:                            (*(*l_element_courant).donnee).objet)).thread).pid,
1.104     bertrand 2549:                            rpl_signull, d_faux) != 0)
1.1       bertrand 2550:                    {
                   2551:                        drapeau_fin = d_vrai;
                   2552:                    }
                   2553:                    else
                   2554:                    {
                   2555:                        drapeau_fin = d_faux;
                   2556:                    }
                   2557:                }
                   2558:                else
                   2559:                {
                   2560:                    if (pthread_mutex_lock(&((*(*((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:                    if ((*(*((struct_processus_fils *)
                   2574:                            (*(*l_element_courant).donnee).objet)).thread)
                   2575:                            .thread_actif == d_faux)
                   2576:                    {
                   2577:                        drapeau_fin = d_vrai;
                   2578:                    }
                   2579:                    else
                   2580:                    {
                   2581:                        drapeau_fin = d_faux;
                   2582:                    }
                   2583: 
                   2584:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   2585:                            (*(*l_element_courant).donnee).objet)).thread)
                   2586:                            .mutex)) != 0)
                   2587:                    {
                   2588:                        if ((*s_etat_processus).profilage == d_vrai)
                   2589:                        {
                   2590:                            profilage(s_etat_processus, NULL);
                   2591:                        }
                   2592: 
                   2593:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2594:                        return;
                   2595:                    }
                   2596:                }
                   2597: 
                   2598:                if (drapeau_fin == d_faux)
                   2599:                {
                   2600:                    /*
                   2601:                     * Le processus n'est pas terminé
                   2602:                     */
                   2603: 
1.84      bertrand 2604:                    if (pthread_mutex_lock(&((*s_etat_processus)
                   2605:                            .mutex_interruptions)) != 0)
                   2606:                    {
1.85      bertrand 2607:                        pthread_mutex_unlock(&((*s_etat_processus)
                   2608:                                .mutex_pile_processus));
1.84      bertrand 2609: 
                   2610:                        if ((*s_etat_processus).profilage == d_vrai)
                   2611:                        {
                   2612:                            profilage(s_etat_processus, NULL);
                   2613:                        }
                   2614: 
                   2615:                        (*s_etat_processus).erreur_systeme =
                   2616:                                d_es_processus;
                   2617:                        return;
                   2618:                    }
                   2619: 
1.83      bertrand 2620:                    if ((*s_etat_processus).nombre_interruptions_non_affectees
                   2621:                            != 0)
                   2622:                    {
                   2623:                        affectation_interruptions_logicielles(s_etat_processus);
                   2624:                    }
                   2625: 
1.84      bertrand 2626:                    if (pthread_mutex_unlock(&((*s_etat_processus)
                   2627:                            .mutex_interruptions)) != 0)
                   2628:                    {
1.85      bertrand 2629:                        pthread_mutex_unlock(&((*s_etat_processus)
                   2630:                                .mutex_pile_processus));
1.84      bertrand 2631: 
                   2632:                        if ((*s_etat_processus).profilage == d_vrai)
                   2633:                        {
                   2634:                            profilage(s_etat_processus, NULL);
                   2635:                        }
                   2636: 
                   2637:                        (*s_etat_processus).erreur_systeme =
                   2638:                                d_es_processus;
                   2639:                        return;
                   2640:                    }
                   2641: 
1.85      bertrand 2642:                    if (pthread_mutex_unlock(&((*s_etat_processus)
                   2643:                            .mutex_pile_processus)) != 0)
1.1       bertrand 2644:                    {
                   2645:                        if ((*s_etat_processus).profilage == d_vrai)
                   2646:                        {
                   2647:                            profilage(s_etat_processus, NULL);
                   2648:                        }
                   2649: 
                   2650:                        (*s_etat_processus).erreur_systeme =
                   2651:                                d_es_processus;
                   2652:                        return;
                   2653:                    }
                   2654: 
1.83      bertrand 2655:                    if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
1.1       bertrand 2656:                    {
                   2657:                        registre_instruction_valide =
                   2658:                                (*s_etat_processus).instruction_valide;
                   2659:                        traitement_interruptions_logicielles(
                   2660:                                s_etat_processus);
                   2661:                        (*s_etat_processus).instruction_valide =
                   2662:                                registre_instruction_valide;
                   2663:                    }
                   2664: 
1.51      bertrand 2665: #                  ifndef SEMAPHORES_NOMMES
                   2666:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   2667:                                != 0)
                   2668: #                  else
                   2669:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   2670: #                  endif
1.1       bertrand 2671:                    {
                   2672:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2673:                        return;
                   2674:                    }
                   2675: 
                   2676:                    nanosleep(&attente, NULL);
                   2677: 
1.51      bertrand 2678: #                  ifndef SEMAPHORES_NOMMES
                   2679:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   2680:                                != 0)
                   2681: #                  else
                   2682:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   2683: #                  endif
1.1       bertrand 2684:                    {
1.50      bertrand 2685:                        if (errno != EINTR)
                   2686:                        {
                   2687:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2688:                            return;
                   2689:                        }
1.1       bertrand 2690:                    }
                   2691: 
                   2692:                    scrutation_injection(s_etat_processus);
                   2693: 
1.85      bertrand 2694:                    if (pthread_mutex_lock(&((*s_etat_processus)
                   2695:                            .mutex_pile_processus)) != 0)
1.1       bertrand 2696:                    {
                   2697:                        if ((*s_etat_processus).profilage == d_vrai)
                   2698:                        {
                   2699:                            profilage(s_etat_processus, NULL);
                   2700:                        }
                   2701: 
                   2702:                        (*s_etat_processus).erreur_systeme =
                   2703:                                d_es_processus;
                   2704:                        return;
                   2705:                    }
                   2706:                }
                   2707:            }
                   2708: 
                   2709:            INCR_GRANULARITE(attente.tv_nsec);
                   2710:        }
                   2711: 
                   2712:        if ((*s_etat_processus).profilage == d_vrai)
                   2713:        {
                   2714:            profilage(s_etat_processus, NULL);
                   2715:        }
                   2716: 
1.85      bertrand 2717:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex_pile_processus))
                   2718:                != 0)
1.1       bertrand 2719:        {
                   2720:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2721:            return;
                   2722:        }
                   2723:    }
                   2724:    else
                   2725:    {
                   2726:        liberation(s_etat_processus, s_objet_argument);
                   2727: 
                   2728:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2729:        return;
                   2730:    }
                   2731: 
                   2732:    liberation(s_etat_processus, s_objet_argument);
                   2733: 
                   2734:    return;
                   2735: }
                   2736: 
                   2737: 
                   2738: /*
                   2739: ================================================================================
                   2740:   Fonction 'wfdata'
                   2741: ================================================================================
                   2742:   Entrées : pointeur sur une structure struct_processus
                   2743: --------------------------------------------------------------------------------
                   2744:   Sorties :
                   2745: --------------------------------------------------------------------------------
                   2746:   Effets de bord : néant
                   2747: ================================================================================
                   2748: */
                   2749: 
                   2750: void
                   2751: instruction_wfdata(struct_processus *s_etat_processus)
                   2752: {
                   2753:    logical1                    drapeau_fin;
                   2754: 
                   2755:    struct_liste_chainee        *l_element_courant;
                   2756: 
                   2757:    struct_objet                *s_objet_argument;
                   2758: 
                   2759:    struct timespec             attente;
                   2760: 
                   2761:    unsigned char               registre_instruction_valide;
                   2762: 
                   2763:    (*s_etat_processus).erreur_execution = d_ex;
                   2764: 
                   2765:    attente.tv_sec = 0;
                   2766:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2767: 
                   2768:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2769:    {
                   2770:        printf("\n  WFDATA ");
                   2771: 
                   2772:        if ((*s_etat_processus).langue == 'F')
                   2773:        {
                   2774:            printf("(attente de données d'un processus fils)\n\n");
                   2775:        }
                   2776:        else
                   2777:        {
                   2778:            printf("(wait for data from child process)\n\n");
                   2779:        }
                   2780: 
                   2781:        printf("    1: %s\n", d_PRC);
                   2782: 
                   2783:        return;
                   2784:    }
                   2785:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2786:    {
                   2787:        (*s_etat_processus).nombre_arguments = -1;
                   2788:        return;
                   2789:    }
                   2790: 
                   2791:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2792:    {
                   2793:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2794:        {
                   2795:            return;
                   2796:        }
                   2797:    }
                   2798: 
                   2799:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2800:            &s_objet_argument) == d_erreur)
                   2801:    {
                   2802:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2803:        return;
                   2804:    }
                   2805: 
                   2806:    if ((*s_objet_argument).type == PRC)
                   2807:    {
                   2808:        drapeau_fin = d_faux;
                   2809: 
                   2810:        if ((*s_etat_processus).profilage == d_vrai)
                   2811:        {
                   2812:            profilage(s_etat_processus, "Interprocess or interthread "
                   2813:                    "communications (WFDATA)");
                   2814: 
                   2815:            if ((*s_etat_processus).erreur_systeme != d_es)
                   2816:            {
                   2817:                return;
                   2818:            }
                   2819:        }
                   2820: 
1.85      bertrand 2821:        if (pthread_mutex_lock(&((*s_etat_processus).mutex_pile_processus))
                   2822:                != 0)
1.1       bertrand 2823:        {
                   2824:            if ((*s_etat_processus).profilage == d_vrai)
                   2825:            {
                   2826:                profilage(s_etat_processus, NULL);
                   2827:            }
                   2828: 
                   2829:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2830:            return;
                   2831:        }
                   2832: 
                   2833:        while(drapeau_fin == d_faux)
                   2834:        {
                   2835:            l_element_courant = (struct_liste_chainee *)
                   2836:                    (*s_etat_processus).l_base_pile_processus;
                   2837: 
                   2838:            while(l_element_courant != NULL)
                   2839:            {
                   2840:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2841:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   2842:                {
                   2843:                    if (((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2844:                            .donnee).objet)).thread).pid ==
                   2845:                            (*(*((struct_processus_fils *)
                   2846:                            (*s_objet_argument).objet)).thread).pid)
                   2847:                            && ((*(*((struct_processus_fils *)
                   2848:                            (*s_objet_argument).objet)).thread)
                   2849:                            .processus_detache == d_vrai))
                   2850:                    {
                   2851:                        break;
                   2852:                    }
                   2853:                }
                   2854:                else
                   2855:                {
                   2856:                    if ((pthread_equal((*(*((struct_processus_fils *)
                   2857:                            (*(*l_element_courant).donnee).objet)).thread).tid,
                   2858:                            (*(*((struct_processus_fils *) (*s_objet_argument)
                   2859:                            .objet)).thread).tid) != 0) &&
                   2860:                            ((*(*((struct_processus_fils *)
                   2861:                            (*(*l_element_courant).donnee).objet)).thread).pid
                   2862:                            == (*(*((struct_processus_fils *)
                   2863:                            (*s_objet_argument).objet)).thread).pid) &&
                   2864:                            ((*(*((struct_processus_fils *)
                   2865:                            (*s_objet_argument).objet)).thread)
                   2866:                            .processus_detache == d_faux))
                   2867:                    {
                   2868:                        break;
                   2869:                    }
                   2870:                }
                   2871: 
                   2872:                l_element_courant = (*l_element_courant).suivant;
                   2873:            }
                   2874: 
                   2875:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2876:            {
                   2877:                if ((*s_etat_processus).profilage == d_vrai)
                   2878:                {
                   2879:                    profilage(s_etat_processus, NULL);
                   2880:                }
                   2881: 
1.85      bertrand 2882:                if (pthread_mutex_unlock(&((*s_etat_processus)
                   2883:                        .mutex_pile_processus)) != 0)
1.1       bertrand 2884:                {
                   2885:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2886:                    return;
                   2887:                }
                   2888: 
                   2889:                liberation(s_etat_processus, s_objet_argument);
                   2890:                return;
                   2891:            }
                   2892: 
                   2893:            if (l_element_courant != NULL)
                   2894:            {
                   2895:                if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
                   2896:                        (*(*l_element_courant).donnee).objet)).thread).mutex))
                   2897:                        != 0)
                   2898:                {
                   2899:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2900:                    return;
                   2901:                }
                   2902: 
                   2903:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   2904:                        .donnee).objet)).thread).nombre_objets_dans_pipe != 0)
                   2905:                {
                   2906:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   2907:                            (*(*l_element_courant).donnee).objet)).thread)
                   2908:                            .mutex)) != 0)
                   2909:                    {
                   2910:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2911:                        return;
                   2912:                    }
                   2913: 
                   2914:                    drapeau_fin = d_vrai;
                   2915:                }
                   2916:                else
                   2917:                {
                   2918:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   2919:                            (*(*l_element_courant).donnee).objet)).thread)
                   2920:                            .mutex)) != 0)
                   2921:                    {
                   2922:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2923:                        return;
                   2924:                    }
                   2925: 
1.85      bertrand 2926:                    if (pthread_mutex_unlock(&((*s_etat_processus)
                   2927:                            .mutex_pile_processus)) != 0)
1.1       bertrand 2928:                    {
                   2929:                        if ((*s_etat_processus).profilage == d_vrai)
                   2930:                        {
                   2931:                            profilage(s_etat_processus, NULL);
                   2932:                        }
                   2933: 
                   2934:                        (*s_etat_processus).erreur_systeme =
                   2935:                                d_es_processus;
                   2936:                        return;
                   2937:                    }
                   2938: 
1.51      bertrand 2939: #                  ifndef SEMAPHORES_NOMMES
                   2940:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   2941:                                != 0)
                   2942: #                  else
                   2943:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   2944: #                  endif
1.12      bertrand 2945:                    {
                   2946:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2947:                        return;
                   2948:                    }
1.1       bertrand 2949: 
                   2950:                    nanosleep(&attente, NULL);
                   2951: 
1.51      bertrand 2952: #                  ifndef SEMAPHORES_NOMMES
                   2953:                        while(sem_wait(&((*s_etat_processus).semaphore_fork))
                   2954:                                != 0)
                   2955: #                  else
                   2956:                        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   2957: #                  endif
1.1       bertrand 2958:                    {
1.50      bertrand 2959:                        if (errno != EINTR)
                   2960:                        {
                   2961:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2962:                            return;
                   2963:                        }
1.1       bertrand 2964:                    }
                   2965: 
                   2966:                    scrutation_injection(s_etat_processus);
                   2967: 
1.84      bertrand 2968:                    if (pthread_mutex_lock(&(*s_etat_processus)
                   2969:                            .mutex_interruptions) != 0)
1.83      bertrand 2970:                    {
                   2971:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2972:                        return;
                   2973:                    }
                   2974: 
1.1       bertrand 2975:                    if ((*s_etat_processus).nombre_interruptions_non_affectees
                   2976:                            != 0)
                   2977:                    {
                   2978:                        affectation_interruptions_logicielles(s_etat_processus);
                   2979:                    }
                   2980: 
1.84      bertrand 2981:                    if (pthread_mutex_unlock(&(*s_etat_processus)
                   2982:                            .mutex_interruptions) != 0)
1.83      bertrand 2983:                    {
                   2984:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2985:                        return;
                   2986:                    }
                   2987: 
1.1       bertrand 2988:                    if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   2989:                    {
                   2990:                        registre_instruction_valide =
                   2991:                                (*s_etat_processus).instruction_valide;
                   2992:                        traitement_interruptions_logicielles(s_etat_processus);
                   2993:                        (*s_etat_processus).instruction_valide =
                   2994:                                registre_instruction_valide;
                   2995:                    }
                   2996: 
                   2997:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2998:                    {
                   2999:                        if ((*s_etat_processus).profilage == d_vrai)
                   3000:                        {
                   3001:                            profilage(s_etat_processus, NULL);
                   3002:                        }
                   3003: 
                   3004:                        return;
                   3005:                    }
                   3006: 
1.85      bertrand 3007:                    if (pthread_mutex_lock(&((*s_etat_processus)
                   3008:                            .mutex_pile_processus)) != 0)
1.1       bertrand 3009:                    {
                   3010:                        if ((*s_etat_processus).profilage == d_vrai)
                   3011:                        {
                   3012:                            profilage(s_etat_processus, NULL);
                   3013:                        }
                   3014: 
                   3015:                        (*s_etat_processus).erreur_systeme =
                   3016:                                d_es_processus;
                   3017:                        return;
                   3018:                    }
                   3019:                }
                   3020:            }
                   3021:            else
                   3022:            {
                   3023:                drapeau_fin = d_vrai;
                   3024:                (*s_etat_processus).erreur_execution = d_ex_processus;
                   3025:            }
                   3026: 
                   3027:            INCR_GRANULARITE(attente.tv_nsec);
                   3028:        }
                   3029: 
                   3030:        if ((*s_etat_processus).profilage == d_vrai)
                   3031:        {
                   3032:            profilage(s_etat_processus, NULL);
                   3033:        }
                   3034: 
1.85      bertrand 3035:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex_pile_processus))
                   3036:                != 0)
1.1       bertrand 3037:        {
                   3038:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   3039:            return;
                   3040:        }
                   3041:    }
                   3042:    else
                   3043:    {
                   3044:        liberation(s_etat_processus, s_objet_argument);
                   3045: 
                   3046:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   3047:        return;
                   3048:    }
                   3049: 
                   3050:    liberation(s_etat_processus, s_objet_argument);
                   3051: 
                   3052:    return;
                   3053: }
                   3054: 
                   3055: 
                   3056: /*
                   3057: ================================================================================
                   3058:   Fonction 'wfsock'
                   3059: ================================================================================
                   3060:   Entrées : pointeur sur une structure struct_processus
                   3061: --------------------------------------------------------------------------------
                   3062:   Sorties :
                   3063: --------------------------------------------------------------------------------
                   3064:   Effets de bord : néant
                   3065: ================================================================================
                   3066: */
                   3067: 
1.98      bertrand 3068: static inline logical1
                   3069: options_sockets(struct_processus *s_etat_processus, struct_socket *s_socket)
                   3070: {
                   3071:    int                         drapeau;
                   3072: 
                   3073:    if (((*s_socket).options & (1 << d_BROADCAST)) != 0)
                   3074:    {
                   3075:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_BROADCAST, &drapeau,
                   3076:                sizeof(drapeau)) != 0)
                   3077:        {
                   3078:            return(d_erreur);
                   3079:        }
                   3080:    }
                   3081: 
                   3082:    if (((*s_socket).options & (1 << d_DONT_ROUTE)) != 0)
                   3083:    {
                   3084:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_DONTROUTE, &drapeau,
                   3085:                sizeof(drapeau)) != 0)
                   3086:        {
                   3087:            return(d_erreur);
                   3088:        }
                   3089:    }
                   3090: 
                   3091:    if (((*s_socket).options & (1 << d_KEEP_ALIVE)) != 0)
                   3092:    {
                   3093:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_KEEPALIVE, &drapeau,
                   3094:                sizeof(drapeau)) != 0)
                   3095:        {
                   3096:            return(d_erreur);
                   3097:        }
                   3098:    }
                   3099: 
1.101     bertrand 3100: #  ifdef SO_PRIORITY
1.98      bertrand 3101:    if (((*s_socket).options & (1 << d_PRIORITY)) != 0)
                   3102:    {
                   3103:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_PRIORITY,
                   3104:                &((*s_socket).priorite), sizeof((*s_socket).priorite)) != 0)
                   3105:        {
                   3106:            return(d_erreur);
                   3107:        }
                   3108:    }
1.101     bertrand 3109: #  endif
1.98      bertrand 3110: 
                   3111:    // Les deux options suivantes ne peuvent être positionnées simultanément.
                   3112: 
                   3113:    if (((*s_socket).options & (1 << d_RECEIVE_BUFFER)) != 0)
                   3114:    {
                   3115:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVBUF,
                   3116:                &((*s_socket).buffer_reception),
                   3117:                sizeof((*s_socket).buffer_reception)) != 0)
                   3118:        {
                   3119:            return(d_erreur);
                   3120:        }
                   3121:    }
                   3122: 
1.101     bertrand 3123: #  ifdef SO_RCVBUFFORCE
1.98      bertrand 3124:    if (((*s_socket).options & (1 << d_FORCE_RECEIVE_BUFFER)) != 0)
                   3125:    {
                   3126:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVBUFFORCE,
                   3127:                &((*s_socket).buffer_reception),
                   3128:                sizeof((*s_socket).buffer_reception)) != 0)
                   3129:        {
                   3130:            return(d_erreur);
                   3131:        }
                   3132:    }
1.101     bertrand 3133: #  endif
1.98      bertrand 3134: 
                   3135:    // Même remarque
                   3136: 
                   3137:    if (((*s_socket).options & (1 << d_SEND_BUFFER)) != 0)
                   3138:    {
                   3139:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDBUF,
                   3140:                &((*s_socket).buffer_emission),
                   3141:                sizeof((*s_socket).buffer_emission)) != 0)
                   3142:        {
                   3143:            return(d_erreur);
                   3144:        }
                   3145:    }
                   3146: 
1.101     bertrand 3147: #  ifdef SO_SNDBUFFORCE
1.98      bertrand 3148:    if (((*s_socket).options & (1 << d_FORCE_SEND_BUFFER)) != 0)
                   3149:    {
                   3150:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDBUFFORCE,
                   3151:                &((*s_socket).buffer_emission),
                   3152:                sizeof((*s_socket).buffer_emission)) != 0)
                   3153:        {
                   3154:            return(d_erreur);
                   3155:        }
                   3156:    }
1.101     bertrand 3157: #  endif
1.98      bertrand 3158: 
                   3159:    if (((*s_socket).options & (1 << d_RECEIVING_TIMEOUT)) != 0)
                   3160:    {
                   3161:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVTIMEO,
                   3162:                &((*s_socket).timeout_emission),
                   3163:                sizeof((*s_socket).timeout_emission)) != 0)
                   3164:        {
                   3165:            return(d_erreur);
                   3166:        }
                   3167:    }
                   3168: 
                   3169:    if (((*s_socket).options & (1 << d_SENDING_TIMEOUT)) != 0)
                   3170:    {
                   3171:        if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDTIMEO,
                   3172:                &((*s_socket).timeout_emission),
                   3173:                sizeof((*s_socket).timeout_emission)) != 0)
                   3174:        {
                   3175:            return(d_erreur);
                   3176:        }
                   3177:    }
                   3178: 
                   3179:    return(d_absence_erreur);;
                   3180: }
                   3181: 
                   3182: 
1.1       bertrand 3183: void
                   3184: instruction_wfsock(struct_processus *s_etat_processus)
                   3185: {
                   3186:    int                     erreur;
                   3187: 
                   3188:    logical1                drapeau;
                   3189: 
                   3190:    socklen_t               longueur;
                   3191: 
                   3192:    struct_liste_chainee    *l_element_courant;
                   3193: 
                   3194:    struct_objet            *s_objet_argument;
                   3195:    struct_objet            *s_objet_resultat;
                   3196: 
1.54      bertrand 3197:    struct pollfd           s_poll;
                   3198: 
1.1       bertrand 3199:    struct sockaddr_in      adresse_ipv4;
1.20      bertrand 3200: #  ifdef IPV6
1.1       bertrand 3201:    struct sockaddr_in6     adresse_ipv6;
1.20      bertrand 3202: #  endif
1.1       bertrand 3203: 
                   3204:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   3205:    {
                   3206:        printf("\n  WFSOCK ");
                   3207: 
                   3208:        if ((*s_etat_processus).langue == 'F')
                   3209:        {
                   3210:            printf("(attente d'une connexion sur une socket)\n\n");
                   3211:        }
                   3212:        else
                   3213:        {
                   3214:            printf("(wait for connection on a socket)\n\n");
                   3215:        }
                   3216: 
                   3217:        printf("    1: %s\n", d_SCK);
                   3218:        printf("->  2: %s\n", d_SCK);
                   3219:        printf("    1: %s\n", d_SCK);
                   3220: 
                   3221:        return;
                   3222:    }
                   3223:    else if ((*s_etat_processus).test_instruction == 'Y')
                   3224:    {
                   3225:        (*s_etat_processus).nombre_arguments = -1;
                   3226:        return;
                   3227:    }
                   3228: 
                   3229:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   3230:    {
                   3231:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   3232:        {
                   3233:            return;
                   3234:        }
                   3235:    }
                   3236: 
                   3237:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3238:            &s_objet_argument) == d_erreur)
                   3239:    {
                   3240:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   3241:        return;
                   3242:    }
                   3243: 
                   3244:    if ((*s_objet_argument).type == SCK)
                   3245:    {
                   3246:        if ((strcmp((*((struct_socket *) (*s_objet_argument).objet)).type,
                   3247:                "STREAM") != 0) && (strcmp((*((struct_socket *)
                   3248:                (*s_objet_argument).objet)).type, "SEQUENTIAL DATAGRAM") != 0))
                   3249:        {
1.54      bertrand 3250:            // Mode non connecté : l'attente se fait sur un poll()
                   3251: 
                   3252:            if ((s_objet_resultat = copie_objet(s_etat_processus,
                   3253:                    s_objet_argument, 'P')) == NULL)
                   3254:            {
                   3255:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3256:                return;
                   3257:            }
                   3258: 
                   3259:            s_poll.fd = (*((struct_socket *) (*s_objet_argument).objet)).socket;
                   3260:            s_poll.events = POLLIN;
                   3261:            s_poll.revents = 0;
                   3262: 
1.55      bertrand 3263:            do
1.54      bertrand 3264:            {
1.55      bertrand 3265:                drapeau = d_vrai;
                   3266: 
                   3267: #              ifndef SEMAPHORES_NOMMES
                   3268:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   3269: #              else
                   3270:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   3271: #              endif
                   3272:                {
                   3273:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   3274:                    return;
                   3275:                }
                   3276: 
                   3277:                if (poll(&s_poll, 1, -1) < 0)
                   3278:                {
                   3279:                    erreur = errno;
                   3280: 
                   3281: #                  ifndef SEMAPHORES_NOMMES
                   3282:                    while(sem_wait(&((*s_etat_processus)
                   3283:                            .semaphore_fork)) != 0)
                   3284: #                  else
                   3285:                    while(sem_wait((*s_etat_processus).semaphore_fork)
                   3286:                            != 0)
                   3287: #                  endif
                   3288: 
                   3289:                    if (erreur != EINTR)
                   3290:                    {
                   3291:                        liberation(s_etat_processus, s_objet_argument);
                   3292:                        liberation(s_etat_processus, s_objet_resultat);
                   3293: 
                   3294:                        (*s_etat_processus).erreur_execution =
                   3295:                                d_ex_erreur_acces_fichier;
                   3296:                        return;
                   3297:                    }
                   3298: 
                   3299:                    scrutation_injection(s_etat_processus);
                   3300: 
                   3301:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3302:                    {
                   3303:                        drapeau = d_vrai;
                   3304:                    }
                   3305:                    else
                   3306:                    {
                   3307:                        drapeau = d_faux;
                   3308:                    }
                   3309:                }
                   3310:                else
1.54      bertrand 3311:                {
1.55      bertrand 3312: #                  ifndef SEMAPHORES_NOMMES
                   3313:                        while(sem_wait(&((*s_etat_processus)
                   3314:                                .semaphore_fork)) != 0)
                   3315: #                  else
                   3316:                        while(sem_wait((*s_etat_processus).semaphore_fork)
                   3317:                                != 0)
                   3318: #                  endif
                   3319:                    {
                   3320:                        if (errno != EINTR)
                   3321:                        {
                   3322:                            (*s_etat_processus).erreur_systeme =
                   3323:                                    d_es_processus;
                   3324:                            return;
                   3325:                        }
                   3326:                    }
1.54      bertrand 3327:                }
1.55      bertrand 3328:            } while(drapeau == d_faux);
1.54      bertrand 3329: 
                   3330:            if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3331:                    s_objet_argument) == d_erreur)
                   3332:            {
                   3333:                return;
                   3334:            }
1.1       bertrand 3335: 
1.54      bertrand 3336:            if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3337:                    s_objet_resultat) == d_erreur)
                   3338:            {
                   3339:                return;
                   3340:            }
1.1       bertrand 3341:        }
1.54      bertrand 3342:        else
1.1       bertrand 3343:        {
1.54      bertrand 3344:            // Mode connecté
1.1       bertrand 3345: 
1.54      bertrand 3346:            if ((s_objet_resultat = copie_objet(s_etat_processus,
                   3347:                    s_objet_argument, 'O')) == NULL)
                   3348:            {
                   3349:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3350:                return;
                   3351:            }
1.1       bertrand 3352: 
1.54      bertrand 3353:            (*((struct_socket *) (*s_objet_resultat).objet)).effacement = 'N';
                   3354:            (*((struct_socket *) (*s_objet_resultat).objet)).socket_en_ecoute
                   3355:                    = 'N';
1.1       bertrand 3356: 
1.54      bertrand 3357:            if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
                   3358:                    PF_INET)
1.1       bertrand 3359:            {
1.54      bertrand 3360:                longueur = sizeof(adresse_ipv4);
                   3361: 
                   3362:                do
                   3363:                {
                   3364:                    drapeau = d_vrai;
1.1       bertrand 3365: 
1.98      bertrand 3366: #                  ifndef SEMAPHORES_NOMMES
1.54      bertrand 3367:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   3368:                                != 0)
1.98      bertrand 3369: #                  else
1.54      bertrand 3370:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1.98      bertrand 3371: #                  endif
1.54      bertrand 3372:                    {
                   3373:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   3374:                        return;
                   3375:                    }
1.1       bertrand 3376: 
1.54      bertrand 3377:                    if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3378:                            .socket = accept((*((struct_socket *)
                   3379:                            (*s_objet_argument).objet)).socket,
                   3380:                            (struct sockaddr *) &adresse_ipv4, &longueur))
                   3381:                            < 0)
                   3382:                    {
                   3383:                        erreur = errno;
1.1       bertrand 3384: 
1.55      bertrand 3385: #                      ifndef SEMAPHORES_NOMMES
1.98      bertrand 3386:                            while(sem_wait(&((*s_etat_processus)
                   3387:                                    .semaphore_fork)) != 0)
1.55      bertrand 3388: #                      else
1.98      bertrand 3389:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3390:                                    != 0)
1.55      bertrand 3391: #                      endif
1.50      bertrand 3392:                        {
1.54      bertrand 3393:                            if (errno != EINTR)
                   3394:                            {
                   3395:                                (*s_etat_processus).erreur_systeme =
                   3396:                                        d_es_processus;
                   3397:                                return;
                   3398:                            }
1.50      bertrand 3399:                        }
1.1       bertrand 3400: 
1.54      bertrand 3401:                        if (erreur != EINTR)
                   3402:                        {
                   3403:                            liberation(s_etat_processus, s_objet_argument);
                   3404:                            liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3405: 
1.54      bertrand 3406:                            (*s_etat_processus).erreur_execution =
                   3407:                                    d_ex_erreur_acces_fichier;
                   3408:                            return;
                   3409:                        }
1.1       bertrand 3410: 
1.54      bertrand 3411:                        scrutation_injection(s_etat_processus);
1.1       bertrand 3412: 
1.54      bertrand 3413:                        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3414:                        {
                   3415:                            drapeau = d_vrai;
                   3416:                        }
                   3417:                        else
                   3418:                        {
                   3419:                            drapeau = d_faux;
                   3420:                        }
1.1       bertrand 3421:                    }
                   3422:                    else
                   3423:                    {
1.98      bertrand 3424: #                      ifndef SEMAPHORES_NOMMES
1.54      bertrand 3425:                            while(sem_wait(&((*s_etat_processus)
                   3426:                                    .semaphore_fork)) != 0)
1.98      bertrand 3427: #                      else
1.54      bertrand 3428:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3429:                                    != 0)
1.98      bertrand 3430: #                      endif
1.50      bertrand 3431:                        {
1.54      bertrand 3432:                            if (errno != EINTR)
                   3433:                            {
                   3434:                                (*s_etat_processus).erreur_systeme =
                   3435:                                        d_es_processus;
                   3436:                                return;
                   3437:                            }
1.50      bertrand 3438:                        }
1.98      bertrand 3439: 
                   3440:                        if (options_sockets(s_etat_processus,
                   3441:                                (*s_objet_resultat).objet) != d_absence_erreur)
                   3442:                        {
                   3443:                            liberation(s_etat_processus, s_objet_argument);
                   3444:                            liberation(s_etat_processus, s_objet_resultat);
                   3445: 
                   3446:                            (*s_etat_processus).erreur_execution =
                   3447:                                    d_ex_erreur_parametre_fichier;
                   3448:                            return;
                   3449:                        }
1.1       bertrand 3450:                    }
1.54      bertrand 3451:                } while(drapeau == d_faux);
                   3452: 
                   3453:                if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3454:                        .adresse_distante = malloc(22 *
                   3455:                        sizeof(unsigned char))) == NULL)
                   3456:                {
                   3457:                    (*s_etat_processus).erreur_systeme =
                   3458:                            d_es_allocation_memoire;
                   3459:                    return;
1.1       bertrand 3460:                }
                   3461: 
1.54      bertrand 3462:                sprintf((*((struct_socket *) (*s_objet_resultat).objet))
                   3463:                        .adresse_distante, "%d.%d.%d.%d(%d)",
                   3464:                        (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF,
                   3465:                        (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF,
                   3466:                        (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF,
                   3467:                        ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF,
                   3468:                        ntohs(adresse_ipv4.sin_port));
                   3469:            }
                   3470:            else if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
                   3471:                    PF_INET6)
1.1       bertrand 3472:            {
1.20      bertrand 3473: #          ifdef IPV6
1.54      bertrand 3474:                longueur = sizeof(adresse_ipv6);
1.1       bertrand 3475: 
1.54      bertrand 3476:                do
                   3477:                {
                   3478:                    drapeau = d_vrai;
1.1       bertrand 3479: 
1.98      bertrand 3480: #                  ifndef SEMAPHORES_NOMMES
1.54      bertrand 3481:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   3482:                                != 0)
1.98      bertrand 3483: #                  else
1.54      bertrand 3484:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1.98      bertrand 3485: #                  endif
1.54      bertrand 3486:                    {
                   3487:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   3488:                        return;
                   3489:                    }
1.1       bertrand 3490: 
1.54      bertrand 3491:                    if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3492:                            .socket = accept((*((struct_socket *)
                   3493:                            (*s_objet_argument).objet)).socket,
                   3494:                            (struct sockaddr *) &adresse_ipv6, &longueur)) < 0)
                   3495:                    {
                   3496:                        erreur = errno;
1.1       bertrand 3497: 
1.98      bertrand 3498: #                      ifndef SEMAPHORES_NOMMES
1.54      bertrand 3499:                            while(sem_wait(&((*s_etat_processus)
                   3500:                                    .semaphore_fork)) != 0)
1.98      bertrand 3501: #                      else
1.54      bertrand 3502:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3503:                                    != 0)
1.98      bertrand 3504: #                      endif
1.50      bertrand 3505:                        {
1.54      bertrand 3506:                            if (errno != EINTR)
                   3507:                            {
                   3508:                                (*s_etat_processus).erreur_systeme =
                   3509:                                        d_es_processus;
                   3510:                                return;
                   3511:                            }
1.50      bertrand 3512:                        }
1.1       bertrand 3513: 
1.54      bertrand 3514:                        if (erreur != EINTR)
                   3515:                        {
                   3516:                            liberation(s_etat_processus, s_objet_argument);
                   3517:                            liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3518: 
1.54      bertrand 3519:                            (*s_etat_processus).erreur_execution =
                   3520:                                    d_ex_erreur_acces_fichier;
                   3521:                            return;
                   3522:                        }
1.1       bertrand 3523: 
1.54      bertrand 3524:                        scrutation_injection(s_etat_processus);
1.1       bertrand 3525: 
1.54      bertrand 3526:                        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3527:                        {
                   3528:                            drapeau = d_vrai;
                   3529:                        }
                   3530:                        else
                   3531:                        {
                   3532:                            drapeau = d_faux;
                   3533:                        }
1.1       bertrand 3534:                    }
                   3535:                    else
                   3536:                    {
1.98      bertrand 3537: #                      ifndef SEMAPHORES_NOMMES
1.54      bertrand 3538:                            while(sem_wait(&((*s_etat_processus)
                   3539:                                    .semaphore_fork)) != 0)
1.98      bertrand 3540: #                      else
1.54      bertrand 3541:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3542:                                    != 0)
1.98      bertrand 3543: #                      endif
1.50      bertrand 3544:                        {
1.54      bertrand 3545:                            if (errno != EINTR)
                   3546:                            {
                   3547:                                (*s_etat_processus).erreur_systeme =
                   3548:                                        d_es_processus;
                   3549:                                return;
                   3550:                            }
1.50      bertrand 3551:                        }
1.98      bertrand 3552: 
                   3553:                        if (options_sockets(s_etat_processus,
                   3554:                                (*s_objet_resultat).objet) != d_absence_erreur)
                   3555:                        {
                   3556:                            liberation(s_etat_processus, s_objet_argument);
                   3557:                            liberation(s_etat_processus, s_objet_resultat);
                   3558: 
                   3559:                            (*s_etat_processus).erreur_execution =
                   3560:                                    d_ex_erreur_parametre_fichier;
                   3561:                            return;
                   3562:                        }
1.1       bertrand 3563:                    }
1.54      bertrand 3564:                } while(drapeau == d_faux);
                   3565: 
                   3566:                if (((*((struct_socket *) (*s_objet_resultat).objet))
1.111   ! bertrand 3567:                        .adresse_distante = malloc(47 *
1.54      bertrand 3568:                        sizeof(unsigned char))) == NULL)
                   3569:                {
                   3570:                    (*s_etat_processus).erreur_systeme =
                   3571:                            d_es_allocation_memoire;
                   3572:                    return;
1.1       bertrand 3573:                }
                   3574: 
                   3575:                sprintf((*((struct_socket *) (*s_objet_resultat)
                   3576:                        .objet)).adresse_distante,
1.111   ! bertrand 3577:                        "%02X%02X:%02X%02X:%02X%02X:%02X%02X:"
        !          3578:                        "%02X%02X:%02X%02X:%02X%02X:%02X%02X(%u)",
        !          3579:                        adresse_ipv6.sin6_addr.s6_addr[0],
        !          3580:                        adresse_ipv6.sin6_addr.s6_addr[1],
        !          3581:                        adresse_ipv6.sin6_addr.s6_addr[2],
        !          3582:                        adresse_ipv6.sin6_addr.s6_addr[3],
        !          3583:                        adresse_ipv6.sin6_addr.s6_addr[4],
        !          3584:                        adresse_ipv6.sin6_addr.s6_addr[5],
        !          3585:                        adresse_ipv6.sin6_addr.s6_addr[6],
        !          3586:                        adresse_ipv6.sin6_addr.s6_addr[7],
        !          3587:                        adresse_ipv6.sin6_addr.s6_addr[8],
        !          3588:                        adresse_ipv6.sin6_addr.s6_addr[9],
        !          3589:                        adresse_ipv6.sin6_addr.s6_addr[10],
        !          3590:                        adresse_ipv6.sin6_addr.s6_addr[11],
        !          3591:                        adresse_ipv6.sin6_addr.s6_addr[12],
        !          3592:                        adresse_ipv6.sin6_addr.s6_addr[13],
        !          3593:                        adresse_ipv6.sin6_addr.s6_addr[14],
        !          3594:                        adresse_ipv6.sin6_addr.s6_addr[15],
1.54      bertrand 3595:                        ntohs(adresse_ipv6.sin6_port));
1.20      bertrand 3596: #          else
1.54      bertrand 3597:                if ((*s_etat_processus).langue == 'F')
                   3598:                {
                   3599:                    printf("+++Attention : Support du protocole"
                   3600:                            " IPv6 indisponible\n");
                   3601:                }
                   3602:                else
                   3603:                {
                   3604:                    printf("+++Warning : IPv6 support "
                   3605:                            "unavailable\n");
                   3606:                }
                   3607: #          endif
1.22      bertrand 3608:            }
                   3609:            else
                   3610:            {
1.54      bertrand 3611:                longueur = 0;
1.1       bertrand 3612: 
1.54      bertrand 3613:                do
                   3614:                {
                   3615:                    drapeau = d_vrai;
1.1       bertrand 3616: 
1.98      bertrand 3617: #                  ifndef SEMAPHORES_NOMMES
1.54      bertrand 3618:                        if (sem_post(&((*s_etat_processus).semaphore_fork))
                   3619:                                != 0)
1.98      bertrand 3620: #                  else
1.54      bertrand 3621:                        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1.98      bertrand 3622: #                  endif
1.54      bertrand 3623:                    {
                   3624:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   3625:                        return;
                   3626:                    }
1.1       bertrand 3627: 
1.54      bertrand 3628:                    if (((*((struct_socket *) (*s_objet_resultat).objet))
                   3629:                            .socket = accept((*((struct_socket *)
                   3630:                            (*s_objet_argument).objet)).socket, NULL,
                   3631:                            &longueur)) < 0)
                   3632:                    {
                   3633:                        erreur = errno;
1.1       bertrand 3634: 
1.98      bertrand 3635: #                      ifndef SEMAPHORES_NOMMES
1.54      bertrand 3636:                            while(sem_wait(&((*s_etat_processus)
                   3637:                                    .semaphore_fork)) != 0)
1.98      bertrand 3638: #                      else
1.54      bertrand 3639:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3640:                                    != 0)
1.98      bertrand 3641: #                      endif
1.50      bertrand 3642:                        {
1.54      bertrand 3643:                            if (errno != EINTR)
                   3644:                            {
                   3645:                                (*s_etat_processus).erreur_systeme =
                   3646:                                        d_es_processus;
                   3647:                                return;
                   3648:                            }
1.50      bertrand 3649:                        }
1.1       bertrand 3650: 
1.54      bertrand 3651:                        if (erreur != EINTR)
                   3652:                        {
                   3653:                            liberation(s_etat_processus, s_objet_argument);
                   3654:                            liberation(s_etat_processus, s_objet_resultat);
1.1       bertrand 3655: 
1.54      bertrand 3656:                            (*s_etat_processus).erreur_execution =
                   3657:                                    d_ex_erreur_acces_fichier;
                   3658:                            return;
                   3659:                        }
1.1       bertrand 3660: 
1.54      bertrand 3661:                        scrutation_injection(s_etat_processus);
1.1       bertrand 3662: 
1.54      bertrand 3663:                        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3664:                        {
                   3665:                            drapeau = d_vrai;
                   3666:                        }
                   3667:                        else
                   3668:                        {
                   3669:                            drapeau = d_faux;
                   3670:                        }
1.1       bertrand 3671:                    }
                   3672:                    else
                   3673:                    {
1.98      bertrand 3674: #                      ifndef SEMAPHORES_NOMMES
1.54      bertrand 3675:                            while(sem_wait(&((*s_etat_processus)
                   3676:                                    .semaphore_fork)) != 0)
1.98      bertrand 3677: #                      else
1.54      bertrand 3678:                            while(sem_wait((*s_etat_processus).semaphore_fork)
                   3679:                                    != 0)
1.98      bertrand 3680: #                      endif
1.50      bertrand 3681:                        {
1.54      bertrand 3682:                            if (errno != EINTR)
                   3683:                            {
                   3684:                                (*s_etat_processus).erreur_systeme =
                   3685:                                        d_es_processus;
                   3686:                                return;
                   3687:                            }
1.50      bertrand 3688:                        }
1.98      bertrand 3689: 
                   3690:                        if (options_sockets(s_etat_processus,
                   3691:                                (*s_objet_resultat).objet) != d_absence_erreur)
                   3692:                        {
                   3693:                            liberation(s_etat_processus, s_objet_argument);
                   3694:                            liberation(s_etat_processus, s_objet_resultat);
                   3695: 
                   3696:                            (*s_etat_processus).erreur_execution =
                   3697:                                    d_ex_erreur_parametre_fichier;
                   3698:                            return;
                   3699:                        }
1.1       bertrand 3700:                    }
1.54      bertrand 3701:                } while(drapeau == d_faux);
                   3702:            }
1.1       bertrand 3703: 
1.54      bertrand 3704:            // Si accept() renvoie une erreur non récupérée, il ne peut s'agir
                   3705:            // que de EINTR sachant qu'une requête d'arrêt est en court de
                   3706:            // traitement.
1.1       bertrand 3707: 
1.54      bertrand 3708:            if ((*((struct_socket *) (*s_objet_resultat).objet)).socket >= 0)
                   3709:            {
                   3710:                l_element_courant = (*s_etat_processus).s_sockets;
1.1       bertrand 3711: 
1.54      bertrand 3712:                if (l_element_courant == NULL)
1.1       bertrand 3713:                {
1.54      bertrand 3714:                    if (((*s_etat_processus).s_sockets =
                   3715:                            allocation_maillon(s_etat_processus)) == NULL)
                   3716:                    {
                   3717:                        (*s_etat_processus).erreur_systeme =
                   3718:                                d_es_allocation_memoire;
                   3719:                        return;
                   3720:                    }
                   3721: 
                   3722:                    (*(*s_etat_processus).s_sockets).suivant = NULL;
                   3723:                    l_element_courant = (*s_etat_processus).s_sockets;
1.1       bertrand 3724:                }
1.54      bertrand 3725:                else
                   3726:                {
                   3727:                    /*
                   3728:                     * Ajout d'un élément à la fin de la liste chaînée
                   3729:                     */
1.1       bertrand 3730: 
1.54      bertrand 3731:                    while((*l_element_courant).suivant != NULL)
                   3732:                    {
                   3733:                        l_element_courant = (*l_element_courant).suivant;
                   3734:                    }
                   3735: 
                   3736:                    if (((*l_element_courant).suivant =
                   3737:                            allocation_maillon(s_etat_processus)) == NULL)
                   3738:                    {
                   3739:                        (*s_etat_processus).erreur_systeme =
                   3740:                                d_es_allocation_memoire;
                   3741:                        return;
                   3742:                    }
1.1       bertrand 3743: 
                   3744:                    l_element_courant = (*l_element_courant).suivant;
1.54      bertrand 3745:                    (*l_element_courant).suivant = NULL;
1.1       bertrand 3746:                }
                   3747: 
1.54      bertrand 3748:                if (((*l_element_courant).donnee = copie_objet(s_etat_processus,
                   3749:                        s_objet_resultat, 'O')) == NULL)
1.1       bertrand 3750:                {
                   3751:                    (*s_etat_processus).erreur_systeme =
                   3752:                            d_es_allocation_memoire;
                   3753:                    return;
                   3754:                }
1.54      bertrand 3755:            }
1.1       bertrand 3756: 
1.54      bertrand 3757:            if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3758:                    s_objet_argument) == d_erreur)
                   3759:            {
                   3760:                return;
1.1       bertrand 3761:            }
                   3762: 
1.54      bertrand 3763:            if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3764:                    s_objet_resultat) == d_erreur)
1.1       bertrand 3765:            {
                   3766:                return;
                   3767:            }
                   3768:        }
                   3769:    }
                   3770:    else
                   3771:    {
                   3772:        liberation(s_etat_processus, s_objet_argument);
                   3773: 
                   3774:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   3775:        return;
                   3776:    }
                   3777: 
                   3778:    return;
                   3779: }
                   3780: 
                   3781: 
                   3782: /*
                   3783: ================================================================================
                   3784:   Fonction 'wfswi'
                   3785: ================================================================================
                   3786:   Entrées : pointeur sur une structure struct_processus
                   3787: --------------------------------------------------------------------------------
                   3788:   Sorties :
                   3789: --------------------------------------------------------------------------------
                   3790:   Effets de bord : néant
                   3791: ================================================================================
                   3792: */
                   3793: 
                   3794: void
                   3795: instruction_wfswi(struct_processus *s_etat_processus)
                   3796: {
                   3797:    integer8                    interruption;
                   3798: 
                   3799:    logical1                    drapeau_fin;
                   3800: 
                   3801:    struct_objet                *s_objet_argument;
                   3802: 
                   3803:    struct timespec             attente;
                   3804: 
                   3805:    (*s_etat_processus).erreur_execution = d_ex;
                   3806: 
                   3807:    attente.tv_sec = 0;
                   3808:    attente.tv_nsec = GRANULARITE_us * 1000;
                   3809: 
                   3810:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   3811:    {
                   3812:        printf("\n  WFSWI ");
                   3813: 
                   3814:        if ((*s_etat_processus).langue == 'F')
                   3815:        {
                   3816:            printf("(attente d'une interruption)\n\n");
                   3817:        }
                   3818:        else
                   3819:        {
                   3820:            printf("(wait for interrupt)\n\n");
                   3821:        }
                   3822: 
                   3823:        printf("    1: %s\n", d_INT);
                   3824: 
                   3825:        return;
                   3826:    }
                   3827:    else if ((*s_etat_processus).test_instruction == 'Y')
                   3828:    {
                   3829:        (*s_etat_processus).nombre_arguments = -1;
                   3830:        return;
                   3831:    }
                   3832: 
                   3833:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   3834:    {
                   3835:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   3836:        {
                   3837:            return;
                   3838:        }
                   3839:    }
                   3840: 
                   3841:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   3842:            &s_objet_argument) == d_erreur)
                   3843:    {
                   3844:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   3845:        return;
                   3846:    }
                   3847: 
                   3848:    if ((*s_objet_argument).type == INT)
                   3849:    {
                   3850:        drapeau_fin = d_faux;
                   3851: 
                   3852:        interruption = (*((integer8 *) (*s_objet_argument).objet));
                   3853: 
                   3854:        if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
                   3855:        {
                   3856:            liberation(s_etat_processus, s_objet_argument);
                   3857: 
                   3858:            (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
                   3859:            return;
                   3860:        }
                   3861: 
                   3862:        while(drapeau_fin == d_faux)
                   3863:        {
                   3864:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   3865:            {
                   3866:                liberation(s_etat_processus, s_objet_argument);
                   3867:                return;
                   3868:            }
                   3869: 
1.84      bertrand 3870:            if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions)
                   3871:                    != 0)
1.83      bertrand 3872:            {
                   3873:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3874:                return;
                   3875:            }
                   3876: 
1.1       bertrand 3877:            if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   3878:            {
                   3879:                affectation_interruptions_logicielles(s_etat_processus);
                   3880:            }
                   3881: 
1.84      bertrand 3882:            if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions)
                   3883:                    != 0)
1.83      bertrand 3884:            {
                   3885:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3886:                return;
                   3887:            }
                   3888: 
1.1       bertrand 3889:            if ((*s_etat_processus).queue_interruptions[interruption - 1] > 0)
                   3890:            {
                   3891:                drapeau_fin = d_vrai;
                   3892:            }
                   3893:            else
                   3894:            {
                   3895:                nanosleep(&attente, NULL);
                   3896:                scrutation_injection(s_etat_processus);
                   3897:                INCR_GRANULARITE(attente.tv_nsec);
                   3898:            }
                   3899:        }
                   3900:    }
                   3901:    else
                   3902:    {
                   3903:        liberation(s_etat_processus, s_objet_argument);
                   3904: 
                   3905:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   3906:        return;
                   3907:    }
                   3908: 
                   3909:    liberation(s_etat_processus, s_objet_argument);
                   3910: 
                   3911:    return;
                   3912: }
                   3913: 
                   3914: 
                   3915: /*
                   3916: ================================================================================
                   3917:   Fonction 'wfpoke'
                   3918: ================================================================================
                   3919:   Entrées : pointeur sur une structure struct_processus
                   3920: --------------------------------------------------------------------------------
                   3921:   Sorties :
                   3922: --------------------------------------------------------------------------------
                   3923:   Effets de bord : néant
                   3924: ================================================================================
                   3925: */
                   3926: 
                   3927: void
                   3928: instruction_wfpoke(struct_processus *s_etat_processus)
                   3929: {
                   3930:    struct timespec             attente;
                   3931: 
                   3932:    unsigned char               registre_instruction_valide;
                   3933: 
                   3934:    (*s_etat_processus).erreur_execution = d_ex;
                   3935: 
                   3936:    attente.tv_sec = 0;
                   3937:    attente.tv_nsec = GRANULARITE_us * 1000;
                   3938: 
                   3939:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   3940:    {
                   3941:        printf("\n  WFPOKE ");
                   3942: 
                   3943:        if ((*s_etat_processus).langue == 'F')
                   3944:        {
                   3945:            printf("(attente de données en provenance du processus père)\n\n");
                   3946:            printf("  Aucun argument\n");
                   3947:        }
                   3948:        else
                   3949:        {
                   3950:            printf("(wait for data from parent process)\n\n");
                   3951:            printf("  No argument\n");
                   3952:        }
                   3953: 
                   3954:        return;
                   3955:    }
                   3956:    else if ((*s_etat_processus).test_instruction == 'Y')
                   3957:    {
                   3958:        (*s_etat_processus).nombre_arguments = -1;
                   3959:        return;
                   3960:    }
                   3961: 
                   3962:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   3963:    {
                   3964:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                   3965:        {
                   3966:            return;
                   3967:        }
                   3968:    }
                   3969: 
                   3970:    if ((*s_etat_processus).presence_pipes == d_faux)
                   3971:    {
                   3972:        (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
                   3973:        return;
                   3974:    }
                   3975: 
                   3976:    if ((*s_etat_processus).nombre_objets_injectes > 0)
                   3977:    {
                   3978:        return;
                   3979:    }
                   3980: 
                   3981:    if ((*s_etat_processus).profilage == d_vrai)
                   3982:    {
                   3983:        profilage(s_etat_processus, "Interprocess or interthread "
                   3984:                "communications (WFPOKE)");
                   3985: 
                   3986:        if ((*s_etat_processus).erreur_systeme != d_es)
                   3987:        {
                   3988:            return;
                   3989:        }
                   3990:    }
                   3991: 
                   3992:    do
                   3993:    {
1.51      bertrand 3994: #      ifndef SEMAPHORES_NOMMES
                   3995:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   3996: #      else
                   3997:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   3998: #      endif
1.1       bertrand 3999:        {
                   4000:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   4001:            return;
                   4002:        }
                   4003: 
                   4004:        nanosleep(&attente, NULL);
                   4005: 
1.51      bertrand 4006: #      ifndef SEMAPHORES_NOMMES
                   4007:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   4008: #      else
                   4009:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   4010: #      endif
1.1       bertrand 4011:        {
1.50      bertrand 4012:            if (errno != EINTR)
                   4013:            {
                   4014:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   4015:                return;
                   4016:            }
1.1       bertrand 4017:        }
                   4018: 
                   4019:        scrutation_injection(s_etat_processus);
                   4020: 
1.84      bertrand 4021:        if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) != 0)
1.83      bertrand 4022:        {
                   4023:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   4024:            return;
                   4025:        }
                   4026: 
1.1       bertrand 4027:        if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   4028:        {
                   4029:            affectation_interruptions_logicielles(s_etat_processus);
                   4030:        }
                   4031: 
1.84      bertrand 4032:        if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) != 0)
1.83      bertrand 4033:        {
                   4034:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   4035:            return;
                   4036:        }
                   4037: 
1.1       bertrand 4038:        if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   4039:        {
                   4040:            registre_instruction_valide =
                   4041:                    (*s_etat_processus).instruction_valide;
                   4042:            traitement_interruptions_logicielles(s_etat_processus);
                   4043:            (*s_etat_processus).instruction_valide =
                   4044:                    registre_instruction_valide;
                   4045:        }
                   4046: 
                   4047:        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   4048:        {
                   4049:            if ((*s_etat_processus).profilage == d_vrai)
                   4050:            {
                   4051:                profilage(s_etat_processus, NULL);
                   4052:            }
                   4053: 
                   4054:            return;
                   4055:        }
                   4056: 
                   4057:        INCR_GRANULARITE(attente.tv_nsec);
                   4058:    } while((*s_etat_processus).nombre_objets_injectes == 0);
                   4059: 
                   4060:    return;
                   4061: }
                   4062: 
                   4063: 
                   4064: /*
                   4065: ================================================================================
                   4066:   Fonction 'wfack'
                   4067: ================================================================================
                   4068:   Entrées : pointeur sur une structure struct_processus
                   4069: --------------------------------------------------------------------------------
                   4070:   Sorties :
                   4071: --------------------------------------------------------------------------------
                   4072:   Effets de bord : néant
                   4073: ================================================================================
                   4074: */
                   4075: 
                   4076: void
                   4077: instruction_wfack(struct_processus *s_etat_processus)
                   4078: {
                   4079:    struct timespec             attente;
                   4080: 
                   4081:    unsigned char               registre_instruction_valide;
                   4082: 
                   4083:    (*s_etat_processus).erreur_execution = d_ex;
                   4084: 
                   4085:    attente.tv_sec = 0;
                   4086:    attente.tv_nsec = GRANULARITE_us * 1000;
                   4087: 
                   4088:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   4089:    {
                   4090:        printf("\n  WFACK ");
                   4091: 
                   4092:        if ((*s_etat_processus).langue == 'F')
                   4093:        {
                   4094:            printf("(attente des acquittements de lecture)\n\n");
                   4095:            printf("  Aucun argument\n");
                   4096:        }
                   4097:        else
                   4098:        {
                   4099:            printf("(wait for reading of data acknowledgement)\n\n");
                   4100:            printf("  No argument\n");
                   4101:        }
                   4102: 
                   4103:        return;
                   4104:    }
                   4105:    else if ((*s_etat_processus).test_instruction == 'Y')
                   4106:    {
                   4107:        (*s_etat_processus).nombre_arguments = -1;
                   4108:        return;
                   4109:    }
                   4110: 
                   4111:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   4112:    {
                   4113:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                   4114:        {
                   4115:            return;
                   4116:        }
                   4117:    }
                   4118: 
                   4119:    if ((*s_etat_processus).presence_pipes == d_faux)
                   4120:    {
                   4121:        (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
                   4122:        return;
                   4123:    }
                   4124: 
                   4125:    if ((*s_etat_processus).profilage == d_vrai)
                   4126:    {
                   4127:        profilage(s_etat_processus, "Interprocess or interthread communications"
                   4128:                " (WFACK)");
                   4129: 
                   4130:        if ((*s_etat_processus).erreur_systeme != d_es)
                   4131:        {
                   4132:            return;
                   4133:        }
                   4134:    }
                   4135: 
                   4136:    while((*s_etat_processus).nombre_objets_envoyes_non_lus != 0)
                   4137:    {
                   4138:        scrutation_injection(s_etat_processus);
                   4139: 
1.84      bertrand 4140:        if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) != 0)
1.83      bertrand 4141:        {
                   4142:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   4143:            return;
                   4144:        }
                   4145: 
1.1       bertrand 4146:        if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   4147:        {
                   4148:            affectation_interruptions_logicielles(s_etat_processus);
                   4149:        }
                   4150: 
1.84      bertrand 4151:        if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) != 0)
1.83      bertrand 4152:        {
                   4153:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   4154:            return;
                   4155:        }
                   4156: 
1.1       bertrand 4157:        if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   4158:        {
                   4159:            registre_instruction_valide =
                   4160:                    (*s_etat_processus).instruction_valide;
                   4161:            traitement_interruptions_logicielles(s_etat_processus);
                   4162:            (*s_etat_processus).instruction_valide =
                   4163:                    registre_instruction_valide;
                   4164:        }
                   4165: 
                   4166:        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   4167:        {
                   4168:            if ((*s_etat_processus).profilage == d_vrai)
                   4169:            {
                   4170:                profilage(s_etat_processus, NULL);
                   4171:            }
                   4172: 
                   4173:            return;
                   4174:        }
                   4175: 
1.51      bertrand 4176: #      ifndef SEMAPHORES_NOMMES
                   4177:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   4178: #      else
                   4179:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                   4180: #      endif
1.12      bertrand 4181:        {
                   4182:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   4183:            return;
                   4184:        }
1.1       bertrand 4185: 
                   4186:        nanosleep(&attente, NULL);
                   4187:        INCR_GRANULARITE(attente.tv_nsec);
                   4188: 
1.51      bertrand 4189: #      ifndef SEMAPHORES_NOMMES
                   4190:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                   4191: #      else
                   4192:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                   4193: #      endif
1.1       bertrand 4194:        {
1.50      bertrand 4195:            if (errno != EINTR)
                   4196:            {
                   4197:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   4198:                return;
                   4199:            }
1.1       bertrand 4200:        }
                   4201:    }
                   4202: 
                   4203:    if ((*s_etat_processus).profilage == d_vrai)
                   4204:    {
                   4205:        profilage(s_etat_processus, NULL);
                   4206:    }
                   4207: 
                   4208:    return;
                   4209: }
                   4210: 
                   4211: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>