File:  [local] / rpl / src / instructions_w1.c
Revision 1.22: download - view: text, annotated - select for diffs - revision graph
Mon Aug 9 13:51:47 2010 UTC (13 years, 8 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Ajout du support des sémaphores SystemV dans le cas où les sémaphores POSIX ne
seraient pas supportés.

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

CVSweb interface <joel.bertrand@systella.fr>