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

Add logsys v3


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2091 fd59a12c-fef9-0310-b244-a6a79926bd2f
Fabio M. Di Nitto 17 лет назад
Родитель
Сommit
c3c75acfd2

+ 3 - 3
conf/corosync.conf

@@ -14,13 +14,13 @@ totem {
 logging {
 	fileline: off
 	to_stderr: yes
-	to_file: yes
+	to_logfile: yes
 	to_syslog: yes
 	logfile: /tmp/corosync.log
 	debug: off
 	timestamp: on
-	logger {
-		ident: AMF
+	logger_subsys {
+		subsys: AMF
 		debug: off
 		tags: enter|leave|trace1|trace2|trace3|trace4|trace6
 	}

+ 1 - 1
exec/apidef.c

@@ -55,7 +55,7 @@
 #include <corosync/lcr/lcr_ifact.h>
 #include "apidef.h"
 
-LOGSYS_DECLARE_SUBSYS ("APIDEF", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("APIDEF");
 
 /*
  * Remove compile warnings about type name changes in corosync_tpg_group

+ 1 - 1
exec/coroipcs.c

@@ -398,7 +398,7 @@ req_setup_recv (
 		api->log_printf ("Invalid security authentication\n");
  	}
 #else /* HAVE_GETPEERUCRED */
- 	api->log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated "
+ 	api->log_printf (LOGSYS_LEVEL_SECURITY, "Connection not authenticated "
  		"because platform does not support "
  		"authentication with sockets, continuing "
  		"with a fake authentication\n");

+ 527 - 234
exec/logsys.c

@@ -4,6 +4,7 @@
  *
  * Author: Steven Dake (sdake@redhat.com)
  * Author: Lon Hohberger (lhh@redhat.com)
+ * Author: Fabio M. Di Nitto (fdinitto@redhat.com)
  *
  * All rights reserved.
  *
@@ -62,7 +63,8 @@
 
 #include <corosync/engine/logsys.h>
 
-/* similar to syslog facilities/priorities tables,
+/*
+ * similar to syslog facilities/priorities tables,
  * make a tag table for internal use
  */
 
@@ -73,20 +75,20 @@ struct syslog_names {
 };
 
 struct syslog_names tagnames[] =
-  {
-    { "log", LOGSYS_TAG_LOG },
-    { "enter", LOGSYS_TAG_ENTER },
-    { "leave", LOGSYS_TAG_LEAVE },
-    { "trace1", LOGSYS_TAG_TRACE1 },
-    { "trace2", LOGSYS_TAG_TRACE2 },
-    { "trace3", LOGSYS_TAG_TRACE3 },
-    { "trace4", LOGSYS_TAG_TRACE4 },
-    { "trace5", LOGSYS_TAG_TRACE5 },
-    { "trace6", LOGSYS_TAG_TRACE6 },
-    { "trace7", LOGSYS_TAG_TRACE7 },
-    { "trace8", LOGSYS_TAG_TRACE8 },
-    { NULL, -1 }
-  };
+{
+	{ "log", LOGSYS_TAG_LOG },
+	{ "enter", LOGSYS_TAG_ENTER },
+	{ "leave", LOGSYS_TAG_LEAVE },
+	{ "trace1", LOGSYS_TAG_TRACE1 },
+	{ "trace2", LOGSYS_TAG_TRACE2 },
+	{ "trace3", LOGSYS_TAG_TRACE3 },
+	{ "trace4", LOGSYS_TAG_TRACE4 },
+	{ "trace5", LOGSYS_TAG_TRACE5 },
+	{ "trace6", LOGSYS_TAG_TRACE6 },
+	{ "trace7", LOGSYS_TAG_TRACE7 },
+	{ "trace8", LOGSYS_TAG_TRACE8 },
+	{ NULL, -1 }
+};
 #endif
 
 /*
@@ -96,34 +98,36 @@ int *flt_data;
 
 int flt_data_size;
 
-#define SUBSYS_MAX 32
-
 #define COMBINE_BUFFER_SIZE 2048
 
-struct logsys_logger {
-	char subsys[64];
-	unsigned int priority;
-	unsigned int tags;
-	unsigned int mode;
-};
+/* values for logsys_logger init_status */
+#define LOGSYS_LOGGER_INIT_DONE		0
+#define LOGSYS_LOGGER_NEEDS_INIT	1
+
+static int logsys_system_needs_init = LOGSYS_LOGGER_NEEDS_INIT;
 
 /*
- * Configuration parameters for logging system
+ * need unlogical order to preserve 64bit alignment
  */
-static const char *logsys_name = NULL;
-
-static unsigned int logsys_mode = LOG_MODE_NOSUBSYS;
-
-static const char *logsys_file = NULL;
-
-static FILE *logsys_file_fp = NULL;
-
-static int logsys_facility = LOG_DAEMON;
+struct logsys_logger {
+	char subsys[LOGSYS_MAX_SUBSYS_NAMELEN];	/* subsystem name */
+	char *logfile;				/* log to file */
+	FILE *logfile_fp;			/* track file descriptor */
+	unsigned int mode;			/* subsystem mode */
+	unsigned int debug;			/* debug on|off */
+	unsigned int tags;			/* trace tags */
+	int syslog_facility;			/* facility */
+	int syslog_priority;			/* priority */
+	int logfile_priority;			/* priority to file */
+	int init_status;			/* internal field to handle init queues
+						   for subsystems */
+};
 
 /*
  * operating global variables
  */
-static struct logsys_logger logsys_loggers[SUBSYS_MAX];
+
+static struct logsys_logger logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT + 1];
 
 static int wthread_active = 0;
 
@@ -161,7 +165,8 @@ void *logsys_rec_end;
 
 #define FDTAIL_INDEX 	(flt_data_size + 1)
 
-static void logsys_atexit (void);
+/* forward declarations */
+static void logsys_close_logfile(int subsysid);
 
 /*
  * Helpers for _logsys_log_rec functionality
@@ -204,7 +209,6 @@ static void logsys_unlock (void)
 }
 #endif
 
-
 /*
  * Before any write operation, a reclaim on the buffer area must be executed
  */
@@ -306,7 +310,7 @@ static void log_printf_to_logs (
 	const char *function_name,
 	int file_line,
 	unsigned int level,
-	char *buffer)
+	const char *buffer)
 {
 	char output_buffer[COMBINE_BUFFER_SIZE];
 	char char_time[128];
@@ -316,7 +320,13 @@ static void log_printf_to_logs (
 	struct timeval tv;
 	int cutoff;
 	unsigned int len;
-	
+	int subsysid;
+
+	subsysid = _logsys_config_subsys_get(subsys);
+	if (subsysid <= - 1) {
+		return;
+	}
+
 	while (format_buffer[format_buffer_idx]) {
 		cutoff = -1;
 		if (format_buffer[format_buffer_idx] == '%') {
@@ -375,41 +385,83 @@ static void log_printf_to_logs (
 
 	/*
 	 * Output to syslog
-	 */	
-	if (logsys_mode & LOG_MODE_OUTPUT_SYSLOG) {
-		syslog (level, "%s", output_buffer);
+	 */
+	if (((logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_SYSLOG) &&
+	     (level <= logsys_loggers[subsysid].syslog_priority)) || 
+	     (logsys_loggers[subsysid].debug != 0)) {
+		syslog (level | logsys_loggers[subsysid].syslog_facility, "%s", output_buffer);
 	}
 
 	/*
 	 * Terminate string with \n \0
 	 */
-	if (logsys_mode & (LOG_MODE_OUTPUT_FILE|LOG_MODE_OUTPUT_STDERR)) {
+	if (logsys_loggers[subsysid].mode & (LOGSYS_MODE_OUTPUT_FILE|LOGSYS_MODE_OUTPUT_STDERR)) {
 		output_buffer[output_buffer_idx++] = '\n';
 		output_buffer[output_buffer_idx] = '\0';
 	}
 
 	/*
 	 * Output to configured file
-	 */	
-	if ((logsys_mode & LOG_MODE_OUTPUT_FILE) && logsys_file_fp) {
+	 */
+	if (((logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_FILE) &&
+	      logsys_loggers[subsysid].logfile_fp &&
+	     (level <= logsys_loggers[subsysid].logfile_priority)) ||
+	     (logsys_loggers[subsysid].debug != 0)) {
 		/*
 		 * Output to a file
 		 */
-		(void)fwrite (output_buffer, strlen (output_buffer), 1, logsys_file_fp);
-		fflush (logsys_file_fp);
+		if ((fwrite (output_buffer, strlen (output_buffer), 1,
+			    logsys_loggers[subsysid].logfile_fp) < 1) ||
+		    (fflush (logsys_loggers[subsysid].logfile_fp) == EOF)) {
+			char tmpbuffer[1024];
+			/*
+			 * if we are here, it's bad.. it's really really bad.
+			 * Best thing would be to light a candle in a church
+			 * and pray.
+			 */
+			snprintf(tmpbuffer, sizeof(tmpbuffer),
+				"LOGSYS EMERGENCY: %s Unable to write to %s.",
+				logsys_loggers[subsysid].subsys,
+				logsys_loggers[subsysid].logfile);
+			pthread_mutex_lock (&logsys_config_mutex);
+			logsys_close_logfile(subsysid);
+			logsys_loggers[subsysid].mode &= ~LOGSYS_MODE_OUTPUT_FILE;
+			pthread_mutex_unlock (&logsys_config_mutex);
+			log_printf_to_logs(logsys_loggers[subsysid].subsys,
+					   __FILE__, __FUNCTION__, __LINE__,
+					   LOGSYS_LEVEL_EMERG, tmpbuffer);
+		}
 	}
 
 	/*
 	 * Output to stderr
-	 */	
-	if (logsys_mode & LOG_MODE_OUTPUT_STDERR) {
-		(void)write (STDERR_FILENO, output_buffer, strlen (output_buffer));
+	 */
+	if (((logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_STDERR) &&
+	     (level <= logsys_loggers[subsysid].logfile_priority)) ||
+	     (logsys_loggers[subsysid].debug != 0)) {
+		if (write (STDERR_FILENO, output_buffer, strlen (output_buffer)) < 0) {
+			char tmpbuffer[1024];
+			/*
+			 * if we are here, it's bad.. it's really really bad.
+			 * Best thing would be to light 20 candles for each saint
+			 * in the calendar and pray a lot...
+			 */
+			pthread_mutex_lock (&logsys_config_mutex);
+			logsys_loggers[subsysid].mode &= ~LOGSYS_MODE_OUTPUT_STDERR;
+			pthread_mutex_unlock (&logsys_config_mutex);
+			snprintf(tmpbuffer, sizeof(tmpbuffer),
+				"LOGSYS EMERGENCY: %s Unable to write to STDERR.",
+				logsys_loggers[subsysid].subsys);
+			log_printf_to_logs(logsys_loggers[subsysid].subsys,
+				__FILE__, __FUNCTION__, __LINE__,
+				LOGSYS_LEVEL_EMERG, tmpbuffer);
+		}
 	}
 }
 
-static void record_print (char *buf)
+static void record_print (const char *buf)
 {
-	int *buf_uint32t = (int *)buf;
+	const int *buf_uint32t = (const int *)buf;
 	unsigned int rec_size = buf_uint32t[0];
 	unsigned int rec_ident = buf_uint32t[1];
 	unsigned int file_line = buf_uint32t[2];
@@ -417,7 +469,7 @@ static void record_print (char *buf)
 	unsigned int i;
 	unsigned int words_processed;
 	unsigned int arg_size_idx;
-	void *arguments[64];
+	const void *arguments[64];
 	unsigned int arg_count;
 
 	arg_size_idx = 4;
@@ -442,10 +494,10 @@ static void record_print (char *buf)
 		(char *)arguments[1],
 		(char *)arguments[2],
 		file_line,
-		level,
+		(level-1),
 		(char *)arguments[3]);
 }
-	
+
 static int record_read (char *buf, int rec_idx, int *log_msg) {
         unsigned int rec_size;
         unsigned int rec_ident;
@@ -582,32 +634,237 @@ static void wthread_create (void)
 	wthread_wait_locked ();
 }
 
+static int _logsys_config_subsys_get_unlocked (const char *subsys)
+{
+	unsigned int i;
+
+	if (!subsys) {
+		return LOGSYS_MAX_SUBSYS_COUNT;
+	}
+
+ 	for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
+		if (strcmp (logsys_loggers[i].subsys, subsys) == 0) {
+			pthread_mutex_unlock (&logsys_config_mutex);
+			return i;
+		}
+	}
+
+	return (-1);
+}
+
+static void syslog_facility_reconf (void)
+{
+	closelog();
+	openlog(logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT].subsys,
+		LOG_CONS|LOG_PID,
+		logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT].syslog_facility);
+}
+
+/*
+ * this is always invoked within the mutex, so it's safe to parse the
+ * whole thing as we need.
+ */
+static void logsys_close_logfile (
+	int subsysid)
+{
+	int i;
+
+	if ((logsys_loggers[subsysid].logfile_fp == NULL) &&
+	    (logsys_loggers[subsysid].logfile == NULL)) {
+		return;
+	}
+
+	/*
+	 * if there is another subsystem or system using the same fp,
+	 * then we clean our own structs, but we can't close the file
+	 * as it is in use by somebody else.
+	 * Only the last users will be allowed to perform the fclose.
+	 */
+ 	for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
+		if ((logsys_loggers[i].logfile_fp == logsys_loggers[subsysid].logfile_fp) &&
+		    (i != subsysid)) {
+			logsys_loggers[subsysid].logfile = NULL;
+			logsys_loggers[subsysid].logfile_fp = NULL;
+			return;
+		}
+	}
+
+	/*
+	 * if we are here, we are the last users of that fp, so we can safely
+	 * close it.
+	 */
+	fclose (logsys_loggers[subsysid].logfile_fp);
+	logsys_loggers[subsysid].logfile_fp = NULL;
+	free (logsys_loggers[subsysid].logfile);
+	logsys_loggers[subsysid].logfile = NULL;
+}
+
+/*
+ * we need a version that can work when somebody else is already
+ * holding a config mutex lock or we will never get out of here
+ */
+static int logsys_config_file_set_unlocked (
+		int subsysid,
+		const char **error_string,
+		const char *file)
+{
+	static char error_string_response[512];
+	int i;
+
+	logsys_close_logfile(subsysid);
+
+	if ((file == NULL) ||
+	    (strcmp(logsys_loggers[subsysid].subsys, "") == 0)) {
+		return (0);
+	}
+
+	for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
+		if ((logsys_loggers[i].logfile != NULL) &&
+			(strcmp (logsys_loggers[i].logfile, file) == 0) &&
+			(i != subsysid)) {
+				logsys_loggers[subsysid].logfile =
+					logsys_loggers[i].logfile;
+				logsys_loggers[subsysid].logfile_fp =
+					logsys_loggers[i].logfile_fp;
+				return (0);
+		}
+	}
+
+	logsys_loggers[subsysid].logfile = strdup(file);
+	if (logsys_loggers[subsysid].logfile == NULL) {
+		snprintf (error_string_response,
+			sizeof(error_string_response),
+			"Unable to allocate memory for logfile '%s'\n",
+			file);
+		*error_string = error_string_response;
+		return (-1);
+	}
+
+	logsys_loggers[subsysid].logfile_fp = fopen (file, "a+");
+	if (logsys_loggers[subsysid].logfile_fp == NULL) {
+		free(logsys_loggers[subsysid].logfile);
+		logsys_loggers[subsysid].logfile = NULL;
+		snprintf (error_string_response,
+			sizeof(error_string_response),
+			"Can't open logfile '%s' for reason (%s).\n",
+				 file, strerror (errno));
+		*error_string = error_string_response;
+		return (-1);
+	}
+
+	return (0);
+}
+
+static void logsys_subsys_init (
+		const char *subsys,
+		int subsysid)
+{
+	if (logsys_system_needs_init == LOGSYS_LOGGER_NEEDS_INIT) {
+		logsys_loggers[subsysid].init_status =
+			LOGSYS_LOGGER_NEEDS_INIT;
+	} else {
+		memcpy(&logsys_loggers[subsysid],
+		       &logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT],
+		       sizeof(logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT]));
+		logsys_loggers[subsysid].tags = LOGSYS_TAG_LOG;
+		logsys_loggers[subsysid].init_status = 
+			LOGSYS_LOGGER_INIT_DONE;
+	}
+	strncpy (logsys_loggers[subsysid].subsys, subsys,
+		LOGSYS_MAX_SUBSYS_NAMELEN);
+}
+
 /*
  * Internal API - exported
  */
-void _logsys_nosubsys_set (void)
+
+int _logsys_system_setup(
+	const char *mainsystem,
+	unsigned int mode,
+	unsigned int debug,
+	const char *logfile,
+	int logfile_priority,
+	int syslog_facility,
+	int syslog_priority,
+	unsigned int tags)
 {
-	logsys_mode |= LOG_MODE_NOSUBSYS;
+	int i;
+	const char *errstr;
+	char tempsubsys[LOGSYS_MAX_SUBSYS_NAMELEN];
+
+	i = LOGSYS_MAX_SUBSYS_COUNT;
+
+	pthread_mutex_lock (&logsys_config_mutex);
+
+	snprintf(logsys_loggers[i].subsys,
+		 LOGSYS_MAX_SUBSYS_NAMELEN,
+		"%s", mainsystem);
+
+	logsys_loggers[i].mode = mode;
+
+	logsys_loggers[i].debug = debug;
+
+	if ((logfile) && strlen(logfile) > 0) {
+		logsys_config_file_set_unlocked (i, &errstr, logfile);
+	}
+	logsys_loggers[i].logfile_priority = logfile_priority;
+
+	logsys_loggers[i].syslog_facility = syslog_facility;
+	logsys_loggers[i].syslog_priority = syslog_priority;
+	syslog_facility_reconf();
+
+	logsys_loggers[i].tags = tags;
+
+	logsys_loggers[i].init_status = LOGSYS_LOGGER_INIT_DONE;
+
+	logsys_system_needs_init = LOGSYS_LOGGER_INIT_DONE;
+
+	for (i = 0; i < LOGSYS_MAX_SUBSYS_COUNT; i++) {
+		if ((strcmp (logsys_loggers[i].subsys, "") != 0) &&
+			(logsys_loggers[i].init_status ==
+			 LOGSYS_LOGGER_NEEDS_INIT)) {
+				strncpy (tempsubsys, logsys_loggers[i].subsys,
+					LOGSYS_MAX_SUBSYS_NAMELEN);
+				logsys_subsys_init(tempsubsys, i);
+		}
+	}
+
+	pthread_mutex_unlock (&logsys_config_mutex);
+
+	return (0);
 }
 
-unsigned int _logsys_subsys_create (
-	const char *subsys,
-	unsigned int priority)
+unsigned int _logsys_subsys_create (const char *subsys)
 {
+	int i;
+
 	assert (subsys != NULL);
 
-	return logsys_config_subsys_set (
-		subsys,
-		LOGSYS_TAG_LOG,
-		priority);
+	pthread_mutex_lock (&logsys_config_mutex);
+
+	i = _logsys_config_subsys_get_unlocked (subsys);
+	if ((i > -1) && (i < LOGSYS_MAX_SUBSYS_COUNT)) {
+		pthread_mutex_unlock (&logsys_config_mutex);
+		return i;
+	}
+
+	for (i = 0; i < LOGSYS_MAX_SUBSYS_COUNT; i++) {
+		if (strcmp (logsys_loggers[i].subsys, "") == 0) {
+			logsys_subsys_init(subsys, i);			
+			break;
+		}
+	}
+
+	assert(i < LOGSYS_MAX_SUBSYS_COUNT);
+
+	pthread_mutex_unlock (&logsys_config_mutex);
+	return i;
 }
 
 int _logsys_wthread_create (void)
 {
-	if ((logsys_mode & LOG_MODE_FORK) == 0) {
-		if (logsys_name != NULL) {
-			openlog (logsys_name, LOG_CONS|LOG_PID, logsys_facility);
-		}
+	if (((logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT].mode & LOGSYS_MODE_FORK) == 0) && 
+		((logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT].mode & LOGSYS_MODE_THREADED) != 0)) {
 		wthread_create();
 		atexit (logsys_atexit);
 	}
@@ -621,9 +878,10 @@ int _logsys_rec_init (unsigned int size)
 	 * Last record ends at zero
 	 */
 	flt_data = malloc ((size + 2) * sizeof (unsigned int));
-	assert (flt_data != NULL);
+	if (flt_data == NULL) {
+		return (-1);
+	}
 	flt_data_size = size;
-	assert (flt_data != NULL);
 	flt_data[FDHEAD_INDEX] = 0;
 	flt_data[FDTAIL_INDEX] = 0;
 
@@ -651,7 +909,7 @@ int _logsys_rec_init (unsigned int size)
  * ... repeats length & arg
  */
 void _logsys_log_rec (
-	int subsys,
+	int subsysid,
 	const char *function_name,
 	const char *file_name,
 	int file_line,
@@ -678,7 +936,7 @@ void _logsys_log_rec (
 	for (;;) {
 		assert (arguments < 64);
 		buf_args[arguments] = va_arg (ap, void *);
-		if (buf_args[arguments] == LOG_REC_END) {
+		if (buf_args[arguments] == LOGSYS_REC_END) {
 			break;
 		}
 		buf_len[arguments] = va_arg (ap, int);
@@ -690,8 +948,8 @@ void _logsys_log_rec (
 	/*
 	 * Encode logsys subsystem identity, filename, and function
 	 */
-	buf_args[0] = logsys_loggers[subsys].subsys;
-	buf_len[0] = strlen (logsys_loggers[subsys].subsys) + 1;
+	buf_args[0] = logsys_loggers[subsysid].subsys;
+	buf_len[0] = strlen (logsys_loggers[subsysid].subsys) + 1;
 	buf_args[1] = file_name;
 	buf_len[1] = strlen (file_name) + 1;
 	buf_args[2] = function_name;
@@ -803,7 +1061,7 @@ void _logsys_log_rec (
 }
 
 void _logsys_log_printf (
-        int subsys,
+        int subsysid,
         const char *function_name,
         const char *file_name,
         int file_line,
@@ -815,12 +1073,10 @@ void _logsys_log_printf (
 	unsigned int len;
 	va_list ap;
 
-	if (logsys_mode & LOG_MODE_NOSUBSYS) {
-		subsys = 0;
-	}
-	if (level > logsys_loggers[subsys].priority) {
-		return;
+	if (subsysid <= -1) {
+		subsysid = LOGSYS_MAX_SUBSYS_COUNT;
 	}
+
 	va_start (ap, format);
 	len = vsprintf (logsys_print_buffer, format, ap);
 	va_end (ap);
@@ -832,20 +1088,20 @@ void _logsys_log_printf (
 	/*
 	 * Create a log record
 	 */
-	_logsys_log_rec (subsys,
+	_logsys_log_rec (subsysid,
 		function_name,
 		file_name,
 		file_line,
 		(level+1) << 28,
 		logsys_print_buffer, len + 1,
-		LOG_REC_END);
+		LOGSYS_REC_END);
 
-	if ((logsys_mode & LOG_MODE_THREADED) == 0) {
+	if ((logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT].mode & LOGSYS_MODE_THREADED) == 0) {
 		/*
 		 * Output (and block) if the log mode is not threaded otherwise
 		 * expect the worker thread to output the log data once signaled
 		 */
-		log_printf_to_logs (logsys_loggers[subsys].subsys,
+		log_printf_to_logs (logsys_loggers[subsysid].subsys,
 			file_name, function_name, file_line, level,
 			logsys_print_buffer);
 	} else {
@@ -856,68 +1112,128 @@ void _logsys_log_printf (
 	}
 }
 
+int _logsys_config_subsys_get (const char *subsys)
+{
+	unsigned int i;
+
+	pthread_mutex_lock (&logsys_config_mutex);
+
+	i = _logsys_config_subsys_get_unlocked (subsys);
+
+	pthread_mutex_unlock (&logsys_config_mutex);
+
+	return i;
+}
+
 /*
  * External Configuration and Initialization API
  */
 void logsys_fork_completed (void)
 {
-	logsys_mode &= ~LOG_MODE_FORK;
+	logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT].mode &= ~LOGSYS_MODE_FORK;
 	_logsys_wthread_create ();
 }
 
-void logsys_config_mode_set (unsigned int mode)
+unsigned int logsys_config_mode_set (const char *subsys, unsigned int mode)
 {
+	int i;
+
 	pthread_mutex_lock (&logsys_config_mutex);
-	logsys_mode = mode;
+	if (subsys != NULL) {
+		i = _logsys_config_subsys_get_unlocked (subsys);
+		if (i >= 0) {
+			logsys_loggers[i].mode = mode;
+			i = 0;
+		}
+	} else {
+		for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
+			logsys_loggers[i].mode = mode;
+		}
+		i = 0;
+	}
 	pthread_mutex_unlock (&logsys_config_mutex);
+
+	return i;
 }
 
-unsigned int logsys_config_mode_get (void)
+unsigned int logsys_config_mode_get (const char *subsys)
 {
-	return logsys_mode;
+	int i;
+
+	i = _logsys_config_subsys_get (subsys);
+	if (i < 0) {
+		return i;
+	}
+
+	return logsys_loggers[i].mode;
 }
 
-static void logsys_close_logfile (void)
+unsigned int logsys_config_tags_set (const char *subsys, unsigned int tags)
 {
-	if (logsys_file_fp != NULL) {
-		fclose (logsys_file_fp);
-		logsys_file_fp = NULL;
+	int i;
+
+	pthread_mutex_lock (&logsys_config_mutex);
+	if (subsys != NULL) {
+		i = _logsys_config_subsys_get_unlocked (subsys);
+		if (i >= 0) {
+			logsys_loggers[i].tags = tags;
+			i = 0;
+		}
+	} else {
+		for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
+			logsys_loggers[i].tags = tags;
+		}
+		i = 0;
 	}
+	pthread_mutex_unlock (&logsys_config_mutex);
+
+	return i;
 }
 
-int logsys_config_file_set (const char **error_string, const char *file)
+unsigned int logsys_config_tags_get (const char *subsys)
 {
-	static char error_string_response[512];
+	int i;
 
-	if (file == NULL) {
-		logsys_close_logfile();
-		return (0);
+	i = _logsys_config_subsys_get (subsys);
+	if (i < 0) {
+		return i;
 	}
 
+	return logsys_loggers[i].tags;
+}
+
+int logsys_config_file_set (
+		const char *subsys,
+		const char **error_string,
+		const char *file)
+{
+	int i;
+	int res;
+
 	pthread_mutex_lock (&logsys_config_mutex);
 
-	if (logsys_mode & LOG_MODE_OUTPUT_FILE) {
-		logsys_file = file;
-		logsys_close_logfile();
-		logsys_file_fp = fopen (file, "a+");
-		if (logsys_file_fp == 0) {
-			snprintf (error_string_response,
-				sizeof(error_string_response),
-				"Can't open logfile '%s' for reason (%s).\n",
-					 file, strerror (errno));
-			*error_string = error_string_response;
-			pthread_mutex_unlock (&logsys_config_mutex);
-			return (-1);
+	if (subsys != NULL) {
+		i = _logsys_config_subsys_get_unlocked (subsys);
+		if (i < 0) {
+			res = i;
+		} else {
+			res = logsys_config_file_set_unlocked(i, error_string, file);
 		}
-	} else
-		logsys_close_logfile();
+	} else {
+		for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
+			logsys_config_file_set_unlocked(i, error_string, file);
+		}
+		res = 0;
+	}
 
 	pthread_mutex_unlock (&logsys_config_mutex);
-	return (0);
+	return res;
 }
 
 int logsys_format_set (const char *format)
 {
+	int ret = 0;
+
 	pthread_mutex_lock (&logsys_config_mutex);
 
 	if (format_buffer) {
@@ -927,15 +1243,15 @@ int logsys_format_set (const char *format)
 
 	if (format) {
 		format_buffer = strdup(format);
+		if (format_buffer == NULL) {
+			ret = -1;
+		}
 	} else {
 		format_buffer = strdup("[%6s] %b");
 	}
-	if (format_buffer == NULL) {
-		return -1;
-	}
 
 	pthread_mutex_unlock (&logsys_config_mutex);
-	return 0;
+	return ret;
 }
 
 char *logsys_format_get (void)
@@ -943,14 +1259,104 @@ char *logsys_format_get (void)
 	return format_buffer;
 }
 
-void logsys_config_facility_set (const char *name, unsigned int facility)
+unsigned int logsys_config_syslog_facility_set (
+	const char *subsys,
+	unsigned int facility)
+{
+	int i;
+
+	pthread_mutex_lock (&logsys_config_mutex);
+	if (subsys != NULL) {
+		i = _logsys_config_subsys_get_unlocked (subsys);
+		if (i >= 0) {
+			logsys_loggers[i].syslog_facility = facility;
+			if (i == LOGSYS_MAX_SUBSYS_COUNT) {
+				syslog_facility_reconf();
+			}
+			i = 0;
+		}
+	} else {
+		for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
+			logsys_loggers[i].syslog_facility = facility;
+		}
+		syslog_facility_reconf();
+		i = 0;
+	}
+	pthread_mutex_unlock (&logsys_config_mutex);
+
+	return i;
+}
+
+unsigned int logsys_config_syslog_priority_set (
+	const char *subsys,
+	unsigned int priority)
 {
+	int i;
+
 	pthread_mutex_lock (&logsys_config_mutex);
+	if (subsys != NULL) {
+		i = _logsys_config_subsys_get_unlocked (subsys);
+		if (i >= 0) {
+			logsys_loggers[i].syslog_priority = priority;
+			i = 0;
+		}
+	} else {
+		for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
+			logsys_loggers[i].syslog_priority = priority;
+		}
+		i = 0;
+	}
+	pthread_mutex_unlock (&logsys_config_mutex);
+
+	return i;
+}
 
-	logsys_name = name;
-	logsys_facility = facility;
+unsigned int logsys_config_logfile_priority_set (
+	const char *subsys,
+	unsigned int priority)
+{
+	int i;
 
+	pthread_mutex_lock (&logsys_config_mutex);
+	if (subsys != NULL) {
+		i = _logsys_config_subsys_get_unlocked (subsys);
+		if (i >= 0) {
+			logsys_loggers[i].logfile_priority = priority;
+			i = 0;
+		}
+	} else {
+		for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
+			logsys_loggers[i].logfile_priority = priority;
+		}
+		i = 0;
+	}
 	pthread_mutex_unlock (&logsys_config_mutex);
+
+	return i;
+}
+
+unsigned int logsys_config_debug_set (
+	const char *subsys,
+	unsigned int debug)
+{
+	int i;
+
+	pthread_mutex_lock (&logsys_config_mutex);
+	if (subsys != NULL) {
+		i = _logsys_config_subsys_get_unlocked (subsys);
+		if (i >= 0) {
+			logsys_loggers[i].debug = debug;
+			i = 0;
+		}
+	} else {
+		for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
+			logsys_loggers[i].debug = debug;
+		}
+		i = 0;
+	}
+	pthread_mutex_unlock (&logsys_config_mutex);
+
+	return i;
 }
 
 int logsys_facility_id_get (const char *name)
@@ -1025,63 +1431,6 @@ const char *logsys_tag_name_get (unsigned int tag)
 	return (NULL);
 }
 
-unsigned int logsys_config_subsys_set (
-	const char *subsys,
-	unsigned int tags,
-	unsigned int priority)
-{
-	int i;
-
-	pthread_mutex_lock (&logsys_config_mutex);
- 	for (i = 0; i < SUBSYS_MAX; i++) {
-		if (strcmp (logsys_loggers[i].subsys, subsys) == 0) {
-			logsys_loggers[i].tags = tags;
-			logsys_loggers[i].priority = priority;
-
-			break;
-		}
-	}
-
-	if (i == SUBSYS_MAX) {
-		for (i = 0; i < SUBSYS_MAX; i++) {
-			if (strcmp (logsys_loggers[i].subsys, "") == 0) {
-				strncpy (logsys_loggers[i].subsys, subsys,
-					sizeof(logsys_loggers[i].subsys));
-				logsys_loggers[i].tags = tags;
-				logsys_loggers[i].priority = priority;
-				break;
-			}
-		}
-	}
-	assert(i < SUBSYS_MAX);
-
-	pthread_mutex_unlock (&logsys_config_mutex);
-	return i;
-}
-
-int logsys_config_subsys_get (
-	const char *subsys,
-	unsigned int *tags,
-	unsigned int *priority)
-{
-	unsigned int i;
-
-	pthread_mutex_lock (&logsys_config_mutex);
-
- 	for (i = 0; i < SUBSYS_MAX; i++) {
-		if (strcmp (logsys_loggers[i].subsys, subsys) == 0) {
-			*tags = logsys_loggers[i].tags;
-			*priority = logsys_loggers[i].priority;
-			pthread_mutex_unlock (&logsys_config_mutex);
-			return i;
-		}
-	}
-
-	pthread_mutex_unlock (&logsys_config_mutex);
-
-	return (-1);
-}
-
 int logsys_log_rec_store (const char *filename)
 {
 	int fd;
@@ -1089,7 +1438,7 @@ int logsys_log_rec_store (const char *filename)
 	size_t size_to_write = (flt_data_size + 2) * sizeof (unsigned int);
 
 	fd = open (filename, O_CREAT|O_RDWR, 0700);
-	if (fd == -1) {
+	if (fd < 0) {
 		return (-1);
 	}
 
@@ -1105,7 +1454,7 @@ int logsys_log_rec_store (const char *filename)
 	return (0);
 }
 
-static void logsys_atexit (void)
+void logsys_atexit (void)
 {
 	if (wthread_active) {
 		wthread_should_exit = 1;
@@ -1113,59 +1462,3 @@ static void logsys_atexit (void)
 		pthread_join (logsys_thread_id, NULL);
 	}
 }
-
-void logsys_atsegv (void)
-{
-	if (wthread_active) {
-		wthread_should_exit = 1;
-		wthread_signal ();
-		pthread_join (logsys_thread_id, NULL);
-	}
-}
-
-int logsys_init (
-	const char *name,
-	int mode,
-	int facility,
-	int priority,
-	const char *file,
-	char *format,
-	int rec_size)
-{
-	const char *errstr;
-
-	_logsys_nosubsys_set ();
-	_logsys_subsys_create (name, priority);
-	strncpy (logsys_loggers[0].subsys, name,
-		 sizeof (logsys_loggers[0].subsys));
-	logsys_config_mode_set (mode);
-	logsys_config_facility_set (name, facility);
-	logsys_config_file_set (&errstr, file);
-	if (logsys_format_set (format))
-		return -1;
-	_logsys_rec_init (rec_size);
-	_logsys_wthread_create ();
-	return (0);
-}
-
-int logsys_conf (
-	char *name,
-	int mode,
-	int facility,
-	int priority,
-	char *file)
-{
-	const char *errstr;
-
-	_logsys_rec_init (100000);
-	strncpy (logsys_loggers[0].subsys, name,
-		sizeof (logsys_loggers[0].subsys));
-	logsys_config_mode_set (mode);
-	logsys_config_facility_set (name, facility);
-	logsys_config_file_set (&errstr, file);
-	return (0);
-}
-
-void logsys_exit (void)
-{
-}

+ 57 - 43
exec/main.c

@@ -84,13 +84,17 @@
 #include "version.h"
 
 LOGSYS_DECLARE_SYSTEM ("corosync",
-	LOG_MODE_OUTPUT_STDERR | LOG_MODE_THREADED | LOG_MODE_FORK,
+	LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_THREADED | LOGSYS_MODE_FORK,
+	0,
 	NULL,
+	LOG_INFO,
 	LOG_DAEMON,
+	LOG_INFO,
+	0,
 	NULL,
 	1000000);
 
-LOGSYS_DECLARE_SUBSYS ("MAIN", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("MAIN");
 
 #define SERVER_BACKLOG 5
 
@@ -116,7 +120,7 @@ static struct objdb_iface_ver0 *objdb = NULL;
 
 static struct corosync_api_v1 *api = NULL;
 
-static struct main_config main_config;
+static struct ug_config ug_config;
 
 unsigned long long *(*main_clm_get_by_nodeid) (unsigned int node_id);
 
@@ -147,9 +151,9 @@ static void *corosync_exit (void *arg)
 	int i;
 
 	mempool_getstats (stats_inuse, stats_avail, stats_memoryused);
-	log_printf (LOG_LEVEL_DEBUG, "Memory pools:\n");
+	log_printf (LOGSYS_LEVEL_DEBUG, "Memory pools:\n");
 	for (i = 0; i < MEMPOOL_GROUP_SIZE; i++) {
-	log_printf (LOG_LEVEL_DEBUG, "order %d size %d inuse %d avail %d memory used %d\n",
+	log_printf (LOGSYS_LEVEL_DEBUG, "order %d size %d inuse %d avail %d memory used %d\n",
 		i, 1<<i, stats_inuse[i], stats_avail[i], stats_memoryused[i]);
 	}
 #endif
@@ -178,7 +182,7 @@ static void sigquit_handler (int num)
 static void sigsegv_handler (int num)
 {
 	(void)signal (SIGSEGV, SIG_DFL);
-	logsys_atsegv();
+	logsys_atexit();
 	logsys_log_rec_store (LOCALSTATEDIR "/lib/corosync/fdata");
 	raise (SIGSEGV);
 }
@@ -186,7 +190,7 @@ static void sigsegv_handler (int num)
 static void sigabrt_handler (int num)
 {
 	(void)signal (SIGABRT, SIG_DFL);
-	logsys_atsegv();
+	logsys_atexit();
 	logsys_log_rec_store (LOCALSTATEDIR "/lib/corosync/fdata");
 	raise (SIGABRT);
 }
@@ -299,8 +303,8 @@ static void confchg_fn (
 static void priv_drop (void)
 {
 return; /* TODO: we are still not dropping privs */
-	setuid (main_config.uid);
-	setegid (main_config.gid);
+	setuid (ug_config.uid);
+	setegid (ug_config.gid);
 }
 
 static void corosync_mempool_init (void)
@@ -309,7 +313,7 @@ static void corosync_mempool_init (void)
 
 	res = mempool_init (pool_sizes);
 	if (res == ENOMEM) {
-		log_printf (LOG_LEVEL_ERROR, "Couldn't allocate memory pools, not enough memory");
+		log_printf (LOGSYS_LEVEL_ERROR, "Couldn't allocate memory pools, not enough memory");
 		corosync_exit_error (AIS_DONE_MEMPOOL_INIT);
 	}
 }
@@ -371,15 +375,15 @@ static void corosync_setscheduler (void)
 		sched_param.sched_priority = sched_priority;
 		res = sched_setscheduler (0, SCHED_RR, &sched_param);
 		if (res == -1) {
-			log_printf (LOG_LEVEL_WARNING, "Could not set SCHED_RR at priority %d: %s\n",
+			log_printf (LOGSYS_LEVEL_WARNING, "Could not set SCHED_RR at priority %d: %s\n",
 				sched_param.sched_priority, strerror (errno));
 		}
 	} else {
-		log_printf (LOG_LEVEL_WARNING, "Could not get maximum scheduler priority: %s\n", strerror (errno));
+		log_printf (LOGSYS_LEVEL_WARNING, "Could not get maximum scheduler priority: %s\n", strerror (errno));
 		sched_priority = 0;
 	}
 #else
-	log_printf(LOG_LEVEL_WARNING, "Scheduler priority left to default value (no OS support)\n");
+	log_printf(LOGSYS_LEVEL_WARNING, "Scheduler priority left to default value (no OS support)\n");
 #endif
 }
 
@@ -402,11 +406,11 @@ static void corosync_mlockall (void)
 	/* under FreeBSD a process with locked page cannot call dlopen
 	 * code disabled until FreeBSD bug i386/93396 was solved
 	 */
-	log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults\n");
+	log_printf (LOGSYS_LEVEL_WARNING, "Could not lock memory of service to avoid page faults\n");
 #else
 	res = mlockall (MCL_CURRENT | MCL_FUTURE);
 	if (res == -1) {
-		log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults: %s\n", strerror (errno));
+		log_printf (LOGSYS_LEVEL_WARNING, "Could not lock memory of service to avoid page faults: %s\n", strerror (errno));
 	};
 #endif
 }
@@ -531,7 +535,7 @@ static int corosync_security_valid (int euid, int egid)
 	if (euid == 0 || egid == 0) {
 		return (1);
 	}
-	if (euid == main_config.uid || egid == main_config.gid) {
+	if (euid == ug_config.uid || egid == ug_config.gid) {
 		return (1);
 	}
 	return (0);
@@ -602,16 +606,16 @@ static void ipc_log_printf (const char *format, ...) {
         va_list ap;
 
         va_start (ap, format);
-	
-       _logsys_log_printf (ipc_subsys_id, __FUNCTION__,	
-                __FILE__, __LINE__, LOG_LEVEL_ERROR, format, ap);
 
-        va_end (ap);
+	_logsys_log_printf (ipc_subsys_id, __FUNCTION__,	
+		__FILE__, __LINE__, LOGSYS_LEVEL_ERROR, format, ap);
+
+	va_end (ap);
 }
 
 static void ipc_fatal_error(const char *error_msg) {
        _logsys_log_printf (ipc_subsys_id, __FUNCTION__,	
-                __FILE__, __LINE__, LOG_LEVEL_ERROR, "%s", error_msg);
+                __FILE__, __LINE__, LOGSYS_LEVEL_ERROR, "%s", error_msg);
 	exit(EXIT_FAILURE);
 }
 
@@ -710,7 +714,7 @@ int main (int argc, char **argv)
 		switch (ch) {
 			case 'f':
 				background = 0;
-				logsys_config_mode_set (LOG_MODE_OUTPUT_STDERR|LOG_MODE_THREADED|LOG_MODE_FORK);
+				logsys_config_mode_set (NULL, LOGSYS_MODE_OUTPUT_STDERR|LOGSYS_MODE_THREADED|LOGSYS_MODE_FORK);
 				break;
 			case 'p':
 				setprio = 0;
@@ -727,9 +731,9 @@ int main (int argc, char **argv)
 	if (background)
 		corosync_tty_detach ();
 
-	log_printf (LOG_LEVEL_NOTICE, "Corosync Executive Service RELEASE '%s'\n", RELEASE_VERSION);
-	log_printf (LOG_LEVEL_NOTICE, "Copyright (C) 2002-2006 MontaVista Software, Inc and contributors.\n");
-	log_printf (LOG_LEVEL_NOTICE, "Copyright (C) 2006-2008 Red Hat, Inc.\n");
+	log_printf (LOGSYS_LEVEL_NOTICE, "Corosync Executive Service RELEASE '%s'\n", RELEASE_VERSION);
+	log_printf (LOGSYS_LEVEL_NOTICE, "Copyright (C) 2002-2006 MontaVista Software, Inc and contributors.\n");
+	log_printf (LOGSYS_LEVEL_NOTICE, "Copyright (C) 2006-2008 Red Hat, Inc.\n");
 
 	(void)signal (SIGINT, sigintr_handler);
 	(void)signal (SIGUSR2, sigusr2_handler);
@@ -745,7 +749,7 @@ int main (int argc, char **argv)
 		serialize_unlock,
 		sched_priority);
 
-	log_printf (LOG_LEVEL_NOTICE, "Corosync Executive Service: started and ready to provide service.\n");
+	log_printf (LOGSYS_LEVEL_NOTICE, "Corosync Executive Service: started and ready to provide service.\n");
 
 	corosync_poll_handle = poll_create ();
 
@@ -759,7 +763,7 @@ int main (int argc, char **argv)
 		&objdb_p,
 		0);
 	if (res == -1) {
-		log_printf (LOG_LEVEL_ERROR, "Corosync Executive couldn't open configuration object database component.\n");
+		log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't open configuration object database component.\n");
 		corosync_exit_error (AIS_DONE_OBJDB);
 	}
 
@@ -800,16 +804,16 @@ int main (int argc, char **argv)
 
 		config = (struct config_iface_ver0 *)config_p;
 		if (res == -1) {
-			log_printf (LOG_LEVEL_ERROR, "Corosync Executive couldn't open configuration component '%s'\n", iface);
+			log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't open configuration component '%s'\n", iface);
 			corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
 		}
 
 		res = config->config_readconfig(objdb, &error_string);
 		if (res == -1) {
-			log_printf (LOG_LEVEL_ERROR, "%s", error_string);
+			log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
 			corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
 		}
-		log_printf (LOG_LEVEL_NOTICE, "%s", error_string);
+		log_printf (LOGSYS_LEVEL_NOTICE, "%s", error_string);
 		config_modules[num_config_modules++] = config;
 
 		iface = strtok(NULL, ":");
@@ -817,27 +821,37 @@ int main (int argc, char **argv)
 	if (config_iface)
 		free(config_iface);
 
-	res = corosync_main_config_read (objdb, &error_string, &main_config);
+	res = corosync_main_config_read (objdb, &error_string, &ug_config);
 	if (res == -1) {
-		log_printf (LOG_LEVEL_ERROR, "%s", error_string);
+		/*
+		 * if we are here, we _must_ flush the logsys queue
+		 * and try to inform that we couldn't read the config.
+		 * this is a desperate attempt before certain death
+		 * and there is no guarantee that we can print to stderr
+		 * nor that logsys is sending the messages where we expect.
+		 */
+		log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
+		logsys_fork_completed ();
+		fprintf(stderr, "%s", error_string);
+		syslog (LOGSYS_LEVEL_ERROR, "%s", error_string);
 		corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
 	}
 
 	res = totem_config_read (objdb, &totem_config, &error_string);
 	if (res == -1) {
-		log_printf (LOG_LEVEL_ERROR, "%s", error_string);
+		log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
 		corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
 	}
 
 	res = totem_config_keyread (objdb, &totem_config, &error_string);
 	if (res == -1) {
-		log_printf (LOG_LEVEL_ERROR, "%s", error_string);
+		log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
 		corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
 	}
 
 	res = totem_config_validate (&totem_config, &error_string);
 	if (res == -1) {
-		log_printf (LOG_LEVEL_ERROR, "%s", error_string);
+		log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
 		corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
 	}
 
@@ -853,12 +867,12 @@ 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", LOG_INFO);
-  	totem_config.totem_logging_configuration.log_level_security = LOG_LEVEL_SECURITY;
-	totem_config.totem_logging_configuration.log_level_error = LOG_LEVEL_ERROR;
-	totem_config.totem_logging_configuration.log_level_warning = LOG_LEVEL_WARNING;
-	totem_config.totem_logging_configuration.log_level_notice = LOG_LEVEL_NOTICE;
-	totem_config.totem_logging_configuration.log_level_debug = LOG_LEVEL_DEBUG;
+		_logsys_subsys_create ("TOTEM");
+  	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;
+	totem_config.totem_logging_configuration.log_level_notice = LOGSYS_LEVEL_NOTICE;
+	totem_config.totem_logging_configuration.log_level_debug = LOGSYS_LEVEL_DEBUG;
 	totem_config.totem_logging_configuration.log_printf = _logsys_log_printf;
 
 	/*
@@ -898,7 +912,7 @@ int main (int argc, char **argv)
 	 */
 	res = corosync_service_defaults_link_and_init (api);
 	if (res == -1) {
-		log_printf (LOG_LEVEL_ERROR, "Could not initialize default services\n");
+		log_printf (LOGSYS_LEVEL_ERROR, "Could not initialize default services\n");
 		corosync_exit_error (AIS_DONE_INIT_SERVICES);
 	}
 
@@ -921,7 +935,7 @@ int main (int argc, char **argv)
  		serialize_lock,
  		serialize_unlock);
 
-	ipc_subsys_id = _logsys_subsys_create ("IPC", LOG_INFO);
+	ipc_subsys_id = _logsys_subsys_create ("IPC");
 
 	ipc_init_state.sched_priority = sched_priority;
 

+ 370 - 202
exec/mainconfig.c

@@ -59,11 +59,6 @@
 static char error_string_response[512];
 static struct objdb_iface_ver0 *global_objdb;
 
-static void add_logsys_config_notification(
-	struct objdb_iface_ver0 *objdb,
-	struct main_config *main_config);
-
-
 /* This just makes the code below a little neater */
 static inline int objdb_get_string (
 	const struct objdb_iface_ver0 *objdb,
@@ -105,7 +100,6 @@ static inline void objdb_get_int (
 	}
 }
 
-
 /**
  * insert_into_buffer
  * @target_buffer: a buffer where to write results
@@ -177,138 +171,324 @@ static int insert_into_buffer(
 	return 0;
 }
 
-static struct logsys_config_struct {
-	char subsys[6];
-	unsigned int priority;
-	unsigned int tags;
-} logsys_logger;
-
-int corosync_main_config_read_logging (
+/*
+ * format set is the only global specific option that
+ * doesn't apply at system/subsystem level.
+ */
+static int corosync_main_config_format_set (
 	struct objdb_iface_ver0 *objdb,
-	const char **error_string,
-	struct main_config *main_config)
+	hdb_handle_t object_handle,
+	const char **error_string)
 {
-	hdb_handle_t object_service_handle;
-	hdb_handle_t object_logger_subsys_handle;
-	char *value;
-	const char *error_reason = error_string_response;
-	hdb_handle_t object_find_handle;
-	hdb_handle_t object_find_logsys_handle;
+	const char *error_reason;
 	char new_format_buffer[PATH_MAX];
+	char *value;
 	int err = 0;
 
-	objdb->object_find_create (
-		OBJECT_PARENT_HANDLE,
-		"logging",
-		strlen ("logging"),
-		&object_find_handle);
-
-	main_config->logmode = LOG_MODE_THREADED | LOG_MODE_FORK;
-	if (objdb->object_find_next (
-		object_find_handle,
-		&object_service_handle) == 0) {
-
-		if (!objdb_get_string (objdb,object_service_handle, "to_file", &value)) {
-			if (strcmp (value, "yes") == 0) {
-				main_config->logmode |= LOG_MODE_OUTPUT_FILE;
+	if (!objdb_get_string (objdb,object_handle, "fileline", &value)) {
+		if (strcmp (value, "on") == 0) {
+			if (!insert_into_buffer(new_format_buffer,
+					sizeof(new_format_buffer),
+					" %f:%l", "s]")) {
+				err = logsys_format_set(new_format_buffer);
 			} else
-			if (strcmp (value, "no") == 0) {
-				main_config->logmode &= ~LOG_MODE_OUTPUT_FILE;
+			if (!insert_into_buffer(new_format_buffer,
+					sizeof(new_format_buffer),
+					"%f:%l", NULL)) {
+				err = logsys_format_set(new_format_buffer);
 			}
+		} else
+		if (strcmp (value, "off") == 0) {
+			/* nothing to do here */
+		} else {
+			error_reason = "unknown value for fileline";
+			goto parse_error;
 		}
-		if (!objdb_get_string (objdb,object_service_handle, "to_syslog", &value)) {
-			if (strcmp (value, "yes") == 0) {
-				main_config->logmode |= LOG_MODE_OUTPUT_SYSLOG;
+	}
+	if (!objdb_get_string (objdb,object_handle, "function_name", &value)) {
+		if (strcmp (value, "on") == 0) {
+			if (!insert_into_buffer(new_format_buffer,
+					sizeof(new_format_buffer),
+					"%n:", "f:")) {
+				err = logsys_format_set(new_format_buffer);
 			} else
-			if (strcmp (value, "no") == 0) {
-				main_config->logmode &= ~LOG_MODE_OUTPUT_SYSLOG;
+			if (!insert_into_buffer(new_format_buffer,
+					sizeof(new_format_buffer),
+					" %n", "s]")) {
+				err = logsys_format_set(new_format_buffer);
 			}
+		} else
+		if (strcmp (value, "off") == 0) {
+			/* nothing to do here */
+		} else {
+			error_reason = "unknown value for function_name";
+			goto parse_error;
 		}
-		if (!objdb_get_string (objdb,object_service_handle, "to_stderr", &value)) {
-			if (strcmp (value, "yes") == 0) {
-				main_config->logmode |= LOG_MODE_OUTPUT_STDERR;
-			} else
-			if (strcmp (value, "no") == 0) {
-				main_config->logmode &= ~LOG_MODE_OUTPUT_STDERR;
+	}
+	if (!objdb_get_string (objdb,object_handle, "timestamp", &value)) {
+		if (strcmp (value, "on") == 0) {
+			if(!insert_into_buffer(new_format_buffer,
+					sizeof(new_format_buffer),
+					"%t ", NULL)) {
+				err = logsys_format_set(new_format_buffer);
 			}
+		} else
+		if (strcmp (value, "off") == 0) {
+			/* nothing to do here */
+		} else {
+			error_reason = "unknown value for timestamp";
+			goto parse_error;
 		}
-		if (!objdb_get_string (objdb,object_service_handle, "fileline", &value)) {
-			if (strcmp (value, "on") == 0) {
-				if (!insert_into_buffer(new_format_buffer,
-						sizeof(new_format_buffer),
-						" %f:%l", "s]")) {
-					err = logsys_format_set(new_format_buffer);
-				} else
-				if (!insert_into_buffer(new_format_buffer,
-						sizeof(new_format_buffer),
-						"%f:%l", NULL)) {
-					err = logsys_format_set(new_format_buffer);
-				}
-			} else
-			if (strcmp (value, "off") == 0) {
-				/* nothing to do here */
-			} else {
+	}
+	if (err) {
+		error_reason = "exhausted virtual memory";
+		goto parse_error;
+	}
+
+	return (0);
+
+parse_error:
+	*error_string = error_reason;
+
+	return (-1);
+}
+
+static int corosync_main_config_set (
+	struct objdb_iface_ver0 *objdb,
+	hdb_handle_t object_handle,
+	const char *subsys,
+	const char **error_string)
+{
+	const char *error_reason = error_string_response;
+	char *value;
+	unsigned int mode;
+
+	/*
+	 * this bit abuses the internal logsys exported API
+	 * to guarantee that all configured subsystems are
+	 * initialized too.
+	 *
+	 * using this approach avoids some headaches caused
+	 * by IPC and TOTEM that have a special logging
+	 * handling requirements
+	 */
+	if (subsys != NULL) {
+		if (_logsys_subsys_create(subsys) < 0) {
+			error_reason = "unable to create new logging subsystem";
+			goto parse_error;
+		}
+	}
+
+	mode = logsys_config_mode_get(subsys);
+	if (mode < 0) {
+		error_reason = "unable to get mode";
+		goto parse_error;
+	}
+
+	if (!objdb_get_string (objdb,object_handle, "to_logfile", &value)) {
+		if (strcmp (value, "yes") == 0) {
+			mode |= LOGSYS_MODE_OUTPUT_FILE;
+			if (logsys_config_mode_set(subsys, mode) < 0) {
+				error_reason = "unable to set mode to_logfile";
+				goto parse_error;
+			}
+		} else
+		if (strcmp (value, "no") == 0) {
+			mode &= ~LOGSYS_MODE_OUTPUT_FILE;
+			if (logsys_config_mode_set(subsys, mode) < 0) {
+				error_reason = "unable to unset mode to_logfile";
 				goto parse_error;
 			}
+		} else {
+			error_reason = "unknown value for to_file";
+			goto parse_error;
 		}
-		if (!objdb_get_string (objdb,object_service_handle, "function_name", &value)) {
-			if (strcmp (value, "on") == 0) {
-				if (!insert_into_buffer(new_format_buffer,
-						sizeof(new_format_buffer),
-						"%n:", "f:")) {
-					err = logsys_format_set(new_format_buffer);
-				} else
-				if (!insert_into_buffer(new_format_buffer,
-						sizeof(new_format_buffer),
-						" %n", "s]")) {
-					err = logsys_format_set(new_format_buffer);
-				}
-			} else
-			if (strcmp (value, "off") == 0) {
-				/* nothing to do here */
-			} else {
+	}
+
+	if (!objdb_get_string (objdb,object_handle, "to_syslog", &value)) {
+		if (strcmp (value, "yes") == 0) {
+			mode |= LOGSYS_MODE_OUTPUT_SYSLOG;
+			if (logsys_config_mode_set(subsys, mode) < 0) {
+				error_reason = "unable to set mode to_syslog";
+				goto parse_error;
+			}
+		} else
+		if (strcmp (value, "no") == 0) {
+			mode &= ~LOGSYS_MODE_OUTPUT_SYSLOG;
+			if (logsys_config_mode_set(subsys, mode) < 0) {
+				error_reason = "unable to unset mode to_syslog";
 				goto parse_error;
 			}
+		} else {
+			error_reason = "unknown value for to_syslog";
+			goto parse_error;
 		}
-		if (!objdb_get_string (objdb,object_service_handle, "timestamp", &value)) {
-			if (strcmp (value, "on") == 0) {
-				if(!insert_into_buffer(new_format_buffer,
-						sizeof(new_format_buffer),
-						"%t ", NULL)) {
-					err = logsys_format_set(new_format_buffer);
-				}
-			} else
-			if (strcmp (value, "off") == 0) {
-				/* nothing to do here */
-			} else {
+	}
+
+	if (!objdb_get_string (objdb,object_handle, "to_stderr", &value)) {
+		if (strcmp (value, "yes") == 0) {
+			mode |= LOGSYS_MODE_OUTPUT_STDERR;
+			if (logsys_config_mode_set(subsys, mode) < 0) {
+				error_reason = "unable to set mode to_stderr";
 				goto parse_error;
 			}
+		} else
+		if (strcmp (value, "no") == 0) {
+			mode &= ~LOGSYS_MODE_OUTPUT_STDERR;
+			if (logsys_config_mode_set(subsys, mode) < 0) {
+				error_reason = "unable to unset mode to_stderr";
+				goto parse_error;
+			}
+		} else {
+			error_reason = "unknown value for to_syslog";
+			goto parse_error;
 		}
-		if (err) {
-			error_reason = "exhausted virtual memory";
+	}
+
+	if (!objdb_get_string (objdb,object_handle, "syslog_facility", &value)) {
+		int syslog_facility;
+
+		syslog_facility = logsys_facility_id_get(value);
+		if (syslog_facility < 0) {
+			error_reason = "unknown syslog facility specified";
+			goto parse_error;
+		}
+		if (logsys_config_syslog_facility_set(subsys,
+						syslog_facility) < 0) {
+			error_reason = "unable to set syslog facility";
+			goto parse_error;
+		}
+	}
+
+	if (!objdb_get_string (objdb,object_handle, "syslog_priority", &value)) {
+		int syslog_priority;
+
+		syslog_priority = logsys_priority_id_get(value);
+		if (syslog_priority < 0) {
+			error_reason = "unknown syslog priority specified";
+			goto parse_error;
+		}
+		if (logsys_config_syslog_priority_set(subsys,
+						syslog_priority) < 0) {
+			error_reason = "unable to set syslog priority";
+			goto parse_error;
+		}
+	}
+
+	if (!objdb_get_string (objdb,object_handle, "logfile", &value)) {
+		if (logsys_config_file_set (subsys, error_string, value) < 0) {
+			goto parse_error;
+		}
+	}
+
+	if (!objdb_get_string (objdb,object_handle, "logfile_priority", &value)) {
+		int logfile_priority;
+
+		logfile_priority = logsys_priority_id_get(value);
+		if (logfile_priority < 0) {
+			error_reason = "unknown logfile priority specified";
+			goto parse_error;
+		}
+		if (logsys_config_logfile_priority_set(subsys,
+						logfile_priority) < 0) {
+			error_reason = "unable to set logfile priority";
 			goto parse_error;
 		}
+	}
 
-		/* free old string on reload */
-		if (main_config->logfile) {
-			free(main_config->logfile);
-			main_config->logfile = NULL;
+	if (!objdb_get_string (objdb, object_handle, "debug", &value)) {
+		if (strcmp (value, "on") == 0) {
+			if (logsys_config_debug_set (subsys, 1) < 0) {
+				error_reason = "unable to set debug on";
+				goto parse_error;
+			}
+		} else
+		if (strcmp (value, "off") == 0) {
+			if (logsys_config_debug_set (subsys, 0) < 0) {
+				error_reason = "unable to set debug off";
+				goto parse_error;
+			}
+		} else {
+			error_reason = "unknown value for debug";
+			goto parse_error;
 		}
-		if (!objdb_get_string (objdb,object_service_handle, "logfile", &value)) {
-			main_config->logfile = strdup (value);
+	}
+
+	if (!objdb_get_string (objdb, object_handle, "tags", &value)) {
+		char *temp, *token;
+		unsigned int tags = 0;
+
+		temp = strdup(value);
+		if (temp == NULL) {
+			error_reason = "exhausted virtual memory";
+			goto parse_error;
 		}
 
-		if (!objdb_get_string (objdb,object_service_handle, "syslog_facility", &value)) {
-			main_config->syslog_facility = logsys_facility_id_get(value);
-			if (main_config->syslog_facility < 0) {
-				error_reason = "unknown syslog facility specified";
+		while ((token = strsep(&temp, "|")) != NULL) {
+			int val;
+
+			val = logsys_tag_id_get(token);
+			if (val < 0) {
+				error_reason = "bad tags value";
 				goto parse_error;
 			}
+			tags |= val;
+		}
+		free(temp);
+
+		tags |= LOGSYS_TAG_LOG;
+
+		if (logsys_config_tags_set (subsys, tags) < 0) {
+			error_reason = "unable to set tags";
+			goto parse_error;
 		}
+	}
 
-		logsys_config_facility_set ("corosync", main_config->syslog_facility);
-		logsys_config_mode_set (main_config->logmode);
-		logsys_config_file_set (error_string, main_config->logfile);
+	return (0);
+
+parse_error:
+	*error_string = error_reason;
+
+	return (-1);
+}
+
+static int corosync_main_config_read_logging (
+	struct objdb_iface_ver0 *objdb,
+	const char **error_string)
+{
+	hdb_handle_t object_service_handle;
+	hdb_handle_t object_logger_subsys_handle;
+	hdb_handle_t object_find_handle;
+	hdb_handle_t object_find_logsys_handle;
+	const char *error_reason;
+	char *value;
+
+	objdb->object_find_create (
+		OBJECT_PARENT_HANDLE,
+		"logging",
+		strlen ("logging"),
+		&object_find_handle);
+
+	if (objdb->object_find_next (
+		object_find_handle,
+		&object_service_handle) == 0) {
+
+		/* format set is supported only for toplevel */
+		if (corosync_main_config_format_set (objdb,
+						       object_service_handle,
+						       &error_reason) < 0) {
+			goto parse_error;
+		}
+
+		if (corosync_main_config_set (objdb,
+						object_service_handle,
+						NULL,
+						&error_reason) < 0) {
+			goto parse_error;
+		}
+
+		/* we will need 2 of these to compensate for new logging
+		 * config format */
 
 		objdb->object_find_create (
 			object_service_handle,
@@ -324,67 +504,65 @@ int corosync_main_config_read_logging (
 				object_logger_subsys_handle,
 				"subsys", &value)) {
 
-				strncpy (logsys_logger.subsys, value,
-					sizeof (logsys_logger.subsys));
+				if (corosync_main_config_set (objdb,
+						object_logger_subsys_handle,
+						value,
+						&error_reason) < 0) {
+					goto parse_error;
+				}
 			}
 			else {
 				error_reason = "subsys required for logger directive";
 				goto parse_error;
 			}
-			if (!objdb_get_string (objdb, object_logger_subsys_handle, "syslog_level", &value)) {
-				logsys_logger.priority = logsys_priority_id_get(value);
-				if (logsys_logger.priority < 0) {
-					error_reason = "unknown syslog priority specified";
-					goto parse_error;
-				}
-			}
-			if (!objdb_get_string (objdb, object_logger_subsys_handle, "debug", &value)) {
-				if (strcmp (value, "on") == 0) {
-					logsys_logger.priority = LOG_LEVEL_DEBUG;
-				} else
-				if (strcmp (value, "off") == 0) {
-					logsys_logger.priority &= ~LOG_LEVEL_DEBUG;
-				} else {
-					goto parse_error;
-				}
-			}
-			if (!objdb_get_string (objdb, object_logger_subsys_handle, "tags", &value)) {
-				char *token = strtok (value, "|");
+		}
+		objdb->object_find_destroy (object_find_logsys_handle);
 
-				while (token != NULL) {
-					int val;
+		objdb->object_find_create (
+			object_service_handle,
+			"logging_daemon",
+			strlen ("logging_daemon"),
+			&object_find_logsys_handle);
 
-					val = logsys_tag_id_get(token);
-					if (val < 0) {
-						error_reason = "bad tags value";
+		while (objdb->object_find_next (
+			object_find_logsys_handle,
+			&object_logger_subsys_handle) == 0) {
+
+			if (!objdb_get_string (objdb,
+				object_logger_subsys_handle,
+				"name", &value)) {
+
+				if ((strcmp(value, "corosync") == 0) &&
+				   (!objdb_get_string (objdb,
+					object_logger_subsys_handle,
+					"subsys", &value))) {
+
+					if (corosync_main_config_set (objdb,
+							object_logger_subsys_handle,
+							value,
+							&error_reason) < 0) {
 						goto parse_error;
 					}
-					logsys_logger.tags |= val;
-					token = strtok(NULL, "|");
+				}
+				else {
+					error_reason = "subsys required for logging_daemon directive";
+					goto parse_error;
 				}
 			}
-			/*
-			 * set individual logger configurations
-			 */
-			logsys_config_subsys_set (
-				logsys_logger.subsys,
-				logsys_logger.tags,
-				logsys_logger.priority);
-
+			else {
+				error_reason = "name required for logging_daemon directive";
+				goto parse_error;
+			}
 		}
 		objdb->object_find_destroy (object_find_logsys_handle);
 	}
-
 	objdb->object_find_destroy (object_find_handle);
 
 	return 0;
 
 parse_error:
-	snprintf (error_string_response, sizeof(error_string_response),
-		 "parse error in config: %s.\n",
-		 error_reason);
+	*error_string = error_reason;
 
-	*error_string = error_string_response;
 	return (-1);
 }
 
@@ -395,7 +573,7 @@ static int uid_determine (const char *req_user)
 
 	passwd = getpwnam(req_user);
 	if (passwd == 0) {
-		log_printf (LOG_LEVEL_ERROR, "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n", req_user);
+		log_printf (LOGSYS_LEVEL_ERROR, "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n", req_user);
 		corosync_exit_error (AIS_DONE_UID_DETERMINE);
 	}
 	ais_uid = passwd->pw_uid;
@@ -410,7 +588,7 @@ static int gid_determine (const char *req_group)
 
 	group = getgrnam (req_group);
 	if (group == 0) {
-		log_printf (LOG_LEVEL_ERROR, "ERROR: The '%s' group is not found in /etc/group, please read the documentation.\n", req_group);
+		log_printf (LOGSYS_LEVEL_ERROR, "ERROR: The '%s' group is not found in /etc/group, please read the documentation.\n", req_group);
 		corosync_exit_error (AIS_DONE_GID_DETERMINE);
 	}
 	ais_gid = group->gr_gid;
@@ -418,19 +596,54 @@ static int gid_determine (const char *req_group)
 	return ais_gid;
 }
 
+static void main_objdb_reload_notify(objdb_reload_notify_type_t type, int flush,
+				     void *priv_data_pt)
+{
+	const char *error_string;
+
+	if (type == OBJDB_RELOAD_NOTIFY_END) {
+
+		/*
+		 * Reload the logsys configuration
+		 */
+		logsys_format_set(NULL);
+		corosync_main_config_read_logging(global_objdb,
+						  &error_string);
+	}
+}
+
+static void add_logsys_config_notification(
+	struct objdb_iface_ver0 *objdb)
+{
+
+	global_objdb = objdb;
+
+	objdb->object_track_start(OBJECT_PARENT_HANDLE,
+				  1,
+				  NULL,
+				  NULL,
+				  NULL,
+				  main_objdb_reload_notify,
+				  NULL);
+
+}
+
 int corosync_main_config_read (
 	struct objdb_iface_ver0 *objdb,
 	const char **error_string,
-	struct main_config *main_config)
+	struct ug_config *ug_config)
 {
 	hdb_handle_t object_service_handle;
 	char *value;
 	const char *error_reason = error_string_response;
 	hdb_handle_t object_find_handle;
 
-	memset (main_config, 0, sizeof (struct main_config));
+	memset (ug_config, 0, sizeof (struct ug_config));
 
-	corosync_main_config_read_logging(objdb, error_string, main_config);
+	if (corosync_main_config_read_logging(objdb, error_string) < 0) {
+		error_reason = *error_string;
+		goto parse_error;
+	}
 
 	objdb->object_find_create (
 		OBJECT_PARENT_HANDLE,
@@ -438,34 +651,25 @@ int corosync_main_config_read (
 		strlen ("aisexec"),
 		&object_find_handle);
 
-	main_config->uid = uid_determine("ais");
-	main_config->gid = gid_determine("ais");
+	ug_config->uid = uid_determine("ais");
+	ug_config->gid = gid_determine("ais");
 
 	if (objdb->object_find_next (
 		object_find_handle,
 		&object_service_handle) == 0) {
 
 		if (!objdb_get_string (objdb,object_service_handle, "user", &value)) {
-			main_config->uid = uid_determine(value);
+			ug_config->uid = uid_determine(value);
 		}
 
 		if (!objdb_get_string (objdb,object_service_handle, "group", &value)) {
-			main_config->gid = gid_determine(value);
+			ug_config->gid = gid_determine(value);
 		}
 	}
 
 	objdb->object_find_destroy (object_find_handle);
 
-	if ((main_config->logmode & LOG_MODE_OUTPUT_FILE) &&
-		(main_config->logfile == NULL)) {
-		error_reason = "logmode set to 'file' but no logfile specified";
-		goto parse_error;
-	}
-
-	if (main_config->syslog_facility == 0)
-		main_config->syslog_facility = LOG_DAEMON;
-
-	add_logsys_config_notification(objdb, main_config);
+	add_logsys_config_notification(objdb);
 
 	logsys_fork_completed ();
 
@@ -479,39 +683,3 @@ parse_error:
 	*error_string = error_string_response;
 	return (-1);
 }
-
-
-static void main_objdb_reload_notify(objdb_reload_notify_type_t type, int flush,
-				     void *priv_data_pt)
-{
-	struct main_config *main_config = priv_data_pt;
-	const char *error_string;
-
-	if (type == OBJDB_RELOAD_NOTIFY_END) {
-
-		/*
-		 * Reload the logsys configuration
-		 */
-		logsys_format_set(NULL);
-		corosync_main_config_read_logging(global_objdb,
-						  &error_string,
-						  main_config);
-	}
-}
-
-static void add_logsys_config_notification(
-	struct objdb_iface_ver0 *objdb,
-	struct main_config *main_config)
-{
-
-	global_objdb = objdb;
-
-	objdb->object_track_start(OBJECT_PARENT_HANDLE,
-				  1,
-				  NULL,
-				  NULL,
-				  NULL,
-				  main_objdb_reload_notify,
-				  main_config);
-
-}

+ 2 - 15
exec/mainconfig.h

@@ -49,15 +49,7 @@ struct dynamic_service {
 };
 #define MAX_DYNAMIC_SERVICES 128
 
-struct main_config {
-	/*
-	 * logging configuration
-	 */
-	char *logfile;
-	unsigned int logmode;
-	unsigned int syslog_facility;
-	unsigned int minimum_priority;
-
+struct ug_config {
 	/*
 	 * user/group to run as
 	 */
@@ -65,14 +57,9 @@ struct main_config {
 	int gid;
 };
 
-int corosync_main_config_read_logging (
-	struct objdb_iface_ver0 *objdb,
-	const char **error_string,
-	struct main_config *main_config);
-
 extern int corosync_main_config_read (
 	struct objdb_iface_ver0 *objdb,
 	const char **error_string,
-	struct main_config *main_config);
+	struct ug_config *ug_config);
 
 #endif /* MAINCONFIG_H_DEFINED */

+ 1 - 1
exec/quorum.c

@@ -63,7 +63,7 @@
 #include "sync.h"
 #include "vsf.h"
 
-LOGSYS_DECLARE_SUBSYS ("QUORUM", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("QUORUM");
 
 static struct quorum_callin_functions *corosync_quorum_fns = NULL;
 

+ 5 - 6
exec/service.c

@@ -55,8 +55,7 @@
 #include <corosync/engine/coroapi.h>
 #include "service.h"
 
-
-LOGSYS_DECLARE_SUBSYS ("SERV", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("SERV");
 
 struct default_service {
 	const char *name;
@@ -153,7 +152,7 @@ unsigned int corosync_service_link_and_init (
 	iface_ver0 = (struct corosync_service_engine_iface_ver0 *)iface_ver0_p;
 
 	if (iface_ver0 == 0) {
-		log_printf(LOG_LEVEL_ERROR, "Service failed to load '%s'.\n", service_name);
+		log_printf(LOGSYS_LEVEL_ERROR, "Service failed to load '%s'.\n", service_name);
 		return (-1);
 	}
 
@@ -204,7 +203,7 @@ unsigned int corosync_service_link_and_init (
 		&service->id,
 		sizeof (service->id));
 
-	log_printf (LOG_LEVEL_NOTICE, "Service initialized '%s'\n", service->name);
+	log_printf (LOGSYS_LEVEL_NOTICE, "Service initialized '%s'\n", service->name);
 	return (res);
 }
 
@@ -230,7 +229,7 @@ static int corosync_service_unlink_common (
 		(void *)&service_id,
 		NULL);
 	
-	log_printf(LOG_LEVEL_NOTICE, "Unloading corosync component: %s v%u\n",
+	log_printf(LOGSYS_LEVEL_NOTICE, "Unloading corosync component: %s v%u\n",
 		service_name, service_version);
 
 	if (ais_service[*service_id]->exec_exit_fn) {
@@ -303,7 +302,7 @@ extern unsigned int corosync_service_unlink_all (
 	hdb_handle_t object_find_handle;
 	int found; 
 
-	log_printf(LOG_LEVEL_NOTICE, "Unloading all corosync components\n");
+	log_printf(LOGSYS_LEVEL_NOTICE, "Unloading all corosync components\n");
 
 	/*
 	 * TODO

+ 11 - 11
exec/sync.c

@@ -61,7 +61,7 @@
 #include "quorum.h"
 #include "sync.h"
 
-LOGSYS_DECLARE_SUBSYS ("SYNC", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("SYNC");
 
 #define MESSAGE_REQ_SYNC_BARRIER 0
 
@@ -260,7 +260,7 @@ int sync_register (
 		sync_deliver_fn,
 		sync_confchg_fn);
 	if (res == -1) {
-		log_printf (LOG_LEVEL_ERROR,
+		log_printf (LOGSYS_LEVEL_ERROR,
 			"Couldn't initialize groups interface.\n");
 		return (-1);
 	}
@@ -270,7 +270,7 @@ int sync_register (
 		&sync_group,
 		1);
 	if (res == -1) {
-		log_printf (LOG_LEVEL_ERROR, "Couldn't join group.\n");
+		log_printf (LOGSYS_LEVEL_ERROR, "Couldn't join group.\n");
 		return (-1);
 	}
 		
@@ -289,9 +289,9 @@ static void sync_primary_callback_fn (
 	int i;
 
 	if (primary_designated) {
-		log_printf (LOG_LEVEL_DEBUG, "This node is within the primary component and will provide service.\n");
+		log_printf (LOGSYS_LEVEL_DEBUG, "This node is within the primary component and will provide service.\n");
 	} else {
-		log_printf (LOG_LEVEL_DEBUG, "This node is within the non-primary component and will NOT provide any services.\n");
+		log_printf (LOGSYS_LEVEL_DEBUG, "This node is within the non-primary component and will NOT provide any services.\n");
 		return;
 	}
 
@@ -336,7 +336,7 @@ static void sync_deliver_fn (
 	unsigned int barrier_completed;
 	int i;
 
-	log_printf (LOG_LEVEL_DEBUG, "confchg entries %lu\n",
+	log_printf (LOGSYS_LEVEL_DEBUG, "confchg entries %lu\n",
 		    (unsigned long int) barrier_data_confchg_entries);
 	if (endian_conversion_required) {
 		sync_endian_convert (req_exec_sync_barrier_start);
@@ -361,7 +361,7 @@ static void sync_deliver_fn (
 	for (i = 0; i < barrier_data_confchg_entries; i++) {
 		if (nodeid == barrier_data_process[i].nodeid) {
 			barrier_data_process[i].completed = 1;
-			log_printf (LOG_LEVEL_DEBUG,
+			log_printf (LOGSYS_LEVEL_DEBUG,
 				"Barrier Start Recieved From %d\n",
 				barrier_data_process[i].nodeid);
 			break;
@@ -372,7 +372,7 @@ static void sync_deliver_fn (
 	 * Test if barrier is complete
 	 */
 	for (i = 0; i < barrier_data_confchg_entries; i++) {
-		log_printf (LOG_LEVEL_DEBUG,
+		log_printf (LOGSYS_LEVEL_DEBUG,
 			"Barrier completion status for nodeid %d = %d. \n",
 			barrier_data_process[i].nodeid,
 			barrier_data_process[i].completed);
@@ -381,7 +381,7 @@ static void sync_deliver_fn (
 		}
 	}
 	if (barrier_completed) {
-		log_printf (LOG_LEVEL_DEBUG,
+		log_printf (LOGSYS_LEVEL_DEBUG,
 			"Synchronization barrier completed\n");
 	}
 	/*
@@ -390,7 +390,7 @@ static void sync_deliver_fn (
 	if (barrier_completed && sync_callbacks.sync_activate) {
 		sync_callbacks.sync_activate ();
 
-		log_printf (LOG_LEVEL_DEBUG,
+		log_printf (LOGSYS_LEVEL_DEBUG,
 			"Committing synchronization for (%s)\n",
 			sync_callbacks.name);
 	}
@@ -408,7 +408,7 @@ static void sync_deliver_fn (
 		 * if sync service found, execute it
 		 */
 		if (sync_processing && sync_callbacks.sync_init) {
-			log_printf (LOG_LEVEL_DEBUG,
+			log_printf (LOGSYS_LEVEL_DEBUG,
 				"Synchronization actions starting for (%s)\n",
 				sync_callbacks.name);
 			sync_service_init (&deliver_ring_id);

+ 1 - 1
exec/totemconfig.c

@@ -763,7 +763,7 @@ static void totem_objdb_reload_notify(objdb_reload_notify_type_t type, int flush
 
 		}
 		else {
-			log_printf(LOG_LEVEL_ERROR, "totem objdb tracking stopped, cannot find totem{} handle on objdb\n");
+			log_printf(LOGSYS_LEVEL_ERROR, "totem objdb tracking stopped, cannot find totem{} handle on objdb\n");
 		}
 	}
 }

+ 2 - 2
exec/util.c

@@ -47,7 +47,7 @@
 #include <corosync/engine/logsys.h>
 #include "util.h"
 
-LOGSYS_DECLARE_SUBSYS ("MAIN", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("MAIN");
 
 /*
  * Compare two names.  returns non-zero on match.
@@ -88,7 +88,7 @@ void _corosync_out_of_memory_error (void)
 void _corosync_exit_error (
 	enum e_ais_done err, const char *file, unsigned int line)
 {
-	log_printf (LOG_LEVEL_ERROR, "AIS Executive exiting "
+	log_printf (LOGSYS_LEVEL_ERROR, "AIS Executive exiting "
 		"with status %d at %s:%u.\n", err, file, line);
 	exit (err);
 }

+ 12 - 12
exec/vsf_quorum.c

@@ -66,7 +66,7 @@
 #include <corosync/engine/coroapi.h>
 #include <corosync/engine/quorum.h>
 
-LOGSYS_DECLARE_SUBSYS ("QUORUM", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("QUORUM");
 
 struct quorum_pd {
 	unsigned char track_flags;
@@ -116,9 +116,9 @@ static void quorum_api_set_quorum(const unsigned int *view_list,
 	primary_designated = quorum;
 
 	if (primary_designated) {
-		log_printf (LOG_LEVEL_NOTICE, "This node is within the primary component and will provide service.\n");
+		log_printf (LOGSYS_LEVEL_NOTICE, "This node is within the primary component and will provide service.\n");
 	} else {
-		log_printf (LOG_LEVEL_NOTICE, "This node is within the non-primary component and will NOT provide any services.\n");
+		log_printf (LOGSYS_LEVEL_NOTICE, "This node is within the non-primary component and will NOT provide any services.\n");
 	}
 
 	quorum_view_list_entries = view_list_entries;
@@ -296,13 +296,13 @@ static int quorum_exec_init_fn (struct corosync_api_v1 *api)
 				0);
 
 			if (res == -1) {
-				log_printf (LOG_LEVEL_NOTICE,
+				log_printf (LOGSYS_LEVEL_NOTICE,
 					    "Couldn't load quorum provider %s\n",
 					    quorum_module);
 				return (-1);
 			}
 
-			log_printf (LOG_LEVEL_NOTICE,
+			log_printf (LOGSYS_LEVEL_NOTICE,
 				    "Using quorum provider %s\n", quorum_module);
 
 			quorum_iface = (struct quorum_services_api_ver1 *)quorum_iface_p;
@@ -323,7 +323,7 @@ static int quorum_lib_init_fn (void *conn)
 {
 	struct quorum_pd *pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
 
-	log_printf(LOG_LEVEL_DEBUG, "lib_init_fn: conn=%p\n", conn);
+	log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p\n", conn);
 
 	list_init (&pd->list);
 	pd->conn = conn;
@@ -335,7 +335,7 @@ static int quorum_lib_exit_fn (void *conn)
 {
 	struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
 
-	log_printf(LOG_LEVEL_DEBUG, "lib_exit_fn: conn=%p\n", conn);
+	log_printf(LOGSYS_LEVEL_DEBUG, "lib_exit_fn: conn=%p\n", conn);
 
 	if (quorum_pd->tracking_enabled) {
 		list_del (&quorum_pd->list);
@@ -366,7 +366,7 @@ static void send_library_notification(void *conn)
 	struct list_head *tmp;
 	int i;
 
-	log_printf(LOG_LEVEL_DEBUG, "sending quorum notification to %p, length = %d\n", conn, size);
+	log_printf(LOGSYS_LEVEL_DEBUG, "sending quorum notification to %p, length = %d\n", conn, size);
 
 	res_lib_quorum_notification->quorate = primary_designated;
 	res_lib_quorum_notification->ring_seq = quorum_ring_id.seq;
@@ -402,7 +402,7 @@ static void message_handler_req_lib_quorum_getquorate (void *conn,
 {
 	struct res_lib_quorum_getquorate res_lib_quorum_getquorate;
 
-	log_printf(LOG_LEVEL_DEBUG, "got quorate request on %p\n", conn);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got quorate request on %p\n", conn);
 
 	/* send status */
 	res_lib_quorum_getquorate.quorate = primary_designated;
@@ -420,7 +420,7 @@ static void message_handler_req_lib_quorum_trackstart (void *conn,
 	mar_res_header_t res;
 	struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
 
-	log_printf(LOG_LEVEL_DEBUG, "got trackstart request on %p\n", conn);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got trackstart request on %p\n", conn);
 
 	/*
 	 * If an immediate listing of the current cluster membership
@@ -428,7 +428,7 @@ static void message_handler_req_lib_quorum_trackstart (void *conn,
 	 */
 	if (req_lib_quorum_trackstart->track_flags & CS_TRACK_CURRENT ||
 	    req_lib_quorum_trackstart->track_flags & CS_TRACK_CHANGES) {
-		log_printf(LOG_LEVEL_DEBUG, "sending initial status to %p\n", conn);
+		log_printf(LOGSYS_LEVEL_DEBUG, "sending initial status to %p\n", conn);
 		send_library_notification(conn);
 	}
 
@@ -456,7 +456,7 @@ static void message_handler_req_lib_quorum_trackstop (void *conn, const void *ms
 	mar_res_header_t res;
 	struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
 
-	log_printf(LOG_LEVEL_DEBUG, "got trackstop request on %p\n", conn);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got trackstop request on %p\n", conn);
 
 	if (quorum_pd->tracking_enabled) {
 		res.error = CS_OK;

+ 3 - 3
exec/vsf_ykd.c

@@ -64,7 +64,7 @@
 #include <corosync/swab.h>
 #include <corosync/lcr/lcr_comp.h>
 
-LOGSYS_DECLARE_SUBSYS ("YKD", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("YKD");
 
 #define YKD_PROCESSOR_COUNT_MAX 32
 
@@ -349,7 +349,7 @@ static void ykd_deliver_fn (
 	 */
 #ifdef TODO
 	if (totemip_localhost_check (source_addr)) {
-		log_printf (LOG_LEVEL_NOTICE,
+		log_printf (LOGSYS_LEVEL_NOTICE,
 			"This processor is within the primary component.\n");
 			primary_designated = 1;
 
@@ -424,7 +424,7 @@ static void ykd_deliver_fn (
 
 		case YKD_MODE_ATTEMPT:
 			if (all_received) {
-				log_printf (LOG_LEVEL_NOTICE,
+				log_printf (LOGSYS_LEVEL_NOTICE,
 					"This processor is within the primary component.\n");
 				primary_designated = 1;
 

+ 169 - 128
include/corosync/engine/logsys.h

@@ -4,6 +4,7 @@
  *
  * Author: Steven Dake (sdake@redhat.com)
  * Author: Lon Hohberger (lhh@redhat.com)
+ * Author: Fabio M. Di Nitto (fdinitto@redhat.com)
  *
  * All rights reserved.
  *
@@ -41,31 +42,35 @@
 #include <assert.h>
 
 /*
- * All of the LOG_MODE's can be ORed together for combined behavior
+ * All of the LOGSYS_MODE's can be ORed together for combined behavior
+ *
+ * FORK and THREADED are ignored for SUBSYSTEMS
  */
-#define LOG_MODE_OUTPUT_FILE		(1<<0)
-#define LOG_MODE_OUTPUT_STDERR		(1<<1)
-#define LOG_MODE_OUTPUT_SYSLOG		(1<<3)
-#define LOG_MODE_NOSUBSYS		(1<<4)
-#define LOG_MODE_FORK			(1<<5)
-#define LOG_MODE_THREADED		(1<<6)
+#define LOGSYS_MODE_OUTPUT_FILE		(1<<0)
+#define LOGSYS_MODE_OUTPUT_STDERR	(1<<1)
+#define LOGSYS_MODE_OUTPUT_SYSLOG	(1<<2)
+#define LOGSYS_MODE_FORK		(1<<3)
+#define LOGSYS_MODE_THREADED		(1<<4)
 
 /*
  * Log priorities, compliant with syslog and SA Forum Log spec.
  */
-#define LOG_LEVEL_EMERG	    		LOG_EMERG
-#define LOG_LEVEL_ALERT			LOG_ALERT
-#define LOG_LEVEL_CRIT			LOG_CRIT
-#define LOG_LEVEL_ERROR			LOG_ERR
-#define LOG_LEVEL_WARNING		LOG_WARNING
-#define LOG_LEVEL_SECURITY		LOG_WARNING // corosync specific
-#define LOG_LEVEL_NOTICE		LOG_NOTICE
-#define LOG_LEVEL_INFO	    		LOG_INFO
-#define LOG_LEVEL_DEBUG			LOG_DEBUG
+#define LOGSYS_LEVEL_EMERG	    		LOG_EMERG
+#define LOGSYS_LEVEL_ALERT			LOG_ALERT
+#define LOGSYS_LEVEL_CRIT			LOG_CRIT
+#define LOGSYS_LEVEL_ERROR			LOG_ERR
+#define LOGSYS_LEVEL_WARNING		LOG_WARNING
+#define LOGSYS_LEVEL_SECURITY		LOG_WARNING // corosync specific
+#define LOGSYS_LEVEL_NOTICE		LOG_NOTICE
+#define LOGSYS_LEVEL_INFO	    		LOG_INFO
+#define LOGSYS_LEVEL_DEBUG			LOG_DEBUG
 
 /*
  * The tag masks are all mutually exclusive
- */	
+ *
+ * LOG is mandatory, but enforced, for subsystems.
+ * Be careful if/when changing tags at runtime.
+ */
 #define LOGSYS_TAG_LOG			(0xff<<28)
 #define LOGSYS_TAG_ENTER		(1<<27)
 #define LOGSYS_TAG_LEAVE		(1<<26)
@@ -79,36 +84,144 @@
 #define LOGSYS_TAG_TRACE8		(1<<18)
 
 /*
- * External API
+ * Internal APIs that must be globally exported
+ * (External API below)
  */
-extern void logsys_config_mode_set (
-	unsigned int mode);
 
-extern unsigned int logsys_config_mode_get (void);
+/*
+ * logsys_logger bits
+ *
+ * SUBSYS_COUNT defines the maximum number of subsystems
+ * SUBSYS_NAMELEN defines the maximum len of a subsystem name
+ */
+#define LOGSYS_MAX_SUBSYS_COUNT		64
+#define LOGSYS_MAX_SUBSYS_NAMELEN	64
+
+extern int _logsys_system_setup(
+	const char *mainsystem,
+	unsigned int mode,
+	unsigned int debug,
+	const char *logfile,
+	int logfile_priority,
+	int syslog_facility,
+	int syslog_priority,
+	unsigned int tags);
 
-extern int logsys_config_file_set (
-	const char **error_string,
-	const char *file);
+extern int _logsys_config_subsys_get (
+	const char *subsys);
 
-extern void logsys_config_facility_set (
-	const char *name,
-	unsigned int facility);
+extern unsigned int _logsys_subsys_create (const char *subsys);
+
+extern int _logsys_rec_init (unsigned int size);
 
+extern void _logsys_log_printf (
+	int subsysid,
+	const char *function_name,
+	const char *file_name,
+	int file_line,
+	unsigned int level,
+	const char *format,
+	...) __attribute__((format(printf, 6, 7)));
+
+extern void _logsys_log_rec (
+	int subsysid,
+	const char *function_name,
+	const char *file_name,
+	int file_line,
+	unsigned int rec_ident,
+	...);
+
+extern int _logsys_wthread_create (void);
+
+static unsigned int logsys_subsys_id __attribute__((unused)) = -1;
+
+/*
+ * External API - init
+ * See below:
+ *
+ * LOGSYS_DECLARE_SYSTEM
+ * LOGSYS_DECLARE_SUBSYS
+ *
+ */
+extern void logsys_fork_completed (void);
+
+extern void logsys_atexit (void);
+
+/*
+ * External API - misc
+ */
+extern int logsys_log_rec_store (const char *filename);
+
+/*
+ * External API - configuration
+ */
+
+/*
+ * configuration bits that can only be done for the whole system
+ */
 extern int logsys_format_set (
 	const char *format);
 
 extern char *logsys_format_get (void);
 
-extern unsigned int logsys_config_subsys_set (
+/*
+ * per system/subsystem settings.
+ *
+ * NOTE: once a subsystem is created and configured, changing
+ * the default does NOT affect the subsystems.
+ *
+ * Pass a NULL subsystem to change them all
+ */
+extern unsigned int logsys_config_syslog_facility_set (
+	const char *subsys,
+	unsigned int facility);
+
+extern unsigned int logsys_config_syslog_priority_set (
 	const char *subsys,
-	unsigned int tags,
 	unsigned int priority);
 
-extern int logsys_config_subsys_get (
+extern unsigned int logsys_config_mode_set (
+	const char *subsys,
+	unsigned int mode);
+
+extern unsigned int logsys_config_mode_get (
+	const char *subsys);
+
+extern unsigned int logsys_config_tags_set (
 	const char *subsys,
-	unsigned int *tags,
-	unsigned int *priority);
+	unsigned int tags);
 
+extern unsigned int logsys_config_tags_get (
+	const char *subsys);
+
+/*
+ * to close a logfile, just invoke this function with a NULL
+ * file or if you want to change logfile, the old one will
+ * be closed for you.
+ */
+extern int logsys_config_file_set (
+	const char *subsys,
+	const char **error_string,
+	const char *file);
+
+extern unsigned int logsys_config_logfile_priority_set (
+	const char *subsys,
+	unsigned int priority);
+
+/*
+ * enabling debug, disable message priority filtering.
+ * everything is sent everywhere. priority values
+ * for file and syslog are not overwritten.
+ */
+extern unsigned int logsys_config_debug_set (
+	const char *subsys,
+	unsigned int value);
+
+/*
+ * External API - helpers
+ *
+ * convert facility/priority/tag to/from name/values
+ */
 extern int logsys_facility_id_get (
 	const char *name);
 
@@ -127,92 +240,42 @@ extern int logsys_tag_id_get (
 extern const char *logsys_tag_name_get (
 	unsigned int tag);
 
-extern void logsys_fork_completed (void);
-
-extern void logsys_flush (void);
-
-extern void logsys_atsegv (void);
-
-extern int logsys_log_rec_store (const char *filename);
-
-/*
- * Internal APIs that must be globally exported
- */
-extern unsigned int _logsys_subsys_create (
-	const char *ident,
-	unsigned int priority);
-
-extern void _logsys_nosubsys_set (void);
-
-extern int _logsys_rec_init (unsigned int size);
-
-extern void _logsys_log_printf (
-	int subsys,
-	const char *function_name,
-	const char *file_name,
-	int file_line,
-	unsigned int level,
-	const char *format,
-	...) __attribute__((format(printf, 6, 7)));
-
-extern void _logsys_log_rec (
-	int subsys,
-	const char *function_name,
-	const char *file_name,
-	int file_line,
-	unsigned int rec_ident,
-	...);
-
-extern int _logsys_wthread_create (void);
-
-static unsigned int logsys_subsys_id __attribute__((unused)) = -1;
-									
 /*
  * External definitions
  */
 extern void *logsys_rec_end;
 
-#define LOG_REC_END (&logsys_rec_end)
+#define LOGSYS_REC_END (&logsys_rec_end)
 
-#define LOGSYS_DECLARE_SYSTEM(name,mode,file,facility,format,rec_size)	\
-__attribute__ ((constructor)) static void logsys_system_init (void)	\
+#define LOGSYS_DECLARE_SYSTEM(name,mode,debug,file,file_priority,	\
+		syslog_facility,syslog_priority,tags,format,rec_size)	\
+__attribute__ ((constructor))						\
+static void logsys_system_init (void)					\
 {									\
-	const char *error_string;						\
+	int err;							\
 									\
-	logsys_config_mode_set (mode);					\
-	logsys_config_file_set (&error_string, (file));			\
-	logsys_config_facility_set (name, (facility));			\
-	logsys_format_set (format); /* FIXME: assert success? */	\
-	_logsys_rec_init (rec_size);					\
-	_logsys_wthread_create();					\
-}
-
-#define LOGSYS_DECLARE_NOSUBSYS(priority)				\
-__attribute__ ((constructor)) static void logsys_nosubsys_init (void)	\
-{									\
-	unsigned int pri, tags;						\
+	err = _logsys_system_setup (name,mode,debug,file,file_priority,	\
+				syslog_facility,syslog_priority,tags);	\
+	assert (err == 0 && "_logsys_system_setup failed");		\
 									\
-	logsys_subsys_id =						\
-		logsys_config_subsys_get("MAIN", &tags, &pri);		\
+	err = logsys_format_set (format);				\
+	assert (err == 0 && "logsys_format_set failed");		\
+									\
+	err = _logsys_rec_init (rec_size);				\
+	assert (err == 0 && "_logsys_rec_init failed");			\
 									\
-	if (logsys_subsys_id == -1) {					\
-		_logsys_nosubsys_set();					\
-		logsys_subsys_id =					\
-			_logsys_subsys_create ("MAIN", (priority));	\
-	}								\
+	err = _logsys_wthread_create();					\
+	assert (err == 0 && "_logsys_wthread_create failed");		\
 }
 
-#define LOGSYS_DECLARE_SUBSYS(subsys,priority)				\
-__attribute__ ((constructor)) static void logsys_subsys_init (void)	\
+#define LOGSYS_DECLARE_SUBSYS(subsys)					\
+__attribute__ ((constructor))						\
+static void logsys_subsys_init (void)					\
 {									\
-	unsigned int pri, tags;						\
-									\
 	logsys_subsys_id =						\
-		logsys_config_subsys_get((subsys), &tags, &pri);	\
-									\
-	if (logsys_subsys_id == -1)					\
-		logsys_subsys_id =					\
-			_logsys_subsys_create ((subsys), (priority));	\
+		_logsys_subsys_create ((subsys));			\
+	assert (logsys_subsys_id < LOGSYS_MAX_SUBSYS_COUNT && 		\
+		"_logsys_subsys_create failed");			\
 }
 
 #define log_rec(rec_ident, args...)					\
@@ -229,12 +292,12 @@ do {									\
 
 #define ENTER() do {							\
 	_logsys_log_rec (logsys_subsys_id, __FUNCTION__,		\
-		__FILE__,  __LINE__, LOGSYS_TAG_ENTER, LOG_REC_END);	\
+		__FILE__,  __LINE__, LOGSYS_TAG_ENTER, LOGSYS_REC_END);	\
 } while(0)
 
 #define LEAVE() do {							\
 	_logsys_log_rec (logsys_subsys_id, __FUNCTION__,		\
-		__FILE__,  __LINE__, LOGSYS_TAG_LEAVE, LOG_REC_END);	\
+		__FILE__,  __LINE__, LOGSYS_TAG_LEAVE, LOGSYS_REC_END);	\
 } while(0)
 
 #define TRACE1(format, args...) do {					\
@@ -277,26 +340,4 @@ do {									\
 		__FILE__,  __LINE__, LOGSYS_TAG_TRACE8, format, ##args);\
 } while(0)
 
-/*
- * For one-time programmatic initialization and configuration of logsys
- * instead of using the DECLARE macros.  These APIs do not allow subsystems
- */
-int logsys_init (
-	const char *name,
-	int mode,
-	int facility,
-	int priority,
-	const char *file,
-	char *format,
-	int rec_size);
-
-int logsys_conf (
-	char *name,
-	int mode,
-	int facility,
-	int priority,
-	char *file);
-
-void logsys_exit (void);
-
 #endif /* LOGSYS_H_DEFINED */

+ 57 - 42
man/corosync.conf.5

@@ -37,7 +37,7 @@
 corosync.conf - corosync executive configuration file
 
 .SH SYNOPSIS
-/etc/ais/corosync.conf
+/etc/corosync.conf
 
 .SH DESCRIPTION
 The corosync.conf instructs the corosync executive about various parameters
@@ -411,11 +411,37 @@ The default is 47 milliseconds.
 .PP
 Within the 
 .B logging
-directive, there are seven configuration options which are all optional:
+directive, there are several configuration options which are all optional.
+
+.PP
+The following 3 options are valid only for the top level logging directive:
+
+.TP
+timestamp
+This specifies that a timestamp is placed on all log messages.
+
+The default is off.
+
+.TP
+fileline
+This specifies that file and line should be printed.
+
+The default is off.
+
+.TP
+function_name
+This specifies that the code function name should be printed.
+
+The default is off.
+
+.PP
+The following options are valid both for top level logging directive
+and they can be overriden in logger_subsys entries.
+
 .TP
 to_stderr
 .TP
-to_file
+to_logfile
 .TP
 to_syslog
 These specify the destination of logging output. Any combination of
@@ -426,11 +452,10 @@ and
 
 The default is syslog and stderr.
 
-
 .TP
 logfile
 If the 
-.B to_file
+.B to_logfile
 directive is set to
 .B yes
 , this option specifies the pathname of the log file.
@@ -438,22 +463,11 @@ directive is set to
 No default.
 
 .TP
-timestamp
-This specifies that a timestamp is placed on all log messages.
-
-The default is off.
-
-.TP
-fileline
-This specifies that file and line should be printed.
-
-The default is off.
-
-.TP
-function_name
-This specifies that the code function name should be printed.
+logfile_priority
+This specifies the logfile priority for this particular subsystem. Ignored if debug is on.
+Possible values are: alert, crit, debug (same as debug = on), emerg, err, info, notice, warning.
 
-The default is off.
+The default is: info.
 
 .TP 
 syslog_facility
@@ -463,22 +477,12 @@ local5, local6 & local7.
 
 The default is daemon.
 
-.PP
-.PP
-Within the 
-.B logging
-directive, logger directives are optional.
-.PP
-.PP
-Within the 
-.B logger_subsys
-sub-directive of logging there are three configuration options:
-
 .TP
-subsys
-This specifies the subsystem identity (name) for which logging is specified. This is the
-name used by a service in the log_init () call. E.g. 'CKPT'. This directive is
-required.
+syslog_priority
+This specifies the syslog level for this particular subsystem. Ignored if debug is on.
+Possible values are: alert, crit, debug (same as debug = on), emerg, err, info, notice, warning.
+
+The default is: info.
 
 .TP
 debug
@@ -486,13 +490,6 @@ This specifies whether debug output is logged for this particular logger.
 
 The default is off.
 
-.TP
-syslog_level
-This specifies the syslog level for this particular subsystem. Ignored if debug is on.
-Possible values are: alert, crit, debug (same as debug = on), emerg, err, info, notice, warning.
-
-The default is: info.
-
 .TP
 tags
 This specifies which tags should be traced for this particular logger.
@@ -505,6 +502,24 @@ enter|leave|trace1|trace2|trace3|...
 
 The default is none.
 
+.PP
+Within the 
+.B logging
+directive, logger_subsys directives are optional.
+
+.PP
+Within the 
+.B logger_subsys
+sub-directive, all of the above logging configuration options are valid and
+can be used to override the default settings.
+The subsys entry, described below, is mandatory to identify the subsystem.
+
+.TP
+subsys
+This specifies the subsystem identity (name) for which logging is specified. This is the
+name used by a service in the log_init () call. E.g. 'CKPT'. This directive is
+required.
+
 .PP
 Within the
 .B aisexec

+ 105 - 66
man/logsys_overview.8

@@ -1,9 +1,10 @@
 .\"/*
-.\" * Copyright (c) 2007 Red Hat, Inc.
+.\" * Copyright (c) 2007-2009 Red Hat, Inc.
 .\" *
 .\" * All rights reserved.
 .\" *
 .\" * Author: Steven Dake (sdake@redhat.com)
+.\" * Author: Fabio M. Di Nitto (fdinitto@redhat.com)
 .\" *
 .\" * This software licensed under BSD license, the text of which follows:
 .\" * 
@@ -31,7 +32,7 @@
 .\" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 .\" * THE POSSIBILITY OF SUCH DAMAGE.
 .\" */
-.TH LOGSYS_OVERVIEW 8 2007-05-15 "corosync Man Page" "Corosync Cluster Engine Programmer's Manual"
+.TH LOGSYS_OVERVIEW 8 2009-04-15 "corosync Man Page" "Corosync Cluster Engine Programmer's Manual"
 .SH OVERVIEW
 The logsys library provides a generically usable logging and tracing system for
 use by applications.  It supports many features including:
@@ -50,34 +51,63 @@ Logging to syslog, file, stderr.
 
 .SH Declaration of the System logger
 The logsys library is initially configured by including logsys.h and declaring
-a logger.  Once the logger is declared either a subsystem logger or nosubsystem
-logger is declared in every file.
+a logger.  Once the logger is declared, optional subsystem loggers can be
+declared in every file.
 
 The definition LOGSYS_DECLARE_SYSTEM is placed after the include section of one
 C file in the application.  This declaration creates a constructor function
-which will be called automatically.  This technique avoids the need for calling
-any setup functions in short applications that don't require it.
-
-#define LOGSYS_DECLARE_SYSTEM(name,mode,file,facility)
-The name parameter is the name of the application.
-The mode parameter is the logging mode of the system.  The following modes
-can be configured by logically ORing these flags:
-LOG_MODE_OUTPUT_FILE: Output all log data to the file parameter of this declaration
-LOG_MODE_OUTPUT_STDERR: Output all log data to the stderr descriptor
-LOG_MODE_OUTPUT_SYSLOG_THREADED: Output all log data to syslog using a non-blocking thread
-LOG_MODE_OUTPUT_SYSLOG_LOSSY: Output all log data without using a thread but potentially losing data.  This mode is not yet implemented.
-LOG_MODE_OUTPUT_SYSLOG_BLOCKING: Output all log data without using a thread and potentially blocking at each syslog call.
-LOG_MODE_DISPLAY_PRIORITY: Output the priority of the log entry in the message contents.  This mode is currently not implemented.
-LOG_MODE_DISPLAY_FILELINE: Output the file and line at which the log message was created.
-LOG_MODE_SHORT_FILELINE: When using LOG_DEBUG level or LOG_MODE_DISPLAY_FILELINE, typically the absolute path to the file (derived at compile-time) is displayed.  Enabling this flag ensures that only the filename and line are displayed.
-LOG_MODE_DISPLAY_TIMESTAMP: Output the timestamp of the message.
-LOG_MODE_BUFFER_BEFORE_CONFIG: This mode is used to buffer log messages before logsys_mode_config is called.  This is useful in applications in which the logging file isn't known before the application is compiled and must be set dynamically.  It is also useful when an application calls fork to disconnect the local tty and should hold logging of messages until after the fork.
-LOG_MODE_FLUSH_AFTER_CONFIG: This mode is used to flush any buffered messages when the LOG_MODE_BUFFER_BEFORE_CONFIG declaration is specified in the declaration of the logger.
-The file parameter specifies the filename that should be used to log messages.  This parameter may be NULL if LOG_MODE_OUTPUT_FILE is not specified.
-The facility parameter is the syslog facility that should be used when logging
+which will be called automatically before main() is executed.  This technique
+avoids the need for calling any setup functions in short applications that don't
+require it and enables full logging capabilities before any application code is
+executed.
+
+#define LOGSYS_DECLARE_SYSTEM (name, mode, debug, file, file_priority,
+syslog_facility, syslog_priority, tags, format, rec_size)
+
+The name parameter is the name of the application or system.
+
+The mode parameter is the logging mode of the system.
+The following modes can be configured by logically ORing these flags:
+
+LOGSYS_MODE_OUTPUT_FILE: Output all log data to the file parameter of this declaration
+
+LOGSYS_MODE_OUTPUT_STDERR: Output all log data to the stderr descriptor
+
+LOGSYS_MODE_OUTPUT_SYSLOG: Output all log data to syslog using a non-blocking thread
+
+LOGSYS_MODE_FORK: This flags tells logsys to queue all data untill the application
+has forked. The application is then responsible to call logsys_fork_completed to flush
+the queue and start logging.
+
+LOGSYS_MODE_THREADED: Starts a separate thread to handle non-blocking logging operations.
+If this flag is not specified, the logging operations are blocking.
+
+The debug parameter, if enabled, turns off all messages priority filtering, recording
+everything everywhere.
+
+The file parameter specifies the filename that should be used to log messages. 
+This parameter may be NULL and no log file will be created.
+
+The file_priority parameter specifies the message priority that should be logged to file.
+
+The syslog_facility parameter is the syslog facility that should be used when logging
 messages.
-LOG_MODE_NOSUBSYS: Enabling this mode removes the subsystem tag from the beginning of the log lines.  This is not recommended for programs which have multiple subsystems.
-LOG_MODE_FILTER_DEBUG_FROM_SYSLOG: Enabling this mode will stop debug messages from being sent to syslog.
+
+The syslog_priority, similar to file_priority, specifies the message priority that should be logged to
+syslog.
+
+The tags parameter enables tracing by logically ORing these flags:
+
+LOGSYS_TAG_ENTER
+
+LOGSYS_TAG_LEAVE
+
+LOGSYS_TAG_TRACE1 to LOGSYS_TAG_TRACE8
+
+The format parameter allows to set custom output format.
+Set to NULL to use built-in default.
+
+The rec_size parameter specifies the flight recorder buffer size.
 
 An example declaration would be:
 
@@ -85,55 +115,53 @@ An example declaration would be:
 
 ... (other #includes)
 
-LOGSYS_DECLARE_SYSTEM ("my_example_app",
-	LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED | LOG_MODE_OUTPUT_FILE,
-	"/tmp/log",
-	LOG_DAEMON);
+LOGSYS_DECLARE_SYSTEM ("test",                            /* name */
+        LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_THREADED, /* mode */
+        0,                                                /* debug */
+        NULL,                                             /* logfile path */
+        LOGSYS_LEVEL_INFO,                                /* logfile_priority */
+        LOG_DAEMON,                                       /* syslog facility */
+        LOGSYS_LEVEL_INFO,                                /* syslog level */
+        0,                                                /* tags */
+        NULL,                                             /* use default format */
+        1000000);                                         /* flight recorder size */
 
-This would output any logging messages to stderr, syslog, and the file /tmp/log.
 
-.SH Declaration of subsystems or no subsystems
+.SH Declaration of subsystems
 The logsys library supports the logging of information to one main system or
-subsystem.  This is specified in each individual object file in the system.
-
-if no subsystems are desired, The define LOGSYS_DECLARE_NOSUBSYS should be
-declared for every object file in the system.  These object files are usually C
-files.
-
-An example of using this would be
+subsystem.  This is specified in each individual object C file in the system
+and it is entirely optional.
 
-LOGSYS_DECLARE_NOSUBSYS (LOG_LEVEL_INFO);
+An example:
 
-Any messages of LOG_LEVEL_INFO priority or higher would be logged.
+LOGSYS_DECLARE_SUBSYS ("subsystest");
 
-If subsystems are desired, the define LOGSYS_DECLARE_SUBSYS should be declared
-for every object file in the system.  It is possible to use the same subsystem
-name in separate object files.  In this case, the individual logging parameters
-for those subsystem identifier will be used.
+It is possible to use the same subsystem name in separate object files. 
+In this case, the individual logging parameters for those subsystem identifier
+will be used.
 
-An example of using this would be
-LOGSYS_DECLARE_SUBSYS ("SYS1", LOG_LEVEL_INFO);
+A newly created subsystem inherits the system configuration at the time of
+creation.
 
-Any message of LOG_LEVEL_INFO priority or higher would be logged and any
-logging within the object file this declaration is specified within will be
-logged to the SYS1 subsystem identifier.
+It is possible to override every configuration option on a subsystem base
+throught the configuration API.
 
 .SH Logging Messages
 The definition log_printf is used to log information to the log.  It works
 in a similiar fashion to printf, except it has a first parameter of level
 which may be the following:
-LOG_EMERG
-LOG_ALERT
-LOG_CRIT
-LOG_ERR
-LOG_WARNING
-LOG_NOTICE
-LOG_INFO
-LOG_DEBUG
+LOGSYS_LEVEL_EMERG
+LOGSYS_LEVEL_ALERT
+LOGSYS_LEVEL_CRIT
+LOGSYS_LEVEL_ERR
+LOGSYS_LEVEL_WARNING
+LOGSYS_LEVEL_NOTICE
+LOGSYS_LEVEL_INFO
+LOGSYS_LEVEL_DEBUG
 
 An example of using log_printf would be
 
-log_printf (LOG_EMERG, "This is an emergency %s value %d\n", string, value);
+log_printf (LOGSYS_LEVEL_EMERG, "This is an emergency %s value %d\n", string, value);
 
 Tracing of functions can be done using ENTER_VOID() or ENTER (format, args) LEAVE_VOID() or LEAVE (format, args);
 
@@ -163,15 +191,26 @@ char *name = "test";
 TRACE7 ("This is a trace 7 log with name %s\n", name);
 
 .SH "SEE ALSO"
+.BR logsys_fork_completed (3),
+.BR logsys_atexit (3),
+.BR logsys_log_rec_store (3),
+.BR logsys_format_set (3),
+.BR logsys_format_get (3),
+.BR logsys_config_mode_set (3),
+.BR logsys_config_file_set (3),
+.BR logsys_config_syslog_facility_set (3),
+.BR logsys_config_syslog_facility_get (3),
 .BR logsys_config_mode_set (3),
+.BR logsys_config_mode_get (3),
+.BR logsys_config_tags_set (3),
+.BR logsys_config_tags_get (3),
 .BR logsys_config_file_set (3),
-.BR logsys_config_facility_set (3),
-.BR logsys_config_facility_set (3),
-.BR logsys_config_priority_set (3),
-.BR logsys_config_subsys_set (3),
-.BR logsys_config_subsys_get (3),
+.BR logsys_config_logfile_priority_set (3),
+.BR logsys_config_debug_set (3),
 .BR logsys_facility_id_get (3),
+.BR logsys_facility_name_get (3),
 .BR logsys_priority_id_get (3),
-.BR logsys_flush (3),
-.BR logsys_atsegv (3),
+.BR logsys_priority_name_get (3),
+.BR logsys_tag_id_get (3),
+.BR logsys_tag_name_get (3)
 .PP

+ 5 - 5
services/cfg.c

@@ -62,7 +62,7 @@
 #include <corosync/engine/logsys.h>
 #include <corosync/engine/coroapi.h>
 
-LOGSYS_DECLARE_SUBSYS ("CFG", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("CFG");
 
 enum cfg_message_req_types {
         MESSAGE_REQ_EXEC_CFG_RINGREENABLE = 0,
@@ -473,7 +473,7 @@ static void check_shutdown_status(void)
 			shutdown_con = NULL;
 		}
 
-		log_printf(LOG_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x\n", shutdown_yes, shutdown_no, shutdown_flags);
+		log_printf(LOGSYS_LEVEL_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x\n", shutdown_yes, shutdown_no, shutdown_flags);
 	}
 	LEAVE();
 }
@@ -603,10 +603,10 @@ static void message_handler_req_exec_cfg_killnode (
 	cs_name_t reason;
 
 	ENTER();
-	log_printf(LOG_DEBUG, "request to kill node %d(us=%d): %s\n",  req_exec_cfg_killnode->nodeid, api->totem_nodeid_get(), reason.value);
+	log_printf(LOGSYS_LEVEL_DEBUG, "request to kill node %d(us=%d): %s\n",  req_exec_cfg_killnode->nodeid, api->totem_nodeid_get(), reason.value);
         if (req_exec_cfg_killnode->nodeid == api->totem_nodeid_get()) {
 		marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
-		log_printf(LOG_NOTICE, "Killed by node %d: %s\n",
+		log_printf(LOGSYS_LEVEL_NOTICE, "Killed by node %d: %s\n",
 			   nodeid, reason.value);
 		corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
 	}
@@ -622,7 +622,7 @@ static void message_handler_req_exec_cfg_shutdown (
 {
 	ENTER();
 
-	log_printf(LOG_NOTICE, "Node %d was shut down by sysadmin\n", nodeid);
+	log_printf(LOGSYS_LEVEL_NOTICE, "Node %d was shut down by sysadmin\n", nodeid);
 	if (nodeid == api->totem_nodeid_get()) {
 		corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
 	}

+ 3 - 3
services/confdb.c

@@ -52,7 +52,7 @@
 #include <corosync/engine/logsys.h>
 #include <corosync/engine/coroapi.h>
 
-LOGSYS_DECLARE_SUBSYS ("CONFDB", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("CONFDB");
 
 static struct corosync_api_v1 *api;
 
@@ -294,13 +294,13 @@ static int confdb_exec_init_fn (
 
 static int confdb_lib_init_fn (void *conn)
 {
-	log_printf(LOG_LEVEL_DEBUG, "lib_init_fn: conn=%p\n", conn);
+	log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p\n", conn);
 	return (0);
 }
 
 static int confdb_lib_exit_fn (void *conn)
 {
-	log_printf(LOG_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
+	log_printf(LOGSYS_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
 	/* cleanup the object trackers for this client. */
 	api->object_track_stop(confdb_notify_lib_of_key_change,
 		confdb_notify_lib_of_new_object,

+ 23 - 23
services/cpg.c

@@ -65,7 +65,7 @@
 #include <corosync/engine/logsys.h>
 #include <corosync/engine/coroapi.h>
 
-LOGSYS_DECLARE_SUBSYS ("CPG", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("CPG");
 
 #define GROUP_HASH_SIZE 32
 
@@ -397,7 +397,7 @@ static int notify_lib_joinlist(
 			count++;
 	}
 
-	log_printf(LOG_LEVEL_DEBUG, "Sending new joinlist (%d elements) to clients\n", count);
+	log_printf(LOGSYS_LEVEL_DEBUG, "Sending new joinlist (%d elements) to clients\n", count);
 
 	size = sizeof(struct res_lib_cpg_confchg_callback) +
 		sizeof(mar_cpg_address_t) * (count + left_list_entries + joined_list_entries);
@@ -490,7 +490,7 @@ static int cpg_lib_exit_fn (void *conn)
 	struct group_info *gi = pi->group;
 	mar_cpg_address_t notify_info;
 
-	log_printf(LOG_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
+	log_printf(LOGSYS_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
 
 	if (gi) {
 		notify_info.pid = pi->pid;
@@ -536,7 +536,7 @@ static struct group_info *get_group(const mar_cpg_name_t *name)
 	if (!gi) {
 		gi = malloc(sizeof(struct group_info));
 		if (!gi) {
-			log_printf(LOG_LEVEL_WARNING, "Unable to allocate group_info struct");
+			log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate group_info struct");
 			return NULL;
 		}
 		memcpy(&gi->group_name, name, sizeof(mar_cpg_name_t));
@@ -595,7 +595,7 @@ static void remove_node_from_groups(
 							gi->rg->left_list_size = PROCESSOR_COUNT_MAX;
 						}
 						else {
-							log_printf(LOG_LEVEL_CRIT, "Unable to allocate removed group struct. CPG callbacks will be junk.");
+							log_printf(LOGSYS_LEVEL_CRIT, "Unable to allocate removed group struct. CPG callbacks will be junk.");
 							return;
 						}
 					}
@@ -611,7 +611,7 @@ static void remove_node_from_groups(
 						newsize = gi->rg->left_list_size * 2;
 						newrg = realloc(gi->rg, sizeof(struct removed_group) + newsize*sizeof(mar_cpg_address_t));
 						if (!newrg) {
-							log_printf(LOG_LEVEL_CRIT, "Unable to realloc removed group struct. CPG callbacks will be junk.");
+							log_printf(LOGSYS_LEVEL_CRIT, "Unable to realloc removed group struct. CPG callbacks will be junk.");
 							return;
 						}
 						newrg->left_list_size = newsize+PROCESSOR_COUNT_MAX;
@@ -656,7 +656,7 @@ static void cpg_confchg_fn (
 				lowest_nodeid = member_list[i];
 		}
 
-		log_printf(LOG_LEVEL_DEBUG, "confchg, low nodeid=%d, us = %d\n", lowest_nodeid, api->totem_nodeid_get());
+		log_printf(LOGSYS_LEVEL_DEBUG, "confchg, low nodeid=%d, us = %d\n", lowest_nodeid, api->totem_nodeid_get());
 		if (lowest_nodeid == api->totem_nodeid_get()) {
 
 			g_req_exec_cpg_downlist.header.id = SERVICE_ID_MAKE(CPG_SERVICE, MESSAGE_REQ_EXEC_CPG_DOWNLIST);
@@ -666,7 +666,7 @@ static void cpg_confchg_fn (
 			for (i = 0; i < left_list_entries; i++) {
 				g_req_exec_cpg_downlist.nodeids[i] = left_list[i];
 			}
-			log_printf(LOG_LEVEL_DEBUG,
+			log_printf(LOGSYS_LEVEL_DEBUG,
 				   "confchg, build downlist: %lu nodes\n",
 				   (long unsigned int) left_list_entries);
 		}
@@ -679,7 +679,7 @@ static void cpg_confchg_fn (
 
 		api->totem_mcast (&req_exec_cpg_iovec, 1, TOTEM_AGREED);
 		g_req_exec_cpg_downlist.left_nodes = 0;
-		log_printf(LOG_LEVEL_DEBUG, "confchg, sent downlist\n");
+		log_printf(LOGSYS_LEVEL_DEBUG, "confchg, sent downlist\n");
 	}
 }
 
@@ -763,7 +763,7 @@ static void do_proc_join(
 
 	pi = malloc(sizeof(struct process_info));
 	if (!pi) {
-		log_printf(LOG_LEVEL_WARNING, "Unable to allocate process_info struct");
+		log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate process_info struct");
 		return;
 	}
 	pi->nodeid = nodeid;
@@ -794,7 +794,7 @@ static void message_handler_req_exec_cpg_downlist (
 	int i;
 	struct list_head removed_list;
 
-	log_printf(LOG_LEVEL_DEBUG, "downlist left_list: %d\n", req_exec_cpg_downlist->left_nodes);
+	log_printf(LOGSYS_LEVEL_DEBUG, "downlist left_list: %d\n", req_exec_cpg_downlist->left_nodes);
 
 	list_init(&removed_list);
 
@@ -825,7 +825,7 @@ static void message_handler_req_exec_cpg_procjoin (
 {
 	const struct req_exec_cpg_procjoin *req_exec_cpg_procjoin = message;
 
-	log_printf(LOG_LEVEL_DEBUG, "got procjoin message from cluster node %d\n", nodeid);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got procjoin message from cluster node %d\n", nodeid);
 
 	do_proc_join(&req_exec_cpg_procjoin->group_name,
 		req_exec_cpg_procjoin->pid, nodeid,
@@ -842,7 +842,7 @@ static void message_handler_req_exec_cpg_procleave (
 	struct list_head *iter;
 	mar_cpg_address_t notify_info;
 
-	log_printf(LOG_LEVEL_DEBUG, "got procleave message from cluster node %d\n", nodeid);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got procleave message from cluster node %d\n", nodeid);
 
 	gi = get_group(&req_exec_cpg_procjoin->group_name); /* this will always succeed ! */
 	assert(gi);
@@ -886,7 +886,7 @@ static void message_handler_req_exec_cpg_joinlist (
 	const mar_res_header_t *res = (const mar_res_header_t *)message;
 	const struct join_list_entry *jle = (const struct join_list_entry *)(message + sizeof(mar_res_header_t));
 
-	log_printf(LOG_LEVEL_NOTICE, "got joinlist message from node %d\n",
+	log_printf(LOGSYS_LEVEL_NOTICE, "got joinlist message from node %d\n",
 		nodeid);
 
 	/* Ignore our own messages */
@@ -957,7 +957,7 @@ static int cpg_exec_send_joinlist(void)
 	struct join_list_entry *jle;
 	struct iovec req_exec_cpg_iovec;
 
-	log_printf(LOG_LEVEL_DEBUG, "sending joinlist to cluster\n");
+	log_printf(LOGSYS_LEVEL_DEBUG, "sending joinlist to cluster\n");
 
 	/* Count the number of groups we are a member of */
 	for (i=0; i<GROUP_HASH_SIZE; i++) {
@@ -978,7 +978,7 @@ static int cpg_exec_send_joinlist(void)
 
 	buf = alloca(sizeof(mar_res_header_t) + sizeof(struct join_list_entry) * count);
 	if (!buf) {
-		log_printf(LOG_LEVEL_WARNING, "Unable to allocate joinlist buffer");
+		log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate joinlist buffer");
 		return -1;
 	}
 
@@ -1016,7 +1016,7 @@ static int cpg_lib_init_fn (void *conn)
 	api->ipc_refcnt_inc (conn);
 	pi->conn = conn;
 
-	log_printf(LOG_LEVEL_DEBUG, "lib_init_fn: conn=%p, pi=%p\n", conn, pi);
+	log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p, pi=%p\n", conn, pi);
 	return (0);
 }
 
@@ -1029,7 +1029,7 @@ static void message_handler_req_lib_cpg_join (void *conn, const void *message)
 	struct group_info *gi;
 	cs_error_t error = CS_OK;
 
-	log_printf(LOG_LEVEL_DEBUG, "got join request on %p, pi=%p, pi->pid=%d\n", conn, pi, pi->pid);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got join request on %p, pi=%p, pi->pid=%d\n", conn, pi, pi->pid);
 
 	/* Already joined on this conn */
 	if (pi->pid) {
@@ -1067,7 +1067,7 @@ static void message_handler_req_lib_cpg_leave (void *conn, const void *message)
 	struct group_info *gi;
 	cs_error_t error = CS_OK;
 
-	log_printf(LOG_LEVEL_DEBUG, "got leave request on %p\n", conn);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got leave request on %p\n", conn);
 
 	if (!pi || !pi->pid || !pi->group) {
 		error = CS_ERR_INVALID_PARAM;
@@ -1100,7 +1100,7 @@ static void message_handler_req_lib_cpg_mcast (void *conn, const void *message)
 	int msglen = req_lib_cpg_mcast->msglen;
 	int result;
 
-	log_printf(LOG_LEVEL_DEBUG, "got mcast request on %p\n", conn);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got mcast request on %p\n", conn);
 
 	/* Can't send if we're not joined */
 	if (!gi) {
@@ -1142,7 +1142,7 @@ static void message_handler_req_lib_cpg_membership (void *conn,
 {
 	struct process_info *pi = (struct process_info *)api->ipc_private_data_get (conn);
 
-	log_printf(LOG_LEVEL_DEBUG, "got membership request on %p\n", conn);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got membership request on %p\n", conn);
 	if (!pi->group) {
 		mar_res_header_t res;
 		res.size = sizeof(res);
@@ -1165,7 +1165,7 @@ static void message_handler_req_lib_cpg_trackstart (void *conn,
 	struct process_info *otherpi;
 	cs_error_t error = CS_OK;
 
-	log_printf(LOG_LEVEL_DEBUG, "got trackstart request on %p\n", conn);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got trackstart request on %p\n", conn);
 
 	gi = get_group(&req_lib_cpg_trackstart->group_name);
 	if (!gi) {
@@ -1193,7 +1193,7 @@ static void message_handler_req_lib_cpg_trackstop (void *conn,
 	struct group_info *gi;
 	cs_error_t error = CS_OK;
 
-	log_printf(LOG_LEVEL_DEBUG, "got trackstop request on %p\n", conn);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got trackstop request on %p\n", conn);
 
 	gi = get_group(&req_lib_cpg_trackstop->group_name);
 	if (!gi) {

+ 2 - 2
services/evs.c

@@ -60,7 +60,7 @@
 #include <corosync/list.h>
 #include <corosync/engine/logsys.h>
 
-LOGSYS_DECLARE_SUBSYS ("EVS", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("EVS");
 
 enum evs_exec_message_req_types {
 	MESSAGE_REQ_EXEC_EVS_MCAST = 0
@@ -255,7 +255,7 @@ static int evs_lib_init_fn (void *conn)
 {
 	struct evs_pd *evs_pd = (struct evs_pd *)api->ipc_private_data_get (conn);
 
-	log_printf (LOG_LEVEL_DEBUG, "Got request to initalize evs service.\n");
+	log_printf (LOGSYS_LEVEL_DEBUG, "Got request to initalize evs service.\n");
 
 	evs_pd->groups = NULL;
 	evs_pd->group_entries = 0;

+ 1 - 1
services/pload.c

@@ -61,7 +61,7 @@
 #include <corosync/list.h>
 #include <corosync/engine/logsys.h>
 
-LOGSYS_DECLARE_SUBSYS ("PLOAD", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("PLOAD");
 
 enum pload_exec_message_req_types {
 	MESSAGE_REQ_EXEC_PLOAD_START = 0,

+ 2 - 2
services/testquorum.c

@@ -63,7 +63,7 @@
 
 #include <corosync/engine/quorum.h>
 
-LOGSYS_DECLARE_SUBSYS ("TEST", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("TEST");
 
 static void test_init(struct corosync_api_v1 *api, quorum_set_quorate_fn_t report);
 
@@ -123,7 +123,7 @@ static void key_change_notify(object_change_type_t change_type,
 
 static void quorum_callback(int quorate, void *context)
 {
-	log_printf(LOG_LEVEL_DEBUG, "quorum callback: quorate = %d\n", quorate);
+	log_printf(LOGSYS_LEVEL_DEBUG, "quorum callback: quorate = %d\n", quorate);
 }
 
 static void test_init(struct corosync_api_v1 *api,

+ 20 - 20
services/votequorum.c

@@ -76,7 +76,7 @@
 #define DEFAULT_QDEV_POLL 10000
 #define DEFAULT_LEAVE_TMO 10000
 
-LOGSYS_DECLARE_SUBSYS ("VOTEQ", LOG_INFO);
+LOGSYS_DECLARE_SUBSYS ("VOTEQ");
 
 enum quorum_message_req_types {
 	MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO  = 0,
@@ -501,7 +501,7 @@ static void read_quorum_config(unsigned int quorum_handle)
 	struct list_head *tmp;
 	struct cluster_node *node;
 
-	log_printf(LOG_INFO, "Reading configuration\n");
+	log_printf(LOGSYS_LEVEL_INFO, "Reading configuration\n");
 
 	objdb_get_int(corosync_api, quorum_handle, "expected_votes", &us->expected_votes, DEFAULT_EXPECTED);
 	objdb_get_int(corosync_api, quorum_handle, "votes", &us->votes, 1);
@@ -528,7 +528,7 @@ static void read_quorum_config(unsigned int quorum_handle)
         }
 
 	if (quorum_flags & VOTEQUORUM_FLAG_FEATURE_TWONODE && cluster_members > 2) {
-		log_printf(LOG_WARNING, "quorum.two_node was set but there are more than 2 nodes in the cluster. It will be ignored.");
+		log_printf(LOGSYS_LEVEL_WARNING, "quorum.two_node was set but there are more than 2 nodes in the cluster. It will be ignored.");
 		quorum_flags &= ~VOTEQUORUM_FLAG_FEATURE_TWONODE;
 	}
 }
@@ -656,7 +656,7 @@ static void send_expectedvotes_notification(void)
 	struct quorum_pd *qpd;
 	struct list_head *tmp;
 
-	log_printf(LOG_DEBUG, "Sending expected votes callback\n");
+	log_printf(LOGSYS_LEVEL_DEBUG, "Sending expected votes callback\n");
 
 	res_lib_votequorum_expectedvotes_notification.header.id = MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION;
 	res_lib_votequorum_expectedvotes_notification.header.size = sizeof(res_lib_votequorum_expectedvotes_notification);
@@ -684,9 +684,9 @@ static void set_quorate(int total_votes)
 	}
 
 	if (cluster_is_quorate && !quorate)
-		log_printf(LOG_INFO, "quorum lost, blocking activity\n");
+		log_printf(LOGSYS_LEVEL_INFO, "quorum lost, blocking activity\n");
 	if (!cluster_is_quorate && quorate)
-		log_printf(LOG_INFO, "quorum regained, resuming activity\n");
+		log_printf(LOGSYS_LEVEL_INFO, "quorum regained, resuming activity\n");
 
 	/* If we are newly quorate, then kill any DISALLOWED nodes */
 	if (!cluster_is_quorate && quorate) {
@@ -719,7 +719,7 @@ static int calculate_quorum(int allow_decrease, int max_expected, unsigned int *
 	list_iterate(nodelist, &cluster_members_list) {
 		node = list_entry(nodelist, struct cluster_node, list);
 
-		log_printf(LOG_DEBUG, "node %x state=%d, votes=%d, expected=%d\n",
+		log_printf(LOGSYS_LEVEL_DEBUG, "node %x state=%d, votes=%d, expected=%d\n",
 			   node->node_id, node->state, node->votes, node->expected_votes);
 
 		if (node->state == NODESTATE_MEMBER) {
@@ -786,7 +786,7 @@ static void recalculate_quorum(int allow_decrease, int by_current_nodes)
 	}
 
 	/* Keep expected_votes at the highest number of votes in the cluster */
-	log_printf(LOG_DEBUG, "total_votes=%d, expected_votes=%d\n", total_votes, us->expected_votes);
+	log_printf(LOGSYS_LEVEL_DEBUG, "total_votes=%d, expected_votes=%d\n", total_votes, us->expected_votes);
 	if (total_votes > us->expected_votes) {
 		us->expected_votes = total_votes;
 		send_expectedvotes_notification();
@@ -1045,7 +1045,7 @@ static void message_handler_req_exec_quorum_nodeinfo (
 	int new_node = 0;
 
 	ENTER();
-	log_printf(LOG_LEVEL_DEBUG, "got nodeinfo message from cluster node %d\n", nodeid);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got nodeinfo message from cluster node %d\n", nodeid);
 
 	node = find_node_by_nodeid(nodeid);
 	if (!node) {
@@ -1063,7 +1063,7 @@ static void message_handler_req_exec_quorum_nodeinfo (
 	 */
 	if (req_exec_quorum_nodeinfo->flags & NODE_FLAGS_SEESDISALLOWED && !have_disallowed()) {
 		/* Must use syslog directly here or the message will never arrive */
-		syslog(LOG_CRIT, "[VOTEQ]: Joined a cluster with disallowed nodes. must die");
+		syslog(LOGSYS_LEVEL_CRIT, "[VOTEQ]: Joined a cluster with disallowed nodes. must die");
 		corosync_api->fatal_error(2, __FILE__, __LINE__);
 		exit(2);
 	}
@@ -1083,12 +1083,12 @@ static void message_handler_req_exec_quorum_nodeinfo (
 		    (req_exec_quorum_nodeinfo->flags & NODE_FLAGS_HASSTATE && req_exec_quorum_nodeinfo->first_trans && !(node->flags & NODE_FLAGS_US) && (us->flags & NODE_FLAGS_HASSTATE))) {
 			if (node->state != NODESTATE_DISALLOWED) {
 				if (cluster_is_quorate) {
-					log_printf(LOG_CRIT, "Killing node %d because it has rejoined the cluster with existing state", node->node_id);
+					log_printf(LOGSYS_LEVEL_CRIT, "Killing node %d because it has rejoined the cluster with existing state", node->node_id);
 					node->state = NODESTATE_DISALLOWED;
 					quorum_exec_send_killnode(nodeid, VOTEQUORUM_REASON_KILL_REJOIN);
 				}
 				else {
-					log_printf(LOG_CRIT, "Node %d not joined to quorum because it has existing state", node->node_id);
+					log_printf(LOGSYS_LEVEL_CRIT, "Node %d not joined to quorum because it has existing state", node->node_id);
 					node->state = NODESTATE_DISALLOWED;
 				}
 			}
@@ -1108,7 +1108,7 @@ static void message_handler_req_exec_quorum_killnode (
 	const struct req_exec_quorum_killnode *req_exec_quorum_killnode = message;
 
 	if (req_exec_quorum_killnode->nodeid == corosync_api->totem_nodeid_get()) {
-		log_printf(LOG_CRIT, "Killed by node %d: %s\n", nodeid, kill_reason(req_exec_quorum_killnode->reason));
+		log_printf(LOGSYS_LEVEL_CRIT, "Killed by node %d: %s\n", nodeid, kill_reason(req_exec_quorum_killnode->reason));
 
 		corosync_api->fatal_error(1, __FILE__, __LINE__);
 		exit(1);
@@ -1123,7 +1123,7 @@ static void message_handler_req_exec_quorum_reconfigure (
 	struct cluster_node *node;
 	struct list_head *nodelist;
 
-	log_printf(LOG_LEVEL_DEBUG, "got reconfigure message from cluster node %d\n", nodeid);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got reconfigure message from cluster node %d\n", nodeid);
 
 	node = find_node_by_nodeid(req_exec_quorum_reconfigure->nodeid);
 	if (!node)
@@ -1196,7 +1196,7 @@ static void message_handler_req_lib_votequorum_getinfo (void *conn, const void *
 	unsigned int total_votes = 0;
 	cs_error_t error = CS_OK;
 
-	log_printf(LOG_LEVEL_DEBUG, "got getinfo request on %p for node %d\n", conn, req_lib_votequorum_getinfo->nodeid);
+	log_printf(LOGSYS_LEVEL_DEBUG, "got getinfo request on %p for node %d\n", conn, req_lib_votequorum_getinfo->nodeid);
 
 	if (req_lib_votequorum_getinfo->nodeid) {
 		node = find_node_by_nodeid(req_lib_votequorum_getinfo->nodeid);
@@ -1249,7 +1249,7 @@ static void message_handler_req_lib_votequorum_getinfo (void *conn, const void *
 	res_lib_votequorum_getinfo.header.id = MESSAGE_RES_VOTEQUORUM_GETINFO;
 	res_lib_votequorum_getinfo.header.error = error;
 	corosync_api->ipc_response_send(conn, &res_lib_votequorum_getinfo, sizeof(res_lib_votequorum_getinfo));
-	log_printf(LOG_LEVEL_DEBUG, "getinfo response error: %d\n", error);
+	log_printf(LOGSYS_LEVEL_DEBUG, "getinfo response error: %d\n", error);
 }
 
 /* Message from the library */
@@ -1375,7 +1375,7 @@ static void quorum_device_timer_fn(void *arg)
 	gettimeofday(&now, NULL);
 	if (quorum_device->last_hello.tv_sec + quorumdev_poll/1000 < now.tv_sec) {
 		quorum_device->state = NODESTATE_DEAD;
-		log_printf(LOG_INFO, "lost contact with quorum device\n");
+		log_printf(LOGSYS_LEVEL_INFO, "lost contact with quorum device\n");
 		recalculate_quorum(0, 0);
 	}
 	else {
@@ -1494,7 +1494,7 @@ static void message_handler_req_lib_votequorum_qdisk_getinfo (void *conn,
 	ENTER();
 
 	if (quorum_device) {
-		log_printf(LOG_LEVEL_DEBUG, "got qdisk_getinfo state %d\n", quorum_device->state);
+		log_printf(LOGSYS_LEVEL_DEBUG, "got qdisk_getinfo state %d\n", quorum_device->state);
 		res_lib_votequorum_qdisk_getinfo.votes = quorum_device->votes;
 		if (quorum_device->state == NODESTATE_MEMBER)
 			res_lib_votequorum_qdisk_getinfo.state = 1;
@@ -1549,7 +1549,7 @@ static void message_handler_req_lib_votequorum_trackstart (void *conn,
 	 */
 	if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CURRENT ||
 	    req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES) {
-		log_printf(LOG_LEVEL_DEBUG, "sending initial status to %p\n", conn);
+		log_printf(LOGSYS_LEVEL_DEBUG, "sending initial status to %p\n", conn);
 		send_quorum_notification(conn, req_lib_votequorum_trackstart->context);
 	}
 
@@ -1695,7 +1695,7 @@ static void votequorum_objdb_reload_notify(
 			reread_config(object_handle);
 		}
 		else {
-			log_printf(LOG_LEVEL_ERROR, "votequorum objdb tracking stopped, cannot find quorum{} handle in objdb\n");
+			log_printf(LOGSYS_LEVEL_ERROR, "votequorum objdb tracking stopped, cannot find quorum{} handle in objdb\n");
 		}
 	}
 }

+ 9 - 4
test/Makefile.am

@@ -34,7 +34,8 @@ MAINTAINERCLEANFILES    = Makefile.in
 INCLUDES       		= -I$(top_builddir)/include -I$(top_srcdir)/include
 
 noinst_PROGRAMS		= testevs evsbench evsverify testcpg testcpg2 cpgbench testconfdb	\
-			logsysbench logsysrec testquorum testvotequorum1 testvotequorum2
+			logsysbench logsysrec testquorum testvotequorum1 testvotequorum2	\
+			logsys_s logsys_t1 logsys_t2
 
 testevs_LDADD		= -levs
 testevs_LDFLAGS		= -L../lib
@@ -60,9 +61,13 @@ logsysbench_LDADD	= -llogsys
 logsysbench_LDFLAGS	= -L../exec
 logsysrec_LDADD		= -llogsys
 logsysrec_LDFLAGS	= -L../exec
+logsys_s_SOURCES	= logsys_s.c logsys_s1.c logsys_s2.c
+logsys_s_LDADD		= -llogsys
+logsys_s_LDFLAGS	= -L../exec
+logsys_t1_LDADD		= -llogsys
+logsys_t1_LDFLAGS	= -L../exec
+logsys_t2_LDADD		= -llogsys
+logsys_t2_LDFLAGS	= -L../exec
 
 lint:
 	-splint $(LINT_FLAGS) $(CFLAGS) *.c
-
-
-

+ 10 - 4
test/logsys_s.c

@@ -36,19 +36,25 @@
 
 #include <stdio.h>
 #include <syslog.h>
-#include "../exec/logsys.h"
+
+#include <corosync/engine/logsys.h>
 
 LOGSYS_DECLARE_SYSTEM ("logsystestsubsystems",
-	LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED, 
+	LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_OUTPUT_SYSLOG,
+	0,
 	NULL,
+	LOGSYS_LEVEL_INFO,
 	LOG_DAEMON,
-	"[%8s] %b",
-	100000);
+	LOGSYS_LEVEL_INFO,
+	0,
+	NULL,
+	1000000);
 
 extern void logsys_s1_print (void);
 extern void logsys_s2_print (void);
 
 int main (void) {
+	logsys_fork_completed();
 	logsys_s1_print();
 	logsys_s2_print();
 	return (0);

+ 7 - 4
test/logsys_s1.c

@@ -36,11 +36,14 @@
 
 #include <stdio.h>
 #include <syslog.h>
-#include "../exec/logsys.h"
 
-LOGSYS_DECLARE_SUBSYS ("SYS1", LOG_ALERT)
+#include <corosync/engine/logsys.h>
+
+void logsys_s1_print (void);
+
+LOGSYS_DECLARE_SUBSYS ("SYS1");
 
 void logsys_s1_print (void) {
-	log_printf (LOG_ALERT, "This is an alert log message\n");
-	log_printf (LOG_WARNING, "This is a warning log message\n");
+	log_printf (LOGSYS_LEVEL_ALERT, "This is an alert log message\n");
+	log_printf (LOGSYS_LEVEL_WARNING, "This is a warning log message\n");
 }

+ 9 - 5
test/logsys_s2.c

@@ -36,12 +36,16 @@
 
 #include <stdio.h>
 #include <syslog.h>
-#include "../exec/logsys.h"
 
-LOGSYS_DECLARE_SUBSYS ("SYS2", LOG_DEBUG)
+#include <corosync/engine/logsys.h>
+
+void logsys_s2_print (void);
+
+LOGSYS_DECLARE_SUBSYS ("SYS2");
 
 void logsys_s2_print (void) {
-	log_printf (LOG_ALERT, "This is an alert log message\n");
-	log_printf (LOG_WARNING, "This is a warning log message\n");
-	log_printf (LOG_DEBUG, "This is a debug log message\n");
+	logsys_config_logfile_priority_set("SYS2", LOGSYS_LEVEL_DEBUG);
+	log_printf (LOGSYS_LEVEL_ALERT, "This is an alert log message\n");
+	log_printf (LOGSYS_LEVEL_WARNING, "This is a warning log message\n");
+	log_printf (LOGSYS_LEVEL_DEBUG, "This is a debug log message\n");
 }

+ 12 - 9
test/logsys_t1.c

@@ -36,20 +36,23 @@
 
 #include <stdio.h>
 #include <syslog.h>
-#include "../exec/logsys.h"
+
+#include <corosync/engine/logsys.h>
 
 LOGSYS_DECLARE_SYSTEM ("logsystestNOsubsystems",
-	LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED, 
+	LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_OUTPUT_SYSLOG, 
+	0,
 	NULL,
+	LOGSYS_LEVEL_DEBUG,
 	LOG_DAEMON,
-	"%6s %b",
-	100000);
-
-LOGSYS_DECLARE_NOSUBSYS(LOG_LEVEL_DEBUG);
+	LOGSYS_LEVEL_DEBUG,
+	0,
+	NULL,
+	1000000);
 
 int main (void) {
-	log_printf (LOG_ALERT, "This is an alert log message\n");
-	log_printf (LOG_WARNING, "This is a warning log message\n");
-	log_printf (LOG_DEBUG, "This is a debug log message\n");
+	log_printf (LOGSYS_LEVEL_ALERT, "This is an alert log message\n");
+	log_printf (LOGSYS_LEVEL_WARNING, "This is a warning log message\n");
+	log_printf (LOGSYS_LEVEL_DEBUG, "This is a debug log message\n");
 	return (0);
 }

+ 22 - 19
test/logsys_t2.c

@@ -36,16 +36,19 @@
 
 #include <stdio.h>
 #include <stdint.h>
-#include "../exec/logsys.h"
+
+#include <corosync/engine/logsys.h>
 
 LOGSYS_DECLARE_SYSTEM ("logtest_t2",
-	LOG_MODE_OUTPUT_STDERR | LOG_MODE_THREADED,
+	LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_THREADED,
+	0,
 	NULL,
+	LOGSYS_LEVEL_INFO,
 	LOG_DAEMON,
+	LOGSYS_LEVEL_INFO,
+	0,
 	NULL,
-	100000);
-
-LOGSYS_DECLARE_NOSUBSYS(LOG_LEVEL_INFO);
+	1000000);
 
 int
 main(int argc, char **argv)
@@ -53,29 +56,29 @@ main(int argc, char **argv)
 	/*
 	 * fork could occur here and the file to output to could be set
 	 */
-	logsys_config_mode_set (LOG_MODE_OUTPUT_STDERR | LOG_MODE_THREADED);
+	logsys_config_mode_set (NULL, LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_THREADED);
 
-	log_printf(LOG_NOTICE, "Hello, world!\n");
-	log_printf(LOG_DEBUG, "If you see this, the logger's busted\n");
+	log_printf(LOGSYS_LEVEL_NOTICE, "Hello, world!\n");
+	log_printf(LOGSYS_LEVEL_DEBUG, "If you see this, the logger's busted\n");
 
-	logsys_config_priority_set (LOG_ALERT);
+	logsys_config_logfile_priority_set (NULL, LOGSYS_LEVEL_ALERT);
 
-	log_printf(LOG_DEBUG, "If you see this, the logger's busted\n");
-	log_printf(LOG_CRIT, "If you see this, the logger's busted\n");
-	log_printf(LOG_ALERT, "Alert 1\n");
+	log_printf(LOGSYS_LEVEL_DEBUG, "If you see this, the logger's busted\n");
+	log_printf(LOGSYS_LEVEL_CRIT, "If you see this, the logger's busted\n");
+	log_printf(LOGSYS_LEVEL_ALERT, "Alert 1\n");
 
-	logsys_config_priority_set (LOG_NOTICE);
+	logsys_config_logfile_priority_set (NULL, LOGSYS_LEVEL_NOTICE);
 
-	log_printf(LOG_CRIT, "Crit 1\n");
-	log_printf(LOG_INFO, "If you see this, the logger's busted\n");
+	log_printf(LOGSYS_LEVEL_CRIT, "Crit 1\n");
+	log_printf(LOGSYS_LEVEL_INFO, "If you see this, the logger's busted\n");
 
-	logsys_config_priority_set (LOG_DEBUG);
+	logsys_config_logfile_priority_set (NULL, LOGSYS_LEVEL_DEBUG);
 
-	log_printf(LOG_DEBUG, "Debug 1\n");
+	log_printf(LOGSYS_LEVEL_DEBUG, "Debug 1\n");
 
-	logsys_config_mode_set (LOG_MODE_OUTPUT_STDERR);
+	logsys_config_mode_set (NULL, LOGSYS_MODE_OUTPUT_STDERR);
 
-	log_printf(LOG_DEBUG, "Debug 2\n");
+	log_printf(LOGSYS_LEVEL_DEBUG, "Debug 2\n");
 
 	return 0;
 }

+ 15 - 13
test/logsysbench.c

@@ -42,13 +42,15 @@
 #include <corosync/engine/logsys.h>
 
 LOGSYS_DECLARE_SYSTEM ("logtest_rec",
-	LOG_MODE_OUTPUT_STDERR | LOG_MODE_THREADED,
+	LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_THREADED,
+	0,                /* debug */
 	NULL,
-	LOG_DAEMON,
-	NULL,
-	100000);
-
-LOGSYS_DECLARE_NOSUBSYS(LOG_LEVEL_INFO);
+	LOGSYS_LEVEL_INFO,   /* logfile_priority */
+	LOG_DAEMON,       /* syslog facility */
+	LOGSYS_LEVEL_INFO,   /* syslog level */
+	0,                /* tags */
+	NULL,             /* use default format */
+	1000000);         /* flight recorder size */
 
 #define LOGREC_ID_CHECKPOINT_CREATE 2
 #define LOGREC_ARGS_CHECKPOINT_CREATE 2
@@ -94,35 +96,35 @@ int main (void)
 	printf ("heating up cache with logrec functionality\n");
 	for (i = 0; i < ITERATIONS; i++) {
 	log_rec (LOGREC_ID_CHECKPOINT_CREATE,
-		"recordA", 8, "recordB", 8, LOG_REC_END);
+		"recordA", 8, "recordB", 8, LOGSYS_REC_END);
 	}
 	bm_start();
 	for (i = 0; i < ITERATIONS; i++) {
 	log_rec (LOGREC_ID_CHECKPOINT_CREATE,
-		buffer, 7, LOG_REC_END);
+		buffer, 7, LOGSYS_REC_END);
 	}
 	bm_finish ("log_rec 1 arguments:");
 	bm_start();
 	for (i = 0; i < ITERATIONS; i++) {
 	log_rec (LOGREC_ID_CHECKPOINT_CREATE,
-		"recordA", 8, LOG_REC_END);
+		"recordA", 8, LOGSYS_REC_END);
 	}
 	bm_finish ("log_rec 2 arguments:");
 	bm_start();
 	for (i = 0; i < 10; i++) {
 	log_rec (LOGREC_ID_CHECKPOINT_CREATE,
-		"recordA", 8, "recordB", 8, LOG_REC_END);
+		"recordA", 8, "recordB", 8, LOGSYS_REC_END);
 	}
 	bm_start();
 	for (i = 0; i < ITERATIONS; i++) {
 	log_rec (LOGREC_ID_CHECKPOINT_CREATE,
-		"recordA", 8, "recordB", 8, "recordC", 8, LOG_REC_END);
+		"recordA", 8, "recordB", 8, "recordC", 8, LOGSYS_REC_END);
 	}
 	bm_finish ("log_rec 3 arguments:");
 	bm_start();
 	for (i = 0; i < ITERATIONS; i++) {
 	log_rec (LOGREC_ID_CHECKPOINT_CREATE,
-		"recordA", 8, "recordB", 8, "recordC", 8, "recordD", 8, LOG_REC_END);
+		"recordA", 8, "recordB", 8, "recordC", 8, "recordD", 8, LOGSYS_REC_END);
 	}
 	bm_finish ("log_rec 4 arguments:");
 
@@ -165,7 +167,7 @@ int main (void)
 
 	bm_start();
 	for (i = 0; i < ITERATIONS; i++) {
-	log_printf (LOG_LEVEL_NOTICE, "test %d", i);
+	log_printf (LOGSYS_LEVEL_NOTICE, "test %d", i);
 	}
 	bm_finish("log_printf");
 */

+ 7 - 5
test/logsysrec.c

@@ -39,14 +39,16 @@
 #include <corosync/engine/logsys.h>
 
 LOGSYS_DECLARE_SYSTEM ("logtest_rec",
-	LOG_MODE_OUTPUT_STDERR | LOG_MODE_THREADED,
+	LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_THREADED,
+	0,
 	NULL,
+	LOG_INFO,
 	LOG_DAEMON,
+	LOG_INFO,
+	0,
 	NULL,
 	100000);
 
-LOGSYS_DECLARE_NOSUBSYS(LOG_LEVEL_INFO);
-
 #define LOGREC_ID_CHECKPOINT_CREATE 2
 #define LOGREC_ARGS_CHECKPOINT_CREATE 2
 
@@ -55,9 +57,9 @@ int main(int argc, char **argv)
 	int i;
 
 	for (i = 0; i < 10; i++) {
-		log_printf (LOG_LEVEL_NOTICE, "This is a test of %s\n", "stringparse");
+		log_printf (LOGSYS_LEVEL_NOTICE, "This is a test of %s\n", "stringparse");
 
-		log_rec (LOGREC_ID_CHECKPOINT_CREATE, "record1", 8, "record22", 9, "record333", 10, "record444", 11, LOG_REC_END);
+		log_rec (LOGREC_ID_CHECKPOINT_CREATE, "record1", 8, "record22", 9, "record333", 10, "record444", 11, LOGSYS_REC_END);
 	}
 	logsys_log_rec_store ("fdata");