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