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

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

CVSweb interface <joel.bertrand@systella.fr>