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

1.1       bertrand    1: /*
                      2: ================================================================================
1.4       bertrand    3:   RPL/2 (R) version 4.0.12
1.1       bertrand    4:   Copyright (C) 1989-2010 Dr. BERTRAND Joël
                      5: 
                      6:   This file is part of RPL/2.
                      7: 
                      8:   RPL/2 is free software; you can redistribute it and/or modify it
                      9:   under the terms of the CeCILL V2 License as published by the french
                     10:   CEA, CNRS and INRIA.
                     11:  
                     12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
                     13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                     14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
                     15:   for more details.
                     16:  
                     17:   You should have received a copy of the CeCILL License
                     18:   along with RPL/2. If not, write to info@cecill.info.
                     19: ================================================================================
                     20: */
                     21: 
                     22: 
                     23: #include "rpl.conv.h"
                     24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   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: {
                    127: #  include                 "garanties.conv.h"
                    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:    
                    229:    if (((*s_objet).type == INT) ||
                    230:            ((*s_objet).type == REL))
                    231:    {
                    232:        if ((*s_objet).type == INT)
                    233:        {
                    234:            attente = (real8) (*((integer8 *) (*s_objet).objet));
                    235:        }
                    236:        else
                    237:        {
                    238:            attente = (*((real8 *) (*s_objet).objet));
                    239:        }
                    240: 
                    241:        if (attente < 0)
                    242:        {
                    243:            liberation(s_etat_processus, s_objet);
                    244: 
                    245:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    246:            return;
                    247:        }
                    248: 
                    249:        temporisation.tv_sec = (long) floor((double) attente);
                    250:        temporisation.tv_nsec = (attente - temporisation.tv_sec) *
                    251:                (long) 1000000000;
                    252: 
                    253:        if ((*s_etat_processus).profilage == d_vrai)
                    254:        {
                    255:            profilage(s_etat_processus, "Sleep function (WAIT)");
                    256: 
                    257:            if ((*s_etat_processus).erreur_systeme != d_es)
                    258:            {
                    259:                return;
                    260:            }
                    261:        }
                    262: 
                    263:        do
                    264:        {
                    265:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    266:            {
                    267:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    268:                return;
                    269:            }
                    270: 
                    271:            code_retour = nanosleep(&temporisation, &temporisation);
                    272:            erreur = errno;
                    273: 
                    274:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                    275:            {
                    276:                if (errno != EINTR)
                    277:                {
                    278:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    279:                    return;
                    280:                }
                    281:            }
                    282: 
                    283:            scrutation_injection(s_etat_processus);
                    284: 
                    285:            if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                    286:            {
                    287:                affectation_interruptions_logicielles(s_etat_processus);
                    288:            }
                    289: 
                    290:            if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                    291:            {
                    292:                traitement_interruptions_logicielles(s_etat_processus);
                    293:            }
                    294:        } while(((code_retour == -1) && (erreur == EINTR))
                    295:                && ((*s_etat_processus).var_volatile_requete_arret == 0));
                    296: 
                    297:        if ((*s_etat_processus).profilage == d_vrai)
                    298:        {
                    299:            profilage(s_etat_processus, NULL);
                    300:        }
                    301:    }
                    302:    else
                    303:    {
                    304:        liberation(s_etat_processus, s_objet);
                    305: 
                    306:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    307:        return;
                    308:    }
                    309: 
                    310:    liberation(s_etat_processus, s_objet);
                    311: 
                    312:    return;
                    313: }
                    314: 
                    315: 
                    316: /*
                    317: ================================================================================
                    318:   Fonction 'wireframe' (passe en mode d'affichage échantillonné)
                    319: ================================================================================
                    320:   Entrées : structure processus
                    321: --------------------------------------------------------------------------------
                    322:   Sorties :
                    323: --------------------------------------------------------------------------------
                    324:   Effets de bord : néant
                    325: ================================================================================
                    326: */
                    327: 
                    328: void
                    329: instruction_wireframe(struct_processus *s_etat_processus)
                    330: {
                    331:    (*s_etat_processus).erreur_execution = d_ex;
                    332: 
                    333:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    334:    {
                    335:        printf("\n  WIREFRAME ");
                    336: 
                    337:        if ((*s_etat_processus).langue == 'F')
                    338:        {
                    339:            printf("(graphique tridimensionnel grillagé)\n\n");
                    340:            printf("  Aucun argument\n");
                    341:        }
                    342:        else
                    343:        {
                    344:            printf("(wireframe 3D graph)\n\n");
                    345:            printf("  No argument\n");
                    346:        }
                    347: 
                    348:        return;
                    349:    }
                    350:    else if ((*s_etat_processus).test_instruction == 'Y')
                    351:    {
                    352:        (*s_etat_processus).nombre_arguments = -1;
                    353:        return;
                    354:    }
                    355: 
                    356:    strcpy((*s_etat_processus).type_trace_eq, "GRILLE 3D");
                    357: 
                    358:    return;
                    359: }
                    360: 
                    361: 
                    362: /*
                    363: ================================================================================
                    364:   Fonction 'write'
                    365: ================================================================================
                    366:   Entrées : structure processus
                    367: --------------------------------------------------------------------------------
                    368:   Sorties :
                    369: --------------------------------------------------------------------------------
                    370:   Effets de bord : néant
                    371: ================================================================================
                    372: */
                    373: 
                    374: void
                    375: instruction_write(struct_processus *s_etat_processus)
                    376: {
1.6     ! bertrand  377:    const char                          *queue;
        !           378: 
1.1       bertrand  379:    int                                 adresse[16];
                    380:    int                                 port;
                    381: 
                    382:    long                                longueur_effective;
                    383:    long                                recursivite;
                    384: 
1.6     ! bertrand  385:    sqlite3_stmt                        *ppStmt;
        !           386: 
1.1       bertrand  387:    ssize_t                             ios;
                    388: 
1.5       bertrand  389:    struct_descripteur_fichier          *descripteur;
                    390: 
1.6     ! bertrand  391:    struct_objet                        *s_objet_argument_1;
1.1       bertrand  392:    struct_objet                        *s_objet_argument_2;
1.6     ! bertrand  393:    struct_objet                        *s_objet_argument_3;
1.1       bertrand  394: 
                    395:    struct sigaction                    action;
                    396:    struct sigaction                    registre;
                    397: 
                    398:    struct sockaddr_in                  adresse_ipv4;
                    399:    struct sockaddr_in6                 adresse_ipv6;
                    400:    struct sockaddr_un                  adresse_unix;
                    401: 
                    402:    struct flock                        lock;
                    403: 
                    404:    uint32_t                            calcul_adresse;
                    405: 
                    406:    unsigned char                       *chaine;
1.5       bertrand  407:    unsigned char                       *chaine_utf8;
1.6     ! bertrand  408:    unsigned char                       *commande;
1.1       bertrand  409: 
                    410:    unsigned long                       i;
                    411: 
                    412:    (*s_etat_processus).erreur_execution = d_ex;
                    413: 
                    414:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    415:    {
                    416:        printf("\n  WRITE ");
                    417: 
                    418:        if ((*s_etat_processus).langue == 'F')
                    419:        {
                    420:            printf("(écriture d'un enregistrement d'un fichier)\n\n");
                    421:        }
                    422:        else
                    423:        {
                    424:            printf("(write a record of a file)\n\n");
                    425:        }
                    426: 
                    427:        printf("    2: %s\n", d_LST);
1.6     ! bertrand  428:        printf("    1: %s, %s\n\n", d_FCH, d_SCK);
1.1       bertrand  429: 
1.6     ! bertrand  430:        printf("    3: %s\n", d_LST);
        !           431:        printf("    2: %s, %s\n", d_INT, d_CHN);
        !           432:        printf("    1: %s\n", d_FCH);
1.1       bertrand  433:        return;
                    434:    }
                    435:    else if ((*s_etat_processus).test_instruction == 'Y')
                    436:    {
                    437:        (*s_etat_processus).nombre_arguments = -1;
                    438:        return;
                    439:    }
                    440: 
                    441:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    442:    {
1.6     ! bertrand  443:        if ((*s_etat_processus).l_base_pile == NULL)
1.1       bertrand  444:        {
1.6     ! bertrand  445:            (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1.1       bertrand  446:            return;
                    447:        }
1.6     ! bertrand  448: 
        !           449:        if ((*(*(*s_etat_processus).l_base_pile).donnee).type == FCH)
        !           450:        {
        !           451:            if ((*((struct_fichier *) (*(*(*s_etat_processus).l_base_pile)
        !           452:                    .donnee).objet)).acces == 'S')
        !           453:            {
        !           454:                if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
        !           455:                {
        !           456:                    return;
        !           457:                }
        !           458:            }
        !           459:            else
        !           460:            {
        !           461:                if (empilement_pile_last(s_etat_processus, 3) == d_erreur)
        !           462:                {
        !           463:                    return;
        !           464:                }
        !           465:            }
        !           466:        }
        !           467:        else
        !           468:        {
        !           469:            if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
        !           470:            {
        !           471:                return;
        !           472:            }
        !           473:        }
1.1       bertrand  474:    }
                    475: 
                    476:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    477:            &s_objet_argument_1) == d_erreur)
                    478:    {
                    479:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    480:        return;
                    481:    }
                    482:    
                    483:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    484:            &s_objet_argument_2) == d_erreur)
                    485:    {
                    486:        liberation(s_etat_processus, s_objet_argument_1);
                    487: 
                    488:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    489:        return;
                    490:    }
                    491:    
1.6     ! bertrand  492:    if ((*s_objet_argument_1).type == FCH)
1.1       bertrand  493:    {
1.5       bertrand  494:        if ((descripteur = descripteur_fichier(s_etat_processus,
                    495:                (struct_fichier *) (*s_objet_argument_1).objet)) == NULL)
                    496:        {
                    497:            return;
                    498:        }
                    499: 
1.1       bertrand  500:        /*
                    501:         * Vérification des verrous
                    502:         */
                    503: 
                    504:        lock.l_type = F_WRLCK;
                    505:        lock.l_whence = SEEK_SET;
                    506:        lock.l_start = 0;
                    507:        lock.l_len = 0;
                    508:        lock.l_pid = getpid();
                    509:        recursivite = 0;
                    510: 
1.5       bertrand  511:        if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
                    512:                == -1)
1.1       bertrand  513:        {
                    514:            liberation(s_etat_processus, s_objet_argument_2);
                    515:            liberation(s_etat_processus, s_objet_argument_1);
                    516: 
                    517:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    518:            return;
                    519:        }
                    520: 
                    521:        if (lock.l_type != F_UNLCK)
                    522:        {
                    523:            liberation(s_etat_processus, s_objet_argument_2);
                    524:            liberation(s_etat_processus, s_objet_argument_1);
                    525: 
                    526:            (*s_etat_processus).erreur_execution =
                    527:                    d_ex_fichier_verrouille;
                    528:            return;
                    529:        }
                    530: 
                    531:        /*
                    532:         * Vérification de l'autorisation d'écriture
                    533:         */
                    534: 
                    535:        if ((*((struct_fichier *) (*s_objet_argument_1).objet))
                    536:                .protection == 'R')
                    537:        {
                    538:            liberation(s_etat_processus, s_objet_argument_2);
                    539:            liberation(s_etat_processus, s_objet_argument_1);
                    540: 
                    541:            (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
                    542:            return;
                    543:        }
                    544: 
                    545:        if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire == 'N')
                    546:        {
                    547:            /*
                    548:             * Fichiers formatés
                    549:             */
                    550: 
1.6     ! bertrand  551:            if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
        !           552:                    == 'S')
1.1       bertrand  553:            {
1.6     ! bertrand  554:                if ((*s_objet_argument_2).type != LST)
        !           555:                {
        !           556:                    liberation(s_etat_processus, s_objet_argument_2);
        !           557:                    liberation(s_etat_processus, s_objet_argument_1);
        !           558: 
        !           559:                    (*s_etat_processus).erreur_execution =
        !           560:                            d_ex_erreur_type_argument;
        !           561:                    return;
        !           562:                }
        !           563: 
        !           564:                if ((chaine = formateur_fichier(s_etat_processus,
        !           565:                        s_objet_argument_2, (*((struct_fichier *)
        !           566:                        (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
        !           567:                        &longueur_effective, &recursivite)) == NULL)
        !           568:                {
        !           569:                    liberation(s_etat_processus, s_objet_argument_2);
        !           570:                    liberation(s_etat_processus, s_objet_argument_1);
1.1       bertrand  571: 
1.6     ! bertrand  572:                    return;
        !           573:                }
1.1       bertrand  574: 
1.5       bertrand  575:                BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
                    576: 
                    577:                if (fseek((*descripteur).descripteur_c, (long) 0, SEEK_END)
                    578:                        != 0)
1.1       bertrand  579:                {
                    580:                    liberation(s_etat_processus, s_objet_argument_2);
                    581:                    liberation(s_etat_processus, s_objet_argument_1);
                    582: 
                    583:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    584:                    return;
                    585:                }
                    586: 
1.5       bertrand  587:                if ((chaine_utf8 = transliteration(s_etat_processus,
                    588:                        chaine, d_locale, "UTF-8")) == NULL)
                    589:                {
1.6     ! bertrand  590:                    free(chaine);
        !           591: 
1.5       bertrand  592:                    liberation(s_etat_processus, s_objet_argument_2);
                    593:                    liberation(s_etat_processus, s_objet_argument_1);
                    594: 
                    595:                    return;
                    596:                }
                    597: 
1.6     ! bertrand  598:                free(chaine);
        !           599: 
1.5       bertrand  600:                if (fprintf((*descripteur).descripteur_c, "%s\n", chaine) < 0)
1.1       bertrand  601:                {
1.5       bertrand  602:                    free(chaine_utf8);
                    603: 
1.1       bertrand  604:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    605:                    return;
                    606:                }
1.5       bertrand  607: 
                    608:                free(chaine_utf8);
1.1       bertrand  609:            }
                    610:            else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                    611:                    == 'D')
                    612:            {
1.6     ! bertrand  613:                BUG(((*descripteur).type != 'S'), uprintf("Bad filetype !\n"));
        !           614: 
        !           615:                if ((*s_objet_argument_2).type != INT)
        !           616:                {
        !           617:                    liberation(s_etat_processus, s_objet_argument_2);
        !           618:                    liberation(s_etat_processus, s_objet_argument_1);
        !           619: 
        !           620:                    (*s_etat_processus).erreur_execution =
        !           621:                            d_ex_erreur_type_argument;
        !           622:                    return;
        !           623:                }
        !           624: 
        !           625:                if (depilement(s_etat_processus, &((*s_etat_processus)
        !           626:                        .l_base_pile), &s_objet_argument_3) == d_erreur)
        !           627:                {
        !           628:                    (*s_etat_processus).erreur_execution = d_ex_manque_argument;
        !           629:                    return;
        !           630:                }
        !           631: 
        !           632:                if ((*s_objet_argument_3).type != LST)
        !           633:                {
        !           634:                    liberation(s_etat_processus, s_objet_argument_3);
        !           635:                    liberation(s_etat_processus, s_objet_argument_2);
        !           636:                    liberation(s_etat_processus, s_objet_argument_1);
        !           637: 
        !           638:                    (*s_etat_processus).erreur_execution =
        !           639:                            d_ex_erreur_type_argument;
        !           640:                    return;
        !           641:                }
        !           642: 
        !           643:                if ((*s_objet_argument_3).objet == NULL)
        !           644:                {
        !           645:                    // Effacement d'un enregistrement
        !           646: 
        !           647:                    if (alsprintf(&commande, "delete from data where "
        !           648:                            "id = %lld", (*((integer8 *)
        !           649:                            (*s_objet_argument_2).objet))) < 0)
        !           650:                    {
        !           651:                        liberation(s_etat_processus, s_objet_argument_3);
        !           652:                        liberation(s_etat_processus, s_objet_argument_2);
        !           653:                        liberation(s_etat_processus, s_objet_argument_1);
        !           654: 
        !           655:                        return;
        !           656:                    }
        !           657:                }
        !           658:                else
        !           659:                {
        !           660:                    // Modification ou création d'un nouvel enregistrement
        !           661: 
        !           662:                    if ((chaine = formateur_fichier(s_etat_processus,
        !           663:                            s_objet_argument_3, (*((struct_fichier *)
        !           664:                            (*s_objet_argument_1).objet)).format, 0, 0, ' ',
        !           665:                            'F', &longueur_effective, &recursivite)) == NULL)
        !           666:                    {
        !           667:                        liberation(s_etat_processus, s_objet_argument_3);
        !           668:                        liberation(s_etat_processus, s_objet_argument_2);
        !           669:                        liberation(s_etat_processus, s_objet_argument_1);
        !           670: 
        !           671:                        return;
        !           672:                    }
        !           673: 
        !           674:                    if ((chaine_utf8 = transliteration(s_etat_processus,
        !           675:                            chaine, d_locale, "UTF-8")) == NULL)
        !           676:                    {
        !           677:                        free(chaine);
        !           678: 
        !           679:                        liberation(s_etat_processus, s_objet_argument_3);
        !           680:                        liberation(s_etat_processus, s_objet_argument_2);
        !           681:                        liberation(s_etat_processus, s_objet_argument_1);
        !           682: 
        !           683:                        return;
        !           684:                    }
        !           685: 
        !           686:                    free(chaine);
        !           687: 
        !           688:                    if (alsprintf(&commande, "insert or replace into data "
        !           689:                            "(id, data) values (%lld, '%s')", (*((integer8 *)
        !           690:                            (*s_objet_argument_2).objet)), chaine_utf8) < 0)
        !           691:                    {
        !           692:                        free(chaine_utf8);
        !           693:                        liberation(s_etat_processus, s_objet_argument_3);
        !           694:                        liberation(s_etat_processus, s_objet_argument_2);
        !           695:                        liberation(s_etat_processus, s_objet_argument_1);
        !           696: 
        !           697:                        return;
        !           698:                    }
        !           699: 
        !           700:                    free(chaine_utf8);
        !           701:                }
        !           702: 
        !           703:                if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite,
        !           704:                        commande, strlen(commande), &ppStmt, &queue)
        !           705:                        != SQLITE_OK)
        !           706:                {
        !           707:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
        !           708:                    return;
        !           709:                }
        !           710: 
        !           711:                if (sqlite3_step(ppStmt) != SQLITE_DONE)
        !           712:                {
        !           713:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
        !           714:                    return;
        !           715:                }
        !           716: 
        !           717:                if (sqlite3_finalize(ppStmt) != SQLITE_OK)
        !           718:                {
        !           719:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
        !           720:                    return;
        !           721:                }
        !           722: 
        !           723:                liberation(s_etat_processus, s_objet_argument_3);
        !           724:                free(commande);
1.1       bertrand  725:            }
                    726:            else
                    727:            {
                    728:                /* Fichiers indexés : panique totale ! */
                    729:            }
                    730:        }
                    731:        else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).binaire
                    732:                == 'Y')
                    733:        {
                    734:            /*
                    735:             * Fichiers non formatés
                    736:             */
                    737: 
                    738:            if ((chaine = formateur_fichier(s_etat_processus,
                    739:                    s_objet_argument_2, (*((struct_fichier *)
                    740:                    (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
                    741:                    &longueur_effective, &recursivite)) == NULL)
                    742:            {
                    743:                liberation(s_etat_processus, s_objet_argument_2);
                    744:                liberation(s_etat_processus, s_objet_argument_1);
                    745: 
                    746:                return;
                    747:            }
                    748: 
                    749:            if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                    750:                    == 'S')
                    751:            {
1.5       bertrand  752:                BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
                    753: 
                    754:                if (fseek((*descripteur).descripteur_c, (long) 0, SEEK_END)
                    755:                        != 0)
1.1       bertrand  756:                {
                    757:                    liberation(s_etat_processus, s_objet_argument_2);
                    758:                    liberation(s_etat_processus, s_objet_argument_1);
                    759: 
                    760:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    761:                    return;
                    762:                }
                    763: 
                    764:                if (fwrite(chaine, sizeof(unsigned char), longueur_effective,
1.5       bertrand  765:                        (*descripteur).descripteur_c) !=
                    766:                        (size_t) longueur_effective)
1.1       bertrand  767:                {
                    768:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    769:                    return;
                    770:                }
                    771:            }
                    772:            else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
                    773:                    == 'D')
                    774:            {
                    775:            }
                    776:            else
                    777:            {
                    778:                /* Fichiers indexés : panique totale ! */
                    779:            }
                    780: 
                    781:            free(chaine);
                    782:        }
                    783:        else
                    784:        {
                    785:            /*
                    786:             * Fichiers de type FLOW
                    787:             */
                    788:        }
                    789:    }
                    790:    else if (((*s_objet_argument_2).type == LST) &&
                    791:            ((*s_objet_argument_1).type == SCK))
                    792:    {
                    793:        /*
                    794:         * Vérification de l'autorisation d'écriture
                    795:         */
                    796: 
                    797:        if ((*((struct_socket *) (*s_objet_argument_1).objet))
                    798:                .protection == 'R')
                    799:        {
                    800:            liberation(s_etat_processus, s_objet_argument_2);
                    801:            liberation(s_etat_processus, s_objet_argument_1);
                    802: 
                    803:            (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
                    804:            return;
                    805:        }
                    806: 
                    807:        if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire == 'N')
                    808:        {
                    809:            /*
                    810:             * Sockets formatées
                    811:             */
                    812: 
                    813:            if ((chaine = formateur_fichier(s_etat_processus,
                    814:                    s_objet_argument_2, (*((struct_socket *)
                    815:                    (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
                    816:                    &longueur_effective, &recursivite)) == NULL)
                    817:            {
                    818:                liberation(s_etat_processus, s_objet_argument_2);
                    819:                liberation(s_etat_processus, s_objet_argument_1);
                    820: 
                    821:                return;
                    822:            }
                    823: 
                    824:            if ((strcmp((*((struct_socket *) (*s_objet_argument_1).objet)).type,
                    825:                    "STREAM") == 0) || (strcmp((*((struct_socket *)
                    826:                    (*s_objet_argument_1).objet)).type,
                    827:                    "SEQUENTIAL DATAGRAM") == 0))
                    828:            { // Sockets connectées
                    829: 
                    830:                action.sa_handler = SIG_IGN;
                    831:                action.sa_flags = SA_ONSTACK;
                    832: 
                    833:                if (sigaction(SIGPIPE, &action, &registre) != 0)
                    834:                {
                    835:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                    836:                    return;
                    837:                }
                    838: 
                    839:                if (sem_post(&((*s_etat_processus).semaphore_fork))
                    840:                        != 0)
                    841:                {
                    842:                    if (sigaction(SIGPIPE, &registre, NULL) != 0)
                    843:                    {
                    844:                        (*s_etat_processus).erreur_systeme = d_es_signal;
                    845:                        return;
                    846:                    }
                    847: 
                    848:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    849:                    return;
                    850:                }
                    851: 
                    852:                if (send((*((struct_socket *) (*s_objet_argument_1).objet))
                    853:                        .socket, chaine, strlen(chaine), 0) < 0)
                    854:                {
                    855:                    ios = errno;
                    856: 
                    857:                    if (sigaction(SIGPIPE, &registre, NULL) != 0)
                    858:                    {
                    859:                        (*s_etat_processus).erreur_systeme = d_es_signal;
                    860:                        return;
                    861:                    }
                    862: 
                    863:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                    864:                    {
                    865:                        if (errno != EINTR)
                    866:                        {
                    867:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                    868:                            return;
                    869:                        }
                    870:                    }
                    871: 
                    872:                    if (ios == EPIPE)
                    873:                    {
                    874:                        (*s_etat_processus).erreur_execution =
                    875:                                d_ex_erreur_acces_fichier;
                    876:                        return;
                    877:                    }
                    878: 
                    879:                    (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    880:                    return;
                    881:                }
                    882: 
                    883:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                    884:                {
                    885:                    if (errno != EINTR)
                    886:                    {
                    887:                        if (sigaction(SIGPIPE, &registre, NULL) != 0)
                    888:                        {
                    889:                            (*s_etat_processus).erreur_systeme = d_es_signal;
                    890:                            return;
                    891:                        }
                    892: 
                    893:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                    894:                        return;
                    895:                    }
                    896:                }
                    897: 
                    898:                if (sigaction(SIGPIPE, &registre, NULL) != 0)
                    899:                {
                    900:                    (*s_etat_processus).erreur_systeme = d_es_signal;
                    901:                    return;
                    902:                }
                    903:            }
                    904:            else
                    905:            { // Sockets non connectées
                    906: 
                    907:                /*
                    908:                 * Vérification de l'adresse distante
                    909:                 */
                    910: 
                    911:                if (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
                    912:                        .adresse_distante, "") == 0)
                    913:                {
                    914:                    liberation(s_etat_processus, s_objet_argument_1);
                    915:                    liberation(s_etat_processus, s_objet_argument_2);
                    916: 
                    917:                    (*s_etat_processus).erreur_execution =
                    918:                            d_ex_erreur_acces_fichier;
                    919:                    return;
                    920:                }
                    921: 
                    922:                /*
                    923:                 * Création de l'adresse logique
                    924:                 */
                    925: 
                    926:                if ((*((struct_socket *) (*s_objet_argument_1).objet))
                    927:                        .domaine == PF_UNIX)
                    928:                {
                    929:                    adresse_unix.sun_family = AF_UNIX;
                    930:                    strncpy(adresse_unix.sun_path, (*((struct_socket *)
                    931:                            (*s_objet_argument_1).objet)).adresse_distante,
                    932:                            108);
                    933:                    adresse_unix.sun_path[108 - 1] = d_code_fin_chaine;
                    934: 
                    935:                    if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    936:                    {
                    937:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                    938:                        return;
                    939:                    }
                    940: 
                    941:                    if (sendto((*((struct_socket *)
                    942:                            (*s_objet_argument_1).objet)).socket, chaine,
                    943:                            strlen(chaine), 0, (struct sockaddr *)
                    944:                            &adresse_unix, sizeof(adresse_unix)) < 0)
                    945:                    {
                    946:                        while(sem_wait(&((*s_etat_processus)
                    947:                                .semaphore_fork)) == -1)
                    948:                        {
                    949:                            if (errno != EINTR)
                    950:                            {
                    951:                                (*s_etat_processus).erreur_systeme =
                    952:                                        d_es_processus;
                    953:                                return;
                    954:                            }
                    955:                        }
                    956: 
                    957:                        (*s_etat_processus).erreur_systeme =
                    958:                                d_es_erreur_fichier;
                    959:                        return;
                    960:                    }
                    961: 
                    962:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                    963:                    {
                    964:                        if (errno != EINTR)
                    965:                        {
                    966:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                    967:                            return;
                    968:                        }
                    969:                    }
                    970:                }
                    971:                else if ((*((struct_socket *) (*s_objet_argument_1).objet))
                    972:                        .domaine == PF_INET)
                    973:                {
                    974:                    if (sscanf((*((struct_socket *)
                    975:                            (*s_objet_argument_1).objet))
                    976:                            .adresse_distante, "%d.%d.%d.%d(%d)",
                    977:                            &(adresse[0]), &(adresse[1]), &(adresse[2]),
                    978:                            &(adresse[3]), &port) == 5)
                    979:                    { // Adresse IPv4
                    980:                        calcul_adresse = 0;
                    981:                        for(i = 0; i < 4; calcul_adresse =
                    982:                                (256 * calcul_adresse) + adresse[i++]);
                    983: 
                    984:                        memset(&adresse_ipv4, 0, sizeof(adresse_ipv4));
                    985:                        adresse_ipv4.sin_family = AF_INET;
                    986:                        adresse_ipv4.sin_port = htons(port);
                    987:                        adresse_ipv4.sin_addr.s_addr = htonl(calcul_adresse);
                    988: 
                    989:                        if (sem_post(&((*s_etat_processus)
                    990:                                .semaphore_fork)) != 0)
                    991:                        {
                    992:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                    993:                            return;
                    994:                        }
                    995: 
                    996:                        if (sendto((*((struct_socket *)
                    997:                                (*s_objet_argument_1).objet)).socket, chaine,
                    998:                                strlen(chaine), 0, (struct sockaddr *)
                    999:                                &adresse_ipv4, sizeof(adresse_ipv4)) < 0)
                   1000:                        {
                   1001:                            while(sem_wait(&((*s_etat_processus)
                   1002:                                    .semaphore_fork)) == -1)
                   1003:                            {
                   1004:                                if (errno != EINTR)
                   1005:                                {
                   1006:                                    (*s_etat_processus).erreur_systeme =
                   1007:                                            d_es_processus;
                   1008:                                    return;
                   1009:                                }
                   1010:                            }
                   1011: 
                   1012:                            (*s_etat_processus).erreur_systeme =
                   1013:                                    d_es_erreur_fichier;
                   1014:                            return;
                   1015:                        }
                   1016: 
                   1017:                        while(sem_wait(&((*s_etat_processus)
                   1018:                                .semaphore_fork)) == -1)
                   1019:                        {
                   1020:                            if (errno != EINTR)
                   1021:                            {
                   1022:                                (*s_etat_processus).erreur_systeme =
                   1023:                                        d_es_processus;
                   1024:                                return;
                   1025:                            }
                   1026:                        }
                   1027:                    }
                   1028:                    else
                   1029:                    {
                   1030:                        liberation(s_etat_processus, s_objet_argument_1);
                   1031:                        liberation(s_etat_processus, s_objet_argument_2);
                   1032: 
                   1033:                        (*s_etat_processus).erreur_execution =
                   1034:                                d_ex_erreur_parametre_fichier;
                   1035:                        return;
                   1036:                    }
                   1037:                }
                   1038:                else if ((*((struct_socket *) (*s_objet_argument_1).objet))
                   1039:                        .domaine == PF_INET6)
                   1040:                {
                   1041:                    if (sscanf((*((struct_socket *) (*s_objet_argument_1)
                   1042:                            .objet)).adresse_distante, "%X:%X:%X:%X:%X:"
                   1043:                            "%X:%X:%X:%X:%X:%X:%X:%X:%X:%X:%X(%d)",
                   1044:                            &(adresse[0]), &(adresse[1]), &(adresse[2]),
                   1045:                            &(adresse[3]), &(adresse[4]), &(adresse[5]),
                   1046:                            &(adresse[6]), &(adresse[7]), &(adresse[8]),
                   1047:                            &(adresse[9]), &(adresse[10]), &(adresse[11]),
                   1048:                            &(adresse[12]), &(adresse[13]), &(adresse[14]),
                   1049:                            &(adresse[15]), &port)== 17)
                   1050:                    { // Adresse IPv6
                   1051:                        memset(&adresse_ipv6, 0, sizeof(adresse_ipv6));
                   1052:                        adresse_ipv6.sin6_family = AF_INET6;
                   1053:                        adresse_ipv6.sin6_port = htons((uint16_t) port);
                   1054: 
                   1055:                        for(i = 0; i < 16;
                   1056:                                adresse_ipv6.sin6_addr.s6_addr[i] =
                   1057:                                adresse[i], i++);
                   1058: 
                   1059:                        if (sem_post(&((*s_etat_processus)
                   1060:                                .semaphore_fork)) != 0)
                   1061:                        {
                   1062:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1063:                            return;
                   1064:                        }
                   1065: 
                   1066:                        if (sendto((*((struct_socket *)
                   1067:                                (*s_objet_argument_1).objet)).socket, chaine,
                   1068:                                strlen(chaine), 0, (struct sockaddr *)
                   1069:                                &adresse_ipv6, sizeof(adresse_ipv6)) < 0)
                   1070:                        {
                   1071:                            while(sem_wait(&((*s_etat_processus)
                   1072:                                    .semaphore_fork)) == -1)
                   1073:                            {
                   1074:                                if (errno != EINTR)
                   1075:                                {
                   1076:                                    (*s_etat_processus).erreur_systeme =
                   1077:                                            d_es_processus;
                   1078:                                    return;
                   1079:                                }
                   1080:                            }
                   1081: 
                   1082:                            (*s_etat_processus).erreur_systeme =
                   1083:                                    d_es_erreur_fichier;
                   1084:                            return;
                   1085:                        }
                   1086: 
                   1087:                        while(sem_wait(&((*s_etat_processus)
                   1088:                                .semaphore_fork)) == -1)
                   1089:                        {
                   1090:                            if (errno != EINTR)
                   1091:                            {
                   1092:                                (*s_etat_processus).erreur_systeme =
                   1093:                                        d_es_processus;
                   1094:                                return;
                   1095:                            }
                   1096:                        }
                   1097:                    }
                   1098:                    else
                   1099:                    {
                   1100:                        liberation(s_etat_processus, s_objet_argument_1);
                   1101:                        liberation(s_etat_processus, s_objet_argument_2);
                   1102: 
                   1103:                        (*s_etat_processus).erreur_execution =
                   1104:                                d_ex_erreur_parametre_fichier;
                   1105:                        return;
                   1106:                    }
                   1107:                }
                   1108:                else 
                   1109:                {
                   1110:                    liberation(s_etat_processus, s_objet_argument_1);
                   1111:                    liberation(s_etat_processus, s_objet_argument_2);
                   1112: 
                   1113:                    (*s_etat_processus).erreur_execution =
                   1114:                            d_ex_erreur_parametre_fichier;
                   1115:                    return;
                   1116:                }
                   1117:            }
                   1118: 
                   1119:            free(chaine);
                   1120:        }
                   1121:        else if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire
                   1122:                == 'Y')
                   1123:        {
                   1124:            /*
                   1125:             * Sockets non formatées
                   1126:             */
                   1127:        }
                   1128:        else
                   1129:        {
                   1130:            /*
                   1131:             *  Sockets de type FLOW
                   1132:             */
                   1133:        }
                   1134:    }
                   1135:    else
                   1136:    {
                   1137:        liberation(s_etat_processus, s_objet_argument_2);
                   1138:        liberation(s_etat_processus, s_objet_argument_1);
                   1139: 
                   1140:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1141:        return;
                   1142:    }
                   1143: 
                   1144:    liberation(s_etat_processus, s_objet_argument_2);
                   1145:    liberation(s_etat_processus, s_objet_argument_1);
                   1146: 
                   1147:    return;
                   1148: }
                   1149: 
                   1150: 
                   1151: /*
                   1152: ================================================================================
                   1153:   Fonction 'wflock'
                   1154: ================================================================================
                   1155:   Entrées : pointeur sur une structure struct_processus
                   1156: --------------------------------------------------------------------------------
                   1157:   Sorties :
                   1158: --------------------------------------------------------------------------------
                   1159:   Effets de bord : néant
                   1160: ================================================================================
                   1161: */
                   1162: 
                   1163: void
                   1164: instruction_wflock(struct_processus *s_etat_processus)
                   1165: {
                   1166:    logical1                    drapeau;
                   1167: 
                   1168:    struct flock                lock;
                   1169: 
                   1170:    struct timespec             attente;
                   1171: 
1.5       bertrand 1172:    struct_descripteur_fichier  *descripteur;
                   1173: 
1.1       bertrand 1174:    struct_objet                *s_objet_argument_1;
                   1175:    struct_objet                *s_objet_argument_2;
                   1176: 
                   1177:    unsigned char               *chaine;
                   1178:    unsigned char               registre_instruction_valide;
                   1179: 
                   1180:    attente.tv_sec = 0;
                   1181:    attente.tv_nsec = GRANULARITE_us * 1000;
                   1182: 
                   1183:    (*s_etat_processus).erreur_execution = d_ex;
                   1184: 
                   1185:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1186:    {
                   1187:        printf("\n  WFLOCK ");
                   1188:        
                   1189:        if ((*s_etat_processus).langue == 'F')
                   1190:        {
                   1191:            printf("(attente du positionnement d'un verrou sur un fichier)"
                   1192:                    "\n\n");
                   1193:        }
                   1194:        else
                   1195:        {
                   1196:            printf("(wait for file lock)\n\n");
                   1197:        }
                   1198: 
                   1199:        printf("    2: %s\n", d_FCH);
                   1200:        printf("    1: %s (READ/WRITE/NONE)\n", d_CHN);
                   1201: 
                   1202:        return;
                   1203:    }
                   1204:    else if ((*s_etat_processus).test_instruction == 'Y')
                   1205:    {
                   1206:        (*s_etat_processus).nombre_arguments = -1;
                   1207:        return;
                   1208:    }
                   1209: 
                   1210:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1211:    {
                   1212:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                   1213:        {
                   1214:            return;
                   1215:        }
                   1216:    }
                   1217: 
                   1218:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1219:            &s_objet_argument_1) == d_erreur)
                   1220:    {
                   1221:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1222:        return;
                   1223:    }
                   1224: 
                   1225:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1226:            &s_objet_argument_2) == d_erreur)
                   1227:    {
                   1228:        liberation(s_etat_processus, s_objet_argument_1);
                   1229: 
                   1230:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1231:        return;
                   1232:    }
                   1233: 
                   1234:    if (((*s_objet_argument_2).type == FCH) &&
                   1235:            ((*s_objet_argument_1).type == CHN))
                   1236:    {
                   1237:        drapeau = d_faux;
                   1238: 
                   1239:        do
                   1240:        {
                   1241:            if ((chaine = conversion_majuscule((unsigned char *)
                   1242:                    (*s_objet_argument_1).objet)) == NULL)
                   1243:            {
                   1244:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1245:                return;
                   1246:            }
                   1247: 
                   1248:            if (strcmp(chaine, "WRITE") == 0)
                   1249:            {
                   1250:                lock.l_type = F_WRLCK;
                   1251:            }
                   1252:            else if (strcmp(chaine, "READ") == 0)
                   1253:            {
                   1254:                lock.l_type = F_RDLCK;
                   1255:            }
                   1256:            else if (strcmp(chaine, "NONE") == 0)
                   1257:            {
                   1258:                lock.l_type = F_UNLCK;
                   1259:            }
                   1260:            else
                   1261:            {
                   1262:                free(chaine);
                   1263: 
                   1264:                liberation(s_etat_processus, s_objet_argument_1);
                   1265:                liberation(s_etat_processus, s_objet_argument_2);
                   1266: 
                   1267:                (*s_etat_processus).erreur_execution = d_ex_verrou_indefini;
                   1268:                return;
                   1269:            }
                   1270: 
                   1271:            free(chaine);
                   1272: 
                   1273:            lock.l_whence = SEEK_SET;
                   1274:            lock.l_start = 0;
                   1275:            lock.l_len = 0;
                   1276:            lock.l_pid = getpid();
                   1277: 
                   1278:            if ((descripteur = descripteur_fichier(s_etat_processus,
                   1279:                    (struct_fichier *) (*s_objet_argument_2).objet)) == NULL)
                   1280:            {
                   1281:                return;
                   1282:            }
                   1283: 
1.5       bertrand 1284:            if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
                   1285:                    == -1)
1.1       bertrand 1286:            {
                   1287:                liberation(s_etat_processus, s_objet_argument_1);
                   1288:                liberation(s_etat_processus, s_objet_argument_2);
                   1289: 
                   1290:                (*s_etat_processus).erreur_execution = d_ex_fichier_verrouille;
                   1291:                return;
                   1292:            }
                   1293: 
                   1294:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1295:            {
                   1296:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1297:                return;
                   1298:            }
                   1299: 
                   1300:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   1301:            {
                   1302:                if (errno != EINTR)
                   1303:                {
                   1304:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1305:                    return;
                   1306:                }
                   1307:            }
                   1308: 
                   1309:            if (lock.l_type == F_UNLCK)
                   1310:            {
                   1311:                drapeau = d_vrai;
                   1312:            }
                   1313:            else
                   1314:            {
                   1315:                if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   1316:                {
                   1317:                    affectation_interruptions_logicielles(s_etat_processus);
                   1318:                }
                   1319: 
                   1320:                if ((*s_etat_processus).nombre_interruptions_en_queue
                   1321:                        != 0)
                   1322:                {
                   1323:                    registre_instruction_valide =
                   1324:                            (*s_etat_processus).instruction_valide;
                   1325:                    traitement_interruptions_logicielles(
                   1326:                            s_etat_processus);
                   1327:                    (*s_etat_processus).instruction_valide =
                   1328:                            registre_instruction_valide;
                   1329:                }
                   1330: 
                   1331:                nanosleep(&attente, NULL);
                   1332:                scrutation_injection(s_etat_processus);
                   1333: 
                   1334:                INCR_GRANULARITE(attente.tv_nsec);
                   1335:            }
                   1336:        } while((drapeau == d_faux) && ((*s_etat_processus)
                   1337:                .var_volatile_requete_arret != -1));
                   1338:    }
                   1339:    else
                   1340:    {
                   1341:        liberation(s_etat_processus, s_objet_argument_1);
                   1342:        liberation(s_etat_processus, s_objet_argument_2);
                   1343: 
                   1344:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1345:        return;
                   1346:    }
                   1347: 
                   1348:    return;
                   1349: }
                   1350: 
                   1351: 
                   1352: /*
                   1353: ================================================================================
                   1354:   Fonction 'wfproc'
                   1355: ================================================================================
                   1356:   Entrées : pointeur sur une structure struct_processus
                   1357: --------------------------------------------------------------------------------
                   1358:   Sorties :
                   1359: --------------------------------------------------------------------------------
                   1360:   Effets de bord : néant
                   1361: ================================================================================
                   1362: */
                   1363: 
                   1364: void
                   1365: instruction_wfproc(struct_processus *s_etat_processus)
                   1366: {
                   1367:    logical1                    drapeau_fin;
                   1368: 
                   1369:    struct_liste_chainee        *l_element_courant;
                   1370: 
                   1371:    struct_objet                *s_objet_argument;
                   1372: 
                   1373:    struct timespec             attente;
                   1374: 
                   1375:    unsigned char               registre_instruction_valide;
                   1376: 
                   1377:    (*s_etat_processus).erreur_execution = d_ex;
                   1378: 
                   1379:    attente.tv_sec = 0;
                   1380:    attente.tv_nsec = GRANULARITE_us * 1000;
                   1381: 
                   1382:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1383:    {
                   1384:        printf("\n  WFPROC ");
                   1385: 
                   1386:        if ((*s_etat_processus).langue == 'F')
                   1387:        {
                   1388:            printf("(attente de la fin d'un processus fils)\n\n");
                   1389:        }
                   1390:        else
                   1391:        {
                   1392:            printf("(wait for child process end)\n\n");
                   1393:        }
                   1394: 
                   1395:        printf("    1: %s\n", d_PRC);
                   1396: 
                   1397:        return;
                   1398:    }
                   1399:    else if ((*s_etat_processus).test_instruction == 'Y')
                   1400:    {
                   1401:        (*s_etat_processus).nombre_arguments = -1;
                   1402:        return;
                   1403:    }
                   1404: 
                   1405:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1406:    {
                   1407:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   1408:        {
                   1409:            return;
                   1410:        }
                   1411:    }
                   1412: 
                   1413:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1414:            &s_objet_argument) == d_erreur)
                   1415:    {
                   1416:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1417:        return;
                   1418:    }
                   1419: 
                   1420:    if ((*s_objet_argument).type == PRC)
                   1421:    {
                   1422:        drapeau_fin = d_faux;
                   1423: 
                   1424:        if ((*s_etat_processus).profilage == d_vrai)
                   1425:        {
                   1426:            profilage(s_etat_processus, "Interprocess or interthread "
                   1427:                    "communications (WFPROC)");
                   1428: 
                   1429:            if ((*s_etat_processus).erreur_systeme != d_es)
                   1430:            {
                   1431:                return;
                   1432:            }
                   1433:        }
                   1434: 
                   1435:        if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   1436:        {
                   1437:            if ((*s_etat_processus).profilage == d_vrai)
                   1438:            {
                   1439:                profilage(s_etat_processus, NULL);
                   1440:            }
                   1441: 
                   1442:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1443:            return;
                   1444:        }
                   1445: 
                   1446:        while(drapeau_fin == d_faux)
                   1447:        {
                   1448:            l_element_courant = (struct_liste_chainee *)
                   1449:                    (*s_etat_processus).l_base_pile_processus;
                   1450: 
                   1451:            while(l_element_courant != NULL)
                   1452:            {
                   1453:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   1454:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   1455:                {
                   1456:                    if ((*(*((struct_processus_fils *)
                   1457:                            (*s_objet_argument).objet)).thread)
                   1458:                            .processus_detache == d_vrai)
                   1459:                    {
                   1460:                        if ((*(*((struct_processus_fils *)
                   1461:                                (*(*l_element_courant)
                   1462:                                .donnee).objet)).thread).pid ==
                   1463:                                (*(*((struct_processus_fils *)
                   1464:                                (*s_objet_argument).objet)).thread).pid)
                   1465:                        {
                   1466:                            break;
                   1467:                        }
                   1468:                    }
                   1469:                }
                   1470:                else
                   1471:                {
                   1472:                    if ((*(*((struct_processus_fils *)
                   1473:                            (*s_objet_argument).objet)).thread)
                   1474:                            .processus_detache == d_faux)
                   1475:                    {
                   1476:                        if ((pthread_equal((*(*((struct_processus_fils *)
                   1477:                                (*(*l_element_courant).donnee).objet)).thread)
                   1478:                                .tid, (*(*((struct_processus_fils *)
                   1479:                                (*s_objet_argument).objet)).thread).tid) != 0)
                   1480:                                && ((*(*((struct_processus_fils *)
                   1481:                                (*(*l_element_courant).donnee).objet)).thread)
                   1482:                                .pid == (*(*((struct_processus_fils *)
                   1483:                                (*s_objet_argument).objet)).thread).pid))
                   1484:                        {
                   1485:                            break;
                   1486:                        }
                   1487:                    }
                   1488:                }
                   1489: 
                   1490:                l_element_courant = (*l_element_courant).suivant;
                   1491:            }
                   1492: 
                   1493:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   1494:            {
                   1495:                if ((*s_etat_processus).profilage == d_vrai)
                   1496:                {
                   1497:                    profilage(s_etat_processus, NULL);
                   1498:                }
                   1499: 
                   1500:                if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   1501:                {
                   1502:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1503:                    return;
                   1504:                }
                   1505: 
                   1506:                liberation(s_etat_processus, s_objet_argument);
                   1507:                return;
                   1508:            }
                   1509: 
                   1510:            if (l_element_courant == NULL)
                   1511:            {
                   1512:                /*
                   1513:                 * Si l_element_courant vaut NULL, le processus n'existe plus.
                   1514:                 */
                   1515: 
                   1516:                drapeau_fin = d_vrai;
                   1517:            }
                   1518:            else
                   1519:            {
                   1520:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   1521:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   1522:                {
                   1523:                    if (kill((*(*((struct_processus_fils *)
                   1524:                            (*(*l_element_courant).donnee).objet)).thread).pid,
                   1525:                            0) != 0)
                   1526:                    {
                   1527:                        drapeau_fin = d_vrai;
                   1528:                    }
                   1529:                    else
                   1530:                    {
                   1531:                        drapeau_fin = d_faux;
                   1532:                    }
                   1533:                }
                   1534:                else
                   1535:                {
                   1536:                    if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
                   1537:                            (*(*l_element_courant).donnee).objet)).thread)
                   1538:                            .mutex)) != 0)
                   1539:                    {
                   1540:                        if ((*s_etat_processus).profilage == d_vrai)
                   1541:                        {
                   1542:                            profilage(s_etat_processus, NULL);
                   1543:                        }
                   1544: 
                   1545:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1546:                        return;
                   1547:                    }
                   1548: 
                   1549:                    if ((*(*((struct_processus_fils *)
                   1550:                            (*(*l_element_courant).donnee).objet)).thread)
                   1551:                            .thread_actif == d_faux)
                   1552:                    {
                   1553:                        drapeau_fin = d_vrai;
                   1554:                    }
                   1555:                    else
                   1556:                    {
                   1557:                        drapeau_fin = d_faux;
                   1558:                    }
                   1559: 
                   1560:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   1561:                            (*(*l_element_courant).donnee).objet)).thread)
                   1562:                            .mutex)) != 0)
                   1563:                    {
                   1564:                        if ((*s_etat_processus).profilage == d_vrai)
                   1565:                        {
                   1566:                            profilage(s_etat_processus, NULL);
                   1567:                        }
                   1568: 
                   1569:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1570:                        return;
                   1571:                    }
                   1572:                }
                   1573: 
                   1574:                if (drapeau_fin == d_faux)
                   1575:                {
                   1576:                    /*
                   1577:                     * Le processus n'est pas terminé
                   1578:                     */
                   1579: 
                   1580:                    if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   1581:                    {
                   1582:                        if ((*s_etat_processus).profilage == d_vrai)
                   1583:                        {
                   1584:                            profilage(s_etat_processus, NULL);
                   1585:                        }
                   1586: 
                   1587:                        (*s_etat_processus).erreur_systeme =
                   1588:                                d_es_processus;
                   1589:                        return;
                   1590:                    }
                   1591: 
                   1592:                    if ((*s_etat_processus).nombre_interruptions_non_affectees
                   1593:                            != 0)
                   1594:                    {
                   1595:                        affectation_interruptions_logicielles(s_etat_processus);
                   1596:                    }
                   1597: 
                   1598:                    if ((*s_etat_processus).nombre_interruptions_en_queue
                   1599:                            != 0)
                   1600:                    {
                   1601:                        registre_instruction_valide =
                   1602:                                (*s_etat_processus).instruction_valide;
                   1603:                        traitement_interruptions_logicielles(
                   1604:                                s_etat_processus);
                   1605:                        (*s_etat_processus).instruction_valide =
                   1606:                                registre_instruction_valide;
                   1607:                    }
                   1608: 
                   1609:                    if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1610:                    {
                   1611:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1612:                        return;
                   1613:                    }
                   1614: 
                   1615:                    nanosleep(&attente, NULL);
                   1616: 
                   1617:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   1618:                    {
                   1619:                        if (errno != EINTR)
                   1620:                        {
                   1621:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1622:                            return;
                   1623:                        }
                   1624:                    }
                   1625: 
                   1626:                    scrutation_injection(s_etat_processus);
                   1627: 
                   1628:                    if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   1629:                    {
                   1630:                        if ((*s_etat_processus).profilage == d_vrai)
                   1631:                        {
                   1632:                            profilage(s_etat_processus, NULL);
                   1633:                        }
                   1634: 
                   1635:                        (*s_etat_processus).erreur_systeme =
                   1636:                                d_es_processus;
                   1637:                        return;
                   1638:                    }
                   1639:                }
                   1640:            }
                   1641: 
                   1642:            INCR_GRANULARITE(attente.tv_nsec);
                   1643:        }
                   1644: 
                   1645:        if ((*s_etat_processus).profilage == d_vrai)
                   1646:        {
                   1647:            profilage(s_etat_processus, NULL);
                   1648:        }
                   1649: 
                   1650:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   1651:        {
                   1652:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1653:            return;
                   1654:        }
                   1655:    }
                   1656:    else
                   1657:    {
                   1658:        liberation(s_etat_processus, s_objet_argument);
                   1659: 
                   1660:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1661:        return;
                   1662:    }
                   1663: 
                   1664:    liberation(s_etat_processus, s_objet_argument);
                   1665: 
                   1666:    return;
                   1667: }
                   1668: 
                   1669: 
                   1670: /*
                   1671: ================================================================================
                   1672:   Fonction 'wfdata'
                   1673: ================================================================================
                   1674:   Entrées : pointeur sur une structure struct_processus
                   1675: --------------------------------------------------------------------------------
                   1676:   Sorties :
                   1677: --------------------------------------------------------------------------------
                   1678:   Effets de bord : néant
                   1679: ================================================================================
                   1680: */
                   1681: 
                   1682: void
                   1683: instruction_wfdata(struct_processus *s_etat_processus)
                   1684: {
                   1685:    logical1                    drapeau_fin;
                   1686: 
                   1687:    struct_liste_chainee        *l_element_courant;
                   1688: 
                   1689:    struct_objet                *s_objet_argument;
                   1690: 
                   1691:    struct timespec             attente;
                   1692: 
                   1693:    unsigned char               registre_instruction_valide;
                   1694: 
                   1695:    (*s_etat_processus).erreur_execution = d_ex;
                   1696: 
                   1697:    attente.tv_sec = 0;
                   1698:    attente.tv_nsec = GRANULARITE_us * 1000;
                   1699: 
                   1700:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1701:    {
                   1702:        printf("\n  WFDATA ");
                   1703: 
                   1704:        if ((*s_etat_processus).langue == 'F')
                   1705:        {
                   1706:            printf("(attente de données d'un processus fils)\n\n");
                   1707:        }
                   1708:        else
                   1709:        {
                   1710:            printf("(wait for data from child process)\n\n");
                   1711:        }
                   1712: 
                   1713:        printf("    1: %s\n", d_PRC);
                   1714: 
                   1715:        return;
                   1716:    }
                   1717:    else if ((*s_etat_processus).test_instruction == 'Y')
                   1718:    {
                   1719:        (*s_etat_processus).nombre_arguments = -1;
                   1720:        return;
                   1721:    }
                   1722: 
                   1723:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1724:    {
                   1725:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   1726:        {
                   1727:            return;
                   1728:        }
                   1729:    }
                   1730: 
                   1731:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1732:            &s_objet_argument) == d_erreur)
                   1733:    {
                   1734:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1735:        return;
                   1736:    }
                   1737: 
                   1738:    if ((*s_objet_argument).type == PRC)
                   1739:    {
                   1740:        drapeau_fin = d_faux;
                   1741: 
                   1742:        if ((*s_etat_processus).profilage == d_vrai)
                   1743:        {
                   1744:            profilage(s_etat_processus, "Interprocess or interthread "
                   1745:                    "communications (WFDATA)");
                   1746: 
                   1747:            if ((*s_etat_processus).erreur_systeme != d_es)
                   1748:            {
                   1749:                return;
                   1750:            }
                   1751:        }
                   1752: 
                   1753:        if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   1754:        {
                   1755:            if ((*s_etat_processus).profilage == d_vrai)
                   1756:            {
                   1757:                profilage(s_etat_processus, NULL);
                   1758:            }
                   1759: 
                   1760:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1761:            return;
                   1762:        }
                   1763: 
                   1764:        while(drapeau_fin == d_faux)
                   1765:        {
                   1766:            l_element_courant = (struct_liste_chainee *)
                   1767:                    (*s_etat_processus).l_base_pile_processus;
                   1768: 
                   1769:            while(l_element_courant != NULL)
                   1770:            {
                   1771:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   1772:                        .donnee).objet)).thread).processus_detache == d_vrai)
                   1773:                {
                   1774:                    if (((*(*((struct_processus_fils *) (*(*l_element_courant)
                   1775:                            .donnee).objet)).thread).pid ==
                   1776:                            (*(*((struct_processus_fils *)
                   1777:                            (*s_objet_argument).objet)).thread).pid)
                   1778:                            && ((*(*((struct_processus_fils *)
                   1779:                            (*s_objet_argument).objet)).thread)
                   1780:                            .processus_detache == d_vrai))
                   1781:                    {
                   1782:                        break;
                   1783:                    }
                   1784:                }
                   1785:                else
                   1786:                {
                   1787:                    if ((pthread_equal((*(*((struct_processus_fils *)
                   1788:                            (*(*l_element_courant).donnee).objet)).thread).tid,
                   1789:                            (*(*((struct_processus_fils *) (*s_objet_argument)
                   1790:                            .objet)).thread).tid) != 0) &&
                   1791:                            ((*(*((struct_processus_fils *)
                   1792:                            (*(*l_element_courant).donnee).objet)).thread).pid
                   1793:                            == (*(*((struct_processus_fils *)
                   1794:                            (*s_objet_argument).objet)).thread).pid) &&
                   1795:                            ((*(*((struct_processus_fils *)
                   1796:                            (*s_objet_argument).objet)).thread)
                   1797:                            .processus_detache == d_faux))
                   1798:                    {
                   1799:                        break;
                   1800:                    }
                   1801:                }
                   1802: 
                   1803:                l_element_courant = (*l_element_courant).suivant;
                   1804:            }
                   1805: 
                   1806:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   1807:            {
                   1808:                if ((*s_etat_processus).profilage == d_vrai)
                   1809:                {
                   1810:                    profilage(s_etat_processus, NULL);
                   1811:                }
                   1812: 
                   1813:                if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   1814:                {
                   1815:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1816:                    return;
                   1817:                }
                   1818: 
                   1819:                liberation(s_etat_processus, s_objet_argument);
                   1820:                return;
                   1821:            }
                   1822: 
                   1823:            if (l_element_courant != NULL)
                   1824:            {
                   1825:                if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
                   1826:                        (*(*l_element_courant).donnee).objet)).thread).mutex))
                   1827:                        != 0)
                   1828:                {
                   1829:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   1830:                    return;
                   1831:                }
                   1832: 
                   1833:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   1834:                        .donnee).objet)).thread).nombre_objets_dans_pipe != 0)
                   1835:                {
                   1836:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   1837:                            (*(*l_element_courant).donnee).objet)).thread)
                   1838:                            .mutex)) != 0)
                   1839:                    {
                   1840:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1841:                        return;
                   1842:                    }
                   1843: 
                   1844:                    drapeau_fin = d_vrai;
                   1845:                }
                   1846:                else
                   1847:                {
                   1848:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   1849:                            (*(*l_element_courant).donnee).objet)).thread)
                   1850:                            .mutex)) != 0)
                   1851:                    {
                   1852:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1853:                        return;
                   1854:                    }
                   1855: 
                   1856:                    if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   1857:                    {
                   1858:                        if ((*s_etat_processus).profilage == d_vrai)
                   1859:                        {
                   1860:                            profilage(s_etat_processus, NULL);
                   1861:                        }
                   1862: 
                   1863:                        (*s_etat_processus).erreur_systeme =
                   1864:                                d_es_processus;
                   1865:                        return;
                   1866:                    }
                   1867: 
                   1868:                    if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   1869:                    {
                   1870:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1871:                        return;
                   1872:                    }
                   1873: 
                   1874:                    nanosleep(&attente, NULL);
                   1875: 
                   1876:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   1877:                    {
                   1878:                        if (errno != EINTR)
                   1879:                        {
                   1880:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1881:                            return;
                   1882:                        }
                   1883:                    }
                   1884: 
                   1885:                    scrutation_injection(s_etat_processus);
                   1886: 
                   1887:                    if ((*s_etat_processus).nombre_interruptions_non_affectees
                   1888:                            != 0)
                   1889:                    {
                   1890:                        affectation_interruptions_logicielles(s_etat_processus);
                   1891:                    }
                   1892: 
                   1893:                    if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   1894:                    {
                   1895:                        registre_instruction_valide =
                   1896:                                (*s_etat_processus).instruction_valide;
                   1897:                        traitement_interruptions_logicielles(s_etat_processus);
                   1898:                        (*s_etat_processus).instruction_valide =
                   1899:                                registre_instruction_valide;
                   1900:                    }
                   1901: 
                   1902:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   1903:                    {
                   1904:                        if ((*s_etat_processus).profilage == d_vrai)
                   1905:                        {
                   1906:                            profilage(s_etat_processus, NULL);
                   1907:                        }
                   1908: 
                   1909:                        return;
                   1910:                    }
                   1911: 
                   1912:                    if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   1913:                    {
                   1914:                        if ((*s_etat_processus).profilage == d_vrai)
                   1915:                        {
                   1916:                            profilage(s_etat_processus, NULL);
                   1917:                        }
                   1918: 
                   1919:                        (*s_etat_processus).erreur_systeme =
                   1920:                                d_es_processus;
                   1921:                        return;
                   1922:                    }
                   1923:                }
                   1924:            }
                   1925:            else
                   1926:            {
                   1927:                drapeau_fin = d_vrai;
                   1928:                (*s_etat_processus).erreur_execution = d_ex_processus;
                   1929:            }
                   1930: 
                   1931:            INCR_GRANULARITE(attente.tv_nsec);
                   1932:        }
                   1933: 
                   1934:        if ((*s_etat_processus).profilage == d_vrai)
                   1935:        {
                   1936:            profilage(s_etat_processus, NULL);
                   1937:        }
                   1938: 
                   1939:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   1940:        {
                   1941:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1942:            return;
                   1943:        }
                   1944:    }
                   1945:    else
                   1946:    {
                   1947:        liberation(s_etat_processus, s_objet_argument);
                   1948: 
                   1949:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1950:        return;
                   1951:    }
                   1952: 
                   1953:    liberation(s_etat_processus, s_objet_argument);
                   1954: 
                   1955:    return;
                   1956: }
                   1957: 
                   1958: 
                   1959: /*
                   1960: ================================================================================
                   1961:   Fonction 'wfsock'
                   1962: ================================================================================
                   1963:   Entrées : pointeur sur une structure struct_processus
                   1964: --------------------------------------------------------------------------------
                   1965:   Sorties :
                   1966: --------------------------------------------------------------------------------
                   1967:   Effets de bord : néant
                   1968: ================================================================================
                   1969: */
                   1970: 
                   1971: void
                   1972: instruction_wfsock(struct_processus *s_etat_processus)
                   1973: {
                   1974:    int                     erreur;
                   1975: 
                   1976:    logical1                drapeau;
                   1977: 
                   1978:    socklen_t               longueur;
                   1979: 
                   1980:    struct_liste_chainee    *l_element_courant;
                   1981: 
                   1982:    struct_objet            *s_objet_argument;
                   1983:    struct_objet            *s_objet_resultat;
                   1984: 
                   1985:    struct sockaddr_in      adresse_ipv4;
                   1986:    struct sockaddr_in6     adresse_ipv6;
                   1987: 
                   1988:    unsigned long           i;
                   1989: 
                   1990:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1991:    {
                   1992:        printf("\n  WFSOCK ");
                   1993: 
                   1994:        if ((*s_etat_processus).langue == 'F')
                   1995:        {
                   1996:            printf("(attente d'une connexion sur une socket)\n\n");
                   1997:        }
                   1998:        else
                   1999:        {
                   2000:            printf("(wait for connection on a socket)\n\n");
                   2001:        }
                   2002: 
                   2003:        printf("    1: %s\n", d_SCK);
                   2004:        printf("->  2: %s\n", d_SCK);
                   2005:        printf("    1: %s\n", d_SCK);
                   2006: 
                   2007:        return;
                   2008:    }
                   2009:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2010:    {
                   2011:        (*s_etat_processus).nombre_arguments = -1;
                   2012:        return;
                   2013:    }
                   2014: 
                   2015:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2016:    {
                   2017:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2018:        {
                   2019:            return;
                   2020:        }
                   2021:    }
                   2022: 
                   2023:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2024:            &s_objet_argument) == d_erreur)
                   2025:    {
                   2026:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2027:        return;
                   2028:    }
                   2029: 
                   2030:    if ((*s_objet_argument).type == SCK)
                   2031:    {
                   2032:        if ((strcmp((*((struct_socket *) (*s_objet_argument).objet)).type,
                   2033:                "STREAM") != 0) && (strcmp((*((struct_socket *)
                   2034:                (*s_objet_argument).objet)).type, "SEQUENTIAL DATAGRAM") != 0))
                   2035:        {
                   2036:            liberation(s_etat_processus, s_objet_argument);
                   2037: 
                   2038:            (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
                   2039:            return;
                   2040:        }
                   2041: 
                   2042:        if ((s_objet_resultat = copie_objet(s_etat_processus, s_objet_argument,
                   2043:                'O')) == NULL)
                   2044:        {
                   2045:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2046:            return;
                   2047:        }
                   2048: 
                   2049:        (*((struct_socket *) (*s_objet_resultat).objet)).socket_en_ecoute = 'N';
                   2050:        (*((struct_socket *) (*s_objet_resultat).objet)).effacement = 'N';
                   2051: 
                   2052:        if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine == PF_INET)
                   2053:        {
                   2054:            longueur = sizeof(adresse_ipv4);
                   2055: 
                   2056:            do
                   2057:            {
                   2058:                drapeau = d_vrai;
                   2059: 
                   2060:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2061:                {
                   2062:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2063:                    return;
                   2064:                }
                   2065: 
                   2066:                if (((*((struct_socket *) (*s_objet_resultat).objet)).socket =
                   2067:                        accept((*((struct_socket *) (*s_objet_argument).objet))
                   2068:                        .socket, (struct sockaddr *) &adresse_ipv4, &longueur))
                   2069:                        < 0)
                   2070:                {
                   2071:                    erreur = errno;
                   2072: 
                   2073:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2074:                    {
                   2075:                        if (errno != EINTR)
                   2076:                        {
                   2077:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2078:                            return;
                   2079:                        }
                   2080:                    }
                   2081: 
                   2082:                    if (erreur != EINTR)
                   2083:                    {
                   2084:                        liberation(s_etat_processus, s_objet_argument);
                   2085:                        liberation(s_etat_processus, s_objet_resultat);
                   2086: 
                   2087:                        (*s_etat_processus).erreur_execution =
                   2088:                                d_ex_erreur_acces_fichier;
                   2089:                        return;
                   2090:                    }
                   2091: 
                   2092:                    scrutation_injection(s_etat_processus);
                   2093: 
                   2094:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2095:                    {
                   2096:                        drapeau = d_vrai;
                   2097:                    }
                   2098:                    else
                   2099:                    {
                   2100:                        drapeau = d_faux;
                   2101:                    }
                   2102:                }
                   2103:                else
                   2104:                {
                   2105:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2106:                    {
                   2107:                        if (errno != EINTR)
                   2108:                        {
                   2109:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2110:                            return;
                   2111:                        }
                   2112:                    }
                   2113:                }
                   2114:            } while(drapeau == d_faux);
                   2115: 
                   2116:            if (((*((struct_socket *) (*s_objet_resultat).objet))
                   2117:                    .adresse_distante = malloc(22 *
                   2118:                    sizeof(unsigned char))) == NULL)
                   2119:            {
                   2120:                (*s_etat_processus).erreur_systeme =
                   2121:                        d_es_allocation_memoire;
                   2122:                return;
                   2123:            }
                   2124: 
                   2125:            sprintf((*((struct_socket *) (*s_objet_resultat).objet))
                   2126:                    .adresse_distante, "%d.%d.%d.%d(%d)",
                   2127:                    (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF,
                   2128:                    (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF,
                   2129:                    (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF,
                   2130:                    ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF,
                   2131:                    ntohs(adresse_ipv4.sin_port));
                   2132:        }
                   2133:        else if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
                   2134:                PF_INET6)
                   2135:        {
                   2136:            longueur = sizeof(adresse_ipv6);
                   2137: 
                   2138:            do
                   2139:            {
                   2140:                drapeau = d_vrai;
                   2141: 
                   2142:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2143:                {
                   2144:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2145:                    return;
                   2146:                }
                   2147: 
                   2148:                if (((*((struct_socket *) (*s_objet_resultat).objet)).socket =
                   2149:                        accept((*((struct_socket *) (*s_objet_argument).objet))
                   2150:                        .socket, (struct sockaddr *) &adresse_ipv6, &longueur))
                   2151:                        < 0)
                   2152:                {
                   2153:                    erreur = errno;
                   2154: 
                   2155:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2156:                    {
                   2157:                        if (errno != EINTR)
                   2158:                        {
                   2159:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2160:                            return;
                   2161:                        }
                   2162:                    }
                   2163: 
                   2164:                    if (erreur != EINTR)
                   2165:                    {
                   2166:                        liberation(s_etat_processus, s_objet_argument);
                   2167:                        liberation(s_etat_processus, s_objet_resultat);
                   2168: 
                   2169:                        (*s_etat_processus).erreur_execution =
                   2170:                                d_ex_erreur_acces_fichier;
                   2171:                        return;
                   2172:                    }
                   2173: 
                   2174:                    scrutation_injection(s_etat_processus);
                   2175: 
                   2176:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2177:                    {
                   2178:                        drapeau = d_vrai;
                   2179:                    }
                   2180:                    else
                   2181:                    {
                   2182:                        drapeau = d_faux;
                   2183:                    }
                   2184:                }
                   2185:                else
                   2186:                {
                   2187:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2188:                    {
                   2189:                        if (errno != EINTR)
                   2190:                        {
                   2191:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2192:                            return;
                   2193:                        }
                   2194:                    }
                   2195:                }
                   2196:            } while(drapeau == d_faux);
                   2197: 
                   2198:            if (((*((struct_socket *) (*s_objet_resultat).objet))
                   2199:                    .adresse_distante = malloc(55 *
                   2200:                    sizeof(unsigned char))) == NULL)
                   2201:            {
                   2202:                (*s_etat_processus).erreur_systeme =
                   2203:                        d_es_allocation_memoire;
                   2204:                return;
                   2205:            }
                   2206: 
                   2207:            (*((struct_socket *) (*s_objet_resultat).objet))
                   2208:                    .adresse_distante = d_code_fin_chaine;
                   2209: 
                   2210:            for(i = 0; i < 16; i++)
                   2211:            {
                   2212:                sprintf((*((struct_socket *) (*s_objet_resultat)
                   2213:                        .objet)).adresse_distante, (i == 0) ? "%s%X" : "%s:%X",
                   2214:                        (*((struct_socket *) (*s_objet_resultat)
                   2215:                        .objet)).adresse_distante,
                   2216:                        adresse_ipv6.sin6_addr.s6_addr[i]);
                   2217:            }
                   2218: 
                   2219:            sprintf((*((struct_socket *) (*s_objet_resultat)
                   2220:                    .objet)).adresse_distante, "%s(%u)",
                   2221:                    (*((struct_socket *) (*s_objet_resultat)
                   2222:                    .objet)).adresse_distante, ntohs(adresse_ipv6.sin6_port));
                   2223:        }
                   2224:        else
                   2225:        {
                   2226:            longueur = 0;
                   2227: 
                   2228:            do
                   2229:            {
                   2230:                drapeau = d_vrai;
                   2231: 
                   2232:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2233:                {
                   2234:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                   2235:                    return;
                   2236:                }
                   2237: 
                   2238:                if (((*((struct_socket *) (*s_objet_resultat).objet)).socket =
                   2239:                        accept((*((struct_socket *) (*s_objet_argument).objet))
                   2240:                        .socket, NULL, &longueur)) < 0)
                   2241:                {
                   2242:                    erreur = errno;
                   2243: 
                   2244:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2245:                    {
                   2246:                        if (errno != EINTR)
                   2247:                        {
                   2248:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2249:                            return;
                   2250:                        }
                   2251:                    }
                   2252: 
                   2253:                    if (erreur != EINTR)
                   2254:                    {
                   2255:                        liberation(s_etat_processus, s_objet_argument);
                   2256:                        liberation(s_etat_processus, s_objet_resultat);
                   2257: 
                   2258:                        (*s_etat_processus).erreur_execution =
                   2259:                                d_ex_erreur_acces_fichier;
                   2260:                        return;
                   2261:                    }
                   2262: 
                   2263:                    scrutation_injection(s_etat_processus);
                   2264: 
                   2265:                    if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2266:                    {
                   2267:                        drapeau = d_vrai;
                   2268:                    }
                   2269:                    else
                   2270:                    {
                   2271:                        drapeau = d_faux;
                   2272:                    }
                   2273:                }
                   2274:                else
                   2275:                {
                   2276:                    while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2277:                    {
                   2278:                        if (errno != EINTR)
                   2279:                        {
                   2280:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2281:                            return;
                   2282:                        }
                   2283:                    }
                   2284:                }
                   2285:            } while(drapeau == d_faux);
                   2286:        }
                   2287: 
                   2288:        // Si accept() renvoie une erreur non récupérée, il ne peut s'agir
                   2289:        // que de EINTR sachant qu'une requête d'arrêt est en court de
                   2290:        // traitement.
                   2291: 
                   2292:        if ((*((struct_socket *) (*s_objet_resultat).objet)).socket >= 0)
                   2293:        {
                   2294:            l_element_courant = (*s_etat_processus).s_sockets;
                   2295: 
                   2296:            if (l_element_courant == NULL)
                   2297:            {
                   2298:                if (((*s_etat_processus).s_sockets =
                   2299:                        allocation_maillon(s_etat_processus)) == NULL)
                   2300:                {
                   2301:                    (*s_etat_processus).erreur_systeme =
                   2302:                            d_es_allocation_memoire;
                   2303:                    return;
                   2304:                }
                   2305: 
                   2306:                (*(*s_etat_processus).s_sockets).suivant = NULL;
                   2307:                l_element_courant = (*s_etat_processus).s_sockets;
                   2308:            }
                   2309:            else
                   2310:            {
                   2311:                /*
                   2312:                 * Ajout d'un élément à la fin de la liste chaînée
                   2313:                 */
                   2314: 
                   2315:                while((*l_element_courant).suivant != NULL)
                   2316:                {
                   2317:                    l_element_courant = (*l_element_courant).suivant;
                   2318:                }
                   2319: 
                   2320:                if (((*l_element_courant).suivant =
                   2321:                        allocation_maillon(s_etat_processus)) == NULL)
                   2322:                {
                   2323:                    (*s_etat_processus).erreur_systeme =
                   2324:                            d_es_allocation_memoire;
                   2325:                    return;
                   2326:                }
                   2327: 
                   2328:                l_element_courant = (*l_element_courant).suivant;
                   2329:                (*l_element_courant).suivant = NULL;
                   2330:            }
                   2331: 
                   2332:            if (((*l_element_courant).donnee = copie_objet(s_etat_processus,
                   2333:                    s_objet_resultat, 'O')) == NULL)
                   2334:            {
                   2335:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2336:                return;
                   2337:            }
                   2338:        }
                   2339: 
                   2340:        if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2341:                s_objet_argument) == d_erreur)
                   2342:        {
                   2343:            return;
                   2344:        }
                   2345: 
                   2346:        if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2347:                s_objet_resultat) == d_erreur)
                   2348:        {
                   2349:            return;
                   2350:        }
                   2351:    }
                   2352:    else
                   2353:    {
                   2354:        liberation(s_etat_processus, s_objet_argument);
                   2355: 
                   2356:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2357:        return;
                   2358:    }
                   2359: 
                   2360:    return;
                   2361: }
                   2362: 
                   2363: 
                   2364: /*
                   2365: ================================================================================
                   2366:   Fonction 'wfswi'
                   2367: ================================================================================
                   2368:   Entrées : pointeur sur une structure struct_processus
                   2369: --------------------------------------------------------------------------------
                   2370:   Sorties :
                   2371: --------------------------------------------------------------------------------
                   2372:   Effets de bord : néant
                   2373: ================================================================================
                   2374: */
                   2375: 
                   2376: void
                   2377: instruction_wfswi(struct_processus *s_etat_processus)
                   2378: {
                   2379:    integer8                    interruption;
                   2380: 
                   2381:    logical1                    drapeau_fin;
                   2382: 
                   2383:    struct_objet                *s_objet_argument;
                   2384: 
                   2385:    struct timespec             attente;
                   2386: 
                   2387:    (*s_etat_processus).erreur_execution = d_ex;
                   2388: 
                   2389:    attente.tv_sec = 0;
                   2390:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2391: 
                   2392:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2393:    {
                   2394:        printf("\n  WFSWI ");
                   2395: 
                   2396:        if ((*s_etat_processus).langue == 'F')
                   2397:        {
                   2398:            printf("(attente d'une interruption)\n\n");
                   2399:        }
                   2400:        else
                   2401:        {
                   2402:            printf("(wait for interrupt)\n\n");
                   2403:        }
                   2404: 
                   2405:        printf("    1: %s\n", d_INT);
                   2406: 
                   2407:        return;
                   2408:    }
                   2409:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2410:    {
                   2411:        (*s_etat_processus).nombre_arguments = -1;
                   2412:        return;
                   2413:    }
                   2414: 
                   2415:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2416:    {
                   2417:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   2418:        {
                   2419:            return;
                   2420:        }
                   2421:    }
                   2422: 
                   2423:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2424:            &s_objet_argument) == d_erreur)
                   2425:    {
                   2426:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   2427:        return;
                   2428:    }
                   2429: 
                   2430:    if ((*s_objet_argument).type == INT)
                   2431:    {
                   2432:        drapeau_fin = d_faux;
                   2433: 
                   2434:        interruption = (*((integer8 *) (*s_objet_argument).objet));
                   2435: 
                   2436:        if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
                   2437:        {
                   2438:            liberation(s_etat_processus, s_objet_argument);
                   2439: 
                   2440:            (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
                   2441:            return;
                   2442:        }
                   2443: 
                   2444:        while(drapeau_fin == d_faux)
                   2445:        {
                   2446:            if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2447:            {
                   2448:                liberation(s_etat_processus, s_objet_argument);
                   2449:                return;
                   2450:            }
                   2451: 
                   2452:            if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   2453:            {
                   2454:                affectation_interruptions_logicielles(s_etat_processus);
                   2455:            }
                   2456: 
                   2457:            if ((*s_etat_processus).queue_interruptions[interruption - 1] > 0)
                   2458:            {
                   2459:                drapeau_fin = d_vrai;
                   2460:            }
                   2461:            else
                   2462:            {
                   2463:                nanosleep(&attente, NULL);
                   2464:                scrutation_injection(s_etat_processus);
                   2465:                INCR_GRANULARITE(attente.tv_nsec);
                   2466:            }
                   2467:        }
                   2468:    }
                   2469:    else
                   2470:    {
                   2471:        liberation(s_etat_processus, s_objet_argument);
                   2472: 
                   2473:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2474:        return;
                   2475:    }
                   2476: 
                   2477:    liberation(s_etat_processus, s_objet_argument);
                   2478: 
                   2479:    return;
                   2480: }
                   2481: 
                   2482: 
                   2483: /*
                   2484: ================================================================================
                   2485:   Fonction 'wfpoke'
                   2486: ================================================================================
                   2487:   Entrées : pointeur sur une structure struct_processus
                   2488: --------------------------------------------------------------------------------
                   2489:   Sorties :
                   2490: --------------------------------------------------------------------------------
                   2491:   Effets de bord : néant
                   2492: ================================================================================
                   2493: */
                   2494: 
                   2495: void
                   2496: instruction_wfpoke(struct_processus *s_etat_processus)
                   2497: {
                   2498:    struct timespec             attente;
                   2499: 
                   2500:    unsigned char               registre_instruction_valide;
                   2501: 
                   2502:    (*s_etat_processus).erreur_execution = d_ex;
                   2503: 
                   2504:    attente.tv_sec = 0;
                   2505:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2506: 
                   2507:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2508:    {
                   2509:        printf("\n  WFPOKE ");
                   2510: 
                   2511:        if ((*s_etat_processus).langue == 'F')
                   2512:        {
                   2513:            printf("(attente de données en provenance du processus père)\n\n");
                   2514:            printf("  Aucun argument\n");
                   2515:        }
                   2516:        else
                   2517:        {
                   2518:            printf("(wait for data from parent process)\n\n");
                   2519:            printf("  No argument\n");
                   2520:        }
                   2521: 
                   2522:        return;
                   2523:    }
                   2524:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2525:    {
                   2526:        (*s_etat_processus).nombre_arguments = -1;
                   2527:        return;
                   2528:    }
                   2529: 
                   2530:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2531:    {
                   2532:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                   2533:        {
                   2534:            return;
                   2535:        }
                   2536:    }
                   2537: 
                   2538:    if ((*s_etat_processus).presence_pipes == d_faux)
                   2539:    {
                   2540:        (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
                   2541:        return;
                   2542:    }
                   2543: 
                   2544:    if ((*s_etat_processus).nombre_objets_injectes > 0)
                   2545:    {
                   2546:        return;
                   2547:    }
                   2548: 
                   2549:    if ((*s_etat_processus).profilage == d_vrai)
                   2550:    {
                   2551:        profilage(s_etat_processus, "Interprocess or interthread "
                   2552:                "communications (WFPOKE)");
                   2553: 
                   2554:        if ((*s_etat_processus).erreur_systeme != d_es)
                   2555:        {
                   2556:            return;
                   2557:        }
                   2558:    }
                   2559: 
                   2560:    do
                   2561:    {
                   2562:        if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2563:        {
                   2564:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2565:            return;
                   2566:        }
                   2567: 
                   2568:        nanosleep(&attente, NULL);
                   2569: 
                   2570:        while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2571:        {
                   2572:            if (errno != EINTR)
                   2573:            {
                   2574:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   2575:                return;
                   2576:            }
                   2577:        }
                   2578: 
                   2579:        scrutation_injection(s_etat_processus);
                   2580: 
                   2581:        if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   2582:        {
                   2583:            affectation_interruptions_logicielles(s_etat_processus);
                   2584:        }
                   2585: 
                   2586:        if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   2587:        {
                   2588:            registre_instruction_valide =
                   2589:                    (*s_etat_processus).instruction_valide;
                   2590:            traitement_interruptions_logicielles(s_etat_processus);
                   2591:            (*s_etat_processus).instruction_valide =
                   2592:                    registre_instruction_valide;
                   2593:        }
                   2594: 
                   2595:        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2596:        {
                   2597:            if ((*s_etat_processus).profilage == d_vrai)
                   2598:            {
                   2599:                profilage(s_etat_processus, NULL);
                   2600:            }
                   2601: 
                   2602:            return;
                   2603:        }
                   2604: 
                   2605:        INCR_GRANULARITE(attente.tv_nsec);
                   2606:    } while((*s_etat_processus).nombre_objets_injectes == 0);
                   2607: 
                   2608:    return;
                   2609: }
                   2610: 
                   2611: 
                   2612: /*
                   2613: ================================================================================
                   2614:   Fonction 'wfack'
                   2615: ================================================================================
                   2616:   Entrées : pointeur sur une structure struct_processus
                   2617: --------------------------------------------------------------------------------
                   2618:   Sorties :
                   2619: --------------------------------------------------------------------------------
                   2620:   Effets de bord : néant
                   2621: ================================================================================
                   2622: */
                   2623: 
                   2624: void
                   2625: instruction_wfack(struct_processus *s_etat_processus)
                   2626: {
                   2627:    struct timespec             attente;
                   2628: 
                   2629:    unsigned char               registre_instruction_valide;
                   2630: 
                   2631:    (*s_etat_processus).erreur_execution = d_ex;
                   2632: 
                   2633:    attente.tv_sec = 0;
                   2634:    attente.tv_nsec = GRANULARITE_us * 1000;
                   2635: 
                   2636:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   2637:    {
                   2638:        printf("\n  WFACK ");
                   2639: 
                   2640:        if ((*s_etat_processus).langue == 'F')
                   2641:        {
                   2642:            printf("(attente des acquittements de lecture)\n\n");
                   2643:            printf("  Aucun argument\n");
                   2644:        }
                   2645:        else
                   2646:        {
                   2647:            printf("(wait for reading of data acknowledgement)\n\n");
                   2648:            printf("  No argument\n");
                   2649:        }
                   2650: 
                   2651:        return;
                   2652:    }
                   2653:    else if ((*s_etat_processus).test_instruction == 'Y')
                   2654:    {
                   2655:        (*s_etat_processus).nombre_arguments = -1;
                   2656:        return;
                   2657:    }
                   2658: 
                   2659:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   2660:    {
                   2661:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                   2662:        {
                   2663:            return;
                   2664:        }
                   2665:    }
                   2666: 
                   2667:    if ((*s_etat_processus).presence_pipes == d_faux)
                   2668:    {
                   2669:        (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
                   2670:        return;
                   2671:    }
                   2672: 
                   2673:    if ((*s_etat_processus).profilage == d_vrai)
                   2674:    {
                   2675:        profilage(s_etat_processus, "Interprocess or interthread communications"
                   2676:                " (WFACK)");
                   2677: 
                   2678:        if ((*s_etat_processus).erreur_systeme != d_es)
                   2679:        {
                   2680:            return;
                   2681:        }
                   2682:    }
                   2683: 
                   2684:    while((*s_etat_processus).nombre_objets_envoyes_non_lus != 0)
                   2685:    {
                   2686:        scrutation_injection(s_etat_processus);
                   2687: 
                   2688:        if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
                   2689:        {
                   2690:            affectation_interruptions_logicielles(s_etat_processus);
                   2691:        }
                   2692: 
                   2693:        if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
                   2694:        {
                   2695:            registre_instruction_valide =
                   2696:                    (*s_etat_processus).instruction_valide;
                   2697:            traitement_interruptions_logicielles(s_etat_processus);
                   2698:            (*s_etat_processus).instruction_valide =
                   2699:                    registre_instruction_valide;
                   2700:        }
                   2701: 
                   2702:        if ((*s_etat_processus).var_volatile_requete_arret != 0)
                   2703:        {
                   2704:            if ((*s_etat_processus).profilage == d_vrai)
                   2705:            {
                   2706:                profilage(s_etat_processus, NULL);
                   2707:            }
                   2708: 
                   2709:            return;
                   2710:        }
                   2711: 
                   2712:        if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                   2713:        {
                   2714:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   2715:            return;
                   2716:        }
                   2717: 
                   2718:        nanosleep(&attente, NULL);
                   2719:        INCR_GRANULARITE(attente.tv_nsec);
                   2720: 
                   2721:        while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
                   2722:        {
                   2723:            if (errno != EINTR)
                   2724:            {
                   2725:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   2726:                return;
                   2727:            }
                   2728:        }
                   2729:    }
                   2730: 
                   2731:    if ((*s_etat_processus).profilage == d_vrai)
                   2732:    {
                   2733:        profilage(s_etat_processus, NULL);
                   2734:    }
                   2735: 
                   2736:    return;
                   2737: }
                   2738: 
                   2739: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>