From 87f3262b61616634677e57d25798f27c82fb5465 Mon Sep 17 00:00:00 2001 From: Yunchih Chen Date: Thu, 4 Apr 2019 21:16:56 +0800 Subject: Fix check_dir bug --- bin/nfcollect.c | 2 +- lib/util.c | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/bin/nfcollect.c b/bin/nfcollect.c index 52791f8..1772c60 100644 --- a/bin/nfcollect.c +++ b/bin/nfcollect.c @@ -119,7 +119,7 @@ int main(int argc, char *argv[]) { g.compression_type = get_compression(compression_flag); if (check_basedir_exist(storage) < 0) - FATAL("Storage directory does not exist"); + FATAL("Storage directory: %s does not exist", storage); // register signal handler if (signal(SIGHUP, sig_handler) == SIG_ERR) diff --git a/lib/util.c b/lib/util.c index ef5238f..5a9076f 100644 --- a/lib/util.c +++ b/lib/util.c @@ -17,13 +17,12 @@ int check_file_size(const char *storage) { int check_basedir_exist(const char *storage) { char *_storage = strdup(storage); char *basedir = dirname(_storage); - free(_storage); - struct stat d; - if (stat(basedir, &d) != 0 || !S_ISDIR(d.st_mode)) { - return -1; - } - return 0; + struct stat d; int ret = 0; + if (stat(basedir, &d) != 0 || !S_ISDIR(d.st_mode)) + ret = -1; + free(_storage); + return ret; } enum CompressionType get_compression(const char *flag) { -- cgit v1.2.3