From d2b745319334a1025b9e47f55928033b8d1c7c46 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Fri, 2 Nov 2018 10:39:18 +0530 Subject: logging: create parent dir if not available As glusterfs logging uses different directory than /var/log (ie, /var/log/glusterfs), there is a chance it may not be present when starting glusterfs. Create parent dir if it doesn't exist. Updates: bz#1193929 Change-Id: I8d6f7e5a608ba53258b14617f5d103d1e98b95c1 Signed-off-by: Amar Tumballi --- libglusterfs/src/logging.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'libglusterfs') diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index 8fffd4174fa..b1a167f7997 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -751,6 +751,26 @@ gf_log_init(void *data, const char *file, const char *ident) return -1; } } else { + /* Also create parent dir */ + char *logdir = gf_strdup(file); + if (!logdir) { + return -1; + } + char *tmp_index = rindex(logdir, '/'); + if (tmp_index) { + tmp_index[0] = '\0'; + } + if (mkdir_p(logdir, 0755, true)) { + /* EEXIST is handled in mkdir_p() itself */ + gf_msg("logging", GF_LOG_ERROR, 0, LG_MSG_STRDUP_ERROR, + "failed to create metrics dir %s (%s)", logdir, + strerror(errno)); + GF_FREE(logdir); + return -1; + } + /* no need of this variable */ + GF_FREE(logdir); + ctx->log.filename = gf_strdup(file); if (!ctx->log.filename) { fprintf(stderr, -- cgit