Jelajahi Sumber

Log: Make reload of logging work

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@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 12 tahun lalu
induk
melakukan
1b6abcc7d5
1 mengubah file dengan 23 tambahan dan 10 penghapusan
  1. 23 10
      exec/logsys.c

+ 23 - 10
exec/logsys.c

@@ -166,15 +166,37 @@ 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),
-			"%s: logfile name exceed maximum system filename lenght",
+			"%s: logfile name exceed maximum system filename length",
 			logsys_loggers[subsysid].subsys);
 		*error_string = error_string_response;
 		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;