File:  [local] / rpl / src / instructions_w1.c
Revision 1.130: download - view: text, annotated - select for diffs - revision graph
Wed Jan 17 16:57:17 2024 UTC (3 months, 1 week ago) by bertrand
Branches: MAIN
CVS tags: HEAD
En route pour la 4.1.36.

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

CVSweb interface <joel.bertrand@systella.fr>