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