From 1e1bda15377a133e9a91e6f99d13e02bf4469269 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Thu, 7 Feb 2019 13:57:21 +0530 Subject: [PATCH 518/529] 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. Upstream fix: >> URL: https://review.gluster.org/21536 BUG: 1570958 Change-Id: I6efaffd1e7e8aee350afcf2ca354b27747ff5e50 Signed-off-by: Amar Tumballi Reviewed-on: https://code.engineering.redhat.com/gerrit/162470 Tested-by: RHGS Build Bot Reviewed-by: Sunil Kumar Heggodu Gopala Acharya --- libglusterfs/src/logging.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index 0f238d0..631bc98 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -758,6 +758,26 @@ gf_log_init (void *data, const char *file, const char *ident) goto out; } + /* 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, _gf_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, "ERROR: updating log-filename failed: %s\n", -- 1.8.3.1