Problems with OCI without an environment (ORACLE_HOME not set)

System: Solaris 9, Sun-Fire-V440
Our application has Oracle 9i as one of the possible persistence backends. Oracle is not always available at all clients sites so we use dlopen/dlsym to access the required OCI functions in clntsh on demand. Moreover, the app is started by inetd, so there is no environment and ORACLE_HOME is not set. The result is that OCIEnvCreate fails and returns -1. Presumably libclntsh.so.9.0 looks for ORACLE_HOME and falls over when it doesn't find it.
Q: Is there a work around for this purely in terms of 9i version software?
One work around we've found is to install Instant Client. IC is intended to run in cases where there is no ORACLE_HOME set. This now acts as a gateway between our app and 9i. However, in order to make our app work with IC we've had to 'crle' the install path of IC. This is not so desirable because it adds to the admin burden.
Q. If the answer to the first question is 'no', is there another way of connecting to Oracle without modifying lib search paths?
I am including skeleton.cpp and the corresponding skeleton.ksh which demonstrates the problem.
Any advice is very much appreciated.
Adam
############## skeleton.cpp ########################
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <link.h>
#include <oci.h>
#include <oratypes.h>
int main(int argc, char *argv[])
OCIEnv *envhp;
sword (*MY_OCIEnvCreate)(...);
char* dlerr;
sword ociret;
if(argc < 1)
exit(1);
char dllname = (char )argv[1];
void *mydll = dlopen(dllname,RTLD_NOW|RTLD_GLOBAL);
if (mydll==NULL)
fprintf(stderr,"Error while loading Oracle module. dlopen() failed.\n"
     "OS says: %s.\n",
     (dlerr=dlerror())?dlerr:"");
exit(1);
MY_OCIEnvCreate = (sword(*)(...)) dlsym(mydll,"OCIEnvCreate");
if (MY_OCIEnvCreate == NULL)
fprintf(stderr,"Error while loading Oracle module function %s.\n"
     "OS says: %s.\n",
     "OCIEnvCreate",
     (dlerr=dlerror())?dlerr:"");
exit(1);
ociret = MY_OCIEnvCreate(&envhp, OCI_DEFAULT, (dvoid *)0,
               0, 0, 0, (size_t)0, (dvoid **)0);
if (OCI_SUCCESS != ociret)
fprintf(stderr, "OCI Error %ld occurred.\n", ociret);
exit(1);
return 0;
########### skeleton.ksh #####################
#!/bin/ksh -vx
ORA_DIR=/usr/opt/oracle/product/9.2.0.1.0
INSTCLI_DIR=/d0/adam/instantclient/instantclient10_1
# Make with 9i libs
CC -ldl -I$ORA_DIR/rdbms/demo -I$ORA_DIR/rdbms/public -o skeleton skeleton.cpp
if [[ $? -ne 0 ]]; then
print "ERROR: compile 1 failed"
exit 1
fi
# expect to succeed with ORACLE_HOME set and fail with ORACLE_HOME unset
export ORACLE_HOME=$ORA_DIR
skeleton $ORA_DIR/lib32/libclntsh.so
if [[ $? -ne 0 ]]; then
print "ERROR: unexpectedly failed in 9i on ORACLE_HOME set"
exit 1
fi
unset ORACLE_HOME
skeleton $ORA_DIR/lib32/libclntsh.so
if [[ $? -eq 0 ]]; then
print "ERROR: unexpectedly succeeded in 9i on ORACLE_HOME set"
exit 1
fi
# Make with Instance Client libs
CC -ldl -I$ORA_DIR/rdbms/demo -I$ORA_DIR/rdbms/public -o skeleton skeleton.cpp
if [[ $? -ne 0 ]]; then
print "ERROR: compile 2 failed"
exit 1
fi
# expect to succeed with ORACLE_HOME unset
skeleton $INSTCLI_DIR/libclntsh.so
if [[ $? -ne 0 ]]; then
print "ERROR: unexpectedly failed with Instance Client 10.1 and ORACLE_HOME set"
exit 1
fi
exit 0
############################################

After some investigation I have found a surprisingly simple solution to this problem. When inetd exec's a process, it provides a bare bones environment that comes from the /etc/default/login file. This environment can be extended using putenv(3C). Thus after dlopen/dlsym of clntsh, the program calls putenv with "ORACLE_HOME=/usr/opt/oracle/product/9.2.0.1.0" as argument. OCIEnvCreate and other OCI calls work fine after this.
Adam

Similar Messages

Maybe you are looking for

  • Any way to Restore Last Manual Sort Order or Prevent from being Overwritten accidentally?

         Help!      I'm constantly accidentally overwriting painstakingly created manual sort ordering (sometimes hours but more often months of accumulated work) in folders with files numbering up to 1,000, when i, however breifly, switch to another sor

  • Url Encoding and decoding

    Hi All, I am trying to encode the url, pass spme parameters and decode them in another jsp. Encoding: <a href="<c:url value="abc.jsp">                     <c:param name="folder" value="${sectionValue.foldername}"/>                     <c:param name="

  • CHILD form error FRM-30100: Block must have at least one primary key item.

    Hi friends, I have increased the DML array of the child block from 1 to 10, but it throws me error: FRM-30100: Block must have at least one primary key item. Block: CEC_ADJUSTMENT_RECON Form: CEC_ADJ FRM-30085: Unable to adjust form for output. How d

  • How can I import my regular Android Browser Bookmarks to Firefox?

    I want to have all of my bookmarks from my old/Google+ browser on Firefox also. Thank you. Andy Heller <sub>edit: removed your mail address from public display, since the only thing it will attract are spam bots. you will be notified per mail once so

  • Think Vantage Access Connections - problem

    I have a ThinkPad X61 Tablet, which I bought in 2009 with Windows XP. Lately, i.e., last 15 days, whenever I try to use the Think Vantage Access Connections to access my wireless connections the window of the program opens up but I see only the upper