Hi Steven,

the patch in attachment enables fileline option for logsys in
mainconfig.c.

We also make some other clean ups to keep the code simpler and be able
to add new functions in time.

- add a prepend_to_buffer generic function so we don't have to repeat
the same all over everytime we add a new config option.

- enable fileline of course to prepend "%l"

- reset the logsys_format on reload. We don't allow custom settings from
corosync and performing a reset at reload to clear the options and set
them again according to the new config is the simplest way to avoid a
lot of useless complexity.

- we also make new_format_buffer more global within the same function
rather than in the timestamp check section so it can be reused for
fileline too.

Fabio
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, "%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);
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to