diff --git a/src/launcher/booster.cpp b/src/launcher/booster.cpp index 731dc3c..1a9ed92 100644 --- a/src/launcher/booster.cpp +++ b/src/launcher/booster.cpp @@ -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(&msg), 1); + ssize_t ret = write(pipeFd(1), reinterpret_cast(&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(&pid), sizeof(pid_t)); + ret = write(pipeFd(1), reinterpret_cast(&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]; +} + diff --git a/src/launcher/booster.h b/src/launcher/booster.h index 1548ebb..9f5a916 100644 --- a/src/launcher/booster.h +++ b/src/launcher/booster.h @@ -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; diff --git a/src/launcher/daemon.cpp b/src/launcher/daemon.cpp index 180c412..eccac5c 100644 --- a/src/launcher/daemon.cpp +++ b/src/launcher/daemon.cpp @@ -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 */ { diff --git a/src/launcher/monitorbooster.cpp b/src/launcher/monitorbooster.cpp index b3bef81..1c3ebd7 100644 --- a/src/launcher/monitorbooster.cpp +++ b/src/launcher/monitorbooster.cpp @@ -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; diff --git a/src/launcher/monitorbooster.h b/src/launcher/monitorbooster.h index 6a2410f..7e8bc15 100644 --- a/src/launcher/monitorbooster.h +++ b/src/launcher/monitorbooster.h @@ -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 */