Sfoglia il codice sorgente

Flushed printing for trunk branch.

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1302 fd59a12c-fef9-0310-b244-a6a79926bd2f
Steven Dake 19 anni fa
parent
commit
53d0f551e4
5 ha cambiato i file con 75 aggiunte e 47 eliminazioni
  1. 9 2
      exec/main.c
  2. 44 42
      exec/print.c
  3. 2 0
      exec/print.h
  4. 17 3
      exec/wthread.c
  5. 3 0
      exec/wthread.h

+ 9 - 2
exec/main.c

@@ -106,6 +106,11 @@ static void sigusr2_handler (int num)
 	}
 }
 
+static void sigsegv_handler (int num)
+{
+	log_atsegv ();
+}
+
 struct totem_ip_address *this_ip;
 struct totem_ip_address this_non_loopback_ip;
 #define LOCALHOST_IP inet_addr("127.0.0.1")
@@ -419,10 +424,14 @@ int main (int argc, char **argv)
 
 	signal (SIGUSR2, sigusr2_handler);
 
+	signal (SIGSEGV, sigsegv_handler);
+
 	openais_timer_init (
 		serialize_mutex_lock,
 		serialize_mutex_unlock);
 
+	log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: started and ready to provide service.\n");
+
 	aisexec_poll_handle = poll_create (
 		serialize_mutex_lock,
 		serialize_mutex_unlock);
@@ -597,8 +606,6 @@ int main (int argc, char **argv)
 		gid_valid,
 		&this_non_loopback_ip);
 
-	log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: started and ready to provide service.\n");
-
 	/*
 	 * Start main processing loop
 	 */

+ 44 - 42
exec/print.c

@@ -3,11 +3,11 @@
  * Copyright (c) 2006 Ericsson AB.
  *
  * Author: Steven Dake (sdake@redhat.com)
- *    original work, Add worker thread to avoid blocking syslog
+ *	original work, Add worker thread to avoid blocking syslog
  *
  * Author: Hans Feldt
- *      Added support for runtime installed loggers, tags tracing,
- *    and file & line printing.
+ *      Added support for runtime installed loggers, tags tracing, 
+ *	and file & line printing.
  *
  * All rights reserved.
  *
@@ -55,7 +55,6 @@
 #include <syslog.h>
 #include <stdlib.h>
 #include <pthread.h>
-#include <signal.h>
 
 #include "print.h"
 #include "totemip.h"
@@ -100,13 +99,19 @@ struct log_data {
 	char *log_string;
 };
 
+static void log_atexit (void);
+
 static int logger_init (const char *ident, int tags, int level, int mode)
 {
 	int i;
 
  	for (i = 0; i < MAX_LOGGERS; i++) {
 		if (strcmp (loggers[i].ident, ident) == 0) {
-			goto done;
+			loggers[i].tags |= tags;
+			if (level > loggers[i].level) {
+				loggers[i].level = level;
+			}
+			break;
 		}
 	}
 
@@ -122,8 +127,8 @@ static int logger_init (const char *ident, int tags, int level, int mode)
 		}
 	}
 
-done:
-	assert (i < MAX_LOGGERS);
+	assert(i < MAX_LOGGERS);
+
 	return i;
 }
 
@@ -178,6 +183,7 @@ static void _log_printf (char *file, int line,
 	int i = 0;
 	int len;
 	struct log_data log_data;
+	unsigned int res = 0;
 
 	assert (id < MAX_LOGGERS);
 
@@ -234,18 +240,15 @@ static void _log_printf (char *file, int line,
 	if (log_data.log_string == NULL) {
 		goto drop_log_msg;
 	}
-
-#ifndef DEBUG
+	
 	if (log_setup_called) {
-		int res = worker_thread_group_work_add (&log_thread_group, &log_data);
+		res = worker_thread_group_work_add (&log_thread_group, &log_data);
 		if (res == 0) {
 			dropped_log_entries = 0;
 		} else {
 			dropped_log_entries += 1;
 		}
-	} else
-#endif
-	{
+	} else {
 		log_printf_worker_fn (NULL, &log_data);	
 	}
 
@@ -261,36 +264,21 @@ int _log_init (const char *ident)
 {
 	assert (ident != NULL);
 
-	if (logmode & LOG_MODE_DEBUG) {
-		return logger_init (ident, TAG_LOG, LOG_LEVEL_DEBUG, 0);
-	} else {
+	/*
+	** do different things before and after log_setup() has been called
+	*/
+	if (log_setup_called) {
 		return logger_init (ident, TAG_LOG, LOG_LEVEL_INFO, 0);
+	} else {
+		return logger_init (ident, ~0, LOG_LEVEL_DEBUG, 0);
 	}
 }
 
-#ifdef PRINT_DEBUG
-static void sigusr2_handler (int num)
-{
-	int i;
-
-	for (i = 0; i < MAX_LOGGERS; i++) {
-		if (strlen (loggers[i].ident) > 0) {
-			printf("ident: %6s, tags: %08x, level: %d\n",
-				loggers[i].ident, loggers[i].tags, loggers[i].level);
-		}
-	}
-}
-#endif
-
 int log_setup (char **error_string, struct main_config *config)
 {
 	int i;
 	static char error_string_response[512];
 
-#ifdef PRINT_DEBUG
-	signal (SIGUSR2, sigusr2_handler);
-#endif
-
 	if (config->logmode & LOG_MODE_FILE) {
 		log_file_fp = fopen (config->logfile, "a+");
 		if (log_file_fp == 0) {
@@ -312,14 +300,14 @@ int log_setup (char **error_string, struct main_config *config)
 	}
 
 	/*
-	** reinit level for all loggers that has initialised
-	** before log_setup() was called.
+	** reinit all loggers that has initialised before log_setup() was called.
 	*/
 	for (i = 0; i < MAX_LOGGERS; i++) {
-		if (strlen (loggers[i].ident) > 0) {
-			if (config->logmode & LOG_MODE_DEBUG) {
-				loggers[i].level = LOG_LEVEL_DEBUG;
-			}
+		loggers[i].tags = TAG_LOG;
+		if (config->logmode & LOG_MODE_DEBUG) {
+			loggers[i].level = LOG_LEVEL_DEBUG;
+		} else {
+			loggers[i].level = LOG_LEVEL_INFO;
 		}
 	}
 
@@ -336,8 +324,6 @@ int log_setup (char **error_string, struct main_config *config)
 			config->logger[i].mode);
 	}
 
-	log_setup_called = 1;
-
 	worker_thread_group_init (
 		&log_thread_group,
 		1,
@@ -347,6 +333,7 @@ int log_setup (char **error_string, struct main_config *config)
 		NULL,
 		log_printf_worker_fn);
 
+	log_setup_called = 1;
 
 	/*
 	** Flush what we have buffered
@@ -355,6 +342,7 @@ int log_setup (char **error_string, struct main_config *config)
 
 	internal_log_printf(__FILE__, __LINE__, LOG_LEVEL_DEBUG, "log setup\n");
 
+	atexit (log_atexit);
 	return (0);
 }
 
@@ -419,3 +407,17 @@ void log_flush(void)
 
 	head = tail = NULL;
 }
+
+static void log_atexit (void)
+{
+	if (log_setup_called) {
+		worker_thread_group_wait (&log_thread_group);
+	}
+}
+
+void log_atsegv (void)
+{
+	log_setup_called = 0;
+	worker_thread_group_exit (&log_thread_group);
+	worker_thread_group_atsegv (&log_thread_group);
+}

+ 2 - 0
exec/print.h

@@ -122,6 +122,8 @@ static inline void log_init (const char *ident)
 	logger_identifier = _log_init (ident);
 }
 
+extern void log_atsegv (void);
+
 #define log_printf(lvl, format, args...) do { \
     if ((lvl) <= loggers[logger_identifier].level)	{ \
 		internal_log_printf2 (__FILE__, __LINE__, lvl, logger_identifier, format, ##args);  \

+ 17 - 3
exec/wthread.c

@@ -63,8 +63,6 @@ struct worker_thread {
 
 void *worker_thread (void *thread_data_in) {
 	struct thread_data *thread_data = (struct thread_data *)thread_data_in;
-	struct orf_token_mcast_thread_state *orf_token_mcast_thread_state =
-		(struct orf_token_mcast_thread_state *)thread_data->thread_state;
 	struct worker_thread *worker_thread =
 		(struct worker_thread *)thread_data->data;
 	void *data_for_worker_fn;
@@ -83,7 +81,7 @@ void *worker_thread (void *thread_data_in) {
 	  	 */
 		data_for_worker_fn = queue_item_get (&worker_thread->queue);
 		pthread_mutex_unlock (&worker_thread->new_work_mutex);
-		worker_thread->worker_thread_group->worker_fn (orf_token_mcast_thread_state, data_for_worker_fn);
+		worker_thread->worker_thread_group->worker_fn (worker_thread->thread_state, data_for_worker_fn);
 		pthread_mutex_lock (&worker_thread->new_work_mutex);
 		queue_item_remove (&worker_thread->queue);
 		pthread_mutex_unlock (&worker_thread->new_work_mutex);
@@ -186,3 +184,19 @@ void worker_thread_group_exit (
 		pthread_cancel (worker_thread_group->threads[i].thread_id);
 	}
 }
+void worker_thread_group_atsegv (
+	struct worker_thread_group *worker_thread_group)
+{
+	void *data_for_worker_fn;
+	struct worker_thread *worker_thread;
+	unsigned int i;
+
+	for (i = 0; i < worker_thread_group->threadcount; i++) {
+		worker_thread = &worker_thread_group->threads[i];
+		while (queue_is_empty (&worker_thread->queue) == 0) {
+			data_for_worker_fn = queue_item_get (&worker_thread->queue);
+			worker_thread->worker_thread_group->worker_fn (worker_thread->thread_state, data_for_worker_fn);
+			queue_item_remove (&worker_thread->queue);
+		}
+	}
+}

+ 3 - 0
exec/wthread.h

@@ -61,4 +61,7 @@ extern void worker_thread_group_wait (
 extern void worker_thread_group_exit (
 	struct worker_thread_group *worker_thread_group);
 
+extern void worker_thread_group_atsegv (
+	struct worker_thread_group *worker_thread_group);
+
 #endif /* WTHREAD_H_DEFINED */