[mapplauncherd] Change booster type to strings

Single-character booster types could potentially conflict when
using out-of-tree boosters, and quickly become confusing.

Old types are mapped for compatibility.
pull/1/head
John Brooks 13 years ago
parent 1a09eb0fe5
commit 25dfb62293

@ -24,22 +24,17 @@
#include <errno.h>
#include <string.h>
const string EBooster::m_socketId = "booster-e";
const string EBooster::m_temporaryProcessName = "booster-e";
const string & EBooster::socketId() const
{
return m_socketId;
}
const string EBooster::m_boosterType = "generic";
const string EBooster::m_temporaryProcessName = "booster-generic";
const string & EBooster::boosterTemporaryProcessName() const
{
return m_temporaryProcessName;
}
char EBooster::boosterType() const
const string & EBooster::boosterType() const
{
return 'e';
return m_boosterType;
}
bool EBooster::preload()

@ -39,10 +39,7 @@ public:
virtual const string &boosterTemporaryProcessName() const;
//! \reimp
virtual char boosterType() const;
//! \reimp
virtual const string & socketId() const;
virtual const string & boosterType() const;
protected:
@ -60,7 +57,7 @@ private:
//! Disable assignment operator
EBooster & operator= (const EBooster & r);
static const string m_socketId;
static const string m_boosterType;
//! Process name to be used when booster is not
//! yet transformed into a running application

@ -178,7 +178,7 @@ static bool invoke_recv_ack(int fd)
}
// Inits a socket connection for the given application type
static int invoker_init(char app_type)
static int invoker_init(const char *app_type)
{
int fd;
struct sockaddr_un sun;
@ -191,11 +191,11 @@ static int invoker_init(char app_type)
}
sun.sun_family = AF_UNIX;
const int maxSize = sizeof(sun.sun_path) - 1;
int maxSize = sizeof(sun.sun_path) - 1;
const char *runtimeDir = getenv("XDG_RUNTIME_DIR");
const char *subpath = "/mapplauncherd/booster-";
const int subpathLen = strlen(subpath) + 1;
const char *subpath = "/mapplauncherd/";
const int subpathLen = strlen(subpath);
if (runtimeDir && *runtimeDir)
strncpy(sun.sun_path, runtimeDir, maxSize - subpathLen);
@ -205,16 +205,11 @@ static int invoker_init(char app_type)
sun.sun_path[maxSize - subpathLen] = 0;
strcat(sun.sun_path, subpath);
if (app_type >= 'a' && app_type <= 'z')
{
int len = strlen(sun.sun_path);
sun.sun_path[len++] = app_type;
sun.sun_path[len] = 0;
}
else
{
die(1, "Unknown type of application: %c\n", app_type);
}
maxSize -= strlen(sun.sun_path);
if (maxSize < strlen(app_type) || strchr(app_type, '/'))
die(1, "Invalid type of application: %s\n", app_type);
strcat(sun.sun_path, app_type);
if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) < 0)
{
@ -625,7 +620,7 @@ static void invoke_fallback(char **prog_argv, char *prog_name, bool wait_term)
// Invokes the given application
static int invoke(int prog_argc, char **prog_argv, char *prog_name,
char app_type, uint32_t magic_options, bool wait_term, unsigned int respawn_delay,
const char *app_type, uint32_t magic_options, bool wait_term, unsigned int respawn_delay,
char *splash_file, char *landscape_splash_file, bool test_mode)
{
int status = 0;
@ -808,16 +803,15 @@ int main(int argc, char *argv[])
usage(1);
}
// Translate 'qt' and 'm' types to 'q' for compatibility
if (!strcmp(app_type, "qt") || !strcmp(app_type, "m"))
app_type = "q";
// Check if application type is unknown. Only accept one character types.
if (!app_type[0] || app_type[1])
{
report(report_error, "Application's type is unknown.\n");
usage(1);
}
// Translate types for compatibility with older versions
if (!strcmp(app_type, "q") || !strcmp(app_type, "qt") || !strcmp(app_type, "m"))
app_type = "qt4";
else if (!strcmp(app_type, "d"))
app_type = "qml";
else if (!strcmp(app_type, "j"))
app_type = "silica";
else if (!strcmp(app_type, "e"))
app_type = "generic";
if (pipe(g_signal_pipe) == -1)
{
@ -827,7 +821,7 @@ int main(int argc, char *argv[])
// Send commands to the launcher daemon
info("Invoking execution: '%s'\n", prog_name);
int ret_val = invoke(prog_argc, prog_argv, prog_name, *app_type, magic_options, wait_term, respawn_delay, splash_file, landscape_splash_file, test_mode);
int ret_val = invoke(prog_argc, prog_argv, prog_name, app_type, magic_options, wait_term, respawn_delay, splash_file, landscape_splash_file, test_mode);
// Sleep for delay before exiting
if (delay)

@ -187,7 +187,7 @@ void Booster::sendDataToParent()
{
// Number of data items to be sent to
// the parent (launcher) process
const unsigned int NUM_DATA_ITEMS = 3;
const unsigned int NUM_DATA_ITEMS = 2;
struct iovec iov[NUM_DATA_ITEMS];
struct msghdr msg;
@ -196,19 +196,15 @@ void Booster::sendDataToParent()
// Signal the parent process that it can create a new
// waiting booster process and close write end
const char booster = boosterType();
iov[0].iov_base = const_cast<char *>(&booster);
iov[0].iov_len = sizeof(char);
// Send to the parent process pid of invoker for tracking
pid_t pid = invokersPid();
iov[1].iov_base = &pid;
iov[1].iov_len = sizeof(pid_t);
iov[0].iov_base = &pid;
iov[0].iov_len = sizeof(pid_t);
// Send to the parent process booster respawn delay value
int delay = m_appData->delay();
iov[2].iov_base = &delay;
iov[2].iov_len = sizeof(int);
iov[1].iov_base = &delay;
iov[1].iov_len = sizeof(int);
msg.msg_iov = iov;
msg.msg_iovlen = NUM_DATA_ITEMS;

@ -102,13 +102,14 @@ public:
int sourceArgc, const char** sourceArgv);
/*!
* \brief Return booster type common to all instances.
* This is used in the simple communication between booster process.
* and the daemon. Override in the custom Booster.
* \brief Return unique booster name
*
* \return A (unique) character representing the type of the Booster.
* The booster name is used as a parameter to invoker to launch processes
* with the given booster, and is used as the name for the booster socket.
*
* \return A (unique) string representing the type of the Booster.
*/
virtual char boosterType() const = 0;
virtual const string & boosterType() const = 0;
/*! Return the process name to be used when booster is not
* yet transformed into a running application (e.g. "booster-m"
@ -128,14 +129,6 @@ public:
//! Get application data object
AppData* appData() const;
/*!
* \brief Return the communication socket used by a Booster.
* This method returns the socket used between invoker and the Booster.
* (common to all Boosters of the type). Override in the custom Booster.
* \return Path to the socket file.
*/
virtual const string & socketId() const = 0;
//! Return true, if in boot mode.
bool bootMode() const;

@ -175,11 +175,11 @@ void Daemon::run(Booster *booster)
else
{
// Create socket for the booster
Logger::logDebug("Daemon: initing socket: %s", booster->socketId().c_str());
m_socketManager->initSocket(booster->socketId());
Logger::logDebug("Daemon: initing socket: %s", booster->boosterType().c_str());
m_socketManager->initSocket(booster->boosterType());
// Fork each booster for the first time
Logger::logDebug("Daemon: forking booster: '%c'", booster->boosterType());
Logger::logDebug("Daemon: forking booster: %s", booster->boosterType().c_str());
forkBooster();
}
@ -268,23 +268,20 @@ void Daemon::run(Booster *booster)
void Daemon::readFromBoosterSocket(int fd)
{
char booster = 0;
pid_t invokerPid = 0;
int delay = 0;
struct msghdr msg;
struct cmsghdr *cmsg;
struct iovec iov[3];
struct iovec iov[2];
char buf[CMSG_SPACE(sizeof(int))];
iov[0].iov_base = &booster;
iov[0].iov_len = sizeof(char);
iov[1].iov_base = &invokerPid;
iov[1].iov_len = sizeof(pid_t);
iov[2].iov_base = &delay;
iov[2].iov_len = sizeof(int);
iov[0].iov_base = &invokerPid;
iov[0].iov_len = sizeof(pid_t);
iov[1].iov_base = &delay;
iov[1].iov_len = sizeof(int);
msg.msg_iov = iov;
msg.msg_iovlen = 3;
msg.msg_iovlen = 2;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_control = buf;
@ -292,7 +289,6 @@ void Daemon::readFromBoosterSocket(int fd)
if (recvmsg(fd, &msg, 0) >= 0)
{
Logger::logDebug("Daemon: booster type: %c\n", booster);
Logger::logDebug("Daemon: invoker's pid: %d\n", invokerPid);
Logger::logDebug("Daemon: respawn delay: %d \n", delay);
if (invokerPid != 0)
@ -317,8 +313,6 @@ void Daemon::readFromBoosterSocket(int fd)
_exit(EXIT_FAILURE);
}
// Fork a new booster of the given type
// 2nd param guarantees some time for the just launched application
// to start up before forking new booster. Not doing this would
// slow down the start-up significantly on single core CPUs.
@ -367,9 +361,7 @@ void Daemon::forkBooster(int sleepTime)
_exit(EXIT_FAILURE);
}
char type = m_booster->boosterType();
// Invalidate current booster pid for the given type
// Invalidate current booster pid
m_boosterPid = 0;
// Fork a new process
@ -413,11 +405,11 @@ void Daemon::forkBooster(int sleepTime)
if (!m_bootMode && sleepTime)
sleep(sleepTime);
Logger::logDebug("Daemon: Running a new Booster of type '%c'", type);
Logger::logDebug("Daemon: Running a new Booster of type '%s'", m_booster->boosterType().c_str());
// Initialize and wait for commands from invoker
m_booster->initialize(m_initialArgc, m_initialArgv, m_boosterLauncherSocket[1],
m_socketManager->findSocket(m_booster->socketId().c_str()),
m_socketManager->findSocket(m_booster->boosterType().c_str()),
m_singleInstance, m_bootMode);
// Run the current Booster

@ -28,26 +28,25 @@ class MyBooster : public Booster
{
public:
MyBooster();
char boosterType() const;
const std::string & socketId() const;
const std::string & boosterType() const;
const std::string & boosterTemporaryProcessName() const;
protected:
bool preload();
private:
const string m_socketId;
const string m_boosterType;
const string m_temporaryProcessName;
};
MyBooster::MyBooster() :
m_socketId("/tmp/MyBooster"),
m_temporaryProcessName("x-booster")
m_boosterType("TestBooster"),
m_temporaryProcessName("test booster")
{}
char MyBooster::boosterType() const
const std::string & MyBooster::boosterType() const
{
return 'x';
return m_boosterType;
}
bool MyBooster::preload()
@ -60,11 +59,6 @@ const std::string & MyBooster::boosterTemporaryProcessName() const
return m_temporaryProcessName;
}
const std::string & MyBooster::socketId() const
{
return m_socketId;
}
void Ut_Booster::initTestCase()
{}

Loading…
Cancel
Save