Changes: NB#274400 (fixes daemon.cpp forkBooster and readFromBoosterSocket + unit tests)

RevBy: Alexey Shilov
pull/1/head
Dmitry Rozenshtein 14 years ago committed by Alexey Shilov
parent c97599ae9c
commit a088e783fd

@ -32,6 +32,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/prctl.h>
#include <sys/syslog.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <glob.h>
@ -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);

@ -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)

@ -45,6 +45,9 @@ private Q_SLOTS:
void testVerifyInstance();
void testReapZombies();
void testSetPidToBooster();
void testLock();
void testForkBooster();
void testReadFromBoosterSocket();
private:
std::tr1::shared_ptr<Daemon> m_subject;

Loading…
Cancel
Save