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