Re: [PATCH] Log: Make reload of logging work

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ACK,

While you're in there, can you fix the spelling of 'lenght' on line 172 too please :-)

Chrissie

On 24/03/14 16:42, Jan Friesse wrote:
When reload was called multiple times (~20), logging to file stopped
working.

Main problem was hidden in the fact, that log file was opened multiple
times, because even target_id was shared via subsystem loggers, file
name was not.

Solution is to ALWAYS set proper log file name into subsystem logger
(copy is stored). This will not only fix problem but also removes small
leak.

Also if filename didn't changed, function can return sooner.

Signed-off-by: Jan Friesse <jfriesse@xxxxxxxxxx>
---
  exec/logsys.c |   31 ++++++++++++++++++++++---------
  1 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/exec/logsys.c b/exec/logsys.c
index 45f1b06..437f1c6 100644
--- a/exec/logsys.c
+++ b/exec/logsys.c
@@ -166,6 +166,12 @@ static int logsys_config_file_set_unlocked (
  		return (0);
  	}

+	if (logsys_loggers[subsysid].target_id > 0 &&
+	    logsys_loggers[subsysid].logfile != NULL &&
+	    strcmp(file, logsys_loggers[subsysid].logfile) == 0) {
+		return (0);
+	}
+
  	if (strlen(file) >= PATH_MAX) {
  		snprintf (error_string_response,
  			sizeof(error_string_response),
@@ -175,6 +181,22 @@ static int logsys_config_file_set_unlocked (
  		return (-1);
  	}

+	if (logsys_loggers[subsysid].logfile != NULL) {
+		free(logsys_loggers[subsysid].logfile);
+		logsys_loggers[subsysid].logfile = NULL;
+	}
+
+	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'",
+			file);
+		*error_string = error_string_response;
+		return (-1);
+	}
+
  	for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
  		if ((logsys_loggers[i].logfile != NULL) &&
  		    (strcmp (logsys_loggers[i].logfile, file) == 0) &&
@@ -186,15 +208,6 @@ static int logsys_config_file_set_unlocked (
  			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'",
-			file);
-		*error_string = error_string_response;
-		return (-1);
-	}

  	if (logsys_loggers[subsysid].target_id > 0) {
  		int num_using_current = 0;


_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss




[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux