问题
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