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

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

CVSweb interface <joel.bertrand@systella.fr>