doesn't matter to me.. new patch in attachment.

I kept the argument documentation there so it's easier to read.

Fabio

On Tue, 2009-03-31 at 22:59 -0700, Steven Dake wrote:
> can't we make log_printf_to_logs take arguments in the order they are
> stored in the buffer instead of changing the passed argument order?
> 
> Regards
> -steve
> 
> On Wed, 2009-04-01 at 07:54 +0200, Fabio M. Di Nitto wrote:
> > Hi Steven,
> > 
> > the patch adds filename support to logsys_format_set.
> > 
> > While testing, I noticed that filename and function name were swapped in
> > the output (basically %n was behaving as %f and viceversa).
> > 
> > Tracked down to that invalid usage of the API at the bottom of the
> > patch.
> > 
> > Fabio
> > _______________________________________________
> > Openais mailing list
> > [email protected]
> > https://lists.linux-foundation.org/mailman/listinfo/openais
> 
Index: exec/mainconfig.c
===================================================================
--- exec/mainconfig.c	(revision 1974)
+++ exec/mainconfig.c	(working copy)
@@ -105,6 +105,17 @@
 	}
 }
 
+static void prepend_to_buffer(char *target_buffer, const char *entry)
+{
+	char *current_format = NULL;
+
+	current_format = logsys_format_get();
+
+	if (!strstr(current_format, entry)) {
+		snprintf(target_buffer, PATH_MAX - 1, "%s %s", entry, current_format);
+	}
+}
+
 static struct logsys_config_struct {
 	char subsys[6];
 	unsigned int priority;
@@ -122,6 +133,7 @@
 	const char *error_reason = error_string_response;
 	hdb_handle_t object_find_handle;
 	hdb_handle_t object_find_logsys_handle;
+	char new_format_buffer[PATH_MAX];
 
 	objdb->object_find_create (
 		OBJECT_PARENT_HANDLE,
@@ -158,20 +170,28 @@
 				main_config->logmode &= ~LOG_MODE_OUTPUT_STDERR;
 			}
 		}
+		if (!objdb_get_string (objdb,object_service_handle, "fileline", &value)) {
+			memset(&new_format_buffer, 0, sizeof(new_format_buffer));
+
+			if (strcmp (value, "on") == 0) {
+				prepend_to_buffer(new_format_buffer, "%f:%n:%l");
+				logsys_format_set(new_format_buffer);
+			} else
+			if (strcmp (value, "off") == 0) {
+				/* nothing to do here */
+			} else {
+				goto parse_error;
+			}
+		}
 		if (!objdb_get_string (objdb,object_service_handle, "timestamp", &value)) {
-			char new_format_buffer[PATH_MAX];
-
 			memset(&new_format_buffer, 0, sizeof(new_format_buffer));
 
 			if (strcmp (value, "on") == 0) {
-				snprintf(new_format_buffer, PATH_MAX-1, "%%t %s", logsys_format_get());
+				prepend_to_buffer(new_format_buffer, "%t");
 				logsys_format_set(new_format_buffer);
 			} else
 			if (strcmp (value, "off") == 0) {
-				if (!strncmp("%t ", logsys_format_get(), 3)) {
-					snprintf(new_format_buffer, PATH_MAX-1, "%s", logsys_format_get() + 3);
-					logsys_format_set(new_format_buffer);
-				}
+				/* nothing to do here */
 			} else {
 				goto parse_error;
 			}
@@ -186,19 +206,6 @@
 			main_config->logfile = strdup (value);
 		}
 
-		if (!objdb_get_string (objdb,object_service_handle, "fileline", &value)) {
-/* TODO
-			if (strcmp (value, "on") == 0) {
-				main_config->logmode |= LOG_MODE_DISPLAY_FILELINE;
-			} else
-			if (strcmp (value, "off") == 0) {
-				main_config->logmode &= ~LOG_MODE_DISPLAY_FILELINE;
-			} else {
-				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) {
@@ -392,6 +399,7 @@
 		/*
 		 * Reload the logsys configuration
 		 */
+		logsys_format_set(NULL);
 		corosync_main_config_read_logging(global_objdb,
 						  &error_string,
 						  main_config);
Index: exec/logsys.c
===================================================================
--- exec/logsys.c	(revision 1975)
+++ exec/logsys.c	(working copy)
@@ -308,8 +308,8 @@
 */
 static void log_printf_to_logs (
 	const char *subsys,
+	const char *file_name,
 	const char *function_name,
-	const char *file_name,
 	int file_line,
 	unsigned int level,
 	char *buffer)
@@ -365,6 +365,10 @@
 					len = strcpy_cutoff (&output_buffer[output_buffer_idx], buffer, cutoff);
 					output_buffer_idx += len;
 					break;
+				case 'f':
+					len = strcpy_cutoff (&output_buffer[output_buffer_idx], file_name, cutoff);
+					output_buffer_idx += len;
+					break;
 			}
 			format_buffer_idx += 1;
 		} else {
@@ -430,6 +434,14 @@
 		arg_size_idx += buf_uint32t[arg_size_idx] + 1;
 		words_processed += buf_uint32t[arg_size_idx] + 1;
 	}
+
+	/*
+	 * (char *)arguments[0] -> subsystem
+	 * (char *)arguments[1] -> file_name
+	 * (char *)arguments[2] -> function_name
+	 * (char *)arguments[3] -> message
+	 */
+
 	log_printf_to_logs (
 		(char *)arguments[0],
 		(char *)arguments[1],
@@ -839,7 +851,7 @@
 		 * expect the worker thread to output the log data once signaled
 		 */
 		log_printf_to_logs (logsys_loggers[subsys].subsys,
-			function_name, file_name, file_line, level,
+			file_name, function_name, file_line, level,
 			logsys_print_buffer);
 	} else {
 		/*
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to