celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1650135 - in /celix/trunk: log_service/private/src/ log_service/public/include/ log_writer/log_writer_stdout/private/src/ log_writer/log_writer_syslog/private/src/ shell/private/src/
Date Wed, 07 Jan 2015 18:28:31 GMT
Author: abroekhuis
Date: Wed Jan  7 18:28:30 2015
New Revision: 1650135

URL: http://svn.apache.org/r1650135
Log:
CELIX-195: Updated log_entry to cache symbolic name to prevent crashes due to invalid pointers
if a bundle is uninstalled.

Modified:
    celix/trunk/log_service/private/src/log_entry.c
    celix/trunk/log_service/public/include/log_entry.h
    celix/trunk/log_writer/log_writer_stdout/private/src/log_writer_stdout.c
    celix/trunk/log_writer/log_writer_syslog/private/src/log_writer_syslog.c
    celix/trunk/shell/private/src/log_command.c

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=1650135&r1=1650134&r2=1650135&view=diff
==============================================================================
--- celix/trunk/log_service/private/src/log_entry.c (original)
+++ celix/trunk/log_service/private/src/log_entry.c Wed Jan  7 18:28:30 2015
@@ -40,12 +40,25 @@ celix_status_t logEntry_create(bundle_pt
     if (*entry == NULL) {
         status = CELIX_ENOMEM;
     } else {
-        (*entry)->bundle = bundle;
-        (*entry)->reference = reference;
         (*entry)->level = level;
         (*entry)->message = strdup(message);
         (*entry)->errorCode = errorCode;
         (*entry)->time = time(NULL);
+
+        (*entry)->bundleSymbolicName = NULL;
+        (*entry)->bundleId = 0;
+    }
+
+    if (status == CELIX_SUCCESS) {
+        status = bundle_getBundleId(bundle, &(*entry)->bundleId);
+    }
+
+    if (status == CELIX_SUCCESS) {
+    	module_pt module = NULL;
+        status = bundle_getCurrentModule(bundle, &module);
+		if (status == CELIX_SUCCESS) {
+			status = module_getSymbolicName(module, &(*entry)->bundleSymbolicName);
+		}
     }
 
     return status;
@@ -60,8 +73,13 @@ celix_status_t logEntry_destroy(log_entr
     return CELIX_SUCCESS;
 }
 
-celix_status_t logEntry_getBundle(log_entry_pt entry, bundle_pt *bundle) {
-    *bundle = entry->bundle;
+celix_status_t logEntry_getBundleSymbolicName(log_entry_pt entry, char **bundleSymbolicName)
{
+    *bundleSymbolicName = entry->bundleSymbolicName;
+    return CELIX_SUCCESS;
+}
+
+celix_status_t logEntry_getBundleId(log_entry_pt entry, long *bundleId) {
+    *bundleId = entry->bundleId;
     return CELIX_SUCCESS;
 }
 
@@ -80,11 +98,6 @@ celix_status_t logEntry_getMessage(log_e
     return CELIX_SUCCESS;
 }
 
-celix_status_t logEntry_getServiceReference(log_entry_pt entry, service_reference_pt *reference)
{
-    *reference = entry->reference;
-    return CELIX_SUCCESS;
-}
-
 celix_status_t logEntry_getTime(log_entry_pt entry, time_t *time) {
     *time = entry->time;
     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=1650135&r1=1650134&r2=1650135&view=diff
==============================================================================
--- celix/trunk/log_service/public/include/log_entry.h (original)
+++ celix/trunk/log_service/public/include/log_entry.h Wed Jan  7 18:28:30 2015
@@ -30,12 +30,13 @@
 #include "log_service.h"
 
 struct log_entry {
-    bundle_pt bundle;
     int errorCode;
     log_level_t level;
     char *message;
-    service_reference_pt reference;
     time_t time;
+
+    char *bundleSymbolicName;
+    long bundleId;
 };
 
 typedef struct log_entry * log_entry_pt;
@@ -44,11 +45,11 @@ celix_status_t logEntry_create(bundle_pt
         log_level_t level, char *message, int errorCode,
         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_getBundleSymbolicName(log_entry_pt entry, char **bundleSymbolicName);
+celix_status_t logEntry_getBundleId(log_entry_pt entry, long *bundleId);
 celix_status_t logEntry_getErrorCode(log_entry_pt entry, int *errorCode);
 celix_status_t logEntry_getLevel(log_entry_pt entry, log_level_t *level);
 celix_status_t logEntry_getMessage(log_entry_pt entry, char **message);
-celix_status_t logEntry_getServiceReference(log_entry_pt entry, service_reference_pt *reference);
 celix_status_t logEntry_getTime(log_entry_pt entry, time_t *time);
 
 #endif /* LOG_ENTRY_H_ */

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=1650135&r1=1650134&r2=1650135&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 Wed Jan  7 18:28:30
2015
@@ -43,13 +43,7 @@ celix_status_t logListener_logged(log_li
     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);
-            }
-        }
+		printf("LogWriter: %s from %s\n", entry->message, entry->bundleSymbolicName);
     }
 
     return status;

Modified: celix/trunk/log_writer/log_writer_syslog/private/src/log_writer_syslog.c
URL: http://svn.apache.org/viewvc/celix/trunk/log_writer/log_writer_syslog/private/src/log_writer_syslog.c?rev=1650135&r1=1650134&r2=1650135&view=diff
==============================================================================
--- celix/trunk/log_writer/log_writer_syslog/private/src/log_writer_syslog.c (original)
+++ celix/trunk/log_writer/log_writer_syslog/private/src/log_writer_syslog.c Wed Jan  7 18:28:30
2015
@@ -43,35 +43,28 @@ 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) {
+	int sysLogLvl = -1;
 
-			int sysLogLvl = -1;
+	switch(entry->level)
+	{
+		case 0x00000001: /*OSGI_LOGSERVICE_ERROR */
+			sysLogLvl = LOG_MAKEPRI(LOG_FAC(LOG_USER), LOG_ERR);
+			break;
+		case 0x00000002: /* OSGI_LOGSERVICE_WARNING */
+			sysLogLvl = LOG_MAKEPRI(LOG_FAC(LOG_USER), LOG_WARNING);
+			break;
+		case 0x00000003: /* OSGI_LOGSERVICE_INFO */
+			sysLogLvl = LOG_MAKEPRI(LOG_FAC(LOG_USER), LOG_INFO);
+			break;
+		case 0x00000004: /* OSGI_LOGSERVICE_DEBUG */
+			sysLogLvl = LOG_MAKEPRI(LOG_FAC(LOG_USER), LOG_DEBUG);
+			break;
+		default:		/* OSGI_LOGSERVICE_INFO */
+			sysLogLvl = LOG_MAKEPRI(LOG_FAC(LOG_USER), LOG_INFO);
+			break;
+	}
 
-			switch(entry->level)
-			{
-				case 0x00000001: /*OSGI_LOGSERVICE_ERROR */
-					sysLogLvl = LOG_MAKEPRI(LOG_FAC(LOG_USER), LOG_ERR);
-					break;
-				case 0x00000002: /* OSGI_LOGSERVICE_WARNING */
-					sysLogLvl = LOG_MAKEPRI(LOG_FAC(LOG_USER), LOG_WARNING);
-					break;
-				case 0x00000003: /* OSGI_LOGSERVICE_INFO */
-					sysLogLvl = LOG_MAKEPRI(LOG_FAC(LOG_USER), LOG_INFO);
-					break;
-				case 0x00000004: /* OSGI_LOGSERVICE_DEBUG */
-					sysLogLvl = LOG_MAKEPRI(LOG_FAC(LOG_USER), LOG_DEBUG);
-					break;
-				default:		/* OSGI_LOGSERVICE_INFO */
-					sysLogLvl = LOG_MAKEPRI(LOG_FAC(LOG_USER), LOG_INFO);
-					break;
-			}
-
-			syslog(sysLogLvl, "[%s]: %s", sName, entry->message);
-		}
-    }
+	syslog(sysLogLvl, "[%s]: %s", entry->bundleSymbolicName, entry->message);
 
     return status;
 }

Modified: celix/trunk/shell/private/src/log_command.c
URL: http://svn.apache.org/viewvc/celix/trunk/shell/private/src/log_command.c?rev=1650135&r1=1650134&r2=1650135&view=diff
==============================================================================
--- celix/trunk/shell/private/src/log_command.c (original)
+++ celix/trunk/shell/private/src/log_command.c Wed Jan  7 18:28:30 2015
@@ -68,25 +68,18 @@ void logCommand_execute(command_pt comma
 			log_entry_pt entry = linkedListIterator_next(iter);
 			char time[20];
 			char *level = NULL;
-			module_pt module = NULL;
-			char *bundleSymbolicName = NULL;
 			char errorString[256];
 
-			celix_status_t status = bundle_getCurrentModule(entry->bundle, &module);
-			if (status == CELIX_SUCCESS) {
-				status = module_getSymbolicName(module, &bundleSymbolicName);
+			strftime(time, 20, "%Y-%m-%d %H:%M:%S", localtime(&entry->time));
+			logCommand_levelAsString(command, entry->level, &level);
 
-				strftime(time, 20, "%Y-%m-%d %H:%M:%S", localtime(&entry->time));
-				logCommand_levelAsString(command, entry->level, &level);
-
-				if (entry->errorCode > 0) {
-					celix_strerror(entry->errorCode, errorString, 256);
-					sprintf(line, "%s - Bundle: %s - %s - %d %s\n", time, bundleSymbolicName, entry->message,
entry->errorCode, errorString);
-					out(line);
-				} else {
-					sprintf(line, "%s - Bundle: %s - %s\n", time, bundleSymbolicName, entry->message);
-					out(line);
-				}
+			if (entry->errorCode > 0) {
+				celix_strerror(entry->errorCode, errorString, 256);
+				sprintf(line, "%s - Bundle: %s - %s - %d %s\n", time, entry->bundleSymbolicName, entry->message,
entry->errorCode, errorString);
+				out(line);
+			} else {
+				sprintf(line, "%s - Bundle: %s - %s\n", time, entry->bundleSymbolicName, entry->message);
+				out(line);
 			}
 		}
 		linkedListIterator_destroy(iter);



Mime
View raw message