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