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

externC tsp00_Bool sqlUpdateLibPathEnvironment ( tsp01_RteError *  RteError  ) 

Update LIBPATH environment.

Parameters:
RteError [out] the error return
Returns:
false if update failed (RteError is filled), true if successfull
Used for starting kernel or regcomp in an environment that allows to find all SAPDB specific DLLs It updates the sharedc library paths environment

Definition at line 792 of file veo01.c.

{
/*
*  It is necessary to add '$DBROOT/lib' to LD_LIBRARY_PATH
*  Otherwise DCOM runs into severe problems.
*  It is necessary to add '$DBROOT/sap' to LD_LIBRARY_PATH
*  Otherwise DCOM specific dlls are not found
    */
#ifdef WIN32
    eo46_rte_error_init ( pRteError ) ;
    return 1;
#else
    static char *envLDLIB = NULL;
    char *oldenvLDLIB = NULL;
    char *pureLDLIBPATH;
    char *currentLDLIBPATH;
    tsp00_Pathc LibPath;
    tsp00_Pathc SapPath;
    int         addLibPath = 0;
    int         addSapPath = 0;
    tsp00_Bool  result = 0;

    eo46_rte_error_init ( pRteError ) ;

    pureLDLIBPATH = getenv(LDLIBPATH_IP00);

    /* Enforce to leave status as setuid root program! */
    if ( getuid() != 0 && geteuid() == 0 )
    {
        setuid(getuid());
    }

    currentLDLIBPATH = eo01_TrimLDLIBPATH(pureLDLIBPATH);

    if ( sqlGetDbrootLibPath(LibPath, 0, pRteError )
        &&  sqlGetDbrootSapPath(SapPath, 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 );
        addSapPath = ( en01_SearchSubPath(currentLDLIBPATH, SapPath) ? 0 : 1 );

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

            if ( currentLDLIBPATH != NULL )
            {
                /* Lib or Sap path are added if not already found (addLibSapPath == 0) */
                /* If either one or two path are added, for each path a colon is needed */
                /* This is handled by 'addLibPath' and 'addSapPath' ! */
                envLDLIB = (char *)malloc( strlen(LDLIBPATH_IP00 "=")
                    + addLibPath * ( strlen(LibPath) + strlen(":") )
                    + addSapPath * ( strlen(SapPath) + strlen(":") )
                    + strlen(currentLDLIBPATH) + 1 );
            }
            else
            {
                /* Lib or Sap path are added if not already found (addLibSapPath == 0) */
                /* +1 is needed for zero termination */
                envLDLIB = (char *)malloc( strlen(LDLIBPATH_IP00 "=")
                    + strlen(LibPath) + strlen(":")
                    + strlen(SapPath)
                    + 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 ( addSapPath != 0 )
                    {
                        /* Add colon to separate SAP path from LIB path */
                        strcat(envLDLIB, ":");
                        strcat(envLDLIB, SapPath);
                    }
                }
                else
                {
                    if ( addSapPath != 0 )
                    {
                        strcat(envLDLIB, SapPath);
                    }
                }

                if ( currentLDLIBPATH != NULL ) /* Append former LDLIBPATH */
                {
                    if ( addLibPath != 0 || addSapPath != 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 = 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;
            tsp00_Pathc SapPath;
            int         addLibPath = 0;
            int         addSapPath = 0;

            result = 0;

            if ( sqlGetDbrootLibPath(LibPath, 0, pRteError )
             &&  sqlGetDbrootSapPath(SapPath, 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 );
                addSapPath = ( en01_SearchSubPath(currentLDLIB64PATH, SapPath) ? 0 : 1 );

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

                    if ( currentLDLIB64PATH != NULL )
                    {
                        /* Lib or Sap path are added if not already found (addLibSapPath == 0) */
                        /* If either one or two path are added, for each path a colon is needed */
                        /* This is handled by 'addLibPath' and 'addSapPath' ! */
                        envLDLIB64 = (char *)malloc( strlen(LDLIBPATH64_SUN "=")
                            + addLibPath * ( strlen(LibPath) + strlen(":") )
                            + addSapPath * ( strlen(SapPath) + strlen(":") )
                            + strlen(currentLDLIB64PATH) + 1 );
                    }
                    else
                    {
                        /* Lib or Sap path are added if not already found (addLibSapPath == 0) */
                        /* +1 is needed for zero termination */
                        envLDLIB64 = (char *)malloc( strlen(LDLIBPATH64_SUN "=")
                            + strlen(LibPath) + strlen(":")
                            + strlen(SapPath)
                            + 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 ( addSapPath != 0 )
                            {
                                /* Add colon to separate SAP path from LIB path */
                                strcat(envLDLIB64, ":");
                                strcat(envLDLIB64, SapPath);
                            }
                        }
                        else
                        {
                            if ( addSapPath != 0 )
                            {
                                strcat(envLDLIB64, SapPath);
                            }
                        }

                        if ( currentLDLIB64PATH != NULL ) /* Append former LDLIBPATH */
                        {
                            if ( addLibPath != 0 || addSapPath != 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