Logo Search packages:      
Sourcecode: maxdb-7.5.00 version File versions

externC tsp00_Bool sqlUpdateNiLibPathEnvironment ( tsp01_RteError *  pRteError  ) 

Update LIBPATH environment for NI.

Parameters:
RteError [out] the error return
Returns:
false if update failed (RteError is filled), true if successfull
Used for starting the niserver so that it is guarantied that the shared objects needed for NI comunication are found (e.g. libsapu16.so).

It updates the shared library paths environment by prefix our libary path (<IndepPgmPath>/lib).

Definition at line 478 of file veo01.c.

{
/*
*  It is necessary to add '<IndepProgPath>/lib' to the LD_LIBRARY_PATH
*  to guaranty that the UNIX SAPNI shared object finds the right SAP objects (e.g. libsapu16.so)
    */
#ifdef WIN32
    eo46_rte_error_init ( pRteError ) ;
    return 1;
#else
    static char *envLDLIB = NULL;
    char *oldenvLDLIB = NULL;
    char *pureLDLIBPATH;
    char *currentLDLIBPATH;
    tsp00_Pathc LibPath;
    int         addLibPath = 0;
    tsp00_Bool  result = 0;

    eo46_rte_error_init ( pRteError ) ;

    pureLDLIBPATH = getenv(LDLIBPATH_IP00);

    currentLDLIBPATH = eo01_TrimLDLIBPATH(pureLDLIBPATH);

    if (sqlGetIndependentLibPath (LibPath, 0, pRteError))
    {
        /* If path is found set add...Path to 0 otherwise to 1! This allows to use it for calculation */
        addLibPath = ( en01_SearchSubPath(currentLDLIBPATH, LibPath) ? 0 : 1 );

        if ( addLibPath == 0
          && currentLDLIBPATH == pureLDLIBPATH )
        {
            /* Nothing to do. Environment already corrected */
            result = 1;
        }
        else
        {
            oldenvLDLIB = envLDLIB;

            if ( currentLDLIBPATH != NULL )
            {
                /* Lib path is added if not already found */
                /* If either one or two path are added, for each path a colon is needed */
                /* This is handled by 'addLibPath'! */
                envLDLIB = (char *)malloc( strlen(LDLIBPATH_IP00 "=")
                    + addLibPath * ( strlen(LibPath) + strlen(":") )
                    + strlen(currentLDLIBPATH) + 1 );
            }
            else
            {
                /* Lib path is added if not already found */
                envLDLIB = (char *)malloc( strlen(LDLIBPATH_IP00 "=")
                    + strlen(LibPath) + strlen(":")
                    + 1 );
            }

            if ( envLDLIB == NULL )
            {
                eo46_set_rte_error (pRteError, 0, "Failed to allocate memory for ", LDLIBPATH_IP00);
            }
            else
            {
                strcpy(envLDLIB, LDLIBPATH_IP00 "=");

                /* Add LIB path always first */
                if ( addLibPath != 0 )
                {
                    strcat(envLDLIB, LibPath);
                }

                if ( currentLDLIBPATH != NULL ) /* Append former LDLIBPATH */
                {
                    if (addLibPath != 0)
                    {
                        strcat(envLDLIB, ":");
                    }

                    strcat(envLDLIB, currentLDLIBPATH);
                }

                if ( putenv(envLDLIB) < 0 )
                {
                    free(envLDLIB);
                    envLDLIB = oldenvLDLIB;
                    eo46_set_rte_error (pRteError, 0, "Failed to putenv ", LDLIBPATH_IP00);
                }
                else
                {
                    if ( oldenvLDLIB != NULL )
                    {
                        free(oldenvLDLIB); /* prevent some memory leak, accept that last malloc is not freed... */
                    }
                    result = 1; /* everything fine */
                }
            }
        }
    }
    else
    {
        eo46_set_rte_error (pRteError, 0, "Failed to get lib and sap path for", LDLIBPATH_IP00);
    }

#if defined(SUN) && defined(BIT64)

    if ( result )
    {
        char *pureLDLIB64PATH;
        pureLDLIB64PATH = getenv(LDLIBPATH64_SUN);

        /* If LD_LIBRARY_PATH64 is not set, we do not override it */
        if ( 0 != pureLDLIB64PATH )
        {
            static char *envLDLIB64 = NULL;
            char *oldenvLDLIB64 = NULL;
            char *currentLDLIB64PATH = pureLDLIB64PATH;
            tsp00_Pathc LibPath;
            int         addLibPath = 0;
            
            result = 0;

            if (sqlGetIndependentLibPath (LibPath, 0, pRteError))
            {
                /* If path is found set add...Path to 0 otherwise to 1! This allows to use it for calculation */
                addLibPath = ( en01_SearchSubPath(currentLDLIB64PATH, LibPath) ? 0 : 1 );

                if ( addLibPath == 0
                  && currentLDLIB64PATH == pureLDLIB64PATH )
                {
                    /* Nothing to do. Environment already corrected */
                    result = 1;
                }
                else
                {
                    oldenvLDLIB64 = envLDLIB64;

                    if ( currentLDLIB64PATH != NULL )
                    {
                        /* Lib path is added if not already found */
                        /* If either one or two path are added, for each path a colon is needed */
                        /* This is handled by 'addLibPath'! */
                        envLDLIB64 = (char *)malloc( strlen(LDLIBPATH64_SUN "=")
                            + addLibPath * ( strlen(LibPath) + strlen(":") )
                            + strlen(currentLDLIB64PATH) + 1 );
                    }
                    else
                    {
                        /* Lib path is added if not already found */
                        envLDLIB64 = (char *)malloc( strlen(LDLIBPATH64_SUN "=")
                            + strlen(LibPath) + strlen(":")
                            + 1 );
                    }

                    if ( envLDLIB64 == NULL )
                    {
                        eo46_set_rte_error (pRteError, 0, "Failed to allocate memory for ", LDLIBPATH64_SUN);
                    }
                    else
                    {
                        strcpy(envLDLIB64, LDLIBPATH64_SUN "=");

                        /* Add LIB path always first */
                        if ( addLibPath != 0 )
                        {
                            strcat(envLDLIB64, LibPath);
                        }

                        if ( currentLDLIB64PATH != NULL ) /* Append former LDLIBPATH */
                        {
                            if (addLibPath != 0)
                            {
                                strcat(envLDLIB64, ":");
                            }

                            strcat(envLDLIB64, currentLDLIB64PATH);
                        }

                        if ( putenv(envLDLIB64) < 0 )
                        {
                            free(envLDLIB64);
                            envLDLIB64 = oldenvLDLIB64;
                            eo46_set_rte_error (pRteError, 0, "Failed to putenv ", LDLIBPATH64_SUN);
                        }
                        else
                        {
                            if ( oldenvLDLIB64 != NULL )
                            {
                                free(oldenvLDLIB64); /* prevent some memory leak, accept that last malloc is not freed... */
                            }
                            result = 1; /* everything fine */
                        }
                    }
                }
            }
            else
            {
                eo46_set_rte_error (pRteError, 0, "Failed to get lib and sap path for", LDLIBPATH64_SUN);
            }
        }
    }
#endif

    return result;
#endif /* else !WIN32 */
}


Generated by  Doxygen 1.6.0   Back to index