From ba010beb35587ef914182f798dd5bca39106dbd2 Mon Sep 17 00:00:00 2001 From: FinnTew Date: Fri, 10 Jan 2025 18:35:47 +0800 Subject: [PATCH 1/3] fix: do not report errors for configuration file errors. --- src/kiwi.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/kiwi.cc b/src/kiwi.cc index e324a7c4..40e27d11 100644 --- a/src/kiwi.cc +++ b/src/kiwi.cc @@ -85,10 +85,15 @@ bool KiwiDB::ParseArgs(int argc, char* argv[]) { {"slaveof", required_argument, 0, 's'}, {"redis-compatible-mode", no_argument, 0, 'c'}, }; // kiwi [/path/to/kiwi.conf] [options] - if (options_.GetConfigName().empty() && argc > 1 && ::access(argv[1], R_OK) == 0) { - options_.SetConfigName(argv[1]); - argc = argc - 1; - argv = argv + 1; + if (options_.GetConfigName().empty() && argc > 1) { + if (::access(argv[1], R_OK) == 0) { + options_.SetConfigName(argv[1]); + argc = argc - 1; + argv = argv + 1; + } else { + std::cerr << "Configuration file [" << argv[1] << "] is not accessible or dose not exist.\n"; + return false; + } } while (1) { int this_option_optind = optind ? optind : 1; From 5c39bc0bb901c51af29d19ef8239dc4bcd6e7ade Mon Sep 17 00:00:00 2001 From: FinnTew Date: Sun, 12 Jan 2025 11:08:18 +0800 Subject: [PATCH 2/3] update --- src/kiwi.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/kiwi.cc b/src/kiwi.cc index 40e27d11..479ec1e2 100644 --- a/src/kiwi.cc +++ b/src/kiwi.cc @@ -85,13 +85,17 @@ bool KiwiDB::ParseArgs(int argc, char* argv[]) { {"slaveof", required_argument, 0, 's'}, {"redis-compatible-mode", no_argument, 0, 'c'}, }; // kiwi [/path/to/kiwi.conf] [options] - if (options_.GetConfigName().empty() && argc > 1) { - if (::access(argv[1], R_OK) == 0) { + if (argv == nullptr) { + return false; + } + if (options_.GetConfigName().empty() && argc > 1 && argv[1] != nullptr) { + struct stat st{}; + if (stat(argv[1], &st) == 0 && S_ISREG(st.st_mode) && ::access(argv[1], R_OK) == 0) { options_.SetConfigName(argv[1]); argc = argc - 1; argv = argv + 1; } else { - std::cerr << "Configuration file [" << argv[1] << "] is not accessible or dose not exist.\n"; + std::cerr << "Configuration file [" << argv[1] << "]: " << strerror(errno) << "\n"; return false; } } From 19af02660768535a2de4829c1c027f6b70ade91e Mon Sep 17 00:00:00 2001 From: FinnTew Date: Sun, 12 Jan 2025 11:15:42 +0800 Subject: [PATCH 3/3] update --- src/kiwi.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kiwi.cc b/src/kiwi.cc index 479ec1e2..4858ac74 100644 --- a/src/kiwi.cc +++ b/src/kiwi.cc @@ -89,7 +89,7 @@ bool KiwiDB::ParseArgs(int argc, char* argv[]) { return false; } if (options_.GetConfigName().empty() && argc > 1 && argv[1] != nullptr) { - struct stat st{}; + struct stat st {}; if (stat(argv[1], &st) == 0 && S_ISREG(st.st_mode) && ::access(argv[1], R_OK) == 0) { options_.SetConfigName(argv[1]); argc = argc - 1;