File:  [local] / rpl / src / instructions_w1.c
Revision 1.94: download - view: text, annotated - select for diffs - revision graph
Tue Jan 27 14:18:08 2015 UTC (9 years, 3 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_20, HEAD
Ajout d'un allocateur utilisant une mémoire cache.

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

CVSweb interface <joel.bertrand@systella.fr>