Просмотр исходного кода

Kill all asserts from logsys and handle proper error return

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2121 fd59a12c-fef9-0310-b244-a6a79926bd2f
Fabio M. Di Nitto 17 лет назад
Родитель
Сommit
230b85044f
4 измененных файлов с 50 добавлено и 20 удалено
  1. 10 6
      exec/logsys.c
  2. 12 0
      exec/main.c
  3. 1 0
      exec/util.c
  4. 27 14
      include/corosync/engine/logsys.h

+ 10 - 6
exec/logsys.c

@@ -37,7 +37,6 @@
 
 #include <config.h>
 
-#include <assert.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
@@ -278,11 +277,10 @@ static inline int strcpy_cutoff (char *dest, const char *src, int cutoff)
 {
 	unsigned int len;
 
-	if (cutoff == -1) {
+	if (cutoff <= 0) {
 		strcpy (dest, src);
 		return (strlen (dest));
 	} else {
-		assert (cutoff > 0);
 		strncpy (dest, src, cutoff);
 		dest[cutoff] = '\0';
 		len = strlen (dest);
@@ -839,7 +837,9 @@ unsigned int _logsys_subsys_create (const char *subsys)
 {
 	int i;
 
-	assert (subsys != NULL);
+	if (subsys == NULL) {
+		return -1;
+	}
 
 	pthread_mutex_lock (&logsys_config_mutex);
 
@@ -856,7 +856,9 @@ unsigned int _logsys_subsys_create (const char *subsys)
 		}
 	}
 
-	assert(i < LOGSYS_MAX_SUBSYS_COUNT);
+	if (i >= LOGSYS_MAX_SUBSYS_COUNT) {
+		i = -1;
+	}
 
 	pthread_mutex_unlock (&logsys_config_mutex);
 	return i;
@@ -935,7 +937,6 @@ void _logsys_log_rec (
 	va_start (ap, rec_ident);
 	arguments = 3;
 	for (;;) {
-		assert (arguments < 64);
 		buf_args[arguments] = va_arg (ap, void *);
 		if (buf_args[arguments] == LOGSYS_REC_END) {
 			break;
@@ -943,6 +944,9 @@ void _logsys_log_rec (
 		buf_len[arguments] = va_arg (ap, int);
 		record_reclaim_size += ((buf_len[arguments] + 3) >> 2) + 1;
 		arguments++;
+		if (arguments >= 64) {
+			break;
+		}
 	}
 	va_end (ap);
 

+ 12 - 0
exec/main.c

@@ -871,6 +871,13 @@ int main (int argc, char **argv)
 	totem_config.totem_logging_configuration = totem_logging_configuration;
 	totem_config.totem_logging_configuration.log_subsys_id =
 		_logsys_subsys_create ("TOTEM");
+
+	if (totem_config.totem_logging_configuration.log_subsys_id < 0) {
+		log_printf (LOGSYS_LEVEL_ERROR,
+			"Unable to initialize TOTEM logging subsystem\n");
+		corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
+	}
+
   	totem_config.totem_logging_configuration.log_level_security = LOGSYS_LEVEL_SECURITY;
 	totem_config.totem_logging_configuration.log_level_error = LOGSYS_LEVEL_ERROR;
 	totem_config.totem_logging_configuration.log_level_warning = LOGSYS_LEVEL_WARNING;
@@ -939,6 +946,11 @@ int main (int argc, char **argv)
  		serialize_unlock);
 
 	ipc_subsys_id = _logsys_subsys_create ("IPC");
+	if (ipc_subsys_id < 0) {
+		log_printf (LOGSYS_LEVEL_ERROR,
+			"Could not initialize IPC logging subsystem\n");
+		corosync_exit_error (AIS_DONE_INIT_SERVICES);
+	}
 
 	ipc_init_state.sched_priority = sched_priority;
 

+ 1 - 0
exec/util.c

@@ -41,6 +41,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <sys/time.h>
+#include <assert.h>
 
 #include <corosync/corotypes.h>
 #include <corosync/list.h>

+ 27 - 14
include/corosync/engine/logsys.h

@@ -38,8 +38,8 @@
 #define LOGSYS_H_DEFINED
 
 #include <stdarg.h>
+#include <stdlib.h>
 #include <syslog.h>
-#include <assert.h>
 
 /*
  * All of the LOGSYS_MODE's can be ORed together for combined behavior
@@ -254,20 +254,30 @@ extern void *logsys_rec_end;
 __attribute__ ((constructor))						\
 static void logsys_system_init (void)					\
 {									\
-	int err;							\
+	if (_logsys_system_setup (name,mode,debug,file,file_priority,	\
+			syslog_facility,syslog_priority,tags) < 0) {	\
+		fprintf (stderr,					\
+			"Unable to setup logging system: %s.\n", name);	\
+		exit (-1);						\
+	}								\
 									\
-	err = _logsys_system_setup (name,mode,debug,file,file_priority,	\
-				syslog_facility,syslog_priority,tags);	\
-	assert (err == 0 && "_logsys_system_setup failed");		\
+	if (logsys_format_set (format) < 0) {				\
+		fprintf (stderr,					\
+			"Unable to setup logging format.\n");		\
+		exit (-1);						\
+	}								\
 									\
-	err = logsys_format_set (format);				\
-	assert (err == 0 && "logsys_format_set failed");		\
+	if (_logsys_rec_init (rec_size) < 0) {				\
+		fprintf (stderr,					\
+			"Unable to initialize log flight recorder.\n");	\
+		exit (-1);						\
+	}								\
 									\
-	err = _logsys_rec_init (rec_size);				\
-	assert (err == 0 && "_logsys_rec_init failed");			\
-									\
-	err = _logsys_wthread_create();					\
-	assert (err == 0 && "_logsys_wthread_create failed");		\
+	if (_logsys_wthread_create() < 0) {				\
+		fprintf (stderr,					\
+			"Unable to initialize logging thread.\n");	\
+		exit (-1);						\
+	}								\
 }
 
 #define LOGSYS_DECLARE_SUBSYS(subsys)					\
@@ -276,8 +286,11 @@ static void logsys_subsys_init (void)					\
 {									\
 	logsys_subsys_id =						\
 		_logsys_subsys_create ((subsys));			\
-	assert (logsys_subsys_id < LOGSYS_MAX_SUBSYS_COUNT && 		\
-		"_logsys_subsys_create failed");			\
+	if (logsys_subsys_id == -1) {					\
+		fprintf (stderr,					\
+		"Unable to create logging subsystem: %s.\n", subsys);	\
+		exit (-1);						\
+	}								\
 }
 
 #define log_rec(rec_ident, args...)					\