diff --git a/src/launcherlib/daemon.cpp b/src/launcherlib/daemon.cpp index 172f3a4..1d88f3a 100644 --- a/src/launcherlib/daemon.cpp +++ b/src/launcherlib/daemon.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -278,7 +279,11 @@ void Daemon::readFromBoosterSocket(int fd) } else { - Logger::logWarning("Daemon: Nothing read from the socket\n"); + // Since Logger is not working in boosters log directly to syslog + syslog(LOG_ERR,"Daemon: Nothing read from the socket\n"); + Logger::logError("Daemon: Nothing read from the socket\n"); + // Critical error communicating with booster. Exiting applauncherd. + _exit(EXIT_FAILURE); } // Fork a new booster of the given type @@ -375,6 +380,15 @@ void Daemon::loadBoosterPlugins() void Daemon::forkBooster(char type, int sleepTime) { + if (!BoosterPluginRegistry::pluginEntry(type)) { + // Since Logger is not working in boosters log directly to syslog + syslog(LOG_ERR,"Daemon: Unknown booster type '%c'\n",type); + Logger::logError("Daemon: Unknown booster type '%c'\n",type); + // Critical error unknown booster type. Exiting applauncherd. + _exit(EXIT_FAILURE); + } + + // Invalidate current booster pid for the given type setPidToBooster(type, 0); diff --git a/tests/common/unittests/ut_daemon/ut_daemon.cpp b/tests/common/unittests/ut_daemon/ut_daemon.cpp index d383494..112c239 100644 --- a/tests/common/unittests/ut_daemon/ut_daemon.cpp +++ b/tests/common/unittests/ut_daemon/ut_daemon.cpp @@ -101,4 +101,52 @@ void Ut_Daemon::testSetPidToBooster() QVERIFY(m_subject->boosterPidForType('c') == 0); } -QTEST_APPLESS_MAIN(Ut_Daemon); +void Ut_Daemon::testLock() +{ + //negative testcase with already locked soket (it's locked by running applauncherd) + QVERIFY(Daemon::lock() == false); + + //negative testcase with wrong lock file descriptor + Daemon::unlock(); + m_subject->m_lockFd = -1; + QVERIFY(Daemon::lock() == false); +} + +void Ut_Daemon::testForkBooster() +{ + //negative testcase for unregistered booster type '0' + pid_t pid = fork(); + if (pid == 0) { // child + // Code only executed by child process + m_subject->forkBooster('0'); + QFAIL("Not exited on invalid booster type"); + _exit(0); //exit from child if something goes wrong + } else if (pid < 0) { // failed to fork + QFAIL("Unable to fork for test _exit"); + } else { //parent only + QTest::qSleep(1000); + int resultCode = QProcess::execute("grep",QStringList() << "Daemon: Unknown booster type '0'" << "/var/log/syslog"); + QVERIFY(resultCode == 0); + } +} + + +void Ut_Daemon::testReadFromBoosterSocket() +{ + //negative testcase reads from invalid socket + pid_t pid = fork(); + if (pid == 0) { // child + // Code only executed by child process + m_subject->readFromBoosterSocket(-1); + QFAIL("Not exited on invalid socket"); + _exit(0); //exit from child if something goes wrong + } else if (pid < 0) { // failed to fork + QFAIL("Unable to fork for test _exit"); + } else { //parent only + QTest::qSleep(1000); + int resultCode = QProcess::execute("grep",QStringList() << "Daemon: Nothing read from the socket" << "/var/log/syslog"); + QVERIFY(resultCode == 0); + } +} + +QTEST_APPLESS_MAIN(Ut_Daemon) diff --git a/tests/common/unittests/ut_daemon/ut_daemon.h b/tests/common/unittests/ut_daemon/ut_daemon.h index 6e9141a..455d45a 100644 --- a/tests/common/unittests/ut_daemon/ut_daemon.h +++ b/tests/common/unittests/ut_daemon/ut_daemon.h @@ -45,6 +45,9 @@ private Q_SLOTS: void testVerifyInstance(); void testReapZombies(); void testSetPidToBooster(); + void testLock(); + void testForkBooster(); + void testReadFromBoosterSocket(); private: std::tr1::shared_ptr m_subject;