Pro*C : Comportement different cmd system() une fois connecté à ORACLE
Linux 3.10.0-514.10.2.el7.x86_64 #1 SMP Mon Feb 20 02:37:52 EST 2017 x86_64 x86_64 x86_64 GNU/Linux
Oracle : Release 11.2.0.4.0
Pro*C/C++: Release 11.2.0.4.0
===============================
Bonjour à tous , je suis en train de migrer une application de HP/UX vers Linux :P
et j'ai un gros soucis sur un Pro*C :oops: qui à un comportement différent entre ces 2 plateformes et la commande "system" 8O
ce soucis se produit uniquement si je suis connecté à une base ORACLE :(
j'ai fait un little script pour vous montré le Pb :calim2:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| #include <stdio.h>
EXEC SQL INCLUDE SQLCA;
main()
{
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR uid[60];
EXEC SQL END DECLARE SECTION;
sprintf((char *) uid.arr,"%s\0","scott/tiger");
uid.len = 11;
printf("----------------------------------------------------------------\n");
lance_cmd("echo Avant connexion");
lance_cmd("nimportenawak");
EXEC SQL CONNECT :uid;
printf("----------------------------------------------------------------\n");
printf("Connexion Oracle = (%d)\n",sqlca.sqlcode);
printf("----------------------------------------------------------------\n");
lance_cmd("echo Apres connexion");
lance_cmd("nimportenawak");
}
lance_cmd(char *cmd)
{
int r;
r = system(cmd);
printf("(%s)==>Resultat(%d)\n",cmd,r);
} |
Le resultat est conforme sous HP/UX ;)
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| ----------------------------------------------------------------
Avant connexion
(echo Avant connexion)==>Resultat(0)
sh: nimportenawak: not found.
(nimportenawak)==>Resultat(32512)
----------------------------------------------------------------
Connexion Oracle = (0)
----------------------------------------------------------------
Apres connexion
(echo Apres connexion)==>Resultat(0)
sh: nimportenawak: not found.
(nimportenawak)==>Resultat(32512) |
par contre sous Linux :( , une fois connecté le code retour de la commande system() est systématiquement à "-1" :calim2: et je ne m'explique pas ce problème :(
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| ----------------------------------------------------------------
Avant connexion
(echo Avant connexion)==>Resultat(0)
sh: nimportenawak: command not found
(nimportenawak)==>Resultat(32512)
----------------------------------------------------------------
Connexion Oracle = (0)
----------------------------------------------------------------
Apres connexion
(echo Apres connexion)==>Resultat(-1)
sh: nimportenawak: command not found
(nimportenawak)==>Resultat(-1) |
si vous avez une idée , je suis preneur
Est-ce que les options de compilation (forcement différente entre HP/UX et Linux) pourrait expliquer ce dysfonctionnement ?
merci de votre aide
c'est un Bug Connu chez Oracle :)
https://support.oracle.com/epmos/fac...mx_427#SYMPTOM
APPLIES TO:
Oracle Database - Enterprise Edition - Version 11.2.0.0 and later
Precompilers - Version 11.2.0.1.0 and later
Linux x86
Linux x86-64
***Checked for relevance on 7th Jul 2016***
SYMPTOMS
On 11.2.0.1.0 when executing the Pro*C or OCI application which runs a system command after connecting to database (i.e after EXEC SQL CONNECT in Pro*C and OCIServerAttach in OCI) always returns -1 even though the command executes successfully.
CHANGES
Upgraded to 11.2.0.1
CAUSE
The cause of this problem has been identified in :
Bug 8996707 : CALLING SYSTEM FUNCTION AFTER OCISERVERATTACH ALWAYS RETURNS -1 ON 11.2
Bug 4478980 : WAITPID() FUNCTION DOES NOT RETURN THE PID OF THE CHILD
The issue is because of bequeath adapter implementation that was changed from 10g as the part of implementation of Bug 4478980. In order to do this implementation, oracle used SA_NOCLDWAIT to handle all the child process using unpublished Bug 6252421.This parameter was available only from 2.6 Linux kernel, hence was included only from 11.2 and was affected.If the user application has already installed a handler then bequeath will default to double forking else it can be forced to do by adding bequeath_detach = true in sqlnet.ora. Hence it is not a bug, but expected behavior.
Adding of this parameter will do double forking to suppress the error.This is explained in Note 452122.1 : The use of Client signal handlers and Oracle BEQUEATH Connections
SOLUTION
Add bequeath_detach=true in the client side sqlnet.ora file