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