X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FDaemon%2FDaemon.test.cc;h=f3dfc1eccd582951a3dd2cce904c4d5aa1919c20;hb=a726ae0cb14d0ce37e5aab3c4e07121bbbd3b31c;hp=7591434158d8a0c0e27cbca16e0e74ddddd5dfdf;hpb=40fa3e3f1e0f639c68bd15bf469e35045f94abee;p=senf.git diff --git a/Utils/Daemon/Daemon.test.cc b/Utils/Daemon/Daemon.test.cc index 7591434..f3dfc1e 100644 --- a/Utils/Daemon/Daemon.test.cc +++ b/Utils/Daemon/Daemon.test.cc @@ -36,6 +36,7 @@ #include "Daemon.hh" #include "../Utils/Exception.hh" #include "../Utils/Backtrace.hh" +#include "../Scheduler/Scheduler.hh" #include "../Utils/auto_unit_test.hh" #include @@ -72,7 +73,7 @@ namespace { } }; - int myMain(int argc, char ** argv) + int myMain(int argc, char const ** argv) { MyDaemon instance; return instance.start(argc, argv); @@ -87,12 +88,13 @@ namespace { ::kill(::getpid(), SIGABRT); }; - int run(int argc, char ** argv) + int run(int argc, char const ** argv) { pid = ::fork(); if (pid < 0) throw senf::SystemException("::fork()"); if (pid == 0) { signal(SIGABRT, &backtrace); + signal(SIGCHLD, SIG_IGN); try { ::_exit(myMain(argc, argv)); } catch (std::exception & ex) { @@ -100,40 +102,49 @@ namespace { } catch (...) { std::cerr << "Unexpected exception" << std::endl; } - ::_exit(2); + ::_exit(125); } + signal(SIGCHLD, SIG_DFL); int status; - if (::waitpid(pid, &status, 0) < 0) throw senf::SystemException("::waitpid()"); - return WIFEXITED(status) ? WEXITSTATUS(status) : -1; + if (::waitpid(pid, &status, 0) < 0) + throw senf::SystemException("::waitpid()"); + if (WIFSIGNALED(status)) + std::cerr << "Terminated with signal " + << senf::signalName(WTERMSIG(status)) << "(" << WTERMSIG(status) << ")\n"; + else if (WIFEXITED(status)) + std::cerr << "Exited normally with exit status " << WEXITSTATUS(status) << "\n"; + return status; } } BOOST_AUTO_UNIT_TEST(testDaemon) { - char * args[] = { "run", - "--console-log=testDaemon.log,none", - "--pid-file=testDaemon.pid" }; - BOOST_CHECK_EQUAL( run(sizeof(args)/sizeof(*args),args), 0 ); + char const * args[] = { "run", + "--console-log=testDaemon.log", + "--pid-file=testDaemon.pid" }; + + SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( run(sizeof(args)/sizeof(*args), args), 0 ) ); BOOST_CHECK( ! boost::filesystem::exists("invalid.log") ); BOOST_CHECK( ! boost::filesystem::exists("invalid.pid") ); - BOOST_REQUIRE( boost::filesystem::exists("testDaemon.pid") ); + BOOST_CHECK( boost::filesystem::exists("testDaemon.pid") ); BOOST_REQUIRE( boost::filesystem::exists("testDaemon.log") ); boost::filesystem::rename("testDaemon.log", "testDaemon.log.1"); { std::ifstream pidFile ("testDaemon.pid"); int pid (0); - BOOST_REQUIRE( pidFile >> pid ); - BOOST_REQUIRE( pid != 0 ); - ::kill(pid, SIGHUP); + BOOST_CHECK( pidFile >> pid ); + BOOST_CHECK( pid != 0 ); + if (pid != 0) + ::kill(pid, SIGHUP); } delay(1000); BOOST_CHECK( ! boost::filesystem::exists("testDaemon.pid") ); BOOST_CHECK( boost::filesystem::exists("testDaemon.log") ); - BOOST_REQUIRE( boost::filesystem::exists("testDaemon.log.1") ); + BOOST_CHECK( boost::filesystem::exists("testDaemon.log.1") ); std::ifstream log ("testDaemon.log.1"); std::stringstream data;