summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
authorPoornima G <pgurusid@redhat.com>2013-12-23 05:11:15 +0000
committerVijay Bellur <vbellur@redhat.com>2013-12-26 03:16:30 -0800
commit0d7279d32d5f55c0210bdcfda2d3f83e35f524b6 (patch)
treea61c51916b467918de7860b74d4029d517b613ea /libglusterfs/src
parent2ba42d07eb967472227eb0a93e4ca2cac7a197b5 (diff)
gfapi: Closed the logfile fd and initialize to NULL in glfs_fini
Currently if logfile is closed and other threads call gf_log after glfs_fini() is executed, it may lead to memory corruption. Adding gf_log_fini() which closes the logfile and initializes the logfile to NULL, thus any further logging happens to stderr. Also added gf_log_globals_fini() which should be filled in the future to release all the logging resources. Change-Id: I879163e1a3636e65300d166f782517ee773cab65 BUG: 1030228 Signed-off-by: Poornima G <pgurusid@redhat.com> Reviewed-on: http://review.gluster.org/6552 Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com> Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/logging.c35
-rw-r--r--libglusterfs/src/logging.h2
2 files changed, 36 insertions, 1 deletions
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c
index e3a4a9fde..0058233a7 100644
--- a/libglusterfs/src/logging.c
+++ b/libglusterfs/src/logging.c
@@ -108,11 +108,44 @@ gf_log_set_xl_loglevel (void *this, gf_loglevel_t level)
}
void
-gf_log_fini (void)
+gf_log_globals_fini (void)
{
pthread_mutex_destroy (&THIS->ctx->log.logfile_mutex);
}
+/** gf_log_fini - function to perform the cleanup of the log information
+ * @data - glusterfs context
+ * @return: success: 0
+ * failure: -1
+ */
+int
+gf_log_fini (void *data)
+{
+ glusterfs_ctx_t *ctx = data;
+ int ret = 0;
+
+ if (ctx == NULL) {
+ ret = -1;
+ goto out;
+ }
+
+ pthread_mutex_lock (&ctx->log.logfile_mutex);
+ {
+ if (ctx->log.logfile) {
+ if (fclose (ctx->log.logfile) != 0)
+ ret = -1;
+ /* Logfile needs to be set to NULL, so that any
+ call to gf_log after calling gf_log_fini, will
+ log the message to stderr.
+ */
+ ctx->log.logfile = NULL;
+ }
+ }
+ pthread_mutex_unlock (&ctx->log.logfile_mutex);
+
+ out:
+ return ret;
+}
#ifdef GF_USE_SYSLOG
/**
diff --git a/libglusterfs/src/logging.h b/libglusterfs/src/logging.h
index cc806a767..e2b7e664d 100644
--- a/libglusterfs/src/logging.h
+++ b/libglusterfs/src/logging.h
@@ -153,6 +153,8 @@ int gf_cmd_log_init (const char *filename);
void set_sys_log_level (gf_loglevel_t level);
+int gf_log_fini(void *data);
+
#define GF_DEBUG(xl, format, args...) \
gf_log ((xl)->name, GF_LOG_DEBUG, format, ##args)
#define GF_INFO(xl, format, args...) \