X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FDaemon%2FDaemon.test.cc;h=f561e97ea377f3bc377c24c3c1b52d9e05183d10;hb=2c6294b3a810ee64e117df1b0da01d6b120534bb;hp=aceed1c34d4b19ca3fbda2c23a4885c4b54d9082;hpb=9e69297ff7a7bcd9d952a38e35bbf124cb7f1dda;p=senf.git diff --git a/Utils/Daemon/Daemon.test.cc b/Utils/Daemon/Daemon.test.cc index aceed1c..f561e97 100644 --- a/Utils/Daemon/Daemon.test.cc +++ b/Utils/Daemon/Daemon.test.cc @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer NETwork research (NET) +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -71,21 +71,23 @@ namespace { } }; - int myMain(int argc, char const ** argv) + int myMain(int argc, char ** argv) { MyDaemon instance; return instance.start(argc, argv); } - int run(int argc, char const ** argv) + int pid; + + int run(int argc, char ** argv) { - int pid (::fork()); - if (pid < 0) senf::throwErrno("::fork()"); + pid = ::fork(); + if (pid < 0) throw senf::SystemException("::fork()"); if (pid == 0) { ::_exit(myMain(argc, argv)); } int status; - if (::waitpid(pid, &status, 0) < 0) senf::throwErrno("::waitpid()"); + if (::waitpid(pid, &status, 0) < 0) throw senf::SystemException("::waitpid()"); return WIFEXITED(status) ? WEXITSTATUS(status) : -1; } @@ -93,23 +95,36 @@ namespace { BOOST_AUTO_UNIT_TEST(testDaemon) { - char const * args[] = { "run", - "--console-log=testDaemon.log,none", - "--pid-file=testDaemon.pid" }; + char * args[] = { "run", + "--console-log=testDaemon.log,none", + "--pid-file=testDaemon.pid" }; 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_CHECK( boost::filesystem::exists("testDaemon.pid") ); + BOOST_REQUIRE( 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); + } + delay(1000); BOOST_CHECK( ! boost::filesystem::exists("testDaemon.pid") ); - BOOST_REQUIRE( boost::filesystem::exists("testDaemon.log") ); + BOOST_CHECK( boost::filesystem::exists("testDaemon.log") ); + BOOST_REQUIRE( boost::filesystem::exists("testDaemon.log.1") ); - std::ifstream log ("testDaemon.log"); + std::ifstream log ("testDaemon.log.1"); std::stringstream data; data << log.rdbuf(); BOOST_CHECK_EQUAL( data.str(), "Running init()\nRunning run()\n" ); BOOST_CHECK_NO_THROW( boost::filesystem::remove("testDaemon.log") ); + BOOST_CHECK_NO_THROW( boost::filesystem::remove("testDaemon.log.1") ); } ///////////////////////////////cc.e////////////////////////////////////////