1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.32
4: Copyright (C) 1989-2020 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 format_oriente_ligne;
414: logical1 mise_a_jour;
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 (write(fileno((*descripteur).descripteur_c),
1365: chaine, (size_t) longueur_effective) !=
1366: (ssize_t) longueur_effective)
1367: {
1368: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1369: return;
1370: }
1371: }
1372: else if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
1373: == 'D')
1374: {
1375: if ((*s_objet_argument_2).type != INT)
1376: {
1377: liberation(s_etat_processus, s_objet_argument_2);
1378: liberation(s_etat_processus, s_objet_argument_1);
1379:
1380: (*s_etat_processus).erreur_execution =
1381: d_ex_erreur_type_argument;
1382: return;
1383: }
1384:
1385: if (depilement(s_etat_processus, &((*s_etat_processus)
1386: .l_base_pile), &s_objet_argument_3) == d_erreur)
1387: {
1388: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1389: return;
1390: }
1391:
1392: if ((*s_objet_argument_3).type != LST)
1393: {
1394: liberation(s_etat_processus, s_objet_argument_3);
1395: liberation(s_etat_processus, s_objet_argument_2);
1396: liberation(s_etat_processus, s_objet_argument_1);
1397:
1398: (*s_etat_processus).erreur_execution =
1399: d_ex_erreur_type_argument;
1400: return;
1401: }
1402:
1403: if ((chaine = formateur_fichier(s_etat_processus,
1404: s_objet_argument_2, (*((struct_fichier *)
1405: (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
1406: &longueur_effective, &recursivite, d_faux)) == NULL)
1407: {
1408: liberation(s_etat_processus, s_objet_argument_2);
1409: liberation(s_etat_processus, s_objet_argument_1);
1410:
1411: return;
1412: }
1413: }
1414: else // Fichiers indexés
1415: {
1416: if ((*s_objet_argument_2).type != LST)
1417: {
1418: liberation(s_etat_processus, s_objet_argument_2);
1419: liberation(s_etat_processus, s_objet_argument_1);
1420:
1421: (*s_etat_processus).erreur_execution =
1422: d_ex_erreur_type_argument;
1423: return;
1424: }
1425:
1426: if ((chaine = formateur_fichier(s_etat_processus,
1427: s_objet_argument_2, (*((struct_fichier *)
1428: (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
1429: &longueur_effective, &recursivite, d_faux)) == NULL)
1430: {
1431: liberation(s_etat_processus, s_objet_argument_2);
1432: liberation(s_etat_processus, s_objet_argument_1);
1433:
1434: return;
1435: }
1436: }
1437:
1438: free(chaine);
1439: }
1440: else
1441: {
1442: /*
1443: * Fichiers de type FLOW
1444: */
1445:
1446: if ((*((struct_fichier *) (*s_objet_argument_1).objet)).acces
1447: == 'S')
1448: {
1449: BUG(((*descripteur).type != 'C'), uprintf("Bad filetype !\n"));
1450:
1451: if ((*s_objet_argument_2).type != LST)
1452: {
1453: liberation(s_etat_processus, s_objet_argument_2);
1454: liberation(s_etat_processus, s_objet_argument_1);
1455:
1456: (*s_etat_processus).erreur_execution =
1457: d_ex_erreur_type_argument;
1458: return;
1459: }
1460:
1461: if ((*((struct_liste_chainee *) (*s_objet_argument_2).objet))
1462: .donnee == NULL)
1463: {
1464: liberation(s_etat_processus, s_objet_argument_2);
1465: liberation(s_etat_processus, s_objet_argument_1);
1466:
1467: (*s_etat_processus).erreur_execution =
1468: d_ex_erreur_type_argument;
1469: return;
1470: }
1471:
1472: l_element_courant = (*s_objet_argument_2).objet;
1473: l_element_courant_format = (struct_liste_chainee *)
1474: (*(*((struct_fichier *) (*s_objet_argument_1).objet))
1475: .format).objet;
1476:
1477: while((l_element_courant != NULL) &&
1478: (l_element_courant_format != NULL))
1479: {
1480: if ((*(*l_element_courant).donnee).type != CHN)
1481: {
1482: liberation(s_etat_processus, s_objet_argument_2);
1483: liberation(s_etat_processus, s_objet_argument_1);
1484:
1485: (*s_etat_processus).erreur_execution =
1486: d_ex_erreur_type_argument;
1487: return;
1488: }
1489:
1490: if ((*(*l_element_courant_format).donnee).type != CHN)
1491: {
1492: liberation(s_etat_processus, s_objet_argument_2);
1493: liberation(s_etat_processus, s_objet_argument_1);
1494:
1495: (*s_etat_processus).erreur_execution =
1496: d_ex_erreur_type_argument;
1497: return;
1498: }
1499:
1500: if ((format_chaine = conversion_majuscule(s_etat_processus,
1501: (unsigned char *) (*(*l_element_courant_format)
1502: .donnee).objet)) == NULL)
1503: {
1504: (*s_etat_processus).erreur_systeme =
1505: d_es_allocation_memoire;
1506: return;
1507: }
1508:
1509: if (strcmp("LINE*(*)", format_chaine) == 0)
1510: {
1511: format_oriente_ligne = d_vrai;
1512: format_degenere = d_vrai;
1513: }
1514: else
1515: {
1516: format_oriente_ligne = d_faux;
1517:
1518: if (strncmp("LENGTH*(", format_chaine, 8) != 0)
1519: {
1520: free(format_chaine);
1521:
1522: liberation(s_etat_processus, s_objet_argument_2);
1523: liberation(s_etat_processus, s_objet_argument_1);
1524:
1525: (*s_etat_processus).erreur_execution =
1526: d_ex_erreur_format_fichier;
1527: return;
1528: }
1529:
1530: longueur = (integer8) strlen(format_chaine);
1531:
1532: if (format_chaine[longueur - 1] != ')')
1533: {
1534: free(format_chaine);
1535:
1536: liberation(s_etat_processus, s_objet_argument_2);
1537: liberation(s_etat_processus, s_objet_argument_1);
1538:
1539: (*s_etat_processus).erreur_execution =
1540: d_ex_erreur_format_fichier;
1541: return;
1542: }
1543:
1544: format_chaine[longueur] = d_code_fin_chaine;
1545:
1546: if (format_chaine[8] == '*')
1547: {
1548: format_degenere = d_vrai;
1549: }
1550: else
1551: {
1552: // Détermination de la longueur
1553: format_degenere = d_faux;
1554:
1555: if (sscanf(&(format_chaine[8]), "%lld", &longueur)
1556: != 1)
1557: {
1558: free(format_chaine);
1559:
1560: liberation(s_etat_processus,
1561: s_objet_argument_2);
1562: liberation(s_etat_processus,
1563: s_objet_argument_1);
1564:
1565: (*s_etat_processus).erreur_execution =
1566: d_ex_erreur_format_fichier;
1567: return;
1568: }
1569: }
1570: }
1571:
1572: free(format_chaine);
1573:
1574: if ((chaine = formateur_flux(s_etat_processus,
1575: (unsigned char *) (*(*l_element_courant).donnee)
1576: .objet, &longueur_effective)) == NULL)
1577: {
1578: (*s_etat_processus).erreur_systeme =
1579: d_es_allocation_memoire;
1580: return;
1581: }
1582:
1583: if ((format_degenere == d_vrai) ||
1584: (longueur_effective < longueur))
1585: {
1586: if (write(fileno((*descripteur).descripteur_c),
1587: chaine, (size_t) longueur_effective)
1588: != (ssize_t) longueur_effective)
1589: {
1590: (*s_etat_processus).erreur_systeme =
1591: d_es_erreur_fichier;
1592: return;
1593: }
1594: }
1595: else
1596: {
1597: if (write(fileno((*descripteur).descripteur_c),
1598: chaine, (size_t) longueur_effective)
1599: != (ssize_t) longueur)
1600: {
1601: (*s_etat_processus).erreur_systeme =
1602: d_es_erreur_fichier;
1603: return;
1604: }
1605: }
1606:
1607: free(chaine);
1608:
1609: if (format_oriente_ligne == d_vrai)
1610: {
1611: if (write(fileno((*descripteur).descripteur_c),
1612: "\n", 1) != 1)
1613: {
1614: (*s_etat_processus).erreur_systeme =
1615: d_es_erreur_fichier;
1616: return;
1617: }
1618: }
1619:
1620: l_element_courant = (*l_element_courant).suivant;
1621: l_element_courant_format = (*l_element_courant_format)
1622: .suivant;
1623: }
1624:
1625: if ((l_element_courant_format != NULL) ||
1626: (l_element_courant != NULL))
1627: {
1628: liberation(s_etat_processus, s_objet_argument_2);
1629: liberation(s_etat_processus, s_objet_argument_1);
1630:
1631: (*s_etat_processus).erreur_execution =
1632: d_ex_erreur_format_fichier;
1633: return;
1634: }
1635: }
1636: else
1637: {
1638: liberation(s_etat_processus, s_objet_argument_1);
1639: liberation(s_etat_processus, s_objet_argument_2);
1640:
1641: (*s_etat_processus).erreur_execution =
1642: d_ex_erreur_type_fichier;
1643: return;
1644: }
1645: }
1646: }
1647: else if (((*s_objet_argument_2).type == LST) &&
1648: ((*s_objet_argument_1).type == SCK))
1649: {
1650: /*
1651: * Vérification de l'autorisation d'écriture
1652: */
1653:
1654: if ((*((struct_socket *) (*s_objet_argument_1).objet))
1655: .protection == 'R')
1656: {
1657: liberation(s_etat_processus, s_objet_argument_2);
1658: liberation(s_etat_processus, s_objet_argument_1);
1659:
1660: (*s_etat_processus).erreur_execution = d_ex_erreur_acces_fichier;
1661: return;
1662: }
1663:
1664: if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire == 'N')
1665: {
1666: /*
1667: * Sockets formatées
1668: */
1669:
1670: if ((chaine = formateur_fichier(s_etat_processus,
1671: s_objet_argument_2, (*((struct_socket *)
1672: (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'F',
1673: &longueur_effective, &recursivite, d_faux)) == NULL)
1674: {
1675: liberation(s_etat_processus, s_objet_argument_2);
1676: liberation(s_etat_processus, s_objet_argument_1);
1677:
1678: return;
1679: }
1680: }
1681: else if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire
1682: == 'Y')
1683: {
1684: /*
1685: * Sockets non formatées
1686: */
1687:
1688: if ((chaine = formateur_fichier(s_etat_processus,
1689: s_objet_argument_2, (*((struct_socket *)
1690: (*s_objet_argument_1).objet)).format, 0, 0, ' ', 'U',
1691: &longueur_effective, &recursivite, d_faux)) == NULL)
1692: {
1693: liberation(s_etat_processus, s_objet_argument_2);
1694: liberation(s_etat_processus, s_objet_argument_1);
1695:
1696: return;
1697: }
1698: }
1699: else
1700: {
1701: /*
1702: * Sockets de type FLOW
1703: */
1704:
1705: if ((*((*((struct_liste_chainee *) (*s_objet_argument_2).objet))
1706: .donnee)).type != CHN)
1707: {
1708: liberation(s_etat_processus, s_objet_argument_2);
1709: liberation(s_etat_processus, s_objet_argument_1);
1710:
1711: (*s_etat_processus).erreur_execution =
1712: d_ex_erreur_type_argument;
1713: return;
1714: }
1715:
1716: if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
1717: (*((*((struct_liste_chainee *) (*s_objet_argument_2)
1718: .objet)).donnee)).objet, &longueur_effective)) == NULL)
1719: {
1720: liberation(s_etat_processus, s_objet_argument_2);
1721: liberation(s_etat_processus, s_objet_argument_1);
1722:
1723: return;
1724: }
1725: }
1726:
1727: if ((strcmp((*((struct_socket *) (*s_objet_argument_1).objet)).type,
1728: "STREAM") == 0) || (strcmp((*((struct_socket *)
1729: (*s_objet_argument_1).objet)).type,
1730: "SEQUENTIAL DATAGRAM") == 0))
1731: { // Sockets connectées
1732: # ifndef SEMAPHORES_NOMMES
1733: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1734: # else
1735: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1736: # endif
1737: {
1738: (*s_etat_processus).erreur_systeme = d_es_processus;
1739: return;
1740: }
1741:
1742: if (pthread_mutex_lock(&mutex_sigaction) != 0)
1743: {
1744: (*s_etat_processus).erreur_systeme = d_es_processus;
1745: return;
1746: }
1747:
1748: action.sa_handler = SIG_IGN;
1749: action.sa_flags = 0;
1750:
1751: if (sigaction(SIGPIPE, &action, ®istre) != 0)
1752: {
1753: pthread_mutex_unlock(&mutex_sigaction);
1754: (*s_etat_processus).erreur_systeme = d_es_signal;
1755: return;
1756: }
1757:
1758: if (send((*((struct_socket *) (*s_objet_argument_1).objet))
1759: .socket, chaine, (size_t) longueur_effective, 0) < 0)
1760: {
1761: ios = errno;
1762:
1763: if (sigaction(SIGPIPE, ®istre, NULL) != 0)
1764: {
1765: pthread_mutex_unlock(&mutex_sigaction);
1766: (*s_etat_processus).erreur_systeme = d_es_signal;
1767: return;
1768: }
1769:
1770: if (pthread_mutex_unlock(&mutex_sigaction) != 0)
1771: {
1772: (*s_etat_processus).erreur_systeme = d_es_processus;
1773: return;
1774: }
1775:
1776: # ifndef SEMAPHORES_NOMMES
1777: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1778: # else
1779: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1780: # endif
1781: {
1782: if (errno != EINTR)
1783: {
1784: (*s_etat_processus).erreur_systeme = d_es_processus;
1785: return;
1786: }
1787: }
1788:
1789: if ((ios == EPIPE) || (ios == ECONNRESET))
1790: {
1791: (*s_etat_processus).erreur_execution =
1792: d_ex_erreur_acces_fichier;
1793: return;
1794: }
1795:
1796: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1797: return;
1798: }
1799:
1800: if (sigaction(SIGPIPE, ®istre, NULL) != 0)
1801: {
1802: pthread_mutex_unlock(&mutex_sigaction);
1803:
1804: # ifndef SEMAPHORES_NOMMES
1805: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1806: # else
1807: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1808: # endif
1809: {
1810: if (errno != EINTR)
1811: {
1812: if (sigaction(SIGPIPE, ®istre, NULL) != 0)
1813: {
1814: pthread_mutex_unlock(&mutex_sigaction);
1815: (*s_etat_processus).erreur_systeme = d_es_signal;
1816: return;
1817: }
1818:
1819: pthread_mutex_unlock(&mutex_sigaction);
1820: (*s_etat_processus).erreur_systeme = d_es_processus;
1821: return;
1822: }
1823: }
1824:
1825: (*s_etat_processus).erreur_systeme = d_es_signal;
1826: return;
1827: }
1828:
1829: if (pthread_mutex_unlock(&mutex_sigaction) != 0)
1830: {
1831: (*s_etat_processus).erreur_systeme = d_es_processus;
1832: return;
1833: }
1834:
1835: # ifndef SEMAPHORES_NOMMES
1836: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1837: # else
1838: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1839: # endif
1840: {
1841: if (errno != EINTR)
1842: {
1843: if (sigaction(SIGPIPE, ®istre, NULL) != 0)
1844: {
1845: (*s_etat_processus).erreur_systeme = d_es_signal;
1846: return;
1847: }
1848:
1849: (*s_etat_processus).erreur_systeme = d_es_processus;
1850: return;
1851: }
1852: }
1853: }
1854: else
1855: { // Sockets non connectées
1856:
1857: /*
1858: * Vérification de l'adresse distante
1859: */
1860:
1861: if (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
1862: .adresse_distante, "") == 0)
1863: {
1864: liberation(s_etat_processus, s_objet_argument_1);
1865: liberation(s_etat_processus, s_objet_argument_2);
1866:
1867: (*s_etat_processus).erreur_execution =
1868: d_ex_erreur_acces_fichier;
1869: return;
1870: }
1871:
1872: /*
1873: * Création de l'adresse logique
1874: */
1875:
1876: if ((*((struct_socket *) (*s_objet_argument_1).objet))
1877: .domaine == PF_UNIX)
1878: {
1879: adresse_unix.sun_family = AF_UNIX;
1880: strncpy(adresse_unix.sun_path, (*((struct_socket *)
1881: (*s_objet_argument_1).objet)).adresse_distante,
1882: UNIX_PATH_MAX);
1883: adresse_unix.sun_path[UNIX_PATH_MAX - 1] =
1884: d_code_fin_chaine;
1885:
1886: # ifndef SEMAPHORES_NOMMES
1887: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1888: # else
1889: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1890: # endif
1891: {
1892: (*s_etat_processus).erreur_systeme = d_es_processus;
1893: return;
1894: }
1895:
1896: if (sendto((*((struct_socket *)
1897: (*s_objet_argument_1).objet)).socket, chaine,
1898: (size_t) longueur_effective, 0, (struct sockaddr *)
1899: &adresse_unix, sizeof(adresse_unix)) < 0)
1900: {
1901: ios = errno;
1902:
1903: # ifndef SEMAPHORES_NOMMES
1904: while(sem_wait(&((*s_etat_processus).semaphore_fork))
1905: != 0)
1906: # else
1907: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1908: # endif
1909: {
1910: if (errno != EINTR)
1911: {
1912: (*s_etat_processus).erreur_systeme = d_es_processus;
1913: return;
1914: }
1915: }
1916:
1917: if ((ios == EPIPE) || (ios == ECONNRESET))
1918: {
1919: (*s_etat_processus).erreur_execution =
1920: d_ex_erreur_acces_fichier;
1921: return;
1922: }
1923:
1924: if (ios == EMSGSIZE)
1925: {
1926: (*s_etat_processus).erreur_execution =
1927: d_ex_taille_message;
1928: return;
1929: }
1930:
1931: (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
1932: return;
1933: }
1934:
1935: # ifndef SEMAPHORES_NOMMES
1936: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1937: # else
1938: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1939: # endif
1940: {
1941: if (errno != EINTR)
1942: {
1943: (*s_etat_processus).erreur_systeme = d_es_processus;
1944: return;
1945: }
1946: }
1947: }
1948: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
1949: .domaine == PF_INET)
1950: {
1951: if (sscanf((*((struct_socket *)
1952: (*s_objet_argument_1).objet))
1953: .adresse_distante, "%d.%d.%d.%d(%d)",
1954: &(adresse[0]), &(adresse[1]), &(adresse[2]),
1955: &(adresse[3]), &port) == 5)
1956: { // Adresse IPv4
1957: calcul_adresse = 0;
1958: for(i = 0; i < 4; calcul_adresse =
1959: (256 * calcul_adresse) +
1960: ((unsigned char) adresse[i++]));
1961:
1962: memset(&adresse_ipv4, 0, sizeof(adresse_ipv4));
1963: adresse_ipv4.sin_family = AF_INET;
1964: adresse_ipv4.sin_port = htons((uint16_t) port);
1965: adresse_ipv4.sin_addr.s_addr = htonl(calcul_adresse);
1966:
1967: # ifndef SEMAPHORES_NOMMES
1968: if (sem_post(&((*s_etat_processus).semaphore_fork))
1969: != 0)
1970: # else
1971: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1972: # endif
1973: {
1974: (*s_etat_processus).erreur_systeme = d_es_processus;
1975: return;
1976: }
1977:
1978: if (sendto((*((struct_socket *)
1979: (*s_objet_argument_1).objet)).socket, chaine,
1980: (size_t) longueur_effective, 0, (struct sockaddr *)
1981: &adresse_ipv4, sizeof(adresse_ipv4)) < 0)
1982: {
1983: ios = errno;
1984:
1985: # ifndef SEMAPHORES_NOMMES
1986: while(sem_wait(&((*s_etat_processus)
1987: .semaphore_fork)) != 0)
1988: # else
1989: while(sem_wait((*s_etat_processus)
1990: .semaphore_fork) != 0)
1991: # endif
1992: {
1993: if (errno != EINTR)
1994: {
1995: (*s_etat_processus).erreur_systeme =
1996: d_es_processus;
1997: return;
1998: }
1999: }
2000:
2001: if ((ios == EPIPE) || (ios == ECONNRESET))
2002: {
2003: (*s_etat_processus).erreur_execution =
2004: d_ex_erreur_acces_fichier;
2005: return;
2006: }
2007:
2008: if (ios == EMSGSIZE)
2009: {
2010: (*s_etat_processus).erreur_execution =
2011: d_ex_taille_message;
2012: return;
2013: }
2014:
2015: (*s_etat_processus).erreur_systeme =
2016: d_es_erreur_fichier;
2017: return;
2018: }
2019:
2020: # ifndef SEMAPHORES_NOMMES
2021: while(sem_wait(&((*s_etat_processus).semaphore_fork))
2022: != 0)
2023: # else
2024: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
2025: # endif
2026: {
2027: if (errno != EINTR)
2028: {
2029: (*s_etat_processus).erreur_systeme = d_es_processus;
2030: return;
2031: }
2032: }
2033: }
2034: else
2035: {
2036: liberation(s_etat_processus, s_objet_argument_1);
2037: liberation(s_etat_processus, s_objet_argument_2);
2038:
2039: (*s_etat_processus).erreur_execution =
2040: d_ex_erreur_parametre_fichier;
2041: return;
2042: }
2043: }
2044: else if ((*((struct_socket *) (*s_objet_argument_1).objet))
2045: .domaine == PF_INET6)
2046: {
2047: if (sscanf((*((struct_socket *) (*s_objet_argument_1)
2048: .objet)).adresse_distante, "%X:%X:%X:%X:%X:"
2049: "%X:%X:%X:%X:%X:%X:%X:%X:%X:%X:%X(%d)",
2050: &(adresse[0]), &(adresse[1]), &(adresse[2]),
2051: &(adresse[3]), &(adresse[4]), &(adresse[5]),
2052: &(adresse[6]), &(adresse[7]), &(adresse[8]),
2053: &(adresse[9]), &(adresse[10]), &(adresse[11]),
2054: &(adresse[12]), &(adresse[13]), &(adresse[14]),
2055: &(adresse[15]), &port)== 17)
2056: { // Adresse IPv6
2057: # ifdef IPV6
2058: memset(&adresse_ipv6, 0, sizeof(adresse_ipv6));
2059: adresse_ipv6.sin6_family = AF_INET6;
2060: adresse_ipv6.sin6_port = htons((uint16_t) port);
2061:
2062: for(i = 0; i < 16;
2063: adresse_ipv6.sin6_addr.s6_addr[i] =
2064: (unsigned char) adresse[i], i++);
2065:
2066: # ifndef SEMAPHORES_NOMMES
2067: if (sem_post(&((*s_etat_processus).semaphore_fork))
2068: != 0)
2069: # else
2070: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
2071: # endif
2072: {
2073: (*s_etat_processus).erreur_systeme = d_es_processus;
2074: return;
2075: }
2076:
2077: if (sendto((*((struct_socket *)
2078: (*s_objet_argument_1).objet)).socket, chaine,
2079: (size_t) longueur_effective, 0, (struct sockaddr *)
2080: &adresse_ipv6, sizeof(adresse_ipv6)) < 0)
2081: {
2082: ios = errno;
2083:
2084: # ifndef SEMAPHORES_NOMMES
2085: while(sem_wait(&((*s_etat_processus)
2086: .semaphore_fork)) != 0)
2087: # else
2088: while(sem_wait((*s_etat_processus)
2089: .semaphore_fork) != 0)
2090: # endif
2091: {
2092: if (errno != EINTR)
2093: {
2094: (*s_etat_processus).erreur_systeme =
2095: d_es_processus;
2096: return;
2097: }
2098: }
2099:
2100: if ((ios == EPIPE) || (ios == ECONNRESET))
2101: {
2102: (*s_etat_processus).erreur_execution =
2103: d_ex_erreur_acces_fichier;
2104: return;
2105: }
2106:
2107: if (ios == EMSGSIZE)
2108: {
2109: (*s_etat_processus).erreur_execution =
2110: d_ex_taille_message;
2111: return;
2112: }
2113:
2114: (*s_etat_processus).erreur_systeme =
2115: d_es_erreur_fichier;
2116: return;
2117: }
2118:
2119: # ifndef SEMAPHORES_NOMMES
2120: while(sem_wait(&((*s_etat_processus).semaphore_fork))
2121: != 0)
2122: # else
2123: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
2124: # endif
2125: {
2126: if (errno != EINTR)
2127: {
2128: (*s_etat_processus).erreur_systeme =
2129: d_es_processus;
2130: return;
2131: }
2132: }
2133: # else
2134: if ((*s_etat_processus).langue == 'F')
2135: {
2136: printf("+++Attention : Support du protocole"
2137: " IPv6 indisponible\n");
2138: }
2139: else
2140: {
2141: printf("+++Warning : IPv6 support "
2142: "unavailable\n");
2143: }
2144: # endif
2145: }
2146: else
2147: {
2148: liberation(s_etat_processus, s_objet_argument_1);
2149: liberation(s_etat_processus, s_objet_argument_2);
2150:
2151: (*s_etat_processus).erreur_execution =
2152: d_ex_erreur_parametre_fichier;
2153: return;
2154: }
2155: }
2156: else
2157: {
2158: liberation(s_etat_processus, s_objet_argument_1);
2159: liberation(s_etat_processus, s_objet_argument_2);
2160:
2161: (*s_etat_processus).erreur_execution =
2162: d_ex_erreur_parametre_fichier;
2163: return;
2164: }
2165: }
2166:
2167: free(chaine);
2168: }
2169: else
2170: {
2171: liberation(s_etat_processus, s_objet_argument_2);
2172: liberation(s_etat_processus, s_objet_argument_1);
2173:
2174: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2175: return;
2176: }
2177:
2178: liberation(s_etat_processus, s_objet_argument_2);
2179: liberation(s_etat_processus, s_objet_argument_1);
2180:
2181: return;
2182: }
2183:
2184:
2185: /*
2186: ================================================================================
2187: Fonction 'wflock'
2188: ================================================================================
2189: Entrées : pointeur sur une structure struct_processus
2190: --------------------------------------------------------------------------------
2191: Sorties :
2192: --------------------------------------------------------------------------------
2193: Effets de bord : néant
2194: ================================================================================
2195: */
2196:
2197: void
2198: instruction_wflock(struct_processus *s_etat_processus)
2199: {
2200: logical1 drapeau;
2201:
2202: struct flock lock;
2203:
2204: struct timespec attente;
2205:
2206: struct_descripteur_fichier *descripteur;
2207:
2208: struct_objet *s_objet_argument_1;
2209: struct_objet *s_objet_argument_2;
2210:
2211: unsigned char *chaine;
2212: unsigned char registre_instruction_valide;
2213:
2214: attente.tv_sec = 0;
2215: attente.tv_nsec = GRANULARITE_us * 1000;
2216:
2217: (*s_etat_processus).erreur_execution = d_ex;
2218:
2219: if ((*s_etat_processus).affichage_arguments == 'Y')
2220: {
2221: printf("\n WFLOCK ");
2222:
2223: if ((*s_etat_processus).langue == 'F')
2224: {
2225: printf("(attente du positionnement d'un verrou sur un fichier)"
2226: "\n\n");
2227: }
2228: else
2229: {
2230: printf("(wait for file lock)\n\n");
2231: }
2232:
2233: printf(" 2: %s\n", d_FCH);
2234: printf(" 1: %s (READ/WRITE/NONE)\n", d_CHN);
2235:
2236: return;
2237: }
2238: else if ((*s_etat_processus).test_instruction == 'Y')
2239: {
2240: (*s_etat_processus).nombre_arguments = -1;
2241: return;
2242: }
2243:
2244: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2245: {
2246: if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
2247: {
2248: return;
2249: }
2250: }
2251:
2252: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2253: &s_objet_argument_1) == d_erreur)
2254: {
2255: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2256: return;
2257: }
2258:
2259: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2260: &s_objet_argument_2) == d_erreur)
2261: {
2262: liberation(s_etat_processus, s_objet_argument_1);
2263:
2264: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2265: return;
2266: }
2267:
2268: if (((*s_objet_argument_2).type == FCH) &&
2269: ((*s_objet_argument_1).type == CHN))
2270: {
2271: drapeau = d_faux;
2272:
2273: do
2274: {
2275: if ((chaine = conversion_majuscule(s_etat_processus,
2276: (unsigned char *) (*s_objet_argument_1).objet)) == NULL)
2277: {
2278: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2279: return;
2280: }
2281:
2282: if (strcmp(chaine, "WRITE") == 0)
2283: {
2284: lock.l_type = F_WRLCK;
2285: }
2286: else if (strcmp(chaine, "READ") == 0)
2287: {
2288: lock.l_type = F_RDLCK;
2289: }
2290: else if (strcmp(chaine, "NONE") == 0)
2291: {
2292: lock.l_type = F_UNLCK;
2293: }
2294: else
2295: {
2296: free(chaine);
2297:
2298: liberation(s_etat_processus, s_objet_argument_1);
2299: liberation(s_etat_processus, s_objet_argument_2);
2300:
2301: (*s_etat_processus).erreur_execution = d_ex_verrou_indefini;
2302: return;
2303: }
2304:
2305: free(chaine);
2306:
2307: lock.l_whence = SEEK_SET;
2308: lock.l_start = 0;
2309: lock.l_len = 0;
2310: lock.l_pid = getpid();
2311:
2312: if ((descripteur = descripteur_fichier(s_etat_processus,
2313: (struct_fichier *) (*s_objet_argument_2).objet)) == NULL)
2314: {
2315: return;
2316: }
2317:
2318: if (fcntl(fileno((*descripteur).descripteur_c), F_GETLK, &lock)
2319: == -1)
2320: {
2321: liberation(s_etat_processus, s_objet_argument_1);
2322: liberation(s_etat_processus, s_objet_argument_2);
2323:
2324: (*s_etat_processus).erreur_execution = d_ex_fichier_verrouille;
2325: return;
2326: }
2327:
2328: if (lock.l_type == F_UNLCK)
2329: {
2330: drapeau = d_vrai;
2331: }
2332: else
2333: {
2334: if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions)
2335: != 0)
2336: {
2337: (*s_etat_processus).erreur_systeme = d_es_processus;
2338: return;
2339: }
2340:
2341: if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
2342: {
2343: affectation_interruptions_logicielles(s_etat_processus);
2344: }
2345:
2346: if (pthread_mutex_unlock(&(*s_etat_processus)
2347: .mutex_interruptions) != 0)
2348: {
2349: (*s_etat_processus).erreur_systeme = d_es_processus;
2350: return;
2351: }
2352:
2353: if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
2354: {
2355: registre_instruction_valide =
2356: (*s_etat_processus).instruction_valide;
2357: traitement_interruptions_logicielles(
2358: s_etat_processus);
2359: (*s_etat_processus).instruction_valide =
2360: registre_instruction_valide;
2361: }
2362:
2363: scrutation_injection(s_etat_processus);
2364:
2365: # ifndef SEMAPHORES_NOMMES
2366: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
2367: # else
2368: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
2369: # endif
2370: {
2371: (*s_etat_processus).erreur_systeme = d_es_processus;
2372: return;
2373: }
2374:
2375: nanosleep(&attente, NULL);
2376:
2377: INCR_GRANULARITE(attente.tv_nsec);
2378:
2379: # ifndef SEMAPHORES_NOMMES
2380: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
2381: # else
2382: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
2383: # endif
2384: {
2385: if (errno != EINTR)
2386: {
2387: (*s_etat_processus).erreur_systeme = d_es_processus;
2388: return;
2389: }
2390: }
2391: }
2392: } while((drapeau == d_faux) && ((*s_etat_processus)
2393: .var_volatile_requete_arret != -1));
2394: }
2395: else
2396: {
2397: liberation(s_etat_processus, s_objet_argument_1);
2398: liberation(s_etat_processus, s_objet_argument_2);
2399:
2400: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2401: return;
2402: }
2403:
2404: return;
2405: }
2406:
2407:
2408: /*
2409: ================================================================================
2410: Fonction 'wfproc'
2411: ================================================================================
2412: Entrées : pointeur sur une structure struct_processus
2413: --------------------------------------------------------------------------------
2414: Sorties :
2415: --------------------------------------------------------------------------------
2416: Effets de bord : néant
2417: ================================================================================
2418: */
2419:
2420: void
2421: instruction_wfproc(struct_processus *s_etat_processus)
2422: {
2423: logical1 drapeau_fin;
2424:
2425: struct_liste_chainee *l_element_courant;
2426:
2427: struct_objet *s_objet_argument;
2428:
2429: struct timespec attente;
2430:
2431: unsigned char registre_instruction_valide;
2432:
2433: (*s_etat_processus).erreur_execution = d_ex;
2434:
2435: attente.tv_sec = 0;
2436: attente.tv_nsec = GRANULARITE_us * 1000;
2437:
2438: if ((*s_etat_processus).affichage_arguments == 'Y')
2439: {
2440: printf("\n WFPROC ");
2441:
2442: if ((*s_etat_processus).langue == 'F')
2443: {
2444: printf("(attente de la fin d'un processus fils)\n\n");
2445: }
2446: else
2447: {
2448: printf("(wait for child process end)\n\n");
2449: }
2450:
2451: printf(" 1: %s\n", d_PRC);
2452:
2453: return;
2454: }
2455: else if ((*s_etat_processus).test_instruction == 'Y')
2456: {
2457: (*s_etat_processus).nombre_arguments = -1;
2458: return;
2459: }
2460:
2461: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2462: {
2463: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
2464: {
2465: return;
2466: }
2467: }
2468:
2469: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2470: &s_objet_argument) == d_erreur)
2471: {
2472: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2473: return;
2474: }
2475:
2476: if ((*s_objet_argument).type == PRC)
2477: {
2478: drapeau_fin = d_faux;
2479:
2480: if ((*s_etat_processus).profilage == d_vrai)
2481: {
2482: profilage(s_etat_processus, "Interprocess or interthread "
2483: "communications (WFPROC)");
2484:
2485: if ((*s_etat_processus).erreur_systeme != d_es)
2486: {
2487: return;
2488: }
2489: }
2490:
2491: if (pthread_mutex_lock(&((*s_etat_processus).mutex_pile_processus))
2492: != 0)
2493: {
2494: if ((*s_etat_processus).profilage == d_vrai)
2495: {
2496: profilage(s_etat_processus, NULL);
2497: }
2498:
2499: (*s_etat_processus).erreur_systeme = d_es_processus;
2500: return;
2501: }
2502:
2503: while(drapeau_fin == d_faux)
2504: {
2505: l_element_courant = (struct_liste_chainee *)
2506: (*s_etat_processus).l_base_pile_processus;
2507:
2508: while(l_element_courant != NULL)
2509: {
2510: if ((*(*((struct_processus_fils *) (*(*l_element_courant)
2511: .donnee).objet)).thread).processus_detache == d_vrai)
2512: {
2513: if ((*(*((struct_processus_fils *)
2514: (*s_objet_argument).objet)).thread)
2515: .processus_detache == d_vrai)
2516: {
2517: if ((*(*((struct_processus_fils *)
2518: (*(*l_element_courant)
2519: .donnee).objet)).thread).pid ==
2520: (*(*((struct_processus_fils *)
2521: (*s_objet_argument).objet)).thread).pid)
2522: {
2523: break;
2524: }
2525: }
2526: }
2527: else
2528: {
2529: if ((*(*((struct_processus_fils *)
2530: (*s_objet_argument).objet)).thread)
2531: .processus_detache == d_faux)
2532: {
2533: if ((pthread_equal((*(*((struct_processus_fils *)
2534: (*(*l_element_courant).donnee).objet)).thread)
2535: .tid, (*(*((struct_processus_fils *)
2536: (*s_objet_argument).objet)).thread).tid) != 0)
2537: && ((*(*((struct_processus_fils *)
2538: (*(*l_element_courant).donnee).objet)).thread)
2539: .pid == (*(*((struct_processus_fils *)
2540: (*s_objet_argument).objet)).thread).pid))
2541: {
2542: break;
2543: }
2544: }
2545: }
2546:
2547: l_element_courant = (*l_element_courant).suivant;
2548: }
2549:
2550: if ((*s_etat_processus).var_volatile_requete_arret != 0)
2551: {
2552: if ((*s_etat_processus).profilage == d_vrai)
2553: {
2554: profilage(s_etat_processus, NULL);
2555: }
2556:
2557: if (pthread_mutex_unlock(&((*s_etat_processus)
2558: .mutex_pile_processus)) != 0)
2559: {
2560: (*s_etat_processus).erreur_systeme = d_es_processus;
2561: return;
2562: }
2563:
2564: liberation(s_etat_processus, s_objet_argument);
2565: return;
2566: }
2567:
2568: if (l_element_courant == NULL)
2569: {
2570: /*
2571: * Si l_element_courant vaut NULL, le processus n'existe plus.
2572: */
2573:
2574: drapeau_fin = d_vrai;
2575: }
2576: else
2577: {
2578: if ((*(*((struct_processus_fils *) (*(*l_element_courant)
2579: .donnee).objet)).thread).processus_detache == d_vrai)
2580: {
2581: if (envoi_signal_processus((*(*((struct_processus_fils *)
2582: (*(*l_element_courant).donnee).objet)).thread).pid,
2583: rpl_signull, d_faux) != 0)
2584: {
2585: drapeau_fin = d_vrai;
2586: }
2587: else
2588: {
2589: drapeau_fin = d_faux;
2590: }
2591: }
2592: else
2593: {
2594: if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
2595: (*(*l_element_courant).donnee).objet)).thread)
2596: .mutex)) != 0)
2597: {
2598: if ((*s_etat_processus).profilage == d_vrai)
2599: {
2600: profilage(s_etat_processus, NULL);
2601: }
2602:
2603: (*s_etat_processus).erreur_systeme = d_es_processus;
2604: return;
2605: }
2606:
2607: if ((*(*((struct_processus_fils *)
2608: (*(*l_element_courant).donnee).objet)).thread)
2609: .thread_actif == d_faux)
2610: {
2611: drapeau_fin = d_vrai;
2612: }
2613: else
2614: {
2615: drapeau_fin = d_faux;
2616: }
2617:
2618: if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
2619: (*(*l_element_courant).donnee).objet)).thread)
2620: .mutex)) != 0)
2621: {
2622: if ((*s_etat_processus).profilage == d_vrai)
2623: {
2624: profilage(s_etat_processus, NULL);
2625: }
2626:
2627: (*s_etat_processus).erreur_systeme = d_es_processus;
2628: return;
2629: }
2630: }
2631:
2632: if (drapeau_fin == d_faux)
2633: {
2634: /*
2635: * Le processus n'est pas terminé
2636: */
2637:
2638: if (pthread_mutex_lock(&((*s_etat_processus)
2639: .mutex_interruptions)) != 0)
2640: {
2641: pthread_mutex_unlock(&((*s_etat_processus)
2642: .mutex_pile_processus));
2643:
2644: if ((*s_etat_processus).profilage == d_vrai)
2645: {
2646: profilage(s_etat_processus, NULL);
2647: }
2648:
2649: (*s_etat_processus).erreur_systeme =
2650: d_es_processus;
2651: return;
2652: }
2653:
2654: if ((*s_etat_processus).nombre_interruptions_non_affectees
2655: != 0)
2656: {
2657: affectation_interruptions_logicielles(s_etat_processus);
2658: }
2659:
2660: if (pthread_mutex_unlock(&((*s_etat_processus)
2661: .mutex_interruptions)) != 0)
2662: {
2663: pthread_mutex_unlock(&((*s_etat_processus)
2664: .mutex_pile_processus));
2665:
2666: if ((*s_etat_processus).profilage == d_vrai)
2667: {
2668: profilage(s_etat_processus, NULL);
2669: }
2670:
2671: (*s_etat_processus).erreur_systeme =
2672: d_es_processus;
2673: return;
2674: }
2675:
2676: if (pthread_mutex_unlock(&((*s_etat_processus)
2677: .mutex_pile_processus)) != 0)
2678: {
2679: if ((*s_etat_processus).profilage == d_vrai)
2680: {
2681: profilage(s_etat_processus, NULL);
2682: }
2683:
2684: (*s_etat_processus).erreur_systeme =
2685: d_es_processus;
2686: return;
2687: }
2688:
2689: if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
2690: {
2691: registre_instruction_valide =
2692: (*s_etat_processus).instruction_valide;
2693: traitement_interruptions_logicielles(
2694: s_etat_processus);
2695: (*s_etat_processus).instruction_valide =
2696: registre_instruction_valide;
2697: }
2698:
2699: # ifndef SEMAPHORES_NOMMES
2700: if (sem_post(&((*s_etat_processus).semaphore_fork))
2701: != 0)
2702: # else
2703: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
2704: # endif
2705: {
2706: (*s_etat_processus).erreur_systeme = d_es_processus;
2707: return;
2708: }
2709:
2710: nanosleep(&attente, NULL);
2711:
2712: # ifndef SEMAPHORES_NOMMES
2713: while(sem_wait(&((*s_etat_processus).semaphore_fork))
2714: != 0)
2715: # else
2716: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
2717: # endif
2718: {
2719: if (errno != EINTR)
2720: {
2721: (*s_etat_processus).erreur_systeme = d_es_processus;
2722: return;
2723: }
2724: }
2725:
2726: scrutation_injection(s_etat_processus);
2727:
2728: if (pthread_mutex_lock(&((*s_etat_processus)
2729: .mutex_pile_processus)) != 0)
2730: {
2731: if ((*s_etat_processus).profilage == d_vrai)
2732: {
2733: profilage(s_etat_processus, NULL);
2734: }
2735:
2736: (*s_etat_processus).erreur_systeme =
2737: d_es_processus;
2738: return;
2739: }
2740: }
2741: }
2742:
2743: INCR_GRANULARITE(attente.tv_nsec);
2744: }
2745:
2746: if ((*s_etat_processus).profilage == d_vrai)
2747: {
2748: profilage(s_etat_processus, NULL);
2749: }
2750:
2751: if (pthread_mutex_unlock(&((*s_etat_processus).mutex_pile_processus))
2752: != 0)
2753: {
2754: (*s_etat_processus).erreur_systeme = d_es_processus;
2755: return;
2756: }
2757: }
2758: else
2759: {
2760: liberation(s_etat_processus, s_objet_argument);
2761:
2762: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2763: return;
2764: }
2765:
2766: liberation(s_etat_processus, s_objet_argument);
2767:
2768: return;
2769: }
2770:
2771:
2772: /*
2773: ================================================================================
2774: Fonction 'wfdata'
2775: ================================================================================
2776: Entrées : pointeur sur une structure struct_processus
2777: --------------------------------------------------------------------------------
2778: Sorties :
2779: --------------------------------------------------------------------------------
2780: Effets de bord : néant
2781: ================================================================================
2782: */
2783:
2784: void
2785: instruction_wfdata(struct_processus *s_etat_processus)
2786: {
2787: logical1 drapeau_fin;
2788:
2789: struct_liste_chainee *l_element_courant;
2790:
2791: struct_objet *s_objet_argument;
2792:
2793: struct timespec attente;
2794:
2795: unsigned char registre_instruction_valide;
2796:
2797: (*s_etat_processus).erreur_execution = d_ex;
2798:
2799: attente.tv_sec = 0;
2800: attente.tv_nsec = GRANULARITE_us * 1000;
2801:
2802: if ((*s_etat_processus).affichage_arguments == 'Y')
2803: {
2804: printf("\n WFDATA ");
2805:
2806: if ((*s_etat_processus).langue == 'F')
2807: {
2808: printf("(attente de données d'un processus fils)\n\n");
2809: }
2810: else
2811: {
2812: printf("(wait for data from child process)\n\n");
2813: }
2814:
2815: printf(" 1: %s\n", d_PRC);
2816:
2817: return;
2818: }
2819: else if ((*s_etat_processus).test_instruction == 'Y')
2820: {
2821: (*s_etat_processus).nombre_arguments = -1;
2822: return;
2823: }
2824:
2825: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2826: {
2827: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
2828: {
2829: return;
2830: }
2831: }
2832:
2833: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2834: &s_objet_argument) == d_erreur)
2835: {
2836: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2837: return;
2838: }
2839:
2840: if ((*s_objet_argument).type == PRC)
2841: {
2842: drapeau_fin = d_faux;
2843:
2844: if ((*s_etat_processus).profilage == d_vrai)
2845: {
2846: profilage(s_etat_processus, "Interprocess or interthread "
2847: "communications (WFDATA)");
2848:
2849: if ((*s_etat_processus).erreur_systeme != d_es)
2850: {
2851: return;
2852: }
2853: }
2854:
2855: if (pthread_mutex_lock(&((*s_etat_processus).mutex_pile_processus))
2856: != 0)
2857: {
2858: if ((*s_etat_processus).profilage == d_vrai)
2859: {
2860: profilage(s_etat_processus, NULL);
2861: }
2862:
2863: (*s_etat_processus).erreur_systeme = d_es_processus;
2864: return;
2865: }
2866:
2867: while(drapeau_fin == d_faux)
2868: {
2869: l_element_courant = (struct_liste_chainee *)
2870: (*s_etat_processus).l_base_pile_processus;
2871:
2872: while(l_element_courant != NULL)
2873: {
2874: if ((*(*((struct_processus_fils *) (*(*l_element_courant)
2875: .donnee).objet)).thread).processus_detache == d_vrai)
2876: {
2877: if (((*(*((struct_processus_fils *) (*(*l_element_courant)
2878: .donnee).objet)).thread).pid ==
2879: (*(*((struct_processus_fils *)
2880: (*s_objet_argument).objet)).thread).pid)
2881: && ((*(*((struct_processus_fils *)
2882: (*s_objet_argument).objet)).thread)
2883: .processus_detache == d_vrai))
2884: {
2885: break;
2886: }
2887: }
2888: else
2889: {
2890: if ((pthread_equal((*(*((struct_processus_fils *)
2891: (*(*l_element_courant).donnee).objet)).thread).tid,
2892: (*(*((struct_processus_fils *) (*s_objet_argument)
2893: .objet)).thread).tid) != 0) &&
2894: ((*(*((struct_processus_fils *)
2895: (*(*l_element_courant).donnee).objet)).thread).pid
2896: == (*(*((struct_processus_fils *)
2897: (*s_objet_argument).objet)).thread).pid) &&
2898: ((*(*((struct_processus_fils *)
2899: (*s_objet_argument).objet)).thread)
2900: .processus_detache == d_faux))
2901: {
2902: break;
2903: }
2904: }
2905:
2906: l_element_courant = (*l_element_courant).suivant;
2907: }
2908:
2909: if ((*s_etat_processus).var_volatile_requete_arret != 0)
2910: {
2911: if ((*s_etat_processus).profilage == d_vrai)
2912: {
2913: profilage(s_etat_processus, NULL);
2914: }
2915:
2916: if (pthread_mutex_unlock(&((*s_etat_processus)
2917: .mutex_pile_processus)) != 0)
2918: {
2919: (*s_etat_processus).erreur_systeme = d_es_processus;
2920: return;
2921: }
2922:
2923: liberation(s_etat_processus, s_objet_argument);
2924: return;
2925: }
2926:
2927: if (l_element_courant != NULL)
2928: {
2929: if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
2930: (*(*l_element_courant).donnee).objet)).thread).mutex))
2931: != 0)
2932: {
2933: (*s_etat_processus).erreur_systeme = d_es_processus;
2934: return;
2935: }
2936:
2937: if ((*(*((struct_processus_fils *) (*(*l_element_courant)
2938: .donnee).objet)).thread).nombre_objets_dans_pipe != 0)
2939: {
2940: if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
2941: (*(*l_element_courant).donnee).objet)).thread)
2942: .mutex)) != 0)
2943: {
2944: (*s_etat_processus).erreur_systeme = d_es_processus;
2945: return;
2946: }
2947:
2948: drapeau_fin = d_vrai;
2949: }
2950: else
2951: {
2952: if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
2953: (*(*l_element_courant).donnee).objet)).thread)
2954: .mutex)) != 0)
2955: {
2956: (*s_etat_processus).erreur_systeme = d_es_processus;
2957: return;
2958: }
2959:
2960: if (pthread_mutex_unlock(&((*s_etat_processus)
2961: .mutex_pile_processus)) != 0)
2962: {
2963: if ((*s_etat_processus).profilage == d_vrai)
2964: {
2965: profilage(s_etat_processus, NULL);
2966: }
2967:
2968: (*s_etat_processus).erreur_systeme =
2969: d_es_processus;
2970: return;
2971: }
2972:
2973: # ifndef SEMAPHORES_NOMMES
2974: if (sem_post(&((*s_etat_processus).semaphore_fork))
2975: != 0)
2976: # else
2977: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
2978: # endif
2979: {
2980: (*s_etat_processus).erreur_systeme = d_es_processus;
2981: return;
2982: }
2983:
2984: nanosleep(&attente, NULL);
2985:
2986: # ifndef SEMAPHORES_NOMMES
2987: while(sem_wait(&((*s_etat_processus).semaphore_fork))
2988: != 0)
2989: # else
2990: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
2991: # endif
2992: {
2993: if (errno != EINTR)
2994: {
2995: (*s_etat_processus).erreur_systeme = d_es_processus;
2996: return;
2997: }
2998: }
2999:
3000: scrutation_injection(s_etat_processus);
3001:
3002: if (pthread_mutex_lock(&(*s_etat_processus)
3003: .mutex_interruptions) != 0)
3004: {
3005: (*s_etat_processus).erreur_systeme = d_es_processus;
3006: return;
3007: }
3008:
3009: if ((*s_etat_processus).nombre_interruptions_non_affectees
3010: != 0)
3011: {
3012: affectation_interruptions_logicielles(s_etat_processus);
3013: }
3014:
3015: if (pthread_mutex_unlock(&(*s_etat_processus)
3016: .mutex_interruptions) != 0)
3017: {
3018: (*s_etat_processus).erreur_systeme = d_es_processus;
3019: return;
3020: }
3021:
3022: if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
3023: {
3024: registre_instruction_valide =
3025: (*s_etat_processus).instruction_valide;
3026: traitement_interruptions_logicielles(s_etat_processus);
3027: (*s_etat_processus).instruction_valide =
3028: registre_instruction_valide;
3029: }
3030:
3031: if ((*s_etat_processus).var_volatile_requete_arret != 0)
3032: {
3033: if ((*s_etat_processus).profilage == d_vrai)
3034: {
3035: profilage(s_etat_processus, NULL);
3036: }
3037:
3038: return;
3039: }
3040:
3041: if (pthread_mutex_lock(&((*s_etat_processus)
3042: .mutex_pile_processus)) != 0)
3043: {
3044: if ((*s_etat_processus).profilage == d_vrai)
3045: {
3046: profilage(s_etat_processus, NULL);
3047: }
3048:
3049: (*s_etat_processus).erreur_systeme =
3050: d_es_processus;
3051: return;
3052: }
3053: }
3054: }
3055: else
3056: {
3057: drapeau_fin = d_vrai;
3058: (*s_etat_processus).erreur_execution = d_ex_processus;
3059: }
3060:
3061: INCR_GRANULARITE(attente.tv_nsec);
3062: }
3063:
3064: if ((*s_etat_processus).profilage == d_vrai)
3065: {
3066: profilage(s_etat_processus, NULL);
3067: }
3068:
3069: if (pthread_mutex_unlock(&((*s_etat_processus).mutex_pile_processus))
3070: != 0)
3071: {
3072: (*s_etat_processus).erreur_systeme = d_es_processus;
3073: return;
3074: }
3075: }
3076: else
3077: {
3078: liberation(s_etat_processus, s_objet_argument);
3079:
3080: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
3081: return;
3082: }
3083:
3084: liberation(s_etat_processus, s_objet_argument);
3085:
3086: return;
3087: }
3088:
3089:
3090: /*
3091: ================================================================================
3092: Fonction 'wfsock'
3093: ================================================================================
3094: Entrées : pointeur sur une structure struct_processus
3095: --------------------------------------------------------------------------------
3096: Sorties :
3097: --------------------------------------------------------------------------------
3098: Effets de bord : néant
3099: ================================================================================
3100: */
3101:
3102: static inline logical1
3103: options_sockets(struct_processus *s_etat_processus, struct_socket *s_socket)
3104: {
3105: int drapeau;
3106:
3107: if (((*s_socket).options & (1 << d_BROADCAST)) != 0)
3108: {
3109: if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_BROADCAST, &drapeau,
3110: sizeof(drapeau)) != 0)
3111: {
3112: return(d_erreur);
3113: }
3114: }
3115:
3116: if (((*s_socket).options & (1 << d_DONT_ROUTE)) != 0)
3117: {
3118: if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_DONTROUTE, &drapeau,
3119: sizeof(drapeau)) != 0)
3120: {
3121: return(d_erreur);
3122: }
3123: }
3124:
3125: if (((*s_socket).options & (1 << d_KEEP_ALIVE)) != 0)
3126: {
3127: if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_KEEPALIVE, &drapeau,
3128: sizeof(drapeau)) != 0)
3129: {
3130: return(d_erreur);
3131: }
3132: }
3133:
3134: # ifdef SO_PRIORITY
3135: if (((*s_socket).options & (1 << d_PRIORITY)) != 0)
3136: {
3137: if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_PRIORITY,
3138: &((*s_socket).priorite), sizeof((*s_socket).priorite)) != 0)
3139: {
3140: return(d_erreur);
3141: }
3142: }
3143: # endif
3144:
3145: // Les deux options suivantes ne peuvent être positionnées simultanément.
3146:
3147: if (((*s_socket).options & (1 << d_RECEIVE_BUFFER)) != 0)
3148: {
3149: if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVBUF,
3150: &((*s_socket).buffer_reception),
3151: sizeof((*s_socket).buffer_reception)) != 0)
3152: {
3153: return(d_erreur);
3154: }
3155: }
3156:
3157: # ifdef SO_RCVBUFFORCE
3158: if (((*s_socket).options & (1 << d_FORCE_RECEIVE_BUFFER)) != 0)
3159: {
3160: if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVBUFFORCE,
3161: &((*s_socket).buffer_reception),
3162: sizeof((*s_socket).buffer_reception)) != 0)
3163: {
3164: return(d_erreur);
3165: }
3166: }
3167: # endif
3168:
3169: // Même remarque
3170:
3171: if (((*s_socket).options & (1 << d_SEND_BUFFER)) != 0)
3172: {
3173: if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDBUF,
3174: &((*s_socket).buffer_emission),
3175: sizeof((*s_socket).buffer_emission)) != 0)
3176: {
3177: return(d_erreur);
3178: }
3179: }
3180:
3181: # ifdef SO_SNDBUFFORCE
3182: if (((*s_socket).options & (1 << d_FORCE_SEND_BUFFER)) != 0)
3183: {
3184: if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDBUFFORCE,
3185: &((*s_socket).buffer_emission),
3186: sizeof((*s_socket).buffer_emission)) != 0)
3187: {
3188: return(d_erreur);
3189: }
3190: }
3191: # endif
3192:
3193: if (((*s_socket).options & (1 << d_RECEIVING_TIMEOUT)) != 0)
3194: {
3195: if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVTIMEO,
3196: &((*s_socket).timeout_emission),
3197: sizeof((*s_socket).timeout_emission)) != 0)
3198: {
3199: return(d_erreur);
3200: }
3201: }
3202:
3203: if (((*s_socket).options & (1 << d_SENDING_TIMEOUT)) != 0)
3204: {
3205: if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDTIMEO,
3206: &((*s_socket).timeout_emission),
3207: sizeof((*s_socket).timeout_emission)) != 0)
3208: {
3209: return(d_erreur);
3210: }
3211: }
3212:
3213: return(d_absence_erreur);;
3214: }
3215:
3216:
3217: void
3218: instruction_wfsock(struct_processus *s_etat_processus)
3219: {
3220: int erreur;
3221:
3222: logical1 drapeau;
3223:
3224: socklen_t longueur;
3225:
3226: struct_liste_chainee *l_element_courant;
3227:
3228: struct_objet *s_objet_argument;
3229: struct_objet *s_objet_resultat;
3230:
3231: struct pollfd s_poll;
3232:
3233: struct sockaddr_in adresse_ipv4;
3234: # ifdef IPV6
3235: struct sockaddr_in6 adresse_ipv6;
3236: # endif
3237:
3238: if ((*s_etat_processus).affichage_arguments == 'Y')
3239: {
3240: printf("\n WFSOCK ");
3241:
3242: if ((*s_etat_processus).langue == 'F')
3243: {
3244: printf("(attente d'une connexion sur une socket)\n\n");
3245: }
3246: else
3247: {
3248: printf("(wait for connection on a socket)\n\n");
3249: }
3250:
3251: printf(" 1: %s\n", d_SCK);
3252: printf("-> 2: %s\n", d_SCK);
3253: printf(" 1: %s\n", d_SCK);
3254:
3255: return;
3256: }
3257: else if ((*s_etat_processus).test_instruction == 'Y')
3258: {
3259: (*s_etat_processus).nombre_arguments = -1;
3260: return;
3261: }
3262:
3263: if (test_cfsf(s_etat_processus, 31) == d_vrai)
3264: {
3265: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
3266: {
3267: return;
3268: }
3269: }
3270:
3271: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3272: &s_objet_argument) == d_erreur)
3273: {
3274: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
3275: return;
3276: }
3277:
3278: if ((*s_objet_argument).type == SCK)
3279: {
3280: if ((strcmp((*((struct_socket *) (*s_objet_argument).objet)).type,
3281: "STREAM") != 0) && (strcmp((*((struct_socket *)
3282: (*s_objet_argument).objet)).type, "SEQUENTIAL DATAGRAM") != 0))
3283: {
3284: // Mode non connecté : l'attente se fait sur un poll()
3285:
3286: if ((s_objet_resultat = copie_objet(s_etat_processus,
3287: s_objet_argument, 'P')) == NULL)
3288: {
3289: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3290: return;
3291: }
3292:
3293: s_poll.fd = (*((struct_socket *) (*s_objet_argument).objet)).socket;
3294: s_poll.events = POLLIN;
3295: s_poll.revents = 0;
3296:
3297: do
3298: {
3299: drapeau = d_vrai;
3300:
3301: # ifndef SEMAPHORES_NOMMES
3302: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
3303: # else
3304: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
3305: # endif
3306: {
3307: (*s_etat_processus).erreur_systeme = d_es_processus;
3308: return;
3309: }
3310:
3311: if (poll(&s_poll, 1, -1) < 0)
3312: {
3313: erreur = errno;
3314:
3315: # ifndef SEMAPHORES_NOMMES
3316: while(sem_wait(&((*s_etat_processus)
3317: .semaphore_fork)) != 0)
3318: # else
3319: while(sem_wait((*s_etat_processus).semaphore_fork)
3320: != 0)
3321: # endif
3322:
3323: if (erreur != EINTR)
3324: {
3325: liberation(s_etat_processus, s_objet_argument);
3326: liberation(s_etat_processus, s_objet_resultat);
3327:
3328: (*s_etat_processus).erreur_execution =
3329: d_ex_erreur_acces_fichier;
3330: return;
3331: }
3332:
3333: scrutation_injection(s_etat_processus);
3334:
3335: if ((*s_etat_processus).var_volatile_requete_arret != 0)
3336: {
3337: drapeau = d_vrai;
3338: }
3339: else
3340: {
3341: drapeau = d_faux;
3342: }
3343: }
3344: else
3345: {
3346: # ifndef SEMAPHORES_NOMMES
3347: while(sem_wait(&((*s_etat_processus)
3348: .semaphore_fork)) != 0)
3349: # else
3350: while(sem_wait((*s_etat_processus).semaphore_fork)
3351: != 0)
3352: # endif
3353: {
3354: if (errno != EINTR)
3355: {
3356: (*s_etat_processus).erreur_systeme =
3357: d_es_processus;
3358: return;
3359: }
3360: }
3361: }
3362: } while(drapeau == d_faux);
3363:
3364: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3365: s_objet_argument) == d_erreur)
3366: {
3367: return;
3368: }
3369:
3370: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3371: s_objet_resultat) == d_erreur)
3372: {
3373: return;
3374: }
3375: }
3376: else
3377: {
3378: // Mode connecté
3379:
3380: if ((s_objet_resultat = copie_objet(s_etat_processus,
3381: s_objet_argument, 'O')) == NULL)
3382: {
3383: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3384: return;
3385: }
3386:
3387: (*((struct_socket *) (*s_objet_resultat).objet)).effacement = 'N';
3388: (*((struct_socket *) (*s_objet_resultat).objet)).socket_en_ecoute
3389: = 'N';
3390:
3391: if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
3392: PF_INET)
3393: {
3394: longueur = sizeof(adresse_ipv4);
3395:
3396: do
3397: {
3398: drapeau = d_vrai;
3399:
3400: # ifndef SEMAPHORES_NOMMES
3401: if (sem_post(&((*s_etat_processus).semaphore_fork))
3402: != 0)
3403: # else
3404: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
3405: # endif
3406: {
3407: (*s_etat_processus).erreur_systeme = d_es_processus;
3408: return;
3409: }
3410:
3411: if (((*((struct_socket *) (*s_objet_resultat).objet))
3412: .socket = accept((*((struct_socket *)
3413: (*s_objet_argument).objet)).socket,
3414: (struct sockaddr *) &adresse_ipv4, &longueur))
3415: < 0)
3416: {
3417: erreur = errno;
3418:
3419: # ifndef SEMAPHORES_NOMMES
3420: while(sem_wait(&((*s_etat_processus)
3421: .semaphore_fork)) != 0)
3422: # else
3423: while(sem_wait((*s_etat_processus).semaphore_fork)
3424: != 0)
3425: # endif
3426: {
3427: if (errno != EINTR)
3428: {
3429: (*s_etat_processus).erreur_systeme =
3430: d_es_processus;
3431: return;
3432: }
3433: }
3434:
3435: if (erreur != EINTR)
3436: {
3437: liberation(s_etat_processus, s_objet_argument);
3438: liberation(s_etat_processus, s_objet_resultat);
3439:
3440: (*s_etat_processus).erreur_execution =
3441: d_ex_erreur_acces_fichier;
3442: return;
3443: }
3444:
3445: scrutation_injection(s_etat_processus);
3446:
3447: if ((*s_etat_processus).var_volatile_requete_arret != 0)
3448: {
3449: drapeau = d_vrai;
3450: }
3451: else
3452: {
3453: drapeau = d_faux;
3454: }
3455: }
3456: else
3457: {
3458: # ifndef SEMAPHORES_NOMMES
3459: while(sem_wait(&((*s_etat_processus)
3460: .semaphore_fork)) != 0)
3461: # else
3462: while(sem_wait((*s_etat_processus).semaphore_fork)
3463: != 0)
3464: # endif
3465: {
3466: if (errno != EINTR)
3467: {
3468: (*s_etat_processus).erreur_systeme =
3469: d_es_processus;
3470: return;
3471: }
3472: }
3473:
3474: if (options_sockets(s_etat_processus,
3475: (*s_objet_resultat).objet) != d_absence_erreur)
3476: {
3477: liberation(s_etat_processus, s_objet_argument);
3478: liberation(s_etat_processus, s_objet_resultat);
3479:
3480: (*s_etat_processus).erreur_execution =
3481: d_ex_erreur_parametre_fichier;
3482: return;
3483: }
3484: }
3485: } while(drapeau == d_faux);
3486:
3487: if (((*((struct_socket *) (*s_objet_resultat).objet))
3488: .adresse_distante = malloc(22 *
3489: sizeof(unsigned char))) == NULL)
3490: {
3491: (*s_etat_processus).erreur_systeme =
3492: d_es_allocation_memoire;
3493: return;
3494: }
3495:
3496: sprintf((*((struct_socket *) (*s_objet_resultat).objet))
3497: .adresse_distante, "%d.%d.%d.%d(%d)",
3498: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 24) & 0xFF,
3499: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 16) & 0xFF,
3500: (ntohl(adresse_ipv4.sin_addr.s_addr) >> 8) & 0xFF,
3501: ntohl(adresse_ipv4.sin_addr.s_addr) & 0xFF,
3502: ntohs(adresse_ipv4.sin_port));
3503: }
3504: else if ((*((struct_socket *) (*s_objet_resultat).objet)).domaine ==
3505: PF_INET6)
3506: {
3507: # ifdef IPV6
3508: longueur = sizeof(adresse_ipv6);
3509:
3510: do
3511: {
3512: drapeau = d_vrai;
3513:
3514: # ifndef SEMAPHORES_NOMMES
3515: if (sem_post(&((*s_etat_processus).semaphore_fork))
3516: != 0)
3517: # else
3518: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
3519: # endif
3520: {
3521: (*s_etat_processus).erreur_systeme = d_es_processus;
3522: return;
3523: }
3524:
3525: if (((*((struct_socket *) (*s_objet_resultat).objet))
3526: .socket = accept((*((struct_socket *)
3527: (*s_objet_argument).objet)).socket,
3528: (struct sockaddr *) &adresse_ipv6, &longueur)) < 0)
3529: {
3530: erreur = errno;
3531:
3532: # ifndef SEMAPHORES_NOMMES
3533: while(sem_wait(&((*s_etat_processus)
3534: .semaphore_fork)) != 0)
3535: # else
3536: while(sem_wait((*s_etat_processus).semaphore_fork)
3537: != 0)
3538: # endif
3539: {
3540: if (errno != EINTR)
3541: {
3542: (*s_etat_processus).erreur_systeme =
3543: d_es_processus;
3544: return;
3545: }
3546: }
3547:
3548: if (erreur != EINTR)
3549: {
3550: liberation(s_etat_processus, s_objet_argument);
3551: liberation(s_etat_processus, s_objet_resultat);
3552:
3553: (*s_etat_processus).erreur_execution =
3554: d_ex_erreur_acces_fichier;
3555: return;
3556: }
3557:
3558: scrutation_injection(s_etat_processus);
3559:
3560: if ((*s_etat_processus).var_volatile_requete_arret != 0)
3561: {
3562: drapeau = d_vrai;
3563: }
3564: else
3565: {
3566: drapeau = d_faux;
3567: }
3568: }
3569: else
3570: {
3571: # ifndef SEMAPHORES_NOMMES
3572: while(sem_wait(&((*s_etat_processus)
3573: .semaphore_fork)) != 0)
3574: # else
3575: while(sem_wait((*s_etat_processus).semaphore_fork)
3576: != 0)
3577: # endif
3578: {
3579: if (errno != EINTR)
3580: {
3581: (*s_etat_processus).erreur_systeme =
3582: d_es_processus;
3583: return;
3584: }
3585: }
3586:
3587: if (options_sockets(s_etat_processus,
3588: (*s_objet_resultat).objet) != d_absence_erreur)
3589: {
3590: liberation(s_etat_processus, s_objet_argument);
3591: liberation(s_etat_processus, s_objet_resultat);
3592:
3593: (*s_etat_processus).erreur_execution =
3594: d_ex_erreur_parametre_fichier;
3595: return;
3596: }
3597: }
3598: } while(drapeau == d_faux);
3599:
3600: if (((*((struct_socket *) (*s_objet_resultat).objet))
3601: .adresse_distante = malloc(47 *
3602: sizeof(unsigned char))) == NULL)
3603: {
3604: (*s_etat_processus).erreur_systeme =
3605: d_es_allocation_memoire;
3606: return;
3607: }
3608:
3609: sprintf((*((struct_socket *) (*s_objet_resultat)
3610: .objet)).adresse_distante,
3611: "%02X%02X:%02X%02X:%02X%02X:%02X%02X:"
3612: "%02X%02X:%02X%02X:%02X%02X:%02X%02X(%u)",
3613: adresse_ipv6.sin6_addr.s6_addr[0],
3614: adresse_ipv6.sin6_addr.s6_addr[1],
3615: adresse_ipv6.sin6_addr.s6_addr[2],
3616: adresse_ipv6.sin6_addr.s6_addr[3],
3617: adresse_ipv6.sin6_addr.s6_addr[4],
3618: adresse_ipv6.sin6_addr.s6_addr[5],
3619: adresse_ipv6.sin6_addr.s6_addr[6],
3620: adresse_ipv6.sin6_addr.s6_addr[7],
3621: adresse_ipv6.sin6_addr.s6_addr[8],
3622: adresse_ipv6.sin6_addr.s6_addr[9],
3623: adresse_ipv6.sin6_addr.s6_addr[10],
3624: adresse_ipv6.sin6_addr.s6_addr[11],
3625: adresse_ipv6.sin6_addr.s6_addr[12],
3626: adresse_ipv6.sin6_addr.s6_addr[13],
3627: adresse_ipv6.sin6_addr.s6_addr[14],
3628: adresse_ipv6.sin6_addr.s6_addr[15],
3629: ntohs(adresse_ipv6.sin6_port));
3630: # else
3631: if ((*s_etat_processus).langue == 'F')
3632: {
3633: printf("+++Attention : Support du protocole"
3634: " IPv6 indisponible\n");
3635: }
3636: else
3637: {
3638: printf("+++Warning : IPv6 support "
3639: "unavailable\n");
3640: }
3641: # endif
3642: }
3643: else
3644: {
3645: longueur = 0;
3646:
3647: do
3648: {
3649: drapeau = d_vrai;
3650:
3651: # ifndef SEMAPHORES_NOMMES
3652: if (sem_post(&((*s_etat_processus).semaphore_fork))
3653: != 0)
3654: # else
3655: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
3656: # endif
3657: {
3658: (*s_etat_processus).erreur_systeme = d_es_processus;
3659: return;
3660: }
3661:
3662: if (((*((struct_socket *) (*s_objet_resultat).objet))
3663: .socket = accept((*((struct_socket *)
3664: (*s_objet_argument).objet)).socket, NULL,
3665: &longueur)) < 0)
3666: {
3667: erreur = errno;
3668:
3669: # ifndef SEMAPHORES_NOMMES
3670: while(sem_wait(&((*s_etat_processus)
3671: .semaphore_fork)) != 0)
3672: # else
3673: while(sem_wait((*s_etat_processus).semaphore_fork)
3674: != 0)
3675: # endif
3676: {
3677: if (errno != EINTR)
3678: {
3679: (*s_etat_processus).erreur_systeme =
3680: d_es_processus;
3681: return;
3682: }
3683: }
3684:
3685: if (erreur != EINTR)
3686: {
3687: liberation(s_etat_processus, s_objet_argument);
3688: liberation(s_etat_processus, s_objet_resultat);
3689:
3690: (*s_etat_processus).erreur_execution =
3691: d_ex_erreur_acces_fichier;
3692: return;
3693: }
3694:
3695: scrutation_injection(s_etat_processus);
3696:
3697: if ((*s_etat_processus).var_volatile_requete_arret != 0)
3698: {
3699: drapeau = d_vrai;
3700: }
3701: else
3702: {
3703: drapeau = d_faux;
3704: }
3705: }
3706: else
3707: {
3708: # ifndef SEMAPHORES_NOMMES
3709: while(sem_wait(&((*s_etat_processus)
3710: .semaphore_fork)) != 0)
3711: # else
3712: while(sem_wait((*s_etat_processus).semaphore_fork)
3713: != 0)
3714: # endif
3715: {
3716: if (errno != EINTR)
3717: {
3718: (*s_etat_processus).erreur_systeme =
3719: d_es_processus;
3720: return;
3721: }
3722: }
3723:
3724: if (options_sockets(s_etat_processus,
3725: (*s_objet_resultat).objet) != d_absence_erreur)
3726: {
3727: liberation(s_etat_processus, s_objet_argument);
3728: liberation(s_etat_processus, s_objet_resultat);
3729:
3730: (*s_etat_processus).erreur_execution =
3731: d_ex_erreur_parametre_fichier;
3732: return;
3733: }
3734: }
3735: } while(drapeau == d_faux);
3736: }
3737:
3738: // Si accept() renvoie une erreur non récupérée, il ne peut s'agir
3739: // que de EINTR sachant qu'une requête d'arrêt est en court de
3740: // traitement.
3741:
3742: if ((*((struct_socket *) (*s_objet_resultat).objet)).socket >= 0)
3743: {
3744: l_element_courant = (*s_etat_processus).s_sockets;
3745:
3746: if (l_element_courant == NULL)
3747: {
3748: if (((*s_etat_processus).s_sockets =
3749: allocation_maillon(s_etat_processus)) == NULL)
3750: {
3751: (*s_etat_processus).erreur_systeme =
3752: d_es_allocation_memoire;
3753: return;
3754: }
3755:
3756: (*(*s_etat_processus).s_sockets).suivant = NULL;
3757: l_element_courant = (*s_etat_processus).s_sockets;
3758: }
3759: else
3760: {
3761: /*
3762: * Ajout d'un élément à la fin de la liste chaînée
3763: */
3764:
3765: while((*l_element_courant).suivant != NULL)
3766: {
3767: l_element_courant = (*l_element_courant).suivant;
3768: }
3769:
3770: if (((*l_element_courant).suivant =
3771: allocation_maillon(s_etat_processus)) == NULL)
3772: {
3773: (*s_etat_processus).erreur_systeme =
3774: d_es_allocation_memoire;
3775: return;
3776: }
3777:
3778: l_element_courant = (*l_element_courant).suivant;
3779: (*l_element_courant).suivant = NULL;
3780: }
3781:
3782: if (((*l_element_courant).donnee = copie_objet(s_etat_processus,
3783: s_objet_resultat, 'O')) == NULL)
3784: {
3785: (*s_etat_processus).erreur_systeme =
3786: d_es_allocation_memoire;
3787: return;
3788: }
3789: }
3790:
3791: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3792: s_objet_argument) == d_erreur)
3793: {
3794: return;
3795: }
3796:
3797: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3798: s_objet_resultat) == d_erreur)
3799: {
3800: return;
3801: }
3802: }
3803: }
3804: else
3805: {
3806: liberation(s_etat_processus, s_objet_argument);
3807:
3808: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
3809: return;
3810: }
3811:
3812: return;
3813: }
3814:
3815:
3816: /*
3817: ================================================================================
3818: Fonction 'wfswi'
3819: ================================================================================
3820: Entrées : pointeur sur une structure struct_processus
3821: --------------------------------------------------------------------------------
3822: Sorties :
3823: --------------------------------------------------------------------------------
3824: Effets de bord : néant
3825: ================================================================================
3826: */
3827:
3828: void
3829: instruction_wfswi(struct_processus *s_etat_processus)
3830: {
3831: integer8 interruption;
3832:
3833: logical1 drapeau_fin;
3834:
3835: struct_objet *s_objet_argument;
3836:
3837: struct timespec attente;
3838:
3839: (*s_etat_processus).erreur_execution = d_ex;
3840:
3841: attente.tv_sec = 0;
3842: attente.tv_nsec = GRANULARITE_us * 1000;
3843:
3844: if ((*s_etat_processus).affichage_arguments == 'Y')
3845: {
3846: printf("\n WFSWI ");
3847:
3848: if ((*s_etat_processus).langue == 'F')
3849: {
3850: printf("(attente d'une interruption)\n\n");
3851: }
3852: else
3853: {
3854: printf("(wait for interrupt)\n\n");
3855: }
3856:
3857: printf(" 1: %s\n", d_INT);
3858:
3859: return;
3860: }
3861: else if ((*s_etat_processus).test_instruction == 'Y')
3862: {
3863: (*s_etat_processus).nombre_arguments = -1;
3864: return;
3865: }
3866:
3867: if (test_cfsf(s_etat_processus, 31) == d_vrai)
3868: {
3869: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
3870: {
3871: return;
3872: }
3873: }
3874:
3875: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
3876: &s_objet_argument) == d_erreur)
3877: {
3878: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
3879: return;
3880: }
3881:
3882: if ((*s_objet_argument).type == INT)
3883: {
3884: drapeau_fin = d_faux;
3885:
3886: interruption = (*((integer8 *) (*s_objet_argument).objet));
3887:
3888: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
3889: {
3890: liberation(s_etat_processus, s_objet_argument);
3891:
3892: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
3893: return;
3894: }
3895:
3896: while(drapeau_fin == d_faux)
3897: {
3898: if ((*s_etat_processus).var_volatile_requete_arret != 0)
3899: {
3900: liberation(s_etat_processus, s_objet_argument);
3901: return;
3902: }
3903:
3904: if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions)
3905: != 0)
3906: {
3907: (*s_etat_processus).erreur_systeme = d_es_processus;
3908: return;
3909: }
3910:
3911: if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
3912: {
3913: affectation_interruptions_logicielles(s_etat_processus);
3914: }
3915:
3916: if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions)
3917: != 0)
3918: {
3919: (*s_etat_processus).erreur_systeme = d_es_processus;
3920: return;
3921: }
3922:
3923: if ((*s_etat_processus).queue_interruptions[interruption - 1] > 0)
3924: {
3925: drapeau_fin = d_vrai;
3926: }
3927: else
3928: {
3929: # ifndef SEMAPHORES_NOMMES
3930: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
3931: # else
3932: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
3933: # endif
3934: {
3935: (*s_etat_processus).erreur_systeme = d_es_processus;
3936: return;
3937: }
3938: nanosleep(&attente, NULL);
3939:
3940: # ifndef SEMAPHORES_NOMMES
3941: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
3942: # else
3943: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
3944: # endif
3945: {
3946: if (errno != EINTR)
3947: {
3948: (*s_etat_processus).erreur_systeme = d_es_processus;
3949: return;
3950: }
3951: }
3952:
3953: scrutation_injection(s_etat_processus);
3954: INCR_GRANULARITE(attente.tv_nsec);
3955: }
3956: }
3957: }
3958: else
3959: {
3960: liberation(s_etat_processus, s_objet_argument);
3961:
3962: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
3963: return;
3964: }
3965:
3966: liberation(s_etat_processus, s_objet_argument);
3967:
3968: return;
3969: }
3970:
3971:
3972: /*
3973: ================================================================================
3974: Fonction 'wfpoke'
3975: ================================================================================
3976: Entrées : pointeur sur une structure struct_processus
3977: --------------------------------------------------------------------------------
3978: Sorties :
3979: --------------------------------------------------------------------------------
3980: Effets de bord : néant
3981: ================================================================================
3982: */
3983:
3984: void
3985: instruction_wfpoke(struct_processus *s_etat_processus)
3986: {
3987: struct timespec attente;
3988:
3989: unsigned char registre_instruction_valide;
3990:
3991: (*s_etat_processus).erreur_execution = d_ex;
3992:
3993: attente.tv_sec = 0;
3994: attente.tv_nsec = GRANULARITE_us * 1000;
3995:
3996: if ((*s_etat_processus).affichage_arguments == 'Y')
3997: {
3998: printf("\n WFPOKE ");
3999:
4000: if ((*s_etat_processus).langue == 'F')
4001: {
4002: printf("(attente de données en provenance du processus père)\n\n");
4003: printf(" Aucun argument\n");
4004: }
4005: else
4006: {
4007: printf("(wait for data from parent process)\n\n");
4008: printf(" No argument\n");
4009: }
4010:
4011: return;
4012: }
4013: else if ((*s_etat_processus).test_instruction == 'Y')
4014: {
4015: (*s_etat_processus).nombre_arguments = -1;
4016: return;
4017: }
4018:
4019: if (test_cfsf(s_etat_processus, 31) == d_vrai)
4020: {
4021: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
4022: {
4023: return;
4024: }
4025: }
4026:
4027: if ((*s_etat_processus).presence_pipes == d_faux)
4028: {
4029: (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
4030: return;
4031: }
4032:
4033: if ((*s_etat_processus).nombre_objets_injectes > 0)
4034: {
4035: return;
4036: }
4037:
4038: if ((*s_etat_processus).profilage == d_vrai)
4039: {
4040: profilage(s_etat_processus, "Interprocess or interthread "
4041: "communications (WFPOKE)");
4042:
4043: if ((*s_etat_processus).erreur_systeme != d_es)
4044: {
4045: return;
4046: }
4047: }
4048:
4049: do
4050: {
4051: # ifndef SEMAPHORES_NOMMES
4052: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
4053: # else
4054: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
4055: # endif
4056: {
4057: (*s_etat_processus).erreur_systeme = d_es_processus;
4058: return;
4059: }
4060:
4061: nanosleep(&attente, NULL);
4062:
4063: # ifndef SEMAPHORES_NOMMES
4064: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
4065: # else
4066: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
4067: # endif
4068: {
4069: if (errno != EINTR)
4070: {
4071: (*s_etat_processus).erreur_systeme = d_es_processus;
4072: return;
4073: }
4074: }
4075:
4076: scrutation_injection(s_etat_processus);
4077:
4078: if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) != 0)
4079: {
4080: (*s_etat_processus).erreur_systeme = d_es_processus;
4081: return;
4082: }
4083:
4084: if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
4085: {
4086: affectation_interruptions_logicielles(s_etat_processus);
4087: }
4088:
4089: if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) != 0)
4090: {
4091: (*s_etat_processus).erreur_systeme = d_es_processus;
4092: return;
4093: }
4094:
4095: if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
4096: {
4097: registre_instruction_valide =
4098: (*s_etat_processus).instruction_valide;
4099: traitement_interruptions_logicielles(s_etat_processus);
4100: (*s_etat_processus).instruction_valide =
4101: registre_instruction_valide;
4102: }
4103:
4104: if ((*s_etat_processus).var_volatile_requete_arret != 0)
4105: {
4106: if ((*s_etat_processus).profilage == d_vrai)
4107: {
4108: profilage(s_etat_processus, NULL);
4109: }
4110:
4111: return;
4112: }
4113:
4114: INCR_GRANULARITE(attente.tv_nsec);
4115: } while((*s_etat_processus).nombre_objets_injectes == 0);
4116:
4117: return;
4118: }
4119:
4120:
4121: /*
4122: ================================================================================
4123: Fonction 'wfack'
4124: ================================================================================
4125: Entrées : pointeur sur une structure struct_processus
4126: --------------------------------------------------------------------------------
4127: Sorties :
4128: --------------------------------------------------------------------------------
4129: Effets de bord : néant
4130: ================================================================================
4131: */
4132:
4133: void
4134: instruction_wfack(struct_processus *s_etat_processus)
4135: {
4136: struct timespec attente;
4137:
4138: unsigned char registre_instruction_valide;
4139:
4140: (*s_etat_processus).erreur_execution = d_ex;
4141:
4142: attente.tv_sec = 0;
4143: attente.tv_nsec = GRANULARITE_us * 1000;
4144:
4145: if ((*s_etat_processus).affichage_arguments == 'Y')
4146: {
4147: printf("\n WFACK ");
4148:
4149: if ((*s_etat_processus).langue == 'F')
4150: {
4151: printf("(attente des acquittements de lecture)\n\n");
4152: printf(" Aucun argument\n");
4153: }
4154: else
4155: {
4156: printf("(wait for reading of data acknowledgement)\n\n");
4157: printf(" No argument\n");
4158: }
4159:
4160: return;
4161: }
4162: else if ((*s_etat_processus).test_instruction == 'Y')
4163: {
4164: (*s_etat_processus).nombre_arguments = -1;
4165: return;
4166: }
4167:
4168: if (test_cfsf(s_etat_processus, 31) == d_vrai)
4169: {
4170: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
4171: {
4172: return;
4173: }
4174: }
4175:
4176: if ((*s_etat_processus).presence_pipes == d_faux)
4177: {
4178: (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
4179: return;
4180: }
4181:
4182: if ((*s_etat_processus).profilage == d_vrai)
4183: {
4184: profilage(s_etat_processus, "Interprocess or interthread communications"
4185: " (WFACK)");
4186:
4187: if ((*s_etat_processus).erreur_systeme != d_es)
4188: {
4189: return;
4190: }
4191: }
4192:
4193: while((*s_etat_processus).nombre_objets_envoyes_non_lus != 0)
4194: {
4195: scrutation_injection(s_etat_processus);
4196:
4197: if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) != 0)
4198: {
4199: (*s_etat_processus).erreur_systeme = d_es_processus;
4200: return;
4201: }
4202:
4203: if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
4204: {
4205: affectation_interruptions_logicielles(s_etat_processus);
4206: }
4207:
4208: if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) != 0)
4209: {
4210: (*s_etat_processus).erreur_systeme = d_es_processus;
4211: return;
4212: }
4213:
4214: if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
4215: {
4216: registre_instruction_valide =
4217: (*s_etat_processus).instruction_valide;
4218: traitement_interruptions_logicielles(s_etat_processus);
4219: (*s_etat_processus).instruction_valide =
4220: registre_instruction_valide;
4221: }
4222:
4223: if ((*s_etat_processus).var_volatile_requete_arret != 0)
4224: {
4225: if ((*s_etat_processus).profilage == d_vrai)
4226: {
4227: profilage(s_etat_processus, NULL);
4228: }
4229:
4230: return;
4231: }
4232:
4233: # ifndef SEMAPHORES_NOMMES
4234: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
4235: # else
4236: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
4237: # endif
4238: {
4239: (*s_etat_processus).erreur_systeme = d_es_processus;
4240: return;
4241: }
4242:
4243: nanosleep(&attente, NULL);
4244: INCR_GRANULARITE(attente.tv_nsec);
4245:
4246: # ifndef SEMAPHORES_NOMMES
4247: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
4248: # else
4249: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
4250: # endif
4251: {
4252: if (errno != EINTR)
4253: {
4254: (*s_etat_processus).erreur_systeme = d_es_processus;
4255: return;
4256: }
4257: }
4258: }
4259:
4260: if ((*s_etat_processus).profilage == d_vrai)
4261: {
4262: profilage(s_etat_processus, NULL);
4263: }
4264:
4265: return;
4266: }
4267:
4268: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>