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