Finished the Linux side changes for the "Cleanup during library unload"
issue.
This commit is contained in:
		| @@ -47,7 +47,7 @@ typedef struct _WrapperAuthCacheEntry | |||||||
| //===[ Global variables ]================================================== | //===[ Global variables ]================================================== | ||||||
|  |  | ||||||
| static | static | ||||||
| BOOLEAN  g_authCacheInitialized = FALSE; | bool     g_authCacheInitialized = false; | ||||||
| HANDLE   g_hCASAContext; | HANDLE   g_hCASAContext; | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -675,7 +675,7 @@ InitializeAuthCache() | |||||||
|    } |    } | ||||||
|    else |    else | ||||||
|    { |    { | ||||||
|       g_authCacheInitialized = TRUE; |       g_authCacheInitialized = true; | ||||||
|       retStatus = CASA_STATUS_SUCCESS; |       retStatus = CASA_STATUS_SUCCESS; | ||||||
|    } |    } | ||||||
|  |  | ||||||
| @@ -687,7 +687,7 @@ InitializeAuthCache() | |||||||
|  |  | ||||||
| //++======================================================================= | //++======================================================================= | ||||||
| void | void | ||||||
| UnInitializeAuthCache() | UnInitializeAuthCache(void) | ||||||
| // | // | ||||||
| //  Arguments:  | //  Arguments:  | ||||||
| // | // | ||||||
| @@ -700,9 +700,6 @@ UnInitializeAuthCache() | |||||||
| // L2 | // L2 | ||||||
| //=======================================================================-- | //=======================================================================-- | ||||||
| { | { | ||||||
|    CasaStatus           retStatus; |  | ||||||
|    SSCS_SECRETSTORE_T   ssId; |  | ||||||
|  |  | ||||||
|    DbgTrace(1, "-UnInitializeAuthCache- Start\n", 0); |    DbgTrace(1, "-UnInitializeAuthCache- Start\n", 0); | ||||||
|  |  | ||||||
|    // Proceed if initialized |    // Proceed if initialized | ||||||
| @@ -715,7 +712,7 @@ UnInitializeAuthCache() | |||||||
|  |  | ||||||
|       // Forget about being initialized |       // Forget about being initialized | ||||||
|       g_hCASAContext = NULL; |       g_hCASAContext = NULL; | ||||||
|       g_authCacheInitialized = FALSE; |       g_authCacheInitialized = false; | ||||||
|    } |    } | ||||||
|  |  | ||||||
|    DbgTrace(1, "-UnInitializeAuthCache- End\n", 0); |    DbgTrace(1, "-UnInitializeAuthCache- End\n", 0); | ||||||
|   | |||||||
| @@ -291,6 +291,11 @@ extern | |||||||
| CasaStatus | CasaStatus | ||||||
| InitializeAuthCache(void); | InitializeAuthCache(void); | ||||||
|  |  | ||||||
|  | extern | ||||||
|  | void | ||||||
|  | UnInitializeAuthCache(void); | ||||||
|  |  | ||||||
|  |  | ||||||
| // | // | ||||||
| // Functions exported by config.c | // Functions exported by config.c | ||||||
| // | // | ||||||
|   | |||||||
| @@ -100,6 +100,9 @@ LIST_ENTRY  normalizedHostNameCacheListHead; | |||||||
| static | static | ||||||
| pthread_mutex_t   g_hNormalizedHostNameCacheMutex = PTHREAD_MUTEX_INITIALIZER; | pthread_mutex_t   g_hNormalizedHostNameCacheMutex = PTHREAD_MUTEX_INITIALIZER; | ||||||
|  |  | ||||||
|  | static | ||||||
|  | bool  hostNameNormalizationInitialized = false; | ||||||
|  |  | ||||||
| // Client configuration file folder | // Client configuration file folder | ||||||
| char  clientConfigFolder[] = "/etc/CASA/authtoken/client"; | char  clientConfigFolder[] = "/etc/CASA/authtoken/client"; | ||||||
|  |  | ||||||
| @@ -832,12 +835,88 @@ InitializeHostNameNormalization(void) | |||||||
|    // Initialize the cache list head |    // Initialize the cache list head | ||||||
|    InitializeListHead(&normalizedHostNameCacheListHead); |    InitializeListHead(&normalizedHostNameCacheListHead); | ||||||
|  |  | ||||||
|  |    // Remember | ||||||
|  |    hostNameNormalizationInitialized = true; | ||||||
|  |  | ||||||
|    DbgTrace(1, "-InitializeHostNameNormalization- End, retStatus = %08X\n", retStatus); |    DbgTrace(1, "-InitializeHostNameNormalization- End, retStatus = %08X\n", retStatus); | ||||||
|  |  | ||||||
|    return retStatus; |    return retStatus; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | //++======================================================================= | ||||||
|  | void | ||||||
|  | UnInitializeHostNameNormalization(void) | ||||||
|  | // | ||||||
|  | //  Arguments:  | ||||||
|  | // | ||||||
|  | //  Returns:    | ||||||
|  | // | ||||||
|  | //  Abstract:   | ||||||
|  | // | ||||||
|  | //  Notes: | ||||||
|  | // | ||||||
|  | // L2 | ||||||
|  | //=======================================================================-- | ||||||
|  | { | ||||||
|  |    LIST_ENTRY                    *pListEntry; | ||||||
|  |    NormalizedHostNameCacheEntry  *pEntry = NULL; | ||||||
|  |  | ||||||
|  |    DbgTrace(1, "-UnInitializeHostNameNormalization- Start\n", 0); | ||||||
|  |  | ||||||
|  |    // Proceed if initialization succeeded | ||||||
|  |    if (hostNameNormalizationInitialized) | ||||||
|  |    { | ||||||
|  |       // Free up any normalized host names in our cache | ||||||
|  |       pListEntry = normalizedHostNameCacheListHead.Flink; | ||||||
|  |       while (pListEntry != &normalizedHostNameCacheListHead) | ||||||
|  |       { | ||||||
|  |          // Get pointer to the entry | ||||||
|  |          pEntry = CONTAINING_RECORD(pListEntry, NormalizedHostNameCacheEntry, listEntry); | ||||||
|  |  | ||||||
|  |          // Remove the entry from the list | ||||||
|  |          RemoveEntryList(pListEntry); | ||||||
|  |  | ||||||
|  |          // Free the entry | ||||||
|  |          if (pEntry->pHostName) | ||||||
|  |             free(pEntry->pHostName); | ||||||
|  |  | ||||||
|  |          if (pEntry->pNormalizedHostName) | ||||||
|  |             free(pEntry->pNormalizedHostName); | ||||||
|  |  | ||||||
|  |          free(pEntry); | ||||||
|  |  | ||||||
|  |          // Try to go to the next entry | ||||||
|  |          pListEntry = normalizedHostNameCacheListHead.Flink; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       // Forget about being initialized | ||||||
|  |       hostNameNormalizationInitialized = false; | ||||||
|  |    } | ||||||
|  |  | ||||||
|  |    DbgTrace(1, "-UnInitializeHostNameNormalization- End", 0); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | //++======================================================================= | ||||||
|  | void __attribute__ ((destructor)) | ||||||
|  | Lib_fini(void) | ||||||
|  | // | ||||||
|  | //  Arguments:  | ||||||
|  | // | ||||||
|  | //  Returns:    | ||||||
|  | // | ||||||
|  | //  Abstract:   | ||||||
|  | // | ||||||
|  | //  Notes: | ||||||
|  | // | ||||||
|  | // L2 | ||||||
|  | //=======================================================================-- | ||||||
|  | { | ||||||
|  |    UnInitializeLibrary(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| //++======================================================================= | //++======================================================================= | ||||||
| //++======================================================================= | //++======================================================================= | ||||||
| //++======================================================================= | //++======================================================================= | ||||||
|   | |||||||
| @@ -46,6 +46,9 @@ CleanupOSSLSupport(void); | |||||||
|  |  | ||||||
| //===[ Global variables ]================================================== | //===[ Global variables ]================================================== | ||||||
|  |  | ||||||
|  | static | ||||||
|  | bool g_rpcInitialized = false; | ||||||
|  |  | ||||||
|  |  | ||||||
| //++======================================================================= | //++======================================================================= | ||||||
| size_t | size_t | ||||||
| @@ -566,6 +569,7 @@ InitializeRpc(void) | |||||||
|       else |       else | ||||||
|       { |       { | ||||||
|          // Success |          // Success | ||||||
|  |          g_rpcInitialized = true; | ||||||
|          retStatus = CASA_STATUS_SUCCESS; |          retStatus = CASA_STATUS_SUCCESS; | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
| @@ -580,6 +584,40 @@ InitializeRpc(void) | |||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | //++======================================================================= | ||||||
|  | void | ||||||
|  | UnInitializeRpc(void) | ||||||
|  | // | ||||||
|  | //  Arguments:  | ||||||
|  | // | ||||||
|  | //  Returns:    | ||||||
|  | // | ||||||
|  | //  Abstract:   | ||||||
|  | // | ||||||
|  | //  Notes: | ||||||
|  | // | ||||||
|  | // L2 | ||||||
|  | //=======================================================================-- | ||||||
|  | { | ||||||
|  |    DbgTrace(1, "-UnInitializeRpc- Start\n", 0); | ||||||
|  |  | ||||||
|  |    // Only try to cleanup if we were initialized | ||||||
|  |    if (g_rpcInitialized) | ||||||
|  |    { | ||||||
|  |       // Cleanup libcurl | ||||||
|  |       curl_global_cleanup(); | ||||||
|  |  | ||||||
|  |       // Cleanup OpenSSL support | ||||||
|  |       CleanupOSSLSupport(); | ||||||
|  |  | ||||||
|  |       // Forget about having been initialized | ||||||
|  |       g_rpcInitialized = false; | ||||||
|  |    } | ||||||
|  |  | ||||||
|  |    DbgTrace(1, "-UnInitializeRpc- End\n", 0); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| //++======================================================================= | //++======================================================================= | ||||||
| //++======================================================================= | //++======================================================================= | ||||||
| //++======================================================================= | //++======================================================================= | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user