This is the mail archive of the
cluster-cvs@sourceware.org
mailing list for the cluster.
cluster: STABLE3 - logt: don't hold fd open when not required
- From: "Fabio M. Di Nitto" <fabbione at fedoraproject dot org>
- To: cluster-cvs-relay at redhat dot com
- Date: Tue, 27 Jan 2009 06:32:32 +0000 (UTC)
- Subject: cluster: STABLE3 - logt: don't hold fd open when not required
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=4bed7542f545c81d41e7dd7193fa6d3a8de3ad89
Commit: 4bed7542f545c81d41e7dd7193fa6d3a8de3ad89
Parent: ddb861cb47be92b89f3b853bf0dcce26bddeaf96
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:07:18 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;