cluster: master - logt: don't hold fd open when not required

Fabio M. Di Nitto fabbione@fedoraproject.org
Tue Jan 27 06:32:00 GMT 2009


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=88ea8eac58662f32b22b011f80eaca2636a036c0
Commit:        88ea8eac58662f32b22b011f80eaca2636a036c0
Parent:        40f37f5d04fb741fb1e6bfc7792f41afa23e7b9a
Author:        Fabio M. Di Nitto <fdinitto@redhat.com>
AuthorDate:    Tue Jan 27 07:07:18 2009 +0100
Committer:     Fabio M. Di Nitto <fdinitto@redhat.com>
CommitterDate: Tue Jan 27 07:32:11 2009 +0100

logt: don't hold fd open when not required

fix corner case where we hold an fd open over a logfile
and we are not logging to file.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
 common/liblogthread/liblogthread.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/common/liblogthread/liblogthread.c b/common/liblogthread/liblogthread.c
index d0b28ad..9254a37 100644
--- a/common/liblogthread/liblogthread.c
+++ b/common/liblogthread/liblogthread.c
@@ -170,13 +170,20 @@ static void _conf(char *name, int mode, int syslog_facility,
 		strncpy(logt_logfile, logfile, PATH_MAX);
 
 	if (logt_mode & LOG_MODE_OUTPUT_FILE && logt_logfile[0]) {
-		if (logt_logfile_fp)
+		if (logt_logfile_fp) {
 			fclose(logt_logfile_fp);
+			logt_logfile_fp = NULL;
+		}
 		logt_logfile_fp = fopen(logt_logfile, "a+");
 		if (logt_logfile_fp != NULL) {
 			fd = fileno(logt_logfile_fp);
 			fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
 		}
+	} else {
+		if (logt_logfile_fp) {
+			fclose(logt_logfile_fp);
+			logt_logfile_fp = NULL;
+		}
 	}
 
 	if (logt_mode & LOG_MODE_OUTPUT_SYSLOG) {
@@ -265,9 +272,10 @@ void logt_exit(void)
 	pthread_mutex_lock(&mutex);
 	/* close syslog + log file */
 	closelog();
-	if (logt_logfile_fp)
+	if (logt_logfile_fp) {
 		fclose(logt_logfile_fp);
-	logt_logfile_fp = NULL;
+		logt_logfile_fp = NULL;
+	}
 
 	/* clean up any pending log messages */
 	dropped = 0;



More information about the Cluster-cvs mailing list