Changes: Daemon::initializeBooster(Booster *) moved to Booster::initialize(...).

RevBy: Antti Kervinen
pull/1/head
Jussi Lind 15 years ago
parent f7146b065e
commit 5d680f7d0c

@ -54,6 +54,53 @@ bool Booster::preload()
return true;
}
void Booster::initialize(int initialArgc, char ** initialArgv, int pipefd[2])
{
m_pipefd[0] = pipefd[0];
m_pipefd[1] = pipefd[1];
// Drop priority (nice = 10)
pushPriority(10);
// Preload stuff
preload();
// Clean-up all the env variables
clearenv();
// Rename process to temporary booster process name, e.g. "booster-m"
renameProcess(initialArgc, initialArgv);
// Restore priority
popPriority();
// Wait and read commands from the invoker
Logger::logNotice("Daemon: Wait for message from invoker");
readCommand();
// Give the process the real application name now that it
// has been read from invoker in readCommand().
renameProcess(initialArgc, initialArgv);
// 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);
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));
if (ret == -1) {
Logger::logError("Daemon: Can't send invoker's pid to launcher process' \n");
}
// close pipe
close(m_pipefd[1]);
}
bool Booster::readCommand()
{
// Setup the conversation channel with the invoker.

@ -51,6 +51,17 @@ public:
//! Destructor
virtual ~Booster();
/*!
* \brief Initializes the booster process.
*/
virtual void initialize(int initialArgc, char ** initialArgv, int pipefd[2]);
/*!
* \brief Preload libraries.
* Override in the custom Booster.
*/
virtual bool preload();
/*!
* \brief Run the application to be invoked.
* This method causes the application binary to be loaded
@ -61,21 +72,6 @@ public:
*/
void run();
/*!
* \brief Wait for connection from invoker and read the input.
* This method accepts a socket connection from the invoker
* and reads the data of an application to be launched.
*
* \return true on success
*/
virtual bool readCommand();
/*!
* \brief Initialize and preload stuff
* Override in the custom Booster.
*/
virtual bool preload();
/*!
* \brief Rename process.
* This method overrides the argument data starting from initialArgv[0].
@ -104,16 +100,25 @@ public:
*/
virtual const string & boosterTemporaryProcessName() const = 0;
//! Get invoker's pid
pid_t invokersPid();
protected:
//! Set nice value and store the old priority. Return true on success.
bool pushPriority(int nice);
//! Restore the old priority stored by the previous successful setPriority().
bool popPriority();
//! Get invoker's pid
pid_t invokersPid();
protected:
/*!
* \brief Wait for connection from invoker and read the input.
* This method accepts a socket connection from the invoker
* and reads the data of an application to be launched.
*
* \return true on success
*/
virtual bool readCommand();
/*!
* \brief Return the communication socket used by a Booster.
@ -153,6 +158,9 @@ private:
//! it can be restored later.
bool m_oldPriorityOk;
//! Pipe used to tell the parent that a new booster is needed
int m_pipefd[2];
#ifdef UNIT_TEST
friend class Ut_Booster;
#endif

@ -162,6 +162,7 @@ void Daemon::run()
forkBooster(WRTBooster::type());
forkBooster(MonitorBooster::type());
// Main loop
while (true)
{
// Wait for something appearing in the pipe
@ -222,9 +223,10 @@ void Daemon::forkBooster(char type, int sleepTime)
// Close unused read end
close(m_pipefd[0]);
// close lock file, it's not needed in the booster
// Close lock file, it's not needed in the booster
Daemon::unlock();
// Set session id
if (setsid() < 0)
{
Logger::logError("Daemon: Setting session id\n");
@ -241,16 +243,13 @@ void Daemon::forkBooster(char type, int sleepTime)
Booster * booster = BoosterFactory::create(type);
if (booster)
{
initializeBooster(booster);
booster->initialize(m_initialArgc, m_initialArgv, m_pipefd);
}
else
{
Logger::logErrorAndDie(EXIT_FAILURE, "Daemon: Unknown booster type \n");
}
// close pipe
close(m_pipefd[1]);
// Don't care about fate of parent applauncherd process any more
prctl(PR_SET_PDEATHSIG, 0);
@ -275,46 +274,6 @@ void Daemon::forkBooster(char type, int sleepTime)
}
}
void Daemon::initializeBooster(Booster * booster)
{
// Drop priority (nice = 10)
booster->pushPriority(10);
// Preload stuff
booster->preload();
// Clean-up all the env variables
clearenv();
// Rename launcher process to booster
booster->renameProcess(m_initialArgc, m_initialArgv);
// Restore priority
booster->popPriority();
// Wait and read commands from the invoker
Logger::logNotice("Daemon: Wait for message from invoker");
booster->readCommand();
// Give to the process an application specific name
booster->renameProcess(m_initialArgc, m_initialArgv);
// Signal the parent process that it can create a new
// waiting booster process and close write end
const char msg = booster->boosterType();
ssize_t ret = write(m_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 = booster->invokersPid();
ret = write(m_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");
}
}
void Daemon::reapZombies()
{
// Loop through all child pid's and wait for them with WNOHANG.

@ -96,9 +96,6 @@ private:
//! Forks and initializes a new Booster
void forkBooster(char type, int sleepTime = 0);
//! Initializes the given booster
void initializeBooster(Booster * booster);
//! Don't use console for output
void consoleQuiet();

@ -66,7 +66,6 @@ void MBooster::setProcessId(int pid)
m_ProcessID = pid;
}
int MBooster::processId()
{
return m_ProcessID;

@ -29,7 +29,6 @@ const string MonitorBooster::m_socketId = "";
int MonitorBooster::m_ProcessID = 0;
const string MonitorBooster::m_temporaryProcessName = "booster-monitor";
MonitorBooster::MonitorBooster()
{
// Add keys to listen to.

Loading…
Cancel
Save