Annotation of rpl/src/instructions_s8.c, revision 1.52

1.1       bertrand    1: /*
                      2: ================================================================================
1.51      bertrand    3:   RPL/2 (R) version 4.1.12
1.42      bertrand    4:   Copyright (C) 1989-2012 Dr. BERTRAND Joël
1.1       bertrand    5: 
                      6:   This file is part of RPL/2.
                      7: 
                      8:   RPL/2 is free software; you can redistribute it and/or modify it
                      9:   under the terms of the CeCILL V2 License as published by the french
                     10:   CEA, CNRS and INRIA.
                     11:  
                     12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
                     13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                     14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
                     15:   for more details.
                     16:  
                     17:   You should have received a copy of the CeCILL License
                     18:   along with RPL/2. If not, write to info@cecill.info.
                     19: ================================================================================
                     20: */
                     21: 
                     22: 
1.15      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   Fonction 'splash'
                     29: ================================================================================
                     30:   Entrées :
                     31: --------------------------------------------------------------------------------
                     32:   Sorties :
                     33: --------------------------------------------------------------------------------
                     34:   Effets de bord : néant
                     35: ================================================================================
                     36: */
                     37: 
                     38: void
                     39: instruction_splash(struct_processus *s_etat_processus)
                     40: {
                     41:    real8                       attente;
                     42: 
                     43:    struct_objet                *s_objet;
                     44: 
                     45:    (*s_etat_processus).erreur_execution = d_ex;
                     46: 
                     47:    if ((*s_etat_processus).affichage_arguments == 'Y')
                     48:    {
                     49:        printf("\n  SPLASH ");
                     50: 
                     51:        if ((*s_etat_processus).langue == 'F')
                     52:        {
                     53:            printf("(écran RPL/2)\n\n");
                     54:        }
                     55:        else
                     56:        {
                     57:            printf("(RPL/2 splash screen)\n\n");
                     58:        }
                     59: 
                     60:        printf("    1: %s, %s\n", d_INT, d_REL);
                     61: 
                     62:        return;
                     63:    }
                     64:    else if ((*s_etat_processus).test_instruction == 'Y')
                     65:    {
                     66:        (*s_etat_processus).nombre_arguments = -1;
                     67:        return;
                     68:    }
                     69:    
                     70:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                     71:    {
                     72:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                     73:        {
                     74:            return;
                     75:        }
                     76:    }
                     77: 
                     78:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                     79:            &s_objet) == d_erreur)
                     80:    {
                     81:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                     82:        return;
                     83:    }
                     84: 
                     85:    if (((*s_objet).type == INT) ||
                     86:            ((*s_objet).type == REL))
                     87:    {
                     88:        if ((*s_objet).type == INT)
                     89:        {
                     90:            attente = (real8) (*((integer8 *) (*s_objet).objet));
                     91:        }
                     92:        else
                     93:        {
                     94:            attente = (*((real8 *) (*s_objet).objet));
                     95:        }
                     96: 
                     97:        if (attente < 0)
                     98:        {
                     99:            liberation(s_etat_processus, s_objet);
                    100: 
                    101:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    102:            return;
                    103:        }
                    104: 
                    105:        encart(s_etat_processus, (unsigned long) (attente * 1E6));
                    106:    }
                    107:    else
                    108:    {
                    109:        liberation(s_etat_processus, s_objet);
                    110: 
                    111:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    112:        return;
                    113:    }
                    114: 
                    115:    liberation(s_etat_processus, s_objet);
                    116: 
                    117:    return;
                    118: }
                    119: 
                    120: 
                    121: /*
                    122: ================================================================================
                    123:   Fonction 'send'
                    124: ================================================================================
                    125:   Entrées :
                    126: --------------------------------------------------------------------------------
                    127:   Sorties :
                    128: --------------------------------------------------------------------------------
                    129:   Effets de bord : néant
                    130: ================================================================================
                    131: */
                    132: 
                    133: void
                    134: instruction_send(struct_processus *s_etat_processus)
                    135: {
                    136:    pid_t                       pid;
                    137: 
                    138:    pthread_t                   tid;
                    139: 
                    140:    sig_atomic_t                registre;
                    141: 
                    142:    ssize_t                     longueur_ecriture;
                    143: 
                    144:    struct_objet                *s_objet;
                    145: 
                    146:    struct timespec             attente;
                    147: 
                    148:    unsigned char               tampon;
                    149: 
                    150:    (*s_etat_processus).erreur_execution = d_ex;
                    151: 
                    152:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    153:    {
                    154:        printf("\n  SEND ");
                    155: 
                    156:        if ((*s_etat_processus).langue == 'F')
                    157:        {
                    158:            printf("(envoi de données au processus père)\n\n");
                    159:        }
                    160:        else
                    161:        {
                    162:            printf("(send data to parent process)\n\n");
                    163:        }
                    164: 
                    165:        printf("    1: %s, %s, %s, %s, %s, %s,\n"
                    166:                "       %s, %s, %s, %s, %s,\n"
                    167:                "       %s, %s, %s, %s, %s\n",
                    168:                d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX,
                    169:                d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_TAB);
                    170: 
                    171:        return;
                    172:    }
                    173:    else if ((*s_etat_processus).test_instruction == 'Y')
                    174:    {
                    175:        (*s_etat_processus).nombre_arguments = -1;
                    176:        return;
                    177:    }
                    178:    
                    179:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    180:    {
                    181:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    182:        {
                    183:            return;
                    184:        }
                    185:    }
                    186: 
                    187:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    188:            &s_objet) == d_erreur)
                    189:    {
                    190:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    191:        return;
                    192:    }
                    193: 
                    194:    if ((*s_etat_processus).presence_pipes == d_faux)
                    195:    {
                    196:        liberation(s_etat_processus, s_objet);
                    197: 
                    198:        (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
                    199:        return;
                    200:    }
                    201: 
                    202:    if (((*s_objet).type != INT) &&
                    203:            ((*s_objet).type != REL) &&
                    204:            ((*s_objet).type != CPL) &&
                    205:            ((*s_objet).type != VIN) &&
                    206:            ((*s_objet).type != VRL) &&
                    207:            ((*s_objet).type != VCX) &&
                    208:            ((*s_objet).type != MIN) &&
                    209:            ((*s_objet).type != MRL) &&
                    210:            ((*s_objet).type != MCX) &&
                    211:            ((*s_objet).type != BIN) &&
                    212:            ((*s_objet).type != NOM) &&
                    213:            ((*s_objet).type != CHN) &&
                    214:            ((*s_objet).type != LST) &&
                    215:            ((*s_objet).type != ALG) &&
                    216:            ((*s_objet).type != RPN) &&
                    217:            ((*s_objet).type != TBL))
                    218:    {
                    219:        liberation(s_etat_processus, s_objet);
                    220: 
                    221:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    222:        return;
                    223:    }
                    224: 
                    225:    /*
                    226:     * On signale au processus père qu'il y a un objet de plus
                    227:     * dans le pipe de données.
                    228:     */
                    229: 
                    230:    registre = (*s_etat_processus).var_volatile_traitement_retarde_stop;
                    231:    (*s_etat_processus).var_volatile_traitement_retarde_stop = 1;
                    232: 
                    233:    if ((*s_etat_processus).processus_detache == d_vrai)
                    234:    {
                    235:        if ((*s_etat_processus).profilage == d_vrai)
                    236:        {
                    237:            profilage(s_etat_processus, "Interprocess communications (SEND)");
                    238: 
                    239:            if ((*s_etat_processus).erreur_systeme != d_es)
                    240:            {
                    241:                return;
                    242:            }
                    243:        }
                    244: 
                    245:        pid = -3;
                    246: 
                    247:        attente.tv_sec = 0;
                    248:        attente.tv_nsec = GRANULARITE_us * 1000;
                    249: 
1.38      bertrand  250: #      ifndef SEMAPHORES_NOMMES
                    251:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    252: #      else
                    253:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    254: #      endif
1.1       bertrand  255:        {
                    256:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    257:            return;
                    258:        }
                    259: 
                    260:        while((longueur_ecriture = write_atomic(s_etat_processus,
                    261:                (*s_etat_processus).pipe_nombre_objets_attente,
                    262:                &pid, sizeof(pid))) != sizeof(pid))
                    263:        {
1.38      bertrand  264: #          ifndef SEMAPHORES_NOMMES
                    265:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    266: #          else
                    267:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    268: #          endif
1.1       bertrand  269:            {
1.37      bertrand  270:                if (errno != EINTR)
                    271:                {
                    272:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    273:                    return;
                    274:                }
1.1       bertrand  275:            }
                    276: 
                    277:            if (longueur_ecriture == -1)
                    278:            {
                    279:                if ((*s_etat_processus).profilage == d_vrai)
                    280:                {
                    281:                    profilage(s_etat_processus, NULL);
                    282:                }
                    283: 
                    284:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    285:                return;
                    286:            }
                    287: 
                    288:            nanosleep(&attente, NULL);
                    289:            INCR_GRANULARITE(attente.tv_nsec);
                    290: 
1.38      bertrand  291: #          ifndef SEMAPHORES_NOMMES
                    292:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    293: #          else
                    294:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    295: #          endif
1.7       bertrand  296:            {
                    297:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    298:                return;
                    299:            }
1.35      bertrand  300: 
                    301:            scrutation_interruptions(s_etat_processus);
1.1       bertrand  302:        }
                    303: 
                    304:        pid = getpid();
                    305: 
                    306:        attente.tv_sec = 0;
                    307:        attente.tv_nsec = GRANULARITE_us * 1000;
                    308: 
                    309:        while((longueur_ecriture = write_atomic(s_etat_processus,
                    310:                (*s_etat_processus).pipe_nombre_objets_attente,
                    311:                &pid, sizeof(pid))) != sizeof(pid))
                    312:        {
1.38      bertrand  313: #          ifndef SEMAPHORES_NOMMES
                    314:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    315: #          else
                    316:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    317: #          endif
1.1       bertrand  318:            {
1.37      bertrand  319:                if (errno != EINTR)
                    320:                {
                    321:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    322:                    return;
                    323:                }
1.1       bertrand  324:            }
                    325: 
                    326:            if (longueur_ecriture == -1)
                    327:            {
                    328:                if ((*s_etat_processus).profilage == d_vrai)
                    329:                {
                    330:                    profilage(s_etat_processus, NULL);
                    331:                }
                    332: 
                    333:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    334:                return;
                    335:            }
                    336: 
                    337:            nanosleep(&attente, NULL);
                    338:            INCR_GRANULARITE(attente.tv_nsec);
                    339: 
1.38      bertrand  340: #          ifndef SEMAPHORES_NOMMES
                    341:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    342: #          else
                    343:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    344: #          endif
1.1       bertrand  345:            {
                    346:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    347:                return;
                    348:            }
1.35      bertrand  349: 
                    350:            scrutation_interruptions(s_etat_processus);
1.1       bertrand  351:        }
                    352: 
1.38      bertrand  353: #      ifndef SEMAPHORES_NOMMES
                    354:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    355: #      else
                    356:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    357: #      endif
1.1       bertrand  358:        {
1.37      bertrand  359:            if (errno != EINTR)
                    360:            {
                    361:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    362:                return;
                    363:            }
1.1       bertrand  364:        }
                    365:    }
                    366:    else
                    367:    {
                    368:        if ((*s_etat_processus).profilage == d_vrai)
                    369:        {
                    370:            profilage(s_etat_processus, "Interthread communications (SEND)");
                    371: 
                    372:            if ((*s_etat_processus).erreur_systeme != d_es)
                    373:            {
                    374:                return;
                    375:            }
                    376:        }
                    377: 
1.48      bertrand  378:        tid = (pthread_t) -3;
1.1       bertrand  379: 
                    380:        attente.tv_sec = 0;
                    381:        attente.tv_nsec = GRANULARITE_us * 1000;
                    382: 
1.38      bertrand  383: #      ifndef SEMAPHORES_NOMMES
                    384:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    385: #      else
                    386:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    387: #      endif
1.1       bertrand  388:        {
                    389:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    390:            return;
                    391:        }
                    392: 
                    393:        while((longueur_ecriture = write_atomic(s_etat_processus,
                    394:                (*s_etat_processus).pipe_nombre_objets_attente,
                    395:                &tid, sizeof(tid))) != sizeof(tid))
                    396:        {
1.38      bertrand  397: #          ifndef SEMAPHORES_NOMMES
                    398:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    399: #          else
                    400:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    401: #          endif
1.1       bertrand  402:            {
1.34      bertrand  403:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    404:                return;
1.1       bertrand  405:            }
                    406: 
                    407:            if (longueur_ecriture == -1)
                    408:            {
                    409:                if ((*s_etat_processus).profilage == d_vrai)
                    410:                {
                    411:                    profilage(s_etat_processus, NULL);
                    412:                }
                    413: 
                    414:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    415:                return;
                    416:            }
                    417: 
                    418:            nanosleep(&attente, NULL);
                    419:            INCR_GRANULARITE(attente.tv_nsec);
                    420: 
1.38      bertrand  421: #          ifndef SEMAPHORES_NOMMES
                    422:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    423: #          else
                    424:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    425: #          endif
1.1       bertrand  426:            {
                    427:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    428:                return;
                    429:            }
1.35      bertrand  430: 
                    431:            scrutation_interruptions(s_etat_processus);
1.1       bertrand  432:        }
                    433: 
                    434:        tid = pthread_self();
                    435: 
                    436:        attente.tv_sec = 0;
                    437:        attente.tv_nsec = GRANULARITE_us * 1000;
                    438: 
                    439:        while((longueur_ecriture = write_atomic(s_etat_processus,
                    440:                (*s_etat_processus).pipe_nombre_objets_attente,
                    441:                &tid, sizeof(tid))) != sizeof(tid))
                    442:        {
1.38      bertrand  443: #          ifndef SEMAPHORES_NOMMES
                    444:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    445: #          else
                    446:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    447: #          endif
1.1       bertrand  448:            {
1.37      bertrand  449:                if (errno != EINTR)
                    450:                {
                    451:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    452:                    return;
                    453:                }
1.1       bertrand  454:            }
                    455: 
                    456:            if (longueur_ecriture == -1)
                    457:            {
                    458:                if ((*s_etat_processus).profilage == d_vrai)
                    459:                {
                    460:                    profilage(s_etat_processus, NULL);
                    461:                }
                    462: 
                    463:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    464:                return;
                    465:            }
                    466: 
                    467:            nanosleep(&attente, NULL);
                    468:            INCR_GRANULARITE(attente.tv_nsec);
                    469: 
1.38      bertrand  470: #          ifndef SEMAPHORES_NOMMES
                    471:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    472: #          else
                    473:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    474: #          endif
1.7       bertrand  475:            {
                    476:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    477:                return;
                    478:            }
1.35      bertrand  479: 
                    480:            scrutation_interruptions(s_etat_processus);
1.1       bertrand  481:        }
                    482: 
1.38      bertrand  483: #      ifndef SEMAPHORES_NOMMES
                    484:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    485: #      else
                    486:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    487: #      endif
1.1       bertrand  488:        {
1.34      bertrand  489:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    490:            return;
1.1       bertrand  491:        }
                    492:    }
                    493: 
                    494:    (*s_etat_processus).nombre_objets_envoyes_non_lus++;
                    495: 
                    496:    attente.tv_sec = 0;
                    497:    attente.tv_nsec = GRANULARITE_us * 1000;
                    498: 
1.38      bertrand  499: #  ifndef SEMAPHORES_NOMMES
                    500:        if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    501: #  else
                    502:        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    503: #  endif
1.7       bertrand  504:    {
                    505:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    506:        return;
                    507:    }
1.1       bertrand  508: 
                    509:    while(read_atomic(s_etat_processus, (*s_etat_processus).pipe_acquittement,
                    510:            &tampon, sizeof(unsigned char)) != sizeof(unsigned char))
                    511:    {
1.38      bertrand  512: #      ifndef SEMAPHORES_NOMMES
                    513:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    514: #      else
                    515:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    516: #      endif
1.1       bertrand  517:        {
1.37      bertrand  518:            if (errno != EINTR)
                    519:            {
                    520:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    521:                return;
                    522:            }
1.1       bertrand  523:        }
                    524: 
                    525:        nanosleep(&attente, NULL);
                    526:        INCR_GRANULARITE(attente.tv_nsec);
                    527: 
1.38      bertrand  528: #      ifndef SEMAPHORES_NOMMES
                    529:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    530: #      else
                    531:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    532: #      endif
1.1       bertrand  533:        {
                    534:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    535:            return;
                    536:        }
1.35      bertrand  537: 
                    538:        scrutation_interruptions(s_etat_processus);
1.1       bertrand  539:    }
                    540: 
1.38      bertrand  541: #  ifndef SEMAPHORES_NOMMES
                    542:        while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    543: #  else
                    544:        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    545: #  endif
1.1       bertrand  546:    {
1.37      bertrand  547:        if (errno != EINTR)
                    548:        {
                    549:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    550:            return;
                    551:        }
1.1       bertrand  552:    }
                    553: 
                    554:    // Envoi d'un PID invalide (-1) pour ne pas bloquer le thread
                    555:    // de surveillance.
                    556: 
                    557:    if ((*s_etat_processus).processus_detache == d_vrai)
                    558:    {
                    559:        pid = -1;
                    560: 
                    561:        attente.tv_sec = 0;
                    562:        attente.tv_nsec = GRANULARITE_us * 1000;
                    563: 
1.38      bertrand  564: #      ifndef SEMAPHORES_NOMMES
                    565:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    566: #      else
                    567:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    568: #      endif
1.1       bertrand  569:        {
                    570:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    571:            return;
                    572:        }
                    573: 
                    574:        while((longueur_ecriture = write_atomic(s_etat_processus,
                    575:                (*s_etat_processus).pipe_nombre_interruptions_attente,
                    576:                &pid, sizeof(pid))) != sizeof(pid))
                    577:        {
1.38      bertrand  578: #          ifndef SEMAPHORES_NOMMES
                    579:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    580: #          else
                    581:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    582: #          endif
1.1       bertrand  583:            {
1.34      bertrand  584:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    585:                return;
1.1       bertrand  586:            }
                    587: 
                    588:            if (longueur_ecriture == -1)
                    589:            {
                    590:                if ((*s_etat_processus).profilage == d_vrai)
                    591:                {
                    592:                    profilage(s_etat_processus, NULL);
                    593:                }
                    594: 
                    595:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    596:                return;
                    597:            }
                    598: 
                    599:            nanosleep(&attente, NULL);
                    600:            INCR_GRANULARITE(attente.tv_nsec);
                    601: 
1.38      bertrand  602: #          ifndef SEMAPHORES_NOMMES
                    603:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    604: #          else
                    605:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    606: #          endif
1.1       bertrand  607:            {
                    608:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    609:                return;
                    610:            }
                    611:        }
                    612: 
1.38      bertrand  613: #      ifndef SEMAPHORES_NOMMES
                    614:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    615: #      else
                    616:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    617: #      endif
1.1       bertrand  618:        {
1.37      bertrand  619:            if (errno != EINTR)
                    620:            {
                    621:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    622:                return;
                    623:            }
1.1       bertrand  624:        }
1.35      bertrand  625: 
                    626:        scrutation_interruptions(s_etat_processus);
1.1       bertrand  627:    }
                    628:    else
                    629:    {
1.48      bertrand  630:        tid = (pthread_t) -1;
1.1       bertrand  631: 
                    632:        attente.tv_sec = 0;
                    633:        attente.tv_nsec = GRANULARITE_us * 1000;
                    634: 
1.38      bertrand  635: #      ifndef SEMAPHORES_NOMMES
                    636:            if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    637: #      else
                    638:            if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    639: #      endif
1.1       bertrand  640:        {
                    641:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    642:            return;
                    643:        }
                    644: 
                    645:        while((longueur_ecriture = write_atomic(s_etat_processus,
                    646:                (*s_etat_processus).pipe_nombre_interruptions_attente,
                    647:                &tid, sizeof(tid))) != sizeof(tid))
                    648:        {
1.38      bertrand  649: #          ifndef SEMAPHORES_NOMMES
                    650:                while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    651: #          else
                    652:                while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    653: #          endif
1.1       bertrand  654:            {
1.37      bertrand  655:                if (errno != EINTR)
                    656:                {
                    657:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    658:                    return;
                    659:                }
1.1       bertrand  660:            }
                    661: 
                    662:            if (longueur_ecriture == -1)
                    663:            {
                    664:                if ((*s_etat_processus).profilage == d_vrai)
                    665:                {
                    666:                    profilage(s_etat_processus, NULL);
                    667:                }
                    668: 
                    669:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    670:                return;
                    671:            }
                    672: 
                    673:            nanosleep(&attente, NULL);
                    674:            INCR_GRANULARITE(attente.tv_nsec);
                    675: 
1.38      bertrand  676: #          ifndef SEMAPHORES_NOMMES
                    677:                if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    678: #          else
                    679:                if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    680: #          endif
1.1       bertrand  681:            {
                    682:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    683:                return;
                    684:            }
1.35      bertrand  685: 
                    686:            scrutation_interruptions(s_etat_processus);
1.1       bertrand  687:        }
                    688: 
1.38      bertrand  689: #      ifndef SEMAPHORES_NOMMES
                    690:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    691: #      else
                    692:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    693: #      endif
1.1       bertrand  694:        {
1.37      bertrand  695:            if (errno != EINTR)
                    696:            {
                    697:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    698:                return;
                    699:            }
1.1       bertrand  700:        }
                    701:    }
                    702: 
                    703:    // ecriture_pipe() ne peut être interrompu par un signal.
                    704: 
1.38      bertrand  705: #  ifndef SEMAPHORES_NOMMES
                    706:        if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    707: #  else
                    708:        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    709: #  endif
1.1       bertrand  710:    {
                    711:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    712:        return;
                    713:    }
                    714: 
                    715:    if (ecriture_pipe(s_etat_processus, (*s_etat_processus).pipe_donnees,
                    716:            s_objet) == d_erreur)
                    717:    {
1.38      bertrand  718: #      ifndef SEMAPHORES_NOMMES
                    719:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    720: #      else
                    721:            while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    722: #      endif
1.1       bertrand  723:        {
1.37      bertrand  724:            if (errno != EINTR)
                    725:            {
                    726:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    727:                return;
                    728:            }
1.1       bertrand  729:        }
                    730: 
                    731:        if ((*s_etat_processus).profilage == d_vrai)
                    732:        {
                    733:            profilage(s_etat_processus, NULL);
                    734:        }
                    735: 
                    736:        liberation(s_etat_processus, s_objet);
                    737:        return;
                    738:    }
                    739: 
1.38      bertrand  740: #  ifndef SEMAPHORES_NOMMES
                    741:        while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
                    742: #  else
                    743:        while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
                    744: #  endif
1.1       bertrand  745:    {
1.37      bertrand  746:        if (errno != EINTR)
                    747:        {
                    748:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    749:            return;
                    750:        }
1.1       bertrand  751:    }
                    752: 
                    753:    if ((*s_etat_processus).profilage == d_vrai)
                    754:    {
                    755:        profilage(s_etat_processus, NULL);
                    756:    }
                    757: 
                    758:    if (registre == 0)
                    759:    {
                    760:        if ((*s_etat_processus).var_volatile_traitement_retarde_stop == -1)
                    761:        {
                    762:            (*s_etat_processus).var_volatile_requete_arret = -1;
                    763:        }
                    764: 
                    765:        (*s_etat_processus).var_volatile_traitement_retarde_stop = registre;
                    766:    }
                    767: 
                    768:    liberation(s_etat_processus, s_objet);
                    769:    return;
                    770: }
                    771: 
                    772: 
                    773: /*
                    774: ================================================================================
                    775:   Fonction 'sqlquery'
                    776: ================================================================================
                    777:   Entrées :
                    778: --------------------------------------------------------------------------------
                    779:   Sorties :
                    780: --------------------------------------------------------------------------------
                    781:   Effets de bord : néant
                    782: ================================================================================
                    783: */
                    784: 
                    785: void
                    786: instruction_sqlquery(struct_processus *s_etat_processus)
                    787: {
                    788: #  define                          d_LONGUEUR  1024
                    789: 
1.40      bertrand  790: #  if defined(MYSQL_SUPPORT) || defined(POSTGRESQL_SUPPORT)
1.1       bertrand  791:    logical1                        connexion_permanente;
1.40      bertrand  792: #  endif
1.1       bertrand  793: 
                    794:    struct_objet                    *s_copie_1;
                    795:    struct_objet                    *s_objet_1;
                    796:    struct_objet                    *s_copie_2;
                    797:    struct_objet                    *s_objet_2;
                    798: 
                    799:    unsigned char                   *tampon;
                    800: 
                    801:    (*s_etat_processus).erreur_execution = d_ex;
                    802: 
                    803:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    804:    {
                    805:        printf("\n  SQLQUERY ");
                    806: 
                    807:        if ((*s_etat_processus).langue == 'F')
                    808:        {
                    809:            printf("(requête SQL)\n\n");
                    810:        }
                    811:        else
                    812:        {
                    813:            printf("(SQL query)\n\n");
                    814:        }
                    815: 
                    816:        printf("    2: %s\n", d_CHN);
                    817:        printf("    1: %s\n", d_LST);
                    818:        printf("->  1: %s\n\n", d_LST);
                    819: 
                    820:        printf("    2: %s\n", d_CHN);
                    821:        printf("    1: %s\n", d_SQL);
                    822:        printf("->  1: %s\n\n", d_LST);
                    823: 
                    824:        if ((*s_etat_processus).langue == 'F')
                    825:        {
                    826:            printf("  Utilisation :\n\n");
                    827:        }
                    828:        else
                    829:        {
                    830:            printf("  Usage:\n\n");
                    831:        }
                    832: 
                    833:        printf("    \"select * from table\"\n");
                    834:        printf("          { \"mysql\" \"server\" \"database\" "
                    835:                "\"user\" \"password\" } SQLQUERY\n");
                    836:        printf("    \"select field from table\"\n");
                    837:        printf("          { \"postgresql:iso-8859-1\" \"server\" "
                    838:                "\"database\" \"user\" \"password\" port }\n");
                    839:        printf("          SQLQUERY\n");
                    840: 
                    841:        return;
                    842:    }
                    843:    else if ((*s_etat_processus).test_instruction == 'Y')
                    844:    {
                    845:        (*s_etat_processus).nombre_arguments = -1;
                    846:        return;
                    847:    }
                    848:    
                    849:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    850:    {
                    851:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    852:        {
                    853:            return;
                    854:        }
                    855:    }
                    856: 
                    857:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    858:            &s_objet_1) == d_erreur)
                    859:    {
                    860:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    861:        return;
                    862:    }
                    863: 
                    864:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    865:            &s_objet_2) == d_erreur)
                    866:    {
                    867:        liberation(s_etat_processus, s_objet_1);
                    868: 
                    869:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    870:        return;
                    871:    }
                    872: 
                    873:    if ((*s_objet_1).type == LST)
                    874:    {
1.40      bertrand  875: #  if defined(MYSQL_SUPPORT) || defined(POSTGRESQL_SUPPORT)
1.1       bertrand  876:        connexion_permanente = d_faux;
1.40      bertrand  877: #  endif
1.1       bertrand  878: 
                    879:        s_copie_1 = s_objet_1;
                    880: 
                    881:        if ((s_objet_1 = parametres_sql(s_etat_processus, s_copie_1)) == NULL)
                    882:        {
                    883:            liberation(s_etat_processus, s_copie_1);
                    884:            liberation(s_etat_processus, s_objet_2);
                    885:            return;
                    886:        }
                    887: 
1.45      bertrand  888:        if ((*s_etat_processus).erreur_execution ==
                    889:                d_ex_instruction_indisponible)
                    890:        {
                    891:            liberation(s_etat_processus, s_objet_1);
                    892:            liberation(s_etat_processus, s_objet_2);
                    893:            liberation(s_etat_processus, s_copie_1);
                    894: 
                    895:            return;
                    896:        }
                    897: 
1.1       bertrand  898:        liberation(s_etat_processus, s_copie_1);
                    899:    }
                    900:    else
                    901:    {
                    902:        if ((*s_objet_1).type == SQL)
                    903:        {
                    904:            if (((*((struct_connecteur_sql *) (*s_objet_1).objet)).pid !=
                    905:                    getpid()) || (pthread_equal((*((struct_connecteur_sql *)
                    906:                    (*s_objet_1).objet)).tid, pthread_self()) == 0))
                    907:            {
                    908:                (*s_etat_processus).erreur_execution =
                    909:                        d_ex_fichier_hors_contexte;
                    910: 
                    911:                liberation(s_etat_processus, s_objet_1);
                    912:                liberation(s_etat_processus, s_objet_2);
                    913:                return;
                    914:            }
                    915:        }
                    916: 
1.40      bertrand  917: #  if defined(MYSQL_SUPPORT) || defined(POSTGRESQL_SUPPORT)
1.1       bertrand  918:        connexion_permanente = d_vrai;
1.40      bertrand  919: #  endif
1.1       bertrand  920:    }
                    921: 
                    922:    if (((*s_objet_1).type == SQL) && ((*s_objet_2).type == CHN))
                    923:    {
                    924:        if ((*((struct_connecteur_sql *) (*s_objet_1).objet)).locale != NULL)
                    925:        {
                    926:            /*
                    927:             * Transcodage de la commande SQL
                    928:             */
                    929: 
                    930:            if ((s_copie_2 = copie_objet(s_etat_processus, s_objet_2, 'O'))
                    931:                    == NULL)
                    932:            {
                    933:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    934:                return;
                    935:            }
                    936: 
                    937:            liberation(s_etat_processus, s_objet_2);
                    938:            s_objet_2 = s_copie_2;
                    939: 
                    940:            tampon = (*s_objet_2).objet;
                    941: 
                    942:            if (((*s_objet_2).objet = transliteration(s_etat_processus, tampon,
                    943:                    (*((struct_connecteur_sql *) (*s_objet_1).objet)).locale,
                    944:                    d_locale)) == NULL)
                    945:            {
                    946:                return;
                    947:            }
                    948: 
                    949:            free(tampon);
                    950:        }
                    951: 
                    952:        /*
                    953:         * Pilote MySQL
                    954:         */
                    955: 
                    956:        if (strcmp((*((struct_connecteur_sql *) (*s_objet_1).objet)).type,
                    957:                "MYSQL") == 0)
                    958:        {
                    959: #          ifdef MYSQL_SUPPORT
                    960: 
1.40      bertrand  961:            unsigned int                i;
                    962:            unsigned int                nombre_colonnes;
                    963: 
                    964:            logical1                    presence_resultat;
                    965: 
                    966:            MYSQL_RES                   *resultat_mysql;
                    967:            MYSQL_ROW                   ligne;
                    968: 
                    969:            struct_objet                *s_objet_resultat;
                    970: 
                    971:            struct_liste_chainee        *l_element_courant;
                    972:            struct_liste_chainee        *l_element_courant_ligne;
1.1       bertrand  973: 
                    974:            if (mysql_real_query((*((struct_connecteur_sql *) (*s_objet_1)
                    975:                    .objet)).descripteur.mysql, (unsigned char *) (*s_objet_2)
                    976:                    .objet, strlen((unsigned char *) (*s_objet_2).objet)) != 0)
                    977:            {
                    978:                if (connexion_permanente == d_faux)
                    979:                {
                    980:                    mysql_close((*((struct_connecteur_sql *) (*s_objet_1)
                    981:                            .objet)).descripteur.mysql);
                    982:                }
                    983: 
                    984:                liberation(s_etat_processus, s_objet_1);
                    985:                liberation(s_etat_processus, s_objet_2);
                    986: 
                    987:                (*s_etat_processus).erreur_execution = d_ex_erreur_sql;
                    988:                return;
                    989:            }
                    990: 
                    991:            if ((resultat_mysql = mysql_store_result(
                    992:                    (*((struct_connecteur_sql *) (*s_objet_1).objet))
                    993:                    .descripteur.mysql)) == NULL)
                    994:            {
                    995:                // La requête ne renvoie rien (exemple : INSERT)
                    996:                presence_resultat = d_faux;
                    997:                nombre_colonnes = 0;
                    998:            }
                    999:            else
                   1000:            {
                   1001:                // La requête renvoie une ou plusieurs valeurs.
                   1002:                presence_resultat = d_vrai;
                   1003:                nombre_colonnes = mysql_field_count((*((struct_connecteur_sql *)
                   1004:                        (*s_objet_1).objet)).descripteur.mysql);
                   1005:            }
                   1006: 
                   1007:            if ((s_objet_resultat = allocation(s_etat_processus, LST))
                   1008:                    == NULL)
                   1009:            {
                   1010:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1011:                return;
                   1012:            }
                   1013: 
                   1014:            (*s_objet_resultat).objet = NULL;
                   1015:            l_element_courant = (*s_objet_resultat).objet;
                   1016: 
                   1017:            while(((presence_resultat == d_vrai) ?
                   1018:                    (ligne = mysql_fetch_row(resultat_mysql)) : NULL) != NULL)
                   1019:            {
                   1020:                unsigned long           *longueurs;
                   1021: 
                   1022:                longueurs = mysql_fetch_lengths(resultat_mysql);
                   1023: 
                   1024:                if (l_element_courant == NULL)
                   1025:                {
                   1026:                    if (((*s_objet_resultat).objet =
                   1027:                            allocation_maillon(s_etat_processus)) == NULL)
                   1028:                    {
                   1029:                        (*s_etat_processus).erreur_systeme =
                   1030:                                d_es_allocation_memoire;
                   1031:                        return;
                   1032:                    }
                   1033: 
                   1034:                    l_element_courant = (struct_liste_chainee *)
                   1035:                            (*s_objet_resultat).objet;
                   1036:                }
                   1037:                else
                   1038:                {
                   1039:                    if (((*l_element_courant).suivant =
                   1040:                            allocation_maillon(s_etat_processus)) == NULL)
                   1041:                    {
                   1042:                        (*s_etat_processus).erreur_systeme =
                   1043:                                d_es_allocation_memoire;
                   1044:                        return;
                   1045:                    }
                   1046: 
                   1047:                    l_element_courant = (*l_element_courant).suivant;
                   1048:                }
                   1049: 
                   1050:                (*l_element_courant).suivant = NULL;
                   1051: 
                   1052:                if (((*l_element_courant).donnee = allocation(s_etat_processus,
                   1053:                        LST)) == NULL)
                   1054:                {
                   1055:                    (*s_etat_processus).erreur_systeme =
                   1056:                            d_es_allocation_memoire;
                   1057:                    return;
                   1058:                }
                   1059: 
                   1060:                (*(*l_element_courant).donnee).objet = NULL;
                   1061:                l_element_courant_ligne = NULL;
                   1062: 
                   1063:                for(i = 0; i < nombre_colonnes; i++)
                   1064:                {
                   1065:                    if (l_element_courant_ligne == NULL)
                   1066:                    {
                   1067:                        if (((*(*l_element_courant).donnee).objet =
                   1068:                                allocation_maillon(s_etat_processus)) == NULL)
                   1069:                        {
                   1070:                            (*s_etat_processus).erreur_systeme =
                   1071:                                    d_es_allocation_memoire;
                   1072:                            return;
                   1073:                        }
                   1074: 
                   1075:                        l_element_courant_ligne = (struct_liste_chainee *)
                   1076:                                (*(*l_element_courant).donnee).objet;
                   1077:                    }
                   1078:                    else
                   1079:                    {
                   1080:                        if (((*l_element_courant_ligne).suivant =
                   1081:                                allocation_maillon(s_etat_processus)) == NULL)
                   1082:                        {
                   1083:                            (*s_etat_processus).erreur_systeme =
                   1084:                                    d_es_allocation_memoire;
                   1085:                            return;
                   1086:                        }
                   1087: 
                   1088:                        l_element_courant_ligne =
                   1089:                                (*l_element_courant_ligne).suivant;
                   1090:                    }
                   1091: 
                   1092:                    (*l_element_courant_ligne).suivant = NULL;
                   1093: 
                   1094:                    if (((*l_element_courant_ligne).donnee =
                   1095:                            allocation(s_etat_processus, CHN)) == NULL)
                   1096:                    {
                   1097:                        (*s_etat_processus).erreur_systeme =
                   1098:                                d_es_allocation_memoire;
                   1099:                        return;
                   1100:                    }
                   1101: 
                   1102:                    if (ligne[i] == NULL)
                   1103:                    {
                   1104:                        if (((*(*l_element_courant_ligne).donnee).objet =
                   1105:                                malloc(5 * sizeof(unsigned char))) == NULL)
                   1106:                        {
                   1107:                            (*s_etat_processus).erreur_systeme =
                   1108:                                    d_es_allocation_memoire;
                   1109:                            return;
                   1110:                        }
                   1111: 
                   1112:                        strcpy((unsigned char *) (*(*l_element_courant_ligne)
                   1113:                                .donnee).objet, "NULL");
                   1114:                    }
                   1115:                    else
                   1116:                    {
                   1117:                        if (((*(*l_element_courant_ligne).donnee).objet =
                   1118:                                malloc((longueurs[i] + 1) *
                   1119:                                sizeof(unsigned char))) == NULL)
                   1120:                        {
                   1121:                            (*s_etat_processus).erreur_systeme =
                   1122:                                    d_es_allocation_memoire;
                   1123:                            return;
                   1124:                        }
                   1125: 
                   1126:                        strcpy((unsigned char *) (*(*l_element_courant_ligne)
                   1127:                                .donnee).objet, ligne[i]);
                   1128:                    }
                   1129:                }
                   1130:            }
                   1131: 
                   1132:            mysql_free_result(resultat_mysql);
                   1133: 
                   1134:            if (connexion_permanente == d_faux)
                   1135:            {
                   1136:                mysql_close((*((struct_connecteur_sql *) (*s_objet_1).objet))
                   1137:                        .descripteur.mysql);
                   1138:            }
                   1139: 
                   1140:            if (presence_resultat == d_vrai)
                   1141:            {
                   1142:                if (empilement(s_etat_processus,
                   1143:                        &((*s_etat_processus).l_base_pile),
                   1144:                        s_objet_resultat) == d_erreur)
                   1145:                {
                   1146:                    return;
                   1147:                }
                   1148:            }
                   1149: 
                   1150: #          else
                   1151: 
                   1152:            if ((*s_etat_processus).langue == 'F')
                   1153:            {
                   1154:                printf("+++Attention : Support de MySQL non compilé !\n");
                   1155:            }
                   1156:            else
                   1157:            {
                   1158:                printf("+++Warning : MySQL support not available !\n");
                   1159:            }
                   1160: 
                   1161:            fflush(stdout);
                   1162: #          endif
                   1163:        }
                   1164: 
                   1165:        /*
                   1166:         * Pilote PostgreSQL
                   1167:         */
                   1168: 
                   1169:        else if (strcmp((*((struct_connecteur_sql *) (*s_objet_1).objet)).type,
                   1170:                "POSTGRESQL") == 0)
                   1171:        {
                   1172: #          ifdef POSTGRESQL_SUPPORT
                   1173: 
1.40      bertrand 1174:            unsigned int                i;
                   1175:            unsigned int                j;
                   1176:            unsigned int                nombre_colonnes;
                   1177:            unsigned int                nombre_lignes;
                   1178: 
                   1179:            logical1                    presence_resultat;
                   1180: 
                   1181:            PGresult                    *resultat_postgresql;
                   1182: 
                   1183:            struct_objet                *s_objet_resultat;
                   1184: 
                   1185:            struct_liste_chainee        *l_element_courant;
                   1186:            struct_liste_chainee        *l_element_courant_ligne;
1.1       bertrand 1187: 
                   1188:            if (PQstatus((*((struct_connecteur_sql *) (*s_objet_1).objet))
                   1189:                    .descripteur.postgresql) != CONNECTION_OK)
                   1190:            {
                   1191:                if (connexion_permanente == d_faux)
                   1192:                {
                   1193:                    PQfinish((*((struct_connecteur_sql *) (*s_objet_1).objet))
                   1194:                            .descripteur.postgresql);
                   1195:                }
                   1196: 
                   1197:                liberation(s_etat_processus, s_objet_1);
                   1198:                liberation(s_etat_processus, s_objet_2);
                   1199: 
                   1200:                (*s_etat_processus).erreur_execution = d_ex_erreur_sql;
                   1201:                return;
                   1202:            }
                   1203: 
                   1204:            resultat_postgresql = PQexec((*((struct_connecteur_sql *)
                   1205:                    (*s_objet_1).objet)).descripteur.postgresql,
                   1206:                    (unsigned char *) (*s_objet_2).objet);
                   1207:            presence_resultat = d_faux;
                   1208: 
                   1209:            switch(PQresultStatus(resultat_postgresql))
                   1210:            {
                   1211:                case PGRES_COMMAND_OK :
                   1212:                { // Commande qui ne renvoit rien
                   1213:                    if ((s_objet_resultat = allocation(s_etat_processus, LST))
                   1214:                            == NULL)
                   1215:                    {
                   1216:                        (*s_etat_processus).erreur_systeme =
                   1217:                                d_es_allocation_memoire;
                   1218:                        return;
                   1219:                    }
                   1220: 
                   1221:                    (*s_objet_resultat).objet = NULL;
                   1222:                    l_element_courant = (*s_objet_resultat).objet;
                   1223:                    presence_resultat = d_vrai;
                   1224: 
                   1225:                    break;
                   1226:                }
                   1227: 
                   1228:                case PGRES_TUPLES_OK :
                   1229:                { // Commande renvoyant des données
                   1230:                    if ((s_objet_resultat = allocation(s_etat_processus, LST))
                   1231:                            == NULL)
                   1232:                    {
                   1233:                        (*s_etat_processus).erreur_systeme =
                   1234:                                d_es_allocation_memoire;
                   1235:                        return;
                   1236:                    }
                   1237: 
                   1238:                    (*s_objet_resultat).objet = NULL;
                   1239:                    l_element_courant = (*s_objet_resultat).objet;
                   1240:                    presence_resultat = d_vrai;
                   1241: 
                   1242:                    nombre_colonnes = PQnfields(resultat_postgresql);
                   1243:                    nombre_lignes = PQntuples(resultat_postgresql);
                   1244: 
                   1245:                    for(i = 0; i < nombre_lignes; i++)
                   1246:                    {
                   1247:                        // Chaînage d'un nouveau maillon de la liste résultat
                   1248: 
                   1249:                        if (l_element_courant == NULL)
                   1250:                        {
                   1251:                            if (((*s_objet_resultat).objet =
                   1252:                                    allocation_maillon(s_etat_processus))
                   1253:                                    == NULL)
                   1254:                            {
                   1255:                                (*s_etat_processus).erreur_systeme =
                   1256:                                        d_es_allocation_memoire;
                   1257:                                return;
                   1258:                            }
                   1259: 
                   1260:                            l_element_courant = (struct_liste_chainee *)
                   1261:                                    (*s_objet_resultat).objet;
                   1262:                        }
                   1263:                        else
                   1264:                        {
                   1265:                            if (((*l_element_courant).suivant =
                   1266:                                    allocation_maillon(s_etat_processus))
                   1267:                                    == NULL)
                   1268:                            {
                   1269:                                (*s_etat_processus).erreur_systeme =
                   1270:                                        d_es_allocation_memoire;
                   1271:                                return;
                   1272:                            }
                   1273: 
                   1274:                            l_element_courant = (*l_element_courant).suivant;
                   1275:                        }
                   1276: 
                   1277:                        (*l_element_courant).suivant = NULL;
                   1278: 
                   1279:                        // Création de la liste fille
                   1280: 
                   1281:                        if (((*l_element_courant).donnee =
                   1282:                                allocation(s_etat_processus, LST)) == NULL)
                   1283:                        {
                   1284:                            (*s_etat_processus).erreur_systeme =
                   1285:                                    d_es_allocation_memoire;
                   1286:                            return;
                   1287:                        }
                   1288: 
                   1289:                        (*(*l_element_courant).donnee).objet = NULL;
                   1290:                        l_element_courant_ligne = NULL;
                   1291: 
                   1292:                        for(j = 0; j < nombre_colonnes; j++)
                   1293:                        {
                   1294:                            if (l_element_courant_ligne == NULL)
                   1295:                            {
                   1296:                                if (((*(*l_element_courant).donnee).objet =
                   1297:                                        allocation_maillon(s_etat_processus))
                   1298:                                        == NULL)
                   1299:                                {
                   1300:                                    (*s_etat_processus).erreur_systeme =
                   1301:                                            d_es_allocation_memoire;
                   1302:                                    return;
                   1303:                                }
                   1304: 
                   1305:                                l_element_courant_ligne =
                   1306:                                        (struct_liste_chainee *)
                   1307:                                        (*(*l_element_courant).donnee).objet;
                   1308:                            }
                   1309:                            else
                   1310:                            {
                   1311:                                if (((*l_element_courant_ligne).suivant =
                   1312:                                        allocation_maillon(s_etat_processus))
                   1313:                                        == NULL)
                   1314:                                {
                   1315:                                    l_element_courant_ligne =
                   1316:                                            (*l_element_courant_ligne).suivant;
                   1317:                                }
                   1318: 
                   1319:                                l_element_courant_ligne =
                   1320:                                        (*l_element_courant_ligne).suivant;
                   1321:                            }
                   1322: 
                   1323:                            (*l_element_courant_ligne).suivant = NULL;
                   1324: 
                   1325:                            if (((*l_element_courant_ligne).donnee =
                   1326:                                    allocation(s_etat_processus, CHN))
                   1327:                                    == NULL)
                   1328:                            {
                   1329:                                (*s_etat_processus).erreur_systeme =
                   1330:                                        d_es_allocation_memoire;
                   1331:                                return;
                   1332:                            }
                   1333: 
                   1334:                            if (PQgetisnull(resultat_postgresql, i, j) != 0)
                   1335:                            {
                   1336:                                if (((*(*l_element_courant_ligne).donnee).objet
                   1337:                                        = malloc(5 * sizeof(unsigned char)))
                   1338:                                        == NULL)
                   1339:                                {
                   1340:                                    (*s_etat_processus).erreur_systeme =
                   1341:                                            d_es_allocation_memoire;
                   1342:                                    return;
                   1343:                                }
                   1344: 
                   1345:                                strcpy((unsigned char *)
                   1346:                                        (*(*l_element_courant_ligne).donnee)
                   1347:                                        .objet, "NULL");
                   1348:                            }
                   1349:                            else
                   1350:                            {
                   1351:                                if (((*(*l_element_courant_ligne).donnee).objet
                   1352:                                        = malloc((PQgetlength(
                   1353:                                        resultat_postgresql, i, j) + 1) *
                   1354:                                        sizeof(unsigned char))) == NULL)
                   1355:                                {
                   1356:                                    (*s_etat_processus).erreur_systeme =
                   1357:                                            d_es_allocation_memoire;
                   1358:                                    return;
                   1359:                                }
                   1360: 
                   1361:                                strcpy((unsigned char *)
                   1362:                                        (*(*l_element_courant_ligne).donnee)
                   1363:                                        .objet, PQgetvalue(resultat_postgresql,
                   1364:                                        i, j));
                   1365:                            }
                   1366:                        }
                   1367:                    }
                   1368: 
                   1369:                    break;
                   1370:                }
                   1371: 
                   1372:                case PGRES_EMPTY_QUERY :
                   1373:                case PGRES_COPY_OUT :
                   1374:                case PGRES_COPY_IN :
                   1375:                case PGRES_BAD_RESPONSE :
                   1376:                case PGRES_NONFATAL_ERROR :
                   1377:                case PGRES_FATAL_ERROR :
                   1378:                default :
                   1379:                {
                   1380:                    printf("%s\n", PQresultErrorMessage(resultat_postgresql));
                   1381:                    PQclear(resultat_postgresql);
                   1382: 
                   1383:                    if (connexion_permanente == d_faux)
                   1384:                    {
                   1385:                        PQfinish((*((struct_connecteur_sql *) (*s_objet_1)
                   1386:                                .objet)).descripteur.postgresql);
                   1387:                    }
                   1388: 
                   1389:                    liberation(s_etat_processus, s_objet_1);
                   1390:                    liberation(s_etat_processus, s_objet_2);
                   1391:  
                   1392:                    (*s_etat_processus).erreur_execution = d_ex_erreur_sql;
                   1393: 
                   1394:                    return;
                   1395:                    break;
                   1396:                }
                   1397:            }
                   1398: 
                   1399:            PQclear(resultat_postgresql);
                   1400: 
                   1401:            if (connexion_permanente == d_faux)
                   1402:            {
                   1403:                PQfinish((*((struct_connecteur_sql *) (*s_objet_1).objet))
                   1404:                        .descripteur.postgresql);
                   1405:            }
                   1406: 
                   1407:            if (presence_resultat == d_vrai)
                   1408:            {
                   1409:                if (empilement(s_etat_processus, &((*s_etat_processus)
                   1410:                        .l_base_pile), s_objet_resultat) == d_erreur)
                   1411:                {
                   1412:                    return;
                   1413:                }
                   1414:            }
                   1415: 
                   1416: #          else
                   1417: 
                   1418:            if ((*s_etat_processus).langue == 'F')
                   1419:            {
                   1420:                printf("+++Attention : Support de PostgreSQL non compilé !\n");
                   1421:            }
                   1422:            else
                   1423:            {
                   1424:                printf("+++Warning : PostgreSQL support not available !\n");
                   1425:            }
                   1426: 
                   1427:            fflush(stdout);
                   1428: #          endif
                   1429:        }
                   1430:        else
                   1431:        {
                   1432:            liberation(s_etat_processus, s_objet_1);
                   1433:            liberation(s_etat_processus, s_objet_2);
                   1434: 
                   1435:            (*s_etat_processus).erreur_execution = d_ex_erreur_sql;
                   1436:            return;
                   1437:        }
                   1438:    }
                   1439:    else
                   1440:    {
                   1441:        liberation(s_etat_processus, s_objet_1);
                   1442:        liberation(s_etat_processus, s_objet_2);
                   1443: 
                   1444:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1445:        return;
                   1446:    }
                   1447: 
                   1448:    liberation(s_etat_processus, s_objet_1);
                   1449:    liberation(s_etat_processus, s_objet_2);
                   1450: 
                   1451:    return;
                   1452: }
                   1453: 
                   1454: 
                   1455: /*
                   1456: ================================================================================
                   1457:   Fonction 'stop'
                   1458: ================================================================================
                   1459:   Entrées :
                   1460: --------------------------------------------------------------------------------
                   1461:   Sorties :
                   1462: --------------------------------------------------------------------------------
                   1463:   Effets de bord : néant
                   1464: ================================================================================
                   1465: */
                   1466: 
                   1467: void
                   1468: instruction_stop(struct_processus *s_etat_processus)
                   1469: {
                   1470:    struct_liste_chainee        *l_element_courant;
                   1471: 
                   1472:    struct_objet                *s_objet;
                   1473: 
                   1474:    (*s_etat_processus).erreur_execution = d_ex;
                   1475: 
                   1476:    if ((*s_etat_processus).affichage_arguments == 'Y')
                   1477:    {
                   1478:        printf("\n  STOP ");
                   1479: 
                   1480:        if ((*s_etat_processus).langue == 'F')
                   1481:        {
                   1482:            printf("(arrêt d'un processus)\n\n");
                   1483:        }
                   1484:        else
                   1485:        {
                   1486:            printf("(kill process)\n\n");
                   1487:        }
                   1488: 
                   1489:        printf("    1: %s\n", d_PRC);
                   1490: 
                   1491:        return;
                   1492:    }
                   1493:    else if ((*s_etat_processus).test_instruction == 'Y')
                   1494:    {
                   1495:        (*s_etat_processus).nombre_arguments = -1;
                   1496:        return;
                   1497:    }
                   1498:    
                   1499:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                   1500:    {
                   1501:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                   1502:        {
                   1503:            return;
                   1504:        }
                   1505:    }
                   1506: 
                   1507:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1508:            &s_objet) == d_erreur)
                   1509:    {
                   1510:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1511:        return;
                   1512:    }
                   1513: 
                   1514:    if ((*s_objet).type == PRC)
                   1515:    {
                   1516:        if ((*(*((struct_processus_fils *) (*s_objet).objet)).thread)
                   1517:                .processus_detache == d_vrai)
                   1518:        {
1.33      bertrand 1519:            envoi_signal_processus((*(*((struct_processus_fils *)
                   1520:                    (*s_objet).objet)).thread).pid, rpl_sigstop);
1.1       bertrand 1521:        }
                   1522:        else
                   1523:        {
                   1524:            if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   1525:            {
                   1526:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1527:                return;
                   1528:            }
                   1529: 
                   1530:            l_element_courant = (struct_liste_chainee *)
                   1531:                    (*s_etat_processus).l_base_pile_processus;
                   1532: 
                   1533:            while(l_element_courant != NULL)
                   1534:            {
                   1535:                if ((*(*((struct_processus_fils *) (*(*l_element_courant)
                   1536:                        .donnee).objet)).thread).processus_detache == d_faux)
                   1537:                {
                   1538:                    if ((pthread_equal((*(*((struct_processus_fils *)
1.9       bertrand 1539:                            (*(*l_element_courant).donnee).objet)).thread).tid,
1.1       bertrand 1540:                            (*(*((struct_processus_fils *)
                   1541:                            (*s_objet).objet)).thread).tid) != 0) &&
                   1542:                            ((*(*((struct_processus_fils *)
                   1543:                            (*(*l_element_courant).donnee).objet)).thread).pid
                   1544:                            == (*(*((struct_processus_fils *)
                   1545:                            (*s_objet).objet)).thread).pid))
                   1546:                    {
                   1547:                        break;
                   1548:                    }
                   1549:                }
                   1550: 
                   1551:                l_element_courant = (*l_element_courant).suivant;
                   1552:            }
                   1553: 
                   1554:            if (l_element_courant != NULL)
                   1555:            {
                   1556:                // Le champ thread_actif est un pointeur sur un champ de la
                   1557:                // structure s_argument_thread libéré par la fonction
                   1558:                // retrait_thread_surveillance().
                   1559: 
                   1560:                if ((*(*((struct_processus_fils *)
                   1561:                        (*s_objet).objet)).thread).thread_actif == d_vrai)
                   1562:                {
                   1563:                    if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
                   1564:                            (*s_objet).objet)).thread).mutex)) != 0)
                   1565:                    {
                   1566:                        if (pthread_mutex_unlock(&((*s_etat_processus).mutex))
                   1567:                                != 0)
                   1568:                        {
                   1569:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1570:                            return;
                   1571:                        }
                   1572: 
                   1573:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1574:                        return;
                   1575:                    }
                   1576: 
                   1577:                    if ((*(*((struct_processus_fils *)
                   1578:                            (*s_objet).objet)).thread).thread_actif == d_vrai)
                   1579:                    {
1.33      bertrand 1580:                        envoi_signal_thread((*(*((struct_processus_fils *)
                   1581:                                (*s_objet).objet)).thread).tid, rpl_sigstop);
1.1       bertrand 1582:                    }
                   1583: 
                   1584:                    if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
                   1585:                            (*s_objet).objet)).thread).mutex)) != 0)
                   1586:                    {
                   1587:                        if (pthread_mutex_unlock(&((*s_etat_processus).mutex))
                   1588:                                != 0)
                   1589:                        {
                   1590:                            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1591:                            return;
                   1592:                        }
                   1593: 
                   1594:                        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1595:                        return;
                   1596:                    }
                   1597:                }
                   1598:            }
                   1599: 
                   1600:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   1601:            {
                   1602:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1603:                return;
                   1604:            }
                   1605:        }
                   1606:    }
                   1607:    else
                   1608:    {
                   1609:        liberation(s_etat_processus, s_objet);
                   1610: 
                   1611:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1612:        return;
                   1613:    }
                   1614: 
                   1615:    liberation(s_etat_processus, s_objet);
                   1616: 
                   1617:    return;
                   1618: }
                   1619: 
                   1620: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>