File:  [local] / rpl / src / instructions_w1.c
Revision 1.17: download - view: text, annotated - select for diffs - revision graph
Mon Jun 28 14:30:33 2010 UTC (13 years, 10 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Ajout d'un CSTOP implicite au lancement de la fonction ATEXIT pour éviter les
traitements involontaires de plusieurs signaux STOP.

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

CVSweb interface <joel.bertrand@systella.fr>