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;
}
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];
m_pipefd[1] = pipefd[1];
setPipeFd(newPipeFd);
// Drop priority (nice = 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
// waiting booster process and close write end
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) {
Logger::logError("Daemon: Can't send signal to launcher process' \n");
}
// Send to the parent process pid of invoker for tracking
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) {
Logger::logError("Daemon: Can't send invoker's pid to launcher process' \n");
}
// close pipe
close(m_pipefd[1]);
close(pipeFd(1));
}
bool Booster::readCommand()
@ -326,3 +325,15 @@ pid_t Booster::invokersPid()
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
* main() has finished.
*/
void run();
virtual void run();
/*!
* \brief Rename process.
@ -128,6 +128,12 @@ protected:
*/
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:
//! Disable copy-constructor
@ -159,7 +165,7 @@ private:
bool m_oldPriorityOk;
//! Pipe used to tell the parent that a new booster is needed
int m_pipefd[2];
int m_pipeFd[2];
#ifdef UNIT_TEST
friend class Ut_Booster;

@ -239,29 +239,30 @@ void Daemon::forkBooster(char type, int sleepTime)
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);
if (booster)
{
booster->initialize(m_initialArgc, m_initialArgv, m_pipefd);
// Don't care about fate of parent applauncherd process any more
prctl(PR_SET_PDEATHSIG, 0);
// Set dumpable flag
prctl(PR_SET_DUMPABLE, 1);
// Run the current Booster
booster->run();
// Finish
delete booster;
exit(EXIT_SUCCESS);
}
else
{
Logger::logErrorAndDie(EXIT_FAILURE, "Daemon: Unknown booster type \n");
}
// Don't care about fate of parent applauncherd process any more
prctl(PR_SET_PDEATHSIG, 0);
// Set dumpable flag
prctl(PR_SET_DUMPABLE, 1);
// Run the current Booster
booster->run();
// Finish
delete booster;
exit(EXIT_SUCCESS);
}
else /* Parent process */
{

@ -55,12 +55,23 @@ void MonitorBooster::addProcessName(const QString & processName)
m_processNames << processName;
}
void MonitorBooster::start()
void MonitorBooster::run()
{
int argc = 0;
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()
{
Q_FOREACH(QString processName, m_processNames) {
@ -73,14 +84,6 @@ char MonitorBooster::type()
return 'k';
}
bool MonitorBooster::readCommand()
{
// never return from here
start();
return true;
}
const string & MonitorBooster::socketName()
{
return m_socketId;

@ -34,7 +34,7 @@ class QString;
* MonitorBooster kills certain boosters e.g. when themeing or language changes.
* Daemon will then restart the boosters.
*/
class MonitorBooster : public QObject, public Booster
class MonitorBooster : public QObject, public Booster
{
Q_OBJECT
@ -56,9 +56,15 @@ class MonitorBooster : public QObject, public Booster
void addProcessName(const QString & processName);
/*! 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.
@ -66,15 +72,6 @@ class MonitorBooster : public QObject, public Booster
*/
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
*/

Loading…
Cancel
Save