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