You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2018/10/12 09:03:50 UTC

[33/34] celix git commit: CELIX-454: Fixes a bug in the pubsub discovery where discovered endpoint listener where not correctly removed.

CELIX-454: Fixes a bug in the pubsub discovery where discovered endpoint listener where not correctly removed.

Also:
- Fixes a mem leak in handling service tracker trackers.
- Adds configuration to log helper to skip DEBUG statement (now default behaviour)
- Update storage cleanup property to boolean and default now clean storage expect if false is set


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/ef40f48c
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/ef40f48c
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/ef40f48c

Branch: refs/heads/develop
Commit: ef40f48c75a1f38509656317464aba2b6f3057d9
Parents: d813507
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Oct 12 10:39:42 2018 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Oct 12 10:39:42 2018 +0200

----------------------------------------------------------------------
 bundles/log_service/src/log_helper.c            | 21 ++++++++++++--------
 .../pubsub_admin_zmq/src/pubsub_zmq_admin.c     |  2 +-
 .../src/pubsub_discovery_impl.c                 |  3 +--
 libs/framework/include/constants.h              |  6 ++++--
 libs/framework/src/bundle_context.c             |  1 +
 libs/framework/src/celix_launcher.c             | 10 ----------
 libs/framework/src/framework.c                  |  7 ++++---
 7 files changed, 24 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/ef40f48c/bundles/log_service/src/log_helper.c
----------------------------------------------------------------------
diff --git a/bundles/log_service/src/log_helper.c b/bundles/log_service/src/log_helper.c
index c0cd309..6570357 100644
--- a/bundles/log_service/src/log_helper.c
+++ b/bundles/log_service/src/log_helper.c
@@ -37,7 +37,11 @@
 
 #include "log_helper.h"
 
-#define LOGHELPER_ENABLE_STDOUT_FALLBACK_PROPERTY_NAME 	"LOGHELPER_ENABLE_STDOUT_FALLBACK"
+#define LOGHELPER_ENABLE_STDOUT_FALLBACK_NAME 				"LOGHELPER_ENABLE_STDOUT_FALLBACK"
+#define LOGHELPER_ENABLE_STDOUT_FALLBACK_DEFAULT 			false
+
+#define LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG_NAME 		"LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG"
+#define LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG_DEFAULT 	false
 
 
 struct log_helper {
@@ -46,6 +50,7 @@ struct log_helper {
 	celix_thread_mutex_t logListLock;
 	array_list_pt logServices;
 	bool stdOutFallback;
+	bool stdOutFallbackIncludeDebug;
 };
 
 celix_status_t logHelper_logServiceAdded(void *handle, service_reference_pt reference, void *service);
@@ -64,16 +69,12 @@ celix_status_t logHelper_create(bundle_context_pt context, log_helper_pt* loghel
 	}
 	else
 	{
-		const char* stdOutFallbackStr = NULL;
 		(*loghelper)->bundleContext = context;
 		(*loghelper)->logServiceTracker = NULL;
 		(*loghelper)->stdOutFallback = false;
 
-		bundleContext_getProperty(context, LOGHELPER_ENABLE_STDOUT_FALLBACK_PROPERTY_NAME, &stdOutFallbackStr);
-
-		if (stdOutFallbackStr != NULL) {
-			(*loghelper)->stdOutFallback = true;
-		}
+		(*loghelper)->stdOutFallback = celix_bundleContext_getPropertyAsBool(context, LOGHELPER_ENABLE_STDOUT_FALLBACK_NAME, LOGHELPER_ENABLE_STDOUT_FALLBACK_DEFAULT);
+		(*loghelper)->stdOutFallbackIncludeDebug = celix_bundleContext_getPropertyAsBool(context, LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG_NAME, LOGHELPER_STDOUT_FALLBACK_INCLUDE_DEBUG_DEFAULT);
 
 		pthread_mutex_init(&(*loghelper)->logListLock, NULL);
         arrayList_create(&(*loghelper)->logServices);
@@ -185,6 +186,7 @@ celix_status_t logHelper_log(log_helper_pt loghelper, log_level_t level, char* m
 
     if (!logged && loghelper->stdOutFallback) {
         char *levelStr = NULL;
+        bool print = true;
 
         switch (level) {
             case OSGI_LOGSERVICE_ERROR:
@@ -199,10 +201,13 @@ celix_status_t logHelper_log(log_helper_pt loghelper, log_level_t level, char* m
             case OSGI_LOGSERVICE_DEBUG:
             default:
                 levelStr = "DEBUG";
+                print = loghelper->stdOutFallbackIncludeDebug;
                 break;
         }
 
-        printf("%s: %s\n", levelStr, msg);
+        if (print) {
+			printf("%s: %s\n", levelStr, msg);
+		}
     }
 
     va_end(listPointer);

http://git-wip-us.apache.org/repos/asf/celix/blob/ef40f48c/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_admin.c
----------------------------------------------------------------------
diff --git a/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_admin.c b/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_admin.c
index 16e1f98..a13cb26 100644
--- a/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_admin.c
+++ b/bundles/pubsub/pubsub_admin_zmq/src/pubsub_zmq_admin.c
@@ -225,7 +225,7 @@ void pubsub_zmqAdmin_destroy(pubsub_zmq_admin_t *psa) {
     hashMap_destroy(psa->topicReceivers.map, true, false);
 
     celixThreadMutex_destroy(&psa->discoveredEndpoints.mutex);
-    hashMap_destroy(psa->discoveredEndpoints.map, true, false);
+    hashMap_destroy(psa->discoveredEndpoints.map, false, false);
 
     celixThreadMutex_destroy(&psa->serializers.mutex);
     hashMap_destroy(psa->serializers.map, false, false);

http://git-wip-us.apache.org/repos/asf/celix/blob/ef40f48c/bundles/pubsub/pubsub_discovery/src/pubsub_discovery_impl.c
----------------------------------------------------------------------
diff --git a/bundles/pubsub/pubsub_discovery/src/pubsub_discovery_impl.c b/bundles/pubsub/pubsub_discovery/src/pubsub_discovery_impl.c
index 0162213..9f3e89d 100644
--- a/bundles/pubsub/pubsub_discovery/src/pubsub_discovery_impl.c
+++ b/bundles/pubsub/pubsub_discovery/src/pubsub_discovery_impl.c
@@ -378,11 +378,10 @@ void pubsub_discovery_discoveredEndpointsListenerAdded(void *handle, void *svc,
 
 void pubsub_discovery_discoveredEndpointsListenerRemoved(void *handle, void *svc, const celix_properties_t *props, const celix_bundle_t *bnd) {
     pubsub_discovery_t *disc = handle;
-    pubsub_discovered_endpoint_listener_t *listener = svc;
 
     long svcId = celix_properties_getAsLong(props, OSGI_FRAMEWORK_SERVICE_ID, -1L);
     celixThreadMutex_lock(&disc->discoveredEndpointsListenersMutex);
-    hashMap_put(disc->discoveredEndpointsListeners, (void*)svcId, listener);
+    hashMap_remove(disc->discoveredEndpointsListeners, (void*)svcId);
     celixThreadMutex_unlock(&disc->discoveredEndpointsListenersMutex);
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/ef40f48c/libs/framework/include/constants.h
----------------------------------------------------------------------
diff --git a/libs/framework/include/constants.h b/libs/framework/include/constants.h
index c54f0cb..a15d8ad 100644
--- a/libs/framework/include/constants.h
+++ b/libs/framework/include/constants.h
@@ -27,6 +27,8 @@
 #ifndef CONSTANTS_H_
 #define CONSTANTS_H_
 
+#include <stdbool.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -68,8 +70,8 @@ static const char *const OSGI_FRAMEWORK_IMPORT_LIBRARY = "Import-Library";
 
 static const char *const OSGI_FRAMEWORK_FRAMEWORK_STORAGE = "org.osgi.framework.storage";
 static const char *const OSGI_FRAMEWORK_STORAGE_USE_TMP_DIR = "org.osgi.framework.storage.use.tmp.dir";
-static const char *const OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN = "org.osgi.framework.storage.clean";
-static const char *const OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT = "onFirstInit";
+static const char *const OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN_NAME = "org.osgi.framework.storage.clean";
+static const bool        OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN_DEFAULT = true;
 static const char *const OSGI_FRAMEWORK_FRAMEWORK_UUID = "org.osgi.framework.uuid";
 
 #define CELIX_AUTO_START_0 "CELIX_AUTO_START_0"

http://git-wip-us.apache.org/repos/asf/celix/blob/ef40f48c/libs/framework/src/bundle_context.c
----------------------------------------------------------------------
diff --git a/libs/framework/src/bundle_context.c b/libs/framework/src/bundle_context.c
index 4f90314..23fde80 100644
--- a/libs/framework/src/bundle_context.c
+++ b/libs/framework/src/bundle_context.c
@@ -673,6 +673,7 @@ void celix_bundleContext_stopTracker(bundle_context_t *ctx, long trackerId) {
         }
         if (svcTrackerTracker != NULL) {
             serviceRegistration_unregister(svcTrackerTracker->hookReg);
+            free(svcTrackerTracker->serviceName);
             free(svcTrackerTracker);
         }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/ef40f48c/libs/framework/src/celix_launcher.c
----------------------------------------------------------------------
diff --git a/libs/framework/src/celix_launcher.c b/libs/framework/src/celix_launcher.c
index b67faad..5df0c85 100644
--- a/libs/framework/src/celix_launcher.c
+++ b/libs/framework/src/celix_launcher.c
@@ -192,17 +192,10 @@ int celixLauncher_launchWithProperties(properties_pt config, framework_pt *frame
 	// Before doing anything else, let's setup Curl
 	curl_global_init(CURL_GLOBAL_NOTHING);
 #endif
-
-
 	status = framework_create(framework, config);
 	if (status == CELIX_SUCCESS) {
 		status = framework_start(*framework);
 	}
-
-	if (status == CELIX_SUCCESS) {
-		printf("Launcher: Framework Started\n");
-	}
-	
 	return status;
 }
 
@@ -212,13 +205,10 @@ void celixLauncher_waitForShutdown(framework_pt framework) {
 
 void celixLauncher_destroy(framework_pt framework) {
 	framework_destroy(framework);
-
 #ifndef CELIX_NO_CURLINIT
 	// Cleanup Curl
 	curl_global_cleanup();
 #endif
-
-	printf("Launcher: Exit\n");
 }
 
 void celixLauncher_stop(framework_pt framework) {

http://git-wip-us.apache.org/repos/asf/celix/blob/ef40f48c/libs/framework/src/framework.c
----------------------------------------------------------------------
diff --git a/libs/framework/src/framework.c b/libs/framework/src/framework.c
index 8d030d5..54fe8d3 100644
--- a/libs/framework/src/framework.c
+++ b/libs/framework/src/framework.c
@@ -543,8 +543,9 @@ celix_status_t fw_init(framework_pt framework) {
 	        status = CELIX_DO_IF(status, bundle_getState(framework->bundle, &state));
 	        if (status == CELIX_SUCCESS) {
 	            if (state == OSGI_FRAMEWORK_BUNDLE_INSTALLED) {
-	                const char *clean = properties_get(framework->configurationMap, OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN);
-	                if (clean != NULL && (strcmp(clean, OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT) == 0)) {
+	                const char *clean = properties_get(framework->configurationMap, OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN_NAME);
+	                bool cleanCache = clean == NULL ? true : strcmp(clean, "false") != 0;
+	                if (cleanCache) {
 	                    bundleCache_delete(framework->cache);
 	                }
 	            }
@@ -2416,7 +2417,7 @@ static celix_status_t frameworkActivator_stop(void * userData, bundle_context_t
 
 	if (bundleContext_getFramework(context, &framework) == CELIX_SUCCESS) {
 
-	    fw_log(framework->logger, OSGI_FRAMEWORK_LOG_INFO, "FRAMEWORK: Start shutdownthread");
+	    fw_log(framework->logger, OSGI_FRAMEWORK_LOG_DEBUG, "FRAMEWORK: Start shutdownthread");
 
         celixThreadMutex_lock(&framework->dispatcher.mutex);
         framework->dispatcher.active = false;