1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.5
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 pollfd s_poll;
2689:
2690: struct sockaddr_in adresse_ipv4;
2691: # ifdef IPV6
2692: struct sockaddr_in6 adresse_ipv6;
2693: # endif
2694:
2695: unsigned long i;
2696:
2697: if ((*s_etat_processus).affichage_arguments == 'Y')
2698: {
2699: printf("\n WFSOCK ");
2700:
2701: if ((*s_etat_processus).langue == 'F')
2702: {
2703: printf("(attente d'une connexion sur une socket)\n\n");
2704: }
2705: else
2706: {
2707: printf("(wait for connection on a socket)\n\n");
2708: }
2709:
2710: printf(" 1: %s\n", d_SCK);
2711: printf("-> 2: %s\n", d_SCK);
2712: printf(" 1: %s\n", d_SCK);
2713:
2714: return;
2715: }
2716: else if ((*s_etat_processus).test_instruction == 'Y')
2717: {
2718: (*s_etat_processus).nombre_arguments = -1;
2719: return;
2720: }
2721:
2722: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2723: {
2724: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
2725: {
2726: return;
2727: }
2728: }
2729:
2730: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2731: &s_objet_argument) == d_erreur)
2732: {
2733: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2734: return;
2735: }
2736:
2737: if ((*s_objet_argument).type == SCK)
2738: {
2739: if ((strcmp((*((struct_socket *) (*s_objet_argument).objet)).type,
2740: "STREAM") != 0) && (strcmp((*((struct_socket *)
2741: (*s_objet_argument).objet)).type, "SEQUENTIAL DATAGRAM") != 0))
2742: {
2743: // Mode non connecté : l'attente se fait sur un poll()
2744:
2745: if ((s_objet_resultat = copie_objet(s_etat_processus,
2746: s_objet_argument, 'P')) == NULL)
2747: {
2748: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2749: return;
2750: }
2751:
2752: s_poll.fd = (*((struct_socket *) (*s_objet_argument).objet)).socket;
2753: s_poll.events = POLLIN;
2754: s_poll.revents = 0;
2755:
2756: while(poll(&s_poll, 1, -1) < 0)
2757: {
2758: if (errno != EINTR)
2759: {
2760: (*s_etat_processus).erreur_systeme =
2761: d_es_erreur_fichier;
2762: return;
2763: }
2764: }
2765:
2766: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2767: s_objet_argument) == d_erreur)
2768: {
2769: return;
2770: }
2771:
2772: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2773: s_objet_resultat) == d_erreur)
2774: {
2775: return;
2776: }
2777: }
2778: else
2779: {
2780: // Mode connecté
2781:
2782: if ((s_objet_resultat = copie_objet(s_etat_processus,
2783: s_objet_argument, 'O')) == NULL)
2784: {
2785: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2786: return;
2787: }
2788:
2789: (*((struct_socket *) (*s_objet_resultat).objet)).effacement = 'N';
2790: (*((struct_socket *) (*s_objet_resultat).objet)).socket_en_ecoute
2791: = 'N';
2792:
2793: if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
2794: PF_INET)
2795: {
2796: longueur = sizeof(adresse_ipv4);
2797:
2798: do
2799: {
2800: drapeau = d_vrai;
2801:
2802: # ifndef SEMAPHORES_NOMMES
2803: if (sem_post(&((*s_etat_processus).semaphore_fork))
2804: != 0)
2805: # else
2806: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
2807: # endif
2808: {
2809: (*s_etat_processus).erreur_systeme = d_es_processus;
2810: return;
2811: }
2812:
2813: if (((*((struct_socket *) (*s_objet_resultat).objet))
2814: .socket = accept((*((struct_socket *)
2815: (*s_objet_argument).objet)).socket,
2816: (struct sockaddr *) &adresse_ipv4, &longueur))
2817: < 0)
2818: {
2819: erreur = errno;
2820:
2821: # ifndef SEMAPHORES_NOMMES
2822: while(sem_wait(&((*s_etat_processus)
2823: .semaphore_fork)) != 0)
2824: # else
2825: while(sem_wait((*s_etat_processus).semaphore_fork)
2826: != 0)
2827: # endif
2828: {
2829: if (errno != EINTR)
2830: {
2831: (*s_etat_processus).erreur_systeme =
2832: d_es_processus;
2833: return;
2834: }
2835: }
2836:
2837: if (erreur != EINTR)
2838: {
2839: liberation(s_etat_processus, s_objet_argument);
2840: liberation(s_etat_processus, s_objet_resultat);
2841:
2842: (*s_etat_processus).erreur_execution =
2843: d_ex_erreur_acces_fichier;
2844: return;
2845: }
2846:
2847: scrutation_injection(s_etat_processus);
2848:
2849: if ((*s_etat_processus).var_volatile_requete_arret != 0)
2850: {
2851: drapeau = d_vrai;
2852: }
2853: else
2854: {
2855: drapeau = d_faux;
2856: }
2857: }
2858: else
2859: {
2860: # ifndef SEMAPHORES_NOMMES
2861: while(sem_wait(&((*s_etat_processus)
2862: .semaphore_fork)) != 0)
2863: # else
2864: while(sem_wait((*s_etat_processus).semaphore_fork)
2865: != 0)
2866: # endif
2867: {
2868: if (errno != EINTR)
2869: {
2870: (*s_etat_processus).erreur_systeme =
2871: d_es_processus;
2872: return;
2873: }
2874: }
2875: }
2876: } while(drapeau == d_faux);
2877:
2878: if (((*((struct_socket *) (*s_objet_resultat).objet))
2879: .adresse_distante = malloc(22 *
2880: sizeof(unsigned char))) == NULL)
2881: {
2882: (*s_etat_processus).erreur_systeme =
2883: d_es_allocation_memoire;
2884: return;
2885: }
2886:
2887: sprintf((*((struct_socket *) (*s_objet_resultat).objet))
2888: .adresse_distante, "%d.%d.%d.%d(%d)",
2889: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF,
2890: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF,
2891: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF,
2892: ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF,
2893: ntohs(adresse_ipv4.sin_port));
2894: }
2895: else if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
2896: PF_INET6)
2897: {
2898: # ifdef IPV6
2899: longueur = sizeof(adresse_ipv6);
2900:
2901: do
2902: {
2903: drapeau = d_vrai;
2904:
2905: # ifndef SEMAPHORES_NOMMES
2906: if (sem_post(&((*s_etat_processus).semaphore_fork))
2907: != 0)
2908: # else
2909: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
2910: # endif
2911: {
2912: (*s_etat_processus).erreur_systeme = d_es_processus;
2913: return;
2914: }
2915:
2916: if (((*((struct_socket *) (*s_objet_resultat).objet))
2917: .socket = accept((*((struct_socket *)
2918: (*s_objet_argument).objet)).socket,
2919: (struct sockaddr *) &adresse_ipv6, &longueur)) < 0)
2920: {
2921: erreur = errno;
2922:
2923: # ifndef SEMAPHORES_NOMMES
2924: while(sem_wait(&((*s_etat_processus)
2925: .semaphore_fork)) != 0)
2926: # else
2927: while(sem_wait((*s_etat_processus).semaphore_fork)
2928: != 0)
2929: # endif
2930: {
2931: if (errno != EINTR)
2932: {
2933: (*s_etat_processus).erreur_systeme =
2934: d_es_processus;
2935: return;
2936: }
2937: }
2938:
2939: if (erreur != EINTR)
2940: {
2941: liberation(s_etat_processus, s_objet_argument);
2942: liberation(s_etat_processus, s_objet_resultat);
2943:
2944: (*s_etat_processus).erreur_execution =
2945: d_ex_erreur_acces_fichier;
2946: return;
2947: }
2948:
2949: scrutation_injection(s_etat_processus);
2950:
2951: if ((*s_etat_processus).var_volatile_requete_arret != 0)
2952: {
2953: drapeau = d_vrai;
2954: }
2955: else
2956: {
2957: drapeau = d_faux;
2958: }
2959: }
2960: else
2961: {
2962: # ifndef SEMAPHORES_NOMMES
2963: while(sem_wait(&((*s_etat_processus)
2964: .semaphore_fork)) != 0)
2965: # else
2966: while(sem_wait((*s_etat_processus).semaphore_fork)
2967: != 0)
2968: # endif
2969: {
2970: if (errno != EINTR)
2971: {
2972: (*s_etat_processus).erreur_systeme =
2973: d_es_processus;
2974: return;
2975: }
2976: }
2977: }
2978: } while(drapeau == d_faux);
2979:
2980: if (((*((struct_socket *) (*s_objet_resultat).objet))
2981: .adresse_distante = malloc(55 *
2982: sizeof(unsigned char))) == NULL)
2983: {
2984: (*s_etat_processus).erreur_systeme =
2985: d_es_allocation_memoire;
2986: return;
2987: }
2988:
2989: (*((struct_socket *) (*s_objet_resultat).objet))
2990: .adresse_distante = d_code_fin_chaine;
2991:
2992: for(i = 0; i < 16; i++)
2993: {
2994: sprintf((*((struct_socket *) (*s_objet_resultat)
2995: .objet)).adresse_distante, (i == 0) ? "%s%X"
2996: : "%s:%X", (*((struct_socket *) (*s_objet_resultat)
2997: .objet)).adresse_distante,
2998: adresse_ipv6.sin6_addr.s6_addr[i]);
2999: }
3000:
3001: sprintf((*((struct_socket *) (*s_objet_resultat)
3002: .objet)).adresse_distante, "%s(%u)",
3003: (*((struct_socket *) (*s_objet_resultat)
3004: .objet)).adresse_distante,
3005: ntohs(adresse_ipv6.sin6_port));
3006: # else
3007: if ((*s_etat_processus).langue == 'F')
3008: {
3009: printf("+++Attention : Support du protocole"
3010: " IPv6 indisponible\n");
3011: }
3012: else
3013: {
3014: printf("+++Warning : IPv6 support "
3015: "unavailable\n");
3016: }
3017: # endif
3018: }
3019: else
3020: {
3021: longueur = 0;
3022:
3023: do
3024: {
3025: drapeau = d_vrai;
3026:
3027: # ifndef SEMAPHORES_NOMMES
3028: if (sem_post(&((*s_etat_processus).semaphore_fork))
3029: != 0)
3030: # else
3031: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
3032: # endif
3033: {
3034: (*s_etat_processus).erreur_systeme = d_es_processus;
3035: return;
3036: }
3037:
3038: if (((*((struct_socket *) (*s_objet_resultat).objet))
3039: .socket = accept((*((struct_socket *)
3040: (*s_objet_argument).objet)).socket, NULL,
3041: &longueur)) < 0)
3042: {
3043: erreur = errno;
3044:
3045: # ifndef SEMAPHORES_NOMMES
3046: while(sem_wait(&((*s_etat_processus)
3047: .semaphore_fork)) != 0)
3048: # else
3049: while(sem_wait((*s_etat_processus).semaphore_fork)
3050: != 0)
3051: # endif
3052: {
3053: if (errno != EINTR)
3054: {
3055: (*s_etat_processus).erreur_systeme =
3056: d_es_processus;
3057: return;
3058: }
3059: }
3060:
3061: if (erreur != EINTR)
3062: {
3063: liberation(s_etat_processus, s_objet_argument);
3064: liberation(s_etat_processus, s_objet_resultat);
3065:
3066: (*s_etat_processus).erreur_execution =
3067: d_ex_erreur_acces_fichier;
3068: return;
3069: }
3070:
3071: scrutation_injection(s_etat_processus);
3072:
3073: if ((*s_etat_processus).var_volatile_requete_arret != 0)
3074: {
3075: drapeau = d_vrai;
3076: }
3077: else
3078: {
3079: drapeau = d_faux;
3080: }
3081: }
3082: else
3083: {
3084: # ifndef SEMAPHORES_NOMMES
3085: while(sem_wait(&((*s_etat_processus)
3086: .semaphore_fork)) != 0)
3087: # else
3088: while(sem_wait((*s_etat_processus).semaphore_fork)
3089: != 0)
3090: # endif
3091: {
3092: if (errno != EINTR)
3093: {
3094: (*s_etat_processus).erreur_systeme =
3095: d_es_processus;
3096: return;
3097: }
3098: }
3099: }
3100: } while(drapeau == d_faux);
3101: }
3102:
3103: // Si accept() renvoie une erreur non récupérée, il ne peut s'agir
3104: // que de EINTR sachant qu'une requête d'arrêt est en court de
3105: // traitement.
3106:
3107: if ((*((struct_socket *) (*s_objet_resultat).objet)).socket >= 0)
3108: {
3109: l_element_courant = (*s_etat_processus).s_sockets;
3110:
3111: if (l_element_courant == NULL)
3112: {
3113: if (((*s_etat_processus).s_sockets =
3114: allocation_maillon(s_etat_processus)) == NULL)
3115: {
3116: (*s_etat_processus).erreur_systeme =
3117: d_es_allocation_memoire;
3118: return;
3119: }
3120:
3121: (*(*s_etat_processus).s_sockets).suivant = NULL;
3122: l_element_courant = (*s_etat_processus).s_sockets;
3123: }
3124: else
3125: {
3126: /*
3127: * Ajout d'un élément à la fin de la liste chaînée
3128: */
3129:
3130: while((*l_element_courant).suivant != NULL)
3131: {
3132: l_element_courant = (*l_element_courant).suivant;
3133: }
3134:
3135: if (((*l_element_courant).suivant =
3136: allocation_maillon(s_etat_processus)) == NULL)
3137: {
3138: (*s_etat_processus).erreur_systeme =
3139: d_es_allocation_memoire;
3140: return;
3141: }
3142:
3143: l_element_courant = (*l_element_courant).suivant;
3144: (*l_element_courant).suivant = NULL;
3145: }
3146:
3147: if (((*l_element_courant).donnee = copie_objet(s_etat_processus,
3148: s_objet_resultat, 'O')) == NULL)
3149: {
3150: (*s_etat_processus).erreur_systeme =
3151: d_es_allocation_memoire;
3152: return;
3153: }
3154: }
3155:
3156: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3157: s_objet_argument) == d_erreur)
3158: {
3159: return;
3160: }
3161:
3162: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3163: s_objet_resultat) == d_erreur)
3164: {
3165: return;
3166: }
3167: }
3168: }
3169: else
3170: {
3171: liberation(s_etat_processus, s_objet_argument);
3172:
3173: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
3174: return;
3175: }
3176:
3177: return;
3178: }
3179:
3180:
3181: /*
3182: ================================================================================
3183: Fonction 'wfswi'
3184: ================================================================================
3185: Entrées : pointeur sur une structure struct_processus
3186: --------------------------------------------------------------------------------
3187: Sorties :
3188: --------------------------------------------------------------------------------
3189: Effets de bord : néant
3190: ================================================================================
3191: */
3192:
3193: void
3194: instruction_wfswi(struct_processus *s_etat_processus)
3195: {
3196: integer8 interruption;
3197:
3198: logical1 drapeau_fin;
3199:
3200: struct_objet *s_objet_argument;
3201:
3202: struct timespec attente;
3203:
3204: (*s_etat_processus).erreur_execution = d_ex;
3205:
3206: attente.tv_sec = 0;
3207: attente.tv_nsec = GRANULARITE_us * 1000;
3208:
3209: if ((*s_etat_processus).affichage_arguments == 'Y')
3210: {
3211: printf("\n WFSWI ");
3212:
3213: if ((*s_etat_processus).langue == 'F')
3214: {
3215: printf("(attente d'une interruption)\n\n");
3216: }
3217: else
3218: {
3219: printf("(wait for interrupt)\n\n");
3220: }
3221:
3222: printf(" 1: %s\n", d_INT);
3223:
3224: return;
3225: }
3226: else if ((*s_etat_processus).test_instruction == 'Y')
3227: {
3228: (*s_etat_processus).nombre_arguments = -1;
3229: return;
3230: }
3231:
3232: if (test_cfsf(s_etat_processus, 31) == d_vrai)
3233: {
3234: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
3235: {
3236: return;
3237: }
3238: }
3239:
3240: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3241: &s_objet_argument) == d_erreur)
3242: {
3243: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
3244: return;
3245: }
3246:
3247: if ((*s_objet_argument).type == INT)
3248: {
3249: drapeau_fin = d_faux;
3250:
3251: interruption = (*((integer8 *) (*s_objet_argument).objet));
3252:
3253: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
3254: {
3255: liberation(s_etat_processus, s_objet_argument);
3256:
3257: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
3258: return;
3259: }
3260:
3261: while(drapeau_fin == d_faux)
3262: {
3263: if ((*s_etat_processus).var_volatile_requete_arret != 0)
3264: {
3265: liberation(s_etat_processus, s_objet_argument);
3266: return;
3267: }
3268:
3269: if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
3270: {
3271: affectation_interruptions_logicielles(s_etat_processus);
3272: }
3273:
3274: if ((*s_etat_processus).queue_interruptions[interruption - 1] > 0)
3275: {
3276: drapeau_fin = d_vrai;
3277: }
3278: else
3279: {
3280: nanosleep(&attente, NULL);
3281: scrutation_injection(s_etat_processus);
3282: INCR_GRANULARITE(attente.tv_nsec);
3283: }
3284: }
3285: }
3286: else
3287: {
3288: liberation(s_etat_processus, s_objet_argument);
3289:
3290: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
3291: return;
3292: }
3293:
3294: liberation(s_etat_processus, s_objet_argument);
3295:
3296: return;
3297: }
3298:
3299:
3300: /*
3301: ================================================================================
3302: Fonction 'wfpoke'
3303: ================================================================================
3304: Entrées : pointeur sur une structure struct_processus
3305: --------------------------------------------------------------------------------
3306: Sorties :
3307: --------------------------------------------------------------------------------
3308: Effets de bord : néant
3309: ================================================================================
3310: */
3311:
3312: void
3313: instruction_wfpoke(struct_processus *s_etat_processus)
3314: {
3315: struct timespec attente;
3316:
3317: unsigned char registre_instruction_valide;
3318:
3319: (*s_etat_processus).erreur_execution = d_ex;
3320:
3321: attente.tv_sec = 0;
3322: attente.tv_nsec = GRANULARITE_us * 1000;
3323:
3324: if ((*s_etat_processus).affichage_arguments == 'Y')
3325: {
3326: printf("\n WFPOKE ");
3327:
3328: if ((*s_etat_processus).langue == 'F')
3329: {
3330: printf("(attente de données en provenance du processus père)\n\n");
3331: printf(" Aucun argument\n");
3332: }
3333: else
3334: {
3335: printf("(wait for data from parent process)\n\n");
3336: printf(" No argument\n");
3337: }
3338:
3339: return;
3340: }
3341: else if ((*s_etat_processus).test_instruction == 'Y')
3342: {
3343: (*s_etat_processus).nombre_arguments = -1;
3344: return;
3345: }
3346:
3347: if (test_cfsf(s_etat_processus, 31) == d_vrai)
3348: {
3349: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
3350: {
3351: return;
3352: }
3353: }
3354:
3355: if ((*s_etat_processus).presence_pipes == d_faux)
3356: {
3357: (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
3358: return;
3359: }
3360:
3361: if ((*s_etat_processus).nombre_objets_injectes > 0)
3362: {
3363: return;
3364: }
3365:
3366: if ((*s_etat_processus).profilage == d_vrai)
3367: {
3368: profilage(s_etat_processus, "Interprocess or interthread "
3369: "communications (WFPOKE)");
3370:
3371: if ((*s_etat_processus).erreur_systeme != d_es)
3372: {
3373: return;
3374: }
3375: }
3376:
3377: do
3378: {
3379: # ifndef SEMAPHORES_NOMMES
3380: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
3381: # else
3382: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
3383: # endif
3384: {
3385: (*s_etat_processus).erreur_systeme = d_es_processus;
3386: return;
3387: }
3388:
3389: nanosleep(&attente, NULL);
3390:
3391: # ifndef SEMAPHORES_NOMMES
3392: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
3393: # else
3394: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
3395: # endif
3396: {
3397: if (errno != EINTR)
3398: {
3399: (*s_etat_processus).erreur_systeme = d_es_processus;
3400: return;
3401: }
3402: }
3403:
3404: scrutation_injection(s_etat_processus);
3405:
3406: if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
3407: {
3408: affectation_interruptions_logicielles(s_etat_processus);
3409: }
3410:
3411: if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
3412: {
3413: registre_instruction_valide =
3414: (*s_etat_processus).instruction_valide;
3415: traitement_interruptions_logicielles(s_etat_processus);
3416: (*s_etat_processus).instruction_valide =
3417: registre_instruction_valide;
3418: }
3419:
3420: if ((*s_etat_processus).var_volatile_requete_arret != 0)
3421: {
3422: if ((*s_etat_processus).profilage == d_vrai)
3423: {
3424: profilage(s_etat_processus, NULL);
3425: }
3426:
3427: return;
3428: }
3429:
3430: INCR_GRANULARITE(attente.tv_nsec);
3431: } while((*s_etat_processus).nombre_objets_injectes == 0);
3432:
3433: return;
3434: }
3435:
3436:
3437: /*
3438: ================================================================================
3439: Fonction 'wfack'
3440: ================================================================================
3441: Entrées : pointeur sur une structure struct_processus
3442: --------------------------------------------------------------------------------
3443: Sorties :
3444: --------------------------------------------------------------------------------
3445: Effets de bord : néant
3446: ================================================================================
3447: */
3448:
3449: void
3450: instruction_wfack(struct_processus *s_etat_processus)
3451: {
3452: struct timespec attente;
3453:
3454: unsigned char registre_instruction_valide;
3455:
3456: (*s_etat_processus).erreur_execution = d_ex;
3457:
3458: attente.tv_sec = 0;
3459: attente.tv_nsec = GRANULARITE_us * 1000;
3460:
3461: if ((*s_etat_processus).affichage_arguments == 'Y')
3462: {
3463: printf("\n WFACK ");
3464:
3465: if ((*s_etat_processus).langue == 'F')
3466: {
3467: printf("(attente des acquittements de lecture)\n\n");
3468: printf(" Aucun argument\n");
3469: }
3470: else
3471: {
3472: printf("(wait for reading of data acknowledgement)\n\n");
3473: printf(" No argument\n");
3474: }
3475:
3476: return;
3477: }
3478: else if ((*s_etat_processus).test_instruction == 'Y')
3479: {
3480: (*s_etat_processus).nombre_arguments = -1;
3481: return;
3482: }
3483:
3484: if (test_cfsf(s_etat_processus, 31) == d_vrai)
3485: {
3486: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
3487: {
3488: return;
3489: }
3490: }
3491:
3492: if ((*s_etat_processus).presence_pipes == d_faux)
3493: {
3494: (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
3495: return;
3496: }
3497:
3498: if ((*s_etat_processus).profilage == d_vrai)
3499: {
3500: profilage(s_etat_processus, "Interprocess or interthread communications"
3501: " (WFACK)");
3502:
3503: if ((*s_etat_processus).erreur_systeme != d_es)
3504: {
3505: return;
3506: }
3507: }
3508:
3509: while((*s_etat_processus).nombre_objets_envoyes_non_lus != 0)
3510: {
3511: scrutation_injection(s_etat_processus);
3512:
3513: if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
3514: {
3515: affectation_interruptions_logicielles(s_etat_processus);
3516: }
3517:
3518: if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
3519: {
3520: registre_instruction_valide =
3521: (*s_etat_processus).instruction_valide;
3522: traitement_interruptions_logicielles(s_etat_processus);
3523: (*s_etat_processus).instruction_valide =
3524: registre_instruction_valide;
3525: }
3526:
3527: if ((*s_etat_processus).var_volatile_requete_arret != 0)
3528: {
3529: if ((*s_etat_processus).profilage == d_vrai)
3530: {
3531: profilage(s_etat_processus, NULL);
3532: }
3533:
3534: return;
3535: }
3536:
3537: # ifndef SEMAPHORES_NOMMES
3538: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
3539: # else
3540: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
3541: # endif
3542: {
3543: (*s_etat_processus).erreur_systeme = d_es_processus;
3544: return;
3545: }
3546:
3547: nanosleep(&attente, NULL);
3548: INCR_GRANULARITE(attente.tv_nsec);
3549:
3550: # ifndef SEMAPHORES_NOMMES
3551: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
3552: # else
3553: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
3554: # endif
3555: {
3556: if (errno != EINTR)
3557: {
3558: (*s_etat_processus).erreur_systeme = d_es_processus;
3559: return;
3560: }
3561: }
3562: }
3563:
3564: if ((*s_etat_processus).profilage == d_vrai)
3565: {
3566: profilage(s_etat_processus, NULL);
3567: }
3568:
3569: return;
3570: }
3571:
3572: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>