From 5f0b736247549f698508dffdc19f5a3739cd2b6b Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Fri, 22 Nov 2019 14:40:32 +0000 Subject: [PATCH] dinitcheck: return EXIT_FAILURE if problem found --- TODO | 12 +++++++++--- src/dinitcheck.cc | 9 ++++++++- src/igr-tests/check-basic/run-test.sh | 1 + src/igr-tests/check-cycle/run-test.sh | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index 964d14a..e6cad60 100644 --- a/TODO +++ b/TODO @@ -1,15 +1,21 @@ For version 0.8.0: ------------------ +* provide a way to check configuration for errors (dinitcheck command) [DONE] * Easy way to reload service description (including if service is running, where possible). -* provide a way to check configuration for errors (dinitcheck command) [In progress] - - man page - - circular dependency checks * report process launch failure reason (stage & errno) via dinitctl. * "chain-to" can result in an unbreakable loop if the chain is circular. Chained services should not be started during shutdown to prevent this (also avoids a race condition where the chained service is left running when everything else has shutdown). * Show "activated" state in "dinitctl list" output +For version 0.9.+: +------------------ +* Service description sanity checks: + - Service type not specified + - maybe default to 'internal' if command not specified + - service command not specified + - errors should also be reported by dinitcheck + For version 1.0: ---------------- * Service description parse errors should report line number diff --git a/src/dinitcheck.cc b/src/dinitcheck.cc index 60fe609..a27a8e4 100644 --- a/src/dinitcheck.cc +++ b/src/dinitcheck.cc @@ -61,6 +61,8 @@ template bool contains(std::vector vec, const T& elem) return std::find(vec.begin(), vec.end(), elem) != vec.end(); } +static bool errors_found = false; + int main(int argc, char **argv) { using namespace std; @@ -133,6 +135,7 @@ int main(int argc, char **argv) } catch (service_load_exc &exc) { std::cerr << "Unable to load service '" << name << "': " << exc.exc_description << "\n"; + errors_found = true; } } @@ -191,6 +194,7 @@ int main(int argc, char **argv) } if (!service_chain.empty()) { + errors_found = true; std::cerr << "Found dependency cycle:\n"; for (auto chain_link : service_chain) { std::cerr << " " << std::get<0>(chain_link)->name << " ->\n"; @@ -200,23 +204,26 @@ int main(int argc, char **argv) // TODO additional: check chain-to, other lint - return 0; + return errors_found ? EXIT_FAILURE : EXIT_SUCCESS; } static void report_service_description_exc(service_description_exc &exc) { std::cerr << "Service '" << exc.service_name << "': " << exc.exc_description << "\n"; + errors_found = true; } static void report_error(std::system_error &exc, const std::string &service_name) { std::cerr << "Service '" << service_name << "', error reading service description: " << exc.what() << "\n"; + errors_found = true; } static void report_dir_error(const char *service_name, const std::string &dirpath) { std::cerr << "Service '" << service_name << "', error reading dependencies from directory " << dirpath << ": " << strerror(errno) << "\n"; + errors_found = true; } // Process a dependency directory - filenames contained within correspond to service names which diff --git a/src/igr-tests/check-basic/run-test.sh b/src/igr-tests/check-basic/run-test.sh index d75048c..7a71ebf 100755 --- a/src/igr-tests/check-basic/run-test.sh +++ b/src/igr-tests/check-basic/run-test.sh @@ -1,6 +1,7 @@ #!/bin/sh ../../dinitcheck -d sd > output.txt 2>&1 +if [ $? != 1 ]; then exit 1; fi STATUS=FAIL if cmp -s expected.txt output.txt; then diff --git a/src/igr-tests/check-cycle/run-test.sh b/src/igr-tests/check-cycle/run-test.sh index d75048c..7a71ebf 100755 --- a/src/igr-tests/check-cycle/run-test.sh +++ b/src/igr-tests/check-cycle/run-test.sh @@ -1,6 +1,7 @@ #!/bin/sh ../../dinitcheck -d sd > output.txt 2>&1 +if [ $? != 1 ]; then exit 1; fi STATUS=FAIL if cmp -s expected.txt output.txt; then -- 2.25.1