celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1642820 - in /celix/trunk: log_service/private/src/ log_service/public/include/ log_writer/log_writer_stdout/private/src/
Date Tue, 02 Dec 2014 08:48:48 GMT
Author: abroekhuis
Date: Tue Dec  2 08:48:48 2014
New Revision: 1642820

URL: http://svn.apache.org/r1642820
Log:
CELIX-189: Fixed segfaults in the log_service and writers.

Modified:
    celix/trunk/log_service/private/src/log.c
    celix/trunk/log_service/private/src/log_entry.c
    celix/trunk/log_service/private/src/log_service_activator.c
    celix/trunk/log_service/private/src/log_service_impl.c
    celix/trunk/log_service/public/include/log_entry.h
    celix/trunk/log_writer/log_writer_stdout/private/src/log_writer_stdout.c

Modified: celix/trunk/log_service/private/src/log.c
URL: http://svn.apache.org/viewvc/celix/trunk/log_service/private/src/log.c?rev=1642820&r1=1642819&r2=1642820&view=diff
==============================================================================
--- celix/trunk/log_service/private/src/log.c (original)
+++ celix/trunk/log_service/private/src/log.c Tue Dec  2 08:48:48 2014
@@ -103,6 +103,11 @@ apr_status_t log_destroy(void *logp) {
 	apr_thread_cond_destroy(log->entriesToDeliver);
 	arrayList_destroy(log->listenerEntries);
 	arrayList_destroy(log->listeners);
+	linked_list_iterator_pt iter = linkedListIterator_create(log->entries, 0);
+	while (linkedListIterator_hasNext(iter)) {
+	    log_entry_pt entry = linkedListIterator_next(iter);
+	    logEntry_destroy(&entry);
+	}
 	linkedList_destroy(log->entries);
 	apr_thread_mutex_destroy(log->lock);
 
@@ -175,7 +180,7 @@ celix_status_t log_bundleChanged(void *l
 	}
 
 	if (message != NULL) {
-		status = logEntry_create(event->bundle, NULL, OSGI_LOGSERVICE_INFO, message, 0, logger->pool,
&entry);
+		status = logEntry_create(event->bundle, NULL, OSGI_LOGSERVICE_INFO, message, 0, &entry);
 		if (status == CELIX_SUCCESS) {
 			status = log_addEntry(logger, entry);
 		}
@@ -189,7 +194,7 @@ celix_status_t log_frameworkEvent(void *
 	log_pt logger = ((framework_listener_pt) listener)->handle;
 	log_entry_pt entry = NULL;
 
-	status = logEntry_create(event->bundle, NULL, (event->type == OSGI_FRAMEWORK_EVENT_ERROR)
? OSGI_LOGSERVICE_ERROR : OSGI_LOGSERVICE_INFO, event->error, event->errorCode, logger->pool,
&entry);
+	status = logEntry_create(event->bundle, NULL, (event->type == OSGI_FRAMEWORK_EVENT_ERROR)
? OSGI_LOGSERVICE_ERROR : OSGI_LOGSERVICE_INFO, event->error, event->errorCode, &entry);
 	if (status == CELIX_SUCCESS) {
 		status = log_addEntry(logger, entry);
 	}
@@ -312,22 +317,24 @@ void * APR_THREAD_FUNC log_listenerThrea
             if (!arrayList_isEmpty(logger->listenerEntries)) {
                 log_entry_pt entry = (log_entry_pt) arrayList_remove(logger->listenerEntries,
0);
 
-                status = apr_thread_mutex_lock(logger->listenerLock);
-                if (status != APR_SUCCESS) {
-                    logger->running = false;
-                    break;
-                } else {
-                    array_list_iterator_pt it = arrayListIterator_create(logger->listeners);
-                    while (arrayListIterator_hasNext(it)) {
-                        log_listener_pt listener = arrayListIterator_next(it);
-                        listener->logged(listener, entry);
-                    }
-					arrayListIterator_destroy(it);
-
-                    status = apr_thread_mutex_unlock(logger->listenerLock);
+                if (entry) {
+                    status = apr_thread_mutex_lock(logger->listenerLock);
                     if (status != APR_SUCCESS) {
                         logger->running = false;
                         break;
+                    } else {
+                        array_list_iterator_pt it = arrayListIterator_create(logger->listeners);
+                        while (arrayListIterator_hasNext(it)) {
+                            log_listener_pt listener = arrayListIterator_next(it);
+                            listener->logged(listener, entry);
+                        }
+                        arrayListIterator_destroy(it);
+
+                        status = apr_thread_mutex_unlock(logger->listenerLock);
+                        if (status != APR_SUCCESS) {
+                            logger->running = false;
+                            break;
+                        }
                     }
                 }
             }

Modified: celix/trunk/log_service/private/src/log_entry.c
URL: http://svn.apache.org/viewvc/celix/trunk/log_service/private/src/log_entry.c?rev=1642820&r1=1642819&r2=1642820&view=diff
==============================================================================
--- celix/trunk/log_service/private/src/log_entry.c (original)
+++ celix/trunk/log_service/private/src/log_entry.c Tue Dec  2 08:48:48 2014
@@ -25,22 +25,23 @@
  */
 
 #include <stddef.h>
+#include <stdlib.h>
 
 #include "log_entry.h"
 
 celix_status_t logEntry_create(bundle_pt bundle, service_reference_pt reference,
         log_level_t level, char *message, int errorCode,
-        apr_pool_t *pool, log_entry_pt *entry) {
+        log_entry_pt *entry) {
     celix_status_t status = CELIX_SUCCESS;
 
-    *entry = apr_palloc(pool, sizeof(**entry));
-    if (entry == NULL) {
+    *entry = malloc(sizeof(**entry));
+    if (*entry == NULL) {
         status = CELIX_ENOMEM;
     } else {
         (*entry)->bundle = bundle;
         (*entry)->reference = reference;
         (*entry)->level = level;
-        (*entry)->message = message;
+        (*entry)->message = strdup(message);
         (*entry)->errorCode = errorCode;
         (*entry)->time = time(NULL);
     }
@@ -48,6 +49,15 @@ celix_status_t logEntry_create(bundle_pt
     return status;
 }
 
+celix_status_t logEntry_destroy(log_entry_pt *entry) {
+    if (*entry) {
+        free((*entry)->message);
+        free(*entry);
+        *entry = NULL;
+    }
+    return CELIX_SUCCESS;
+}
+
 celix_status_t logEntry_getBundle(log_entry_pt entry, bundle_pt *bundle) {
     *bundle = entry->bundle;
     return CELIX_SUCCESS;

Modified: celix/trunk/log_service/private/src/log_service_activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/log_service/private/src/log_service_activator.c?rev=1642820&r1=1642819&r2=1642820&view=diff
==============================================================================
--- celix/trunk/log_service/private/src/log_service_activator.c (original)
+++ celix/trunk/log_service/private/src/log_service_activator.c Tue Dec  2 08:48:48 2014
@@ -43,6 +43,10 @@ struct logActivator {
     bundle_listener_pt bundleListener;
     framework_listener_pt frameworkListener;
 
+    log_pt logger;
+    service_factory_pt factory;
+    log_reader_data_pt reader;
+    log_reader_service_pt reader_service;
 };
 
 celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
@@ -61,6 +65,12 @@ celix_status_t bundleActivator_create(bu
 		activator->logServiceFactoryReg = NULL;
 		activator->logReaderServiceReg = NULL;
 		activator->pool = mp;
+
+		activator->logger = NULL;
+		activator->factory = NULL;
+		activator->reader = NULL;
+		activator->reader_service = NULL;
+
         *userData = activator;
     }
 
@@ -70,40 +80,34 @@ celix_status_t bundleActivator_create(bu
 celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
     struct logActivator * activator = (struct logActivator *) userData;
     celix_status_t status = CELIX_SUCCESS;
-    service_factory_pt factory = NULL;
-    log_pt logger = NULL;
-
-    log_reader_data_pt reader = NULL;
-    log_reader_service_pt reader_service = NULL;
-
 
-    log_create(activator->pool, &logger);
+    log_create(activator->pool, &activator->logger);
 
     // Add logger as Bundle- and FrameworkEvent listener
     activator->bundleListener = apr_palloc(activator->pool, sizeof(*activator->bundleListener));
-    activator->bundleListener->handle = logger;
+    activator->bundleListener->handle = activator->logger;
     activator->bundleListener->bundleChanged = log_bundleChanged;
     bundleContext_addBundleListener(context, activator->bundleListener);
 
     activator->frameworkListener = apr_palloc(activator->pool, sizeof(*activator->frameworkListener));
-    activator->frameworkListener->handle = logger;
+    activator->frameworkListener->handle = activator->logger;
     activator->frameworkListener->frameworkEvent = log_frameworkEvent;
     bundleContext_addFrameworkListener(context, activator->frameworkListener);
 
-    logFactory_create(activator->pool, logger, &factory);
+    logFactory_create(activator->pool, activator->logger, &activator->factory);
 
-    bundleContext_registerServiceFactory(context, (char *) OSGI_LOGSERVICE_NAME, factory,
NULL, &activator->logServiceFactoryReg);
+    bundleContext_registerServiceFactory(context, (char *) OSGI_LOGSERVICE_NAME, activator->factory,
NULL, &activator->logServiceFactoryReg);
 
-    logReaderService_create(logger, activator->pool, &reader);
+    logReaderService_create(activator->logger, activator->pool, &activator->reader);
 
-    reader_service = apr_palloc(activator->pool, sizeof(*reader_service));
-    reader_service->reader = reader;
-    reader_service->getLog = logReaderService_getLog;
-    reader_service->addLogListener = logReaderService_addLogListener;
-    reader_service->removeLogListener = logReaderService_removeLogListener;
-    reader_service->removeAllLogListener = logReaderService_removeAllLogListener;
+    activator->reader_service = apr_palloc(activator->pool, sizeof(*activator->reader_service));
+    activator->reader_service->reader = activator->reader;
+    activator->reader_service->getLog = logReaderService_getLog;
+    activator->reader_service->addLogListener = logReaderService_addLogListener;
+    activator->reader_service->removeLogListener = logReaderService_removeLogListener;
+    activator->reader_service->removeAllLogListener = logReaderService_removeAllLogListener;
 
-    bundleContext_registerService(context, (char *) OSGI_LOGSERVICE_READER_SERVICE_NAME,
reader_service, NULL, &activator->logReaderServiceReg);
+    bundleContext_registerService(context, (char *) OSGI_LOGSERVICE_READER_SERVICE_NAME,
activator->reader_service, NULL, &activator->logReaderServiceReg);
 
     return status;
 }
@@ -116,9 +120,16 @@ celix_status_t bundleActivator_stop(void
 	serviceRegistration_unregister(activator->logServiceFactoryReg);
 	activator->logServiceFactoryReg = NULL;
 
+	// logReaderService_destroy(activator->reader);
+	// free(activator->reader_service);
+
+	// logFactory_destroy(activator->factory);
+
 	bundleContext_removeBundleListener(context, activator->bundleListener);
 	bundleContext_removeFrameworkListener(context, activator->frameworkListener);
 
+	// log_destroy(activator->logger);
+
     return CELIX_SUCCESS;
 }
 

Modified: celix/trunk/log_service/private/src/log_service_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/log_service/private/src/log_service_impl.c?rev=1642820&r1=1642819&r2=1642820&view=diff
==============================================================================
--- celix/trunk/log_service/private/src/log_service_impl.c (original)
+++ celix/trunk/log_service/private/src/log_service_impl.c Tue Dec  2 08:48:48 2014
@@ -59,7 +59,7 @@ celix_status_t logService_logSr(log_serv
     if (reference != NULL) {
     	serviceReference_getBundle(reference, &bundle);
     }
-    logEntry_create(bundle, reference, level, message, 0, logger->pool, &entry);
+    logEntry_create(bundle, reference, level, message, 0, &entry);
     log_addEntry(logger->log, entry);
 
     return CELIX_SUCCESS;

Modified: celix/trunk/log_service/public/include/log_entry.h
URL: http://svn.apache.org/viewvc/celix/trunk/log_service/public/include/log_entry.h?rev=1642820&r1=1642819&r2=1642820&view=diff
==============================================================================
--- celix/trunk/log_service/public/include/log_entry.h (original)
+++ celix/trunk/log_service/public/include/log_entry.h Tue Dec  2 08:48:48 2014
@@ -44,7 +44,8 @@ typedef struct log_entry * log_entry_pt;
 
 celix_status_t logEntry_create(bundle_pt bundle, service_reference_pt reference,
         log_level_t level, char *message, int errorCode,
-        apr_pool_t *pool, log_entry_pt *entry);
+        log_entry_pt *entry);
+celix_status_t logEntry_destroy(log_entry_pt *entry);
 celix_status_t logEntry_getBundle(log_entry_pt entry, bundle_pt *bundle);
 celix_status_t logEntry_getErrorCode(log_entry_pt entry, int *errorCode);
 celix_status_t logEntry_getLevel(log_entry_pt entry, log_level_t *level);

Modified: celix/trunk/log_writer/log_writer_stdout/private/src/log_writer_stdout.c
URL: http://svn.apache.org/viewvc/celix/trunk/log_writer/log_writer_stdout/private/src/log_writer_stdout.c?rev=1642820&r1=1642819&r2=1642820&view=diff
==============================================================================
--- celix/trunk/log_writer/log_writer_stdout/private/src/log_writer_stdout.c (original)
+++ celix/trunk/log_writer/log_writer_stdout/private/src/log_writer_stdout.c Tue Dec  2 08:48:48
2014
@@ -40,12 +40,16 @@ celix_status_t logListener_logged(log_li
     module_pt module = NULL;
     char *sName = NULL;
 
-    status = bundle_getCurrentModule(entry->bundle, &module);
-    if (status == CELIX_SUCCESS) {
-		status = module_getSymbolicName(module, &sName);
-		if (status == CELIX_SUCCESS) {
-			printf("LogWriter: %s from %s\n", entry->message, sName);
-		}
+    if (!entry) {
+        status = CELIX_ILLEGAL_ARGUMENT;
+    } else {
+        status = bundle_getCurrentModule(entry->bundle, &module);
+        if (status == CELIX_SUCCESS) {
+            status = module_getSymbolicName(module, &sName);
+            if (status == CELIX_SUCCESS) {
+                printf("LogWriter: %s from %s\n", entry->message, sName);
+            }
+        }
     }
 
     return status;



Mime
View raw message