system() returns -1, errno=10 when logged into Oracle

北城以北 提交于 2019-12-20 02:56:45

问题


After an EXEC SQL CONNECT user/pass; command, system("") returns a -1 with errno=10.

We've migrated this program from Oracle 10g on HP-UX to Oracle 11g on Red Hat Linux. This was not happening on HP-UX / Oracle 10g.

#include <errno.h>
#include <dirent.h>
#include <sys/types.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <sys/stat.h>

typedef char vc2[10];
typedef char vc4[20];

EXEC SQL INCLUDE sqlca;

char *oracleid = "user/pass";
char msg[400];
char env[20][200];
#define DEBUG 1
int  status = 1;


int main( argc, argv )
int argc;
char **argv;
{
    int        load_stat;

    EXEC SQL BEGIN DECLARE SECTION;

    EXEC SQL TYPE vc2 is STRING(11) REFERENCE;

    vc2        load_date;

    EXEC SQL END DECLARE SECTION;

        load_stat = system("");
sprintf(msg,"Value of errno: %d\n", errno);
fprintf(stderr,"%s\n",msg);
sprintf(msg, "status: %d\n ",load_stat);
fprintf(stderr,"%s\n",msg);

sprintf(msg, "ORACLE Logon ID is %s\n",oracleid);
fprintf(stderr,"%s\n",msg);

    EXEC SQL CONNECT :oracleid;

fprintf(stderr,"Connected to Oracle\n");
        load_stat = system("");
sprintf(msg,"Value of errno: %d\n", errno);
fprintf(stderr,"%s\n",msg);
sprintf(msg, "status 2: %d \n",load_stat);
fprintf(stderr,"%s\n",msg);

    EXEC SQL COMMIT RELEASE;

fprintf(stderr,"released Oracle\n");
        load_stat = system("");
sprintf(msg,"Value of errno: %d\n", errno);
fprintf(stderr,"%s\n",msg);
sprintf(msg, "status 3: %d \n",load_stat);
fprintf(stderr,"%s\n",msg);

exit(0);
}

The above code returns the following:

Value of errno: 0

status: 0

Oracle Login ID is user/pass

Connected to Oracle

Value of errno: 10

status 2: -1

released Oracle

Value of errno: 10

status 3: -1


回答1:


This is Oracle being awful. They've installed a SIGCHLD handler that reaps any child process that exits, breaking any use of child processes in the application. You can probably fix it by calling signal(SIGCHLD,SIG_DFL) after connecting to uninstall their nonsense.



来源:https://stackoverflow.com/questions/55307361/system-returns-1-errno-10-when-logged-into-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!