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