Changes: Made MonitorBooster to re-implement run() and initialize().

pull/1/head
Jussi Lind 15 years ago
parent 5d680f7d0c
commit ba3776508b

@ -54,10 +54,9 @@ bool Booster::preload()
return true; return true;
} }
void Booster::initialize(int initialArgc, char ** initialArgv, int pipefd[2]) void Booster::initialize(int initialArgc, char ** initialArgv, int newPipeFd[2])
{ {
m_pipefd[0] = pipefd[0]; setPipeFd(newPipeFd);
m_pipefd[1] = pipefd[1];
// Drop priority (nice = 10) // Drop priority (nice = 10)
pushPriority(10); pushPriority(10);
@ -85,20 +84,20 @@ void Booster::initialize(int initialArgc, char ** initialArgv, int pipefd[2])
// Signal the parent process that it can create a new // Signal the parent process that it can create a new
// waiting booster process and close write end // waiting booster process and close write end
const char msg = boosterType(); const char msg = boosterType();
ssize_t ret = write(m_pipefd[1], reinterpret_cast<const void *>(&msg), 1); ssize_t ret = write(pipeFd(1), reinterpret_cast<const void *>(&msg), 1);
if (ret == -1) { if (ret == -1) {
Logger::logError("Daemon: Can't send signal to launcher process' \n"); Logger::logError("Daemon: Can't send signal to launcher process' \n");
} }
// Send to the parent process pid of invoker for tracking // Send to the parent process pid of invoker for tracking
pid_t pid = invokersPid(); pid_t pid = invokersPid();
ret = write(m_pipefd[1], reinterpret_cast<const void *>(&pid), sizeof(pid_t)); ret = write(pipeFd(1), reinterpret_cast<const void *>(&pid), sizeof(pid_t));
if (ret == -1) { if (ret == -1) {
Logger::logError("Daemon: Can't send invoker's pid to launcher process' \n"); Logger::logError("Daemon: Can't send invoker's pid to launcher process' \n");
} }
// close pipe // close pipe
close(m_pipefd[1]); close(pipeFd(1));
} }
bool Booster::readCommand() bool Booster::readCommand()
@ -326,3 +325,15 @@ pid_t Booster::invokersPid()
return 0; return 0;
} }
} }
void Booster::setPipeFd(int newPipeFd[2])
{
m_pipeFd[0] = newPipeFd[0];
m_pipeFd[1] = newPipeFd[1];
}
int Booster::pipeFd(bool whichEnd) const
{
return m_pipeFd[whichEnd];
}

@ -70,7 +70,7 @@ public:
* exits with corresponding exit-code after the execution of * exits with corresponding exit-code after the execution of
* main() has finished. * main() has finished.
*/ */
void run(); virtual void run();
/*! /*!
* \brief Rename process. * \brief Rename process.
@ -128,6 +128,12 @@ protected:
*/ */
virtual const string & socketId() const = 0; virtual const string & socketId() const = 0;
//! Sets pipe fd's used to communicate with the parent process
void setPipeFd(int pipeFd[2]);
//! Returns the given pipe fd (0 = read end, 1 = write end)
int pipeFd(bool whichEnd) const;
private: private:
//! Disable copy-constructor //! Disable copy-constructor
@ -159,7 +165,7 @@ private:
bool m_oldPriorityOk; bool m_oldPriorityOk;
//! Pipe used to tell the parent that a new booster is needed //! Pipe used to tell the parent that a new booster is needed
int m_pipefd[2]; int m_pipeFd[2];
#ifdef UNIT_TEST #ifdef UNIT_TEST
friend class Ut_Booster; friend class Ut_Booster;

@ -239,16 +239,11 @@ void Daemon::forkBooster(char type, int sleepTime)
Logger::logNotice("Daemon: Running a new Booster of %c type...", type); Logger::logNotice("Daemon: Running a new Booster of %c type...", type);
// Create a new booster and initialize it // Create a new booster, initialize and run it
Booster * booster = BoosterFactory::create(type); Booster * booster = BoosterFactory::create(type);
if (booster) if (booster)
{ {
booster->initialize(m_initialArgc, m_initialArgv, m_pipefd); booster->initialize(m_initialArgc, m_initialArgv, m_pipefd);
}
else
{
Logger::logErrorAndDie(EXIT_FAILURE, "Daemon: Unknown booster type \n");
}
// Don't care about fate of parent applauncherd process any more // Don't care about fate of parent applauncherd process any more
prctl(PR_SET_PDEATHSIG, 0); prctl(PR_SET_PDEATHSIG, 0);
@ -261,8 +256,14 @@ void Daemon::forkBooster(char type, int sleepTime)
// Finish // Finish
delete booster; delete booster;
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
else
{
Logger::logErrorAndDie(EXIT_FAILURE, "Daemon: Unknown booster type \n");
}
}
else /* Parent process */ else /* Parent process */
{ {
// Store the pid so that we can reap it later // Store the pid so that we can reap it later

@ -55,12 +55,23 @@ void MonitorBooster::addProcessName(const QString & processName)
m_processNames << processName; m_processNames << processName;
} }
void MonitorBooster::start() void MonitorBooster::run()
{ {
int argc = 0; int argc = 0;
QCoreApplication(argc, 0).exec(); QCoreApplication(argc, 0).exec();
} }
void MonitorBooster::initialize(int initialArgc, char ** initialArgv, int newPipeFd[2])
{
setPipeFd(newPipeFd);
// Clean-up all the env variables
clearenv();
// Rename process to temporary booster process name
renameProcess(initialArgc, initialArgv);
}
void MonitorBooster::killProcesses() void MonitorBooster::killProcesses()
{ {
Q_FOREACH(QString processName, m_processNames) { Q_FOREACH(QString processName, m_processNames) {
@ -73,14 +84,6 @@ char MonitorBooster::type()
return 'k'; return 'k';
} }
bool MonitorBooster::readCommand()
{
// never return from here
start();
return true;
}
const string & MonitorBooster::socketName() const string & MonitorBooster::socketName()
{ {
return m_socketId; return m_socketId;

@ -56,9 +56,15 @@ class MonitorBooster : public QObject, public Booster
void addProcessName(const QString & processName); void addProcessName(const QString & processName);
/*! Starts the killer. This will initialize a QCoreApplication, does /*! Starts the killer. This will initialize a QCoreApplication, does
* not return. * not return. reimp.
*/ */
void start(); virtual void run();
//! \reimp
virtual char boosterType() const { return type(); }
//! \reimp
virtual void initialize(int initialArgc, char ** initialArgv, int pipeFd[2]);
/*! /*!
* \brief Return a unique character ('k') represtenting the type of MonitorBooster. * \brief Return a unique character ('k') represtenting the type of MonitorBooster.
@ -66,15 +72,6 @@ class MonitorBooster : public QObject, public Booster
*/ */
static char type(); static char type();
/*!
* \brief Override default behaviour, don't wait for commands from invoker.
* \return true on success
*/
virtual bool readCommand();
//! \reimp
virtual char boosterType() const { return type(); }
/*! /*!
* \brief Keep booster pid, should be reset before booster run application's main() function * \brief Keep booster pid, should be reset before booster run application's main() function
*/ */

Loading…
Cancel
Save