File:  [local] / rpl / src / instructions_w1.c
Revision 1.5: download - view: text, annotated - select for diffs - revision graph
Sat Mar 6 18:29:07 2010 UTC (14 years, 2 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Tous les noms de fichiers sont maintenant en UTF-8. Le contenu
des fichiers formatés est converti en UTF-8. Ces modifications sont
faites pour avoir un fonctionnement cohérent avec la bibliothèque sqlite.

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

CVSweb interface <joel.bertrand@systella.fr>