From c265653b4507e0af5333c9ce51cd4d7420266436 Mon Sep 17 00:00:00 2001 From: oetiker Date: Tue, 21 Dec 2010 16:19:12 +0000 Subject: [PATCH] handle the case where the realpath of the suggested journaldir does not exist. Patch by Alex Bennee and Tobi Oetiker git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@2153 a5681a0c-68f1-0310-ab6d-d61299d08faa --- src/rrd_daemon.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c index 1a20974..a200135 100644 --- a/src/rrd_daemon.c +++ b/src/rrd_daemon.c @@ -3533,23 +3533,30 @@ static int read_options (int argc, char **argv) /* {{{ */ case 'j': { char journal_dir_actual[PATH_MAX]; - const char *dir; - dir = journal_dir = strdup(realpath((const char *)optarg, journal_dir_actual)); - - status = rrd_mkdir_p(dir, 0777); - if (status != 0) - { - fprintf(stderr, "Failed to create journal directory '%s': %s\n", - dir, rrd_strerror(errno)); - return 6; - } - - if (access(dir, R_OK|W_OK|X_OK) != 0) - { - fprintf(stderr, "Must specify a writable directory with -j! (%s)\n", - errno ? rrd_strerror(errno) : ""); - return 6; - } + journal_dir = realpath((const char *)optarg, journal_dir_actual); + if (journal_dir) + { + // if we were able to properly resolve the path, lets have a copy + // for use outside this block. + journal_dir = strdup(journal_dir); + status = rrd_mkdir_p(journal_dir, 0777); + if (status != 0) + { + fprintf(stderr, "Failed to create journal directory '%s': %s\n", + journal_dir, rrd_strerror(errno)); + return 6; + } + if (access(journal_dir, R_OK|W_OK|X_OK) != 0) + { + fprintf(stderr, "Must specify a writable directory with -j! (%s)\n", + errno ? rrd_strerror(errno) : ""); + return 6; + } + } else { + fprintf(stderr, "Unable to resolve journal path (%s,%s)\n", optarg, + errno ? rrd_strerror(errno) : ""); + return 6; + } } break; -- 2.11.0