Warm tip: This article is reproduced from serverfault.com, please click

Pro*C program run properly in AIX but not in RHEL

发布于 2020-12-02 14:47:50

I have some trouble running a binary done with proC code. I can compile it (without warnings) in my new server RHEL (7.8) but it loops until it failed. I made a simple proC script to test the compilation (see below). This script runs easily in my previous server AIX (6.1.0.0). The DB is Oracle 11c.

  • Oracle client in AIX : .../oracle/10.2
  • Oracle client in RHEL : .../oracle/12102/cli64

Here my simple code I want to compile and execute :

#include "demo.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sqlca.h>
#include <oraca.h>

int code_erreur;
char libelle_erreur[200];

EXEC ORACLE OPTION (ORACA=YES);

EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR username[30];
    VARCHAR password[30];
    VARCHAR host[30];

    VARCHAR dynstmt[80];
    VARCHAR mData[81];

EXEC SQL END DECLARE SECTION;

int connect()
{
    printf("\nConnection to %s@%s\n",username.arr,host.arr);

    EXEC SQL CONNECT :username IDENTIFIED BY :password USING :host;

    printf("Connection established\n");
    return 0;
}

void sqlerr()
{
    code_erreur = sqlca.sqlcode;
    strcpy(libelle_erreur,sqlca.sqlerrm.sqlerrmc);
    printf("SQL ERROR : %d,%s ;\n", code_erreur,libelle_erreur);
    printf("sqlca.sqlerrd : %d\n",sqlca.sqlerrd[2]);
}

int loadData()
{
    int lIter;

    strcpy(dynstmt.arr, "SELECT BANNER FROM V$VERSION\n");
    dynstmt.len = strlen(dynstmt.arr);

    printf("%s", (char *)dynstmt.arr);

    EXEC SQL PREPARE S FROM :dynstmt;
    EXEC SQL DECLARE lCursorData CURSOR FOR S;
    EXEC SQL OPEN lCursorData;

    for (lIter=0;lIter<10;lIter++)
    {
        EXEC SQL WHENEVER NOT FOUND DO break;
        EXEC SQL FETCH lCursorData INTO :mData;
        printf("%s\n", mData.arr);
    }
    EXECL SQL CLOSE lCursorData;
    return 0;
}

void main()
{
    int lRetour=0;
    printf("Start demo\n");

    strcpy((char *)username.arr,"USER");
    username.len=(unsigned short)strlen((char *)username.arr);

    strcpy((char *)password.arr,"PASS");
    password.len=(unsigned short)strlen((char *)password.arr);

    strcpy((char *)host.arr,"HOST");
    host.len=(unsigned short)strlen((char *)host.arr);

    EXEC SQL WHENEVER SQLERROR do sqlerr();
    lRetour = connect();
    lRetour = loadData();

    EXEC SQL COMMIT WORK RELEASE;

    printf("End demo\n");
    exit(0);
}

When I compile it and execute it on my AIX server, here what I got :

Start demo

Connection to USER@HOST
Connection established
SELECT BANNER FROM V$VERSION
[...]
End demo

But when I compile it on RHEL and execute it, the binary loops until a memory fault :

[...]
Connection to USER@HOST

Connection to USER@HOST

Connection to USER@HOST
Memory fault

Of course I want the same AIX result in RHEL.

Questioner
Funkynene
Viewed
11
Lorinczy Zsigmond 2020-12-04 15:29:29

Your connect function should be defined as static, otherwize it replaces connect(2) library function from libc.

@@ -20,7 +20,7 @@

 EXEC SQL END DECLARE SECTION;

-int connect()
+static int connect()
 {
     printf("\nConnection to %s@%s\n",username.arr,host.arr);

@@ -57,7 +57,7 @@