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