From: oetiker Date: Tue, 21 Dec 2010 16:19:12 +0000 (+0000) Subject: handle the case where the realpath of the suggested journaldir does not exist. Patch... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4392bc1c7c53a19c15adbf8912963278b64fb3fd;p=rrdtool-all.git 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@2153 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/program/src/rrd_daemon.c b/program/src/rrd_daemon.c index 1a20974d..a2001359 100644 --- a/program/src/rrd_daemon.c +++ b/program/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;