summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmar Tumballi <amarts@redhat.com>2018-11-02 10:39:18 +0530
committerAmar Tumballi <amarts@redhat.com>2018-11-06 04:17:42 +0000
commitd2b745319334a1025b9e47f55928033b8d1c7c46 (patch)
tree65863080ce28289800b1d373f4dd1ed8c00002d5
parent3c6cf9a4a1b46cab2dc53c1ee0afca0fe993102e (diff)
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 <amarts@redhat.com>
-rw-r--r--libglusterfs/src/logging.c20
1 files changed, 20 insertions, 0 deletions
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,