New: Basic implementation of the e-booster.

pull/1/head
Jussi Lind 15 years ago
parent 038bf86bc5
commit 28d852e015

@ -1,6 +1,7 @@
usr/bin/applauncherd.bin usr/bin/applauncherd.bin
usr/lib/applauncherd/libapplauncherd.so usr/lib/applauncherd/libapplauncherd.so
usr/bin/applauncherd usr/bin/applauncherd
usr/lib/applauncherd/libebooster.so
usr/lib/applauncherd/libmbooster.so usr/lib/applauncherd/libmbooster.so
usr/lib/applauncherd/libqtbooster.so usr/lib/applauncherd/libqtbooster.so
usr/lib/applauncherd/libqdeclarativebooster.so usr/lib/applauncherd/libqdeclarativebooster.so

@ -7,6 +7,9 @@ add_subdirectory(launcher)
# Sub build: launcher library # Sub build: launcher library
add_subdirectory(launcherlib) add_subdirectory(launcherlib)
# Sub build: ebooster plugin
add_subdirectory(ebooster)
# Sub build: mbooster plugin # Sub build: mbooster plugin
add_subdirectory(mbooster) add_subdirectory(mbooster)

@ -0,0 +1,28 @@
# Qt support
include(${QT_USE_FILE})
set(LAUNCHER "${CMAKE_HOME_DIRECTORY}/src/launcherlib")
set(COMMON "${CMAKE_HOME_DIRECTORY}/src/common")
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${COMMON} ${LAUNCHER})
# Hide all symbols except the ones explicitly exported in the code (like main())
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
# Set sources
set(SRC ebooster.cpp pluginfactory.cpp ${LAUNCHER}/appdata.cpp ${LAUNCHER}/booster.cpp
${LAUNCHER}/connection.cpp ${LAUNCHER}/logger.cpp
${LAUNCHER}/singleinstance.cpp ${LAUNCHER}/socketmanager.cpp
${COMMON}/eventhandler.cpp)
set(MOC_HDRS ${COMMON}/eventhandler.h)
qt4_wrap_cpp(MOC_SRC ${MOC_HDRS})
# Set libraries to be linked.
link_libraries(${MEEGOTOUCH_LIBRARIES} ${LIBDL} ${QT_QTCORE_LIBRARY})
# Set executable
add_library(ebooster MODULE ${SRC} ${MOC_SRC})
# Add install rule
install(TARGETS ebooster DESTINATION /usr/lib/applauncherd/)

@ -0,0 +1,87 @@
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of applauncherd
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#include "ebooster.h"
#include "logger.h"
#include <errno.h>
#ifdef HAVE_MCOMPONENTCACHE
#include <mcomponentcache.h>
#endif
const string EBooster::m_socketId = "/tmp/booste";
const string EBooster::m_temporaryProcessName = "booster-e";
const string & EBooster::socketId() const
{
return m_socketId;
}
const string & EBooster::socketName()
{
return m_socketId;
}
const string & EBooster::temporaryProcessName()
{
return m_temporaryProcessName;
}
const string & EBooster::boosterTemporaryProcessName() const
{
return temporaryProcessName();
}
char EBooster::type()
{
return 'e';
}
bool EBooster::preload()
{
return true;
}
int EBooster::launchProcess()
{
Booster::setEnvironmentBeforeLaunch();
// Ensure a NULL-terminated argv
char ** dummyArgv = new char * [appData()->argc() + 1];
const int i2 = appData()->argc();
for (int i = 0; i < i2; i++)
dummyArgv[i] = strdup(appData()->argv()[i]);
dummyArgv[i2] = NULL;
// Exec the binary (execv returns only in case of an error).
if (execv(appData()->fileName().c_str(),
dummyArgv))
{
Logger::logError("EBooster: Couldn't execv '%s': %s",
appData()->fileName().c_str(),
strerror(errno));
}
// Delete dummy argv if execv failed
for (int i = 0; i < i2; i++)
delete dummyArgv[i];
return EXIT_FAILURE;
}

@ -0,0 +1,111 @@
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of applauncherd
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#ifndef EBOOSTER_H
#define EBOOSTER_H
#include "booster.h"
#include "eventhandler.h"
#include <tr1/memory>
using std::tr1::shared_ptr;
#include <signal.h>
/*!
\class EBooster
\brief EBooster is a "booster" that only exec()'s the given binary.
This can be used with e.g. splash screen to launch any application.
*/
class EBooster : public Booster
{
public:
//! \brief Constructor
EBooster() {}
//! \brief Destructor
virtual ~EBooster() {}
/*!
* \brief Return the socket name common to all EBooster objects.
* \return Path to the socket file.
*/
static const string & socketName();
//! Return the process name to be used when booster is not
//! yet transformed into a running application
static const string & temporaryProcessName();
//! \reimp
virtual const string & boosterTemporaryProcessName() const;
//! \reimp
virtual char boosterType() const { return type(); }
/*!
* \brief Return a unique character ('e') represtenting the type of EBoosters.
* \return Type character.
*/
static char type();
//! \reimp
virtual const string & socketId() const;
protected:
//! \reimp
virtual int launchProcess();
//! \reimp
virtual bool preload();
private:
//! Disable copy-constructor
EBooster(const EBooster & r);
//! Disable assignment operator
EBooster & operator= (const EBooster & r);
static const string m_socketId;
//! Process name to be used when booster is not
//! yet transformed into a running application
static const string m_temporaryProcessName;
//! wait for socket connection
void accept();
private slots:
//! Qt signal handler for SIGHUP.
void handleSigHup();
//! Qt signal handler for theme change
void notifyThemeChange();
#ifdef UNIT_TEST
friend class Ut_EBooster;
#endif
};
#endif // EBooster_H

@ -0,0 +1,45 @@
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of applauncherd
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#include "ebooster.h"
#include <QtCore>
extern "C"
{
// Create a new plugin instance.
Q_DECL_EXPORT void * create()
{
return new EBooster;
}
Q_DECL_EXPORT char type()
{
return EBooster::type();
}
Q_DECL_EXPORT const char * socketName()
{
return EBooster::socketName().c_str();
}
Q_DECL_EXPORT const char * temporaryProcessName()
{
return EBooster::temporaryProcessName().c_str();
}
}

@ -31,5 +31,6 @@ void invoke_send_str(int fd, char *str);
#define INVOKER_M_SOCK "/tmp/boostm" #define INVOKER_M_SOCK "/tmp/boostm"
#define INVOKER_QT_SOCK "/tmp/boostq" #define INVOKER_QT_SOCK "/tmp/boostq"
#define INVOKER_QDECL_SOCK "/tmp/boostd" #define INVOKER_QDECL_SOCK "/tmp/boostd"
#define INVOKER_EXEC_SOCK "/tmp/booste"
#endif #endif

@ -58,9 +58,10 @@ static const unsigned char EXIT_STATUS_APPLICATION_NOT_FOUND = 0x7f;
// Enumeration of possible application types: // Enumeration of possible application types:
// M_APP : MeeGo Touch application // M_APP : MeeGo Touch application
// QT_APP : Qt/generic application // QT_APP : Qt/generic application
// QDECL_APP: QDeclarative (QML) application // QDECL_APP : QDeclarative (QML) application
// EXEC_APP : Executable generic application (can be used with splash screen)
// //
enum APP_TYPE { M_APP, QT_APP, QDECL_APP, UNKNOWN_APP }; enum APP_TYPE { M_APP, QT_APP, QDECL_APP, EXEC_APP, UNKNOWN_APP };
// Environment // Environment
extern char ** environ; extern char ** environ;
@ -210,6 +211,10 @@ static int invoker_init(enum APP_TYPE app_type)
{ {
strncpy(sun.sun_path, INVOKER_QDECL_SOCK, maxSize); strncpy(sun.sun_path, INVOKER_QDECL_SOCK, maxSize);
} }
else if (app_type == EXEC_APP)
{
strncpy(sun.sun_path, INVOKER_EXEC_SOCK, maxSize);
}
else else
{ {
die(1, "Unknown type of application: %d\n", app_type); die(1, "Unknown type of application: %d\n", app_type);
@ -402,8 +407,10 @@ static void usage(int status)
"TYPE chooses the type of booster used. Qt-booster may be used to\n" "TYPE chooses the type of booster used. Qt-booster may be used to\n"
"launch anything. Possible values for TYPE:\n" "launch anything. Possible values for TYPE:\n"
" m Launch a MeeGo Touch application.\n" " m Launch a MeeGo Touch application.\n"
" qt Launch a Qt application.\n" " q (or qt) Launch a Qt application.\n"
" d Launch a Qt Declarative (QML) application.\n\n" " d Launch a Qt Declarative (QML) application.\n"
" e Launch any application, even if it's not a library.\n"
" Can be used if only splash screen is wanted.\n\n"
"Options:\n" "Options:\n"
" -c, --creds Print Aegis security credentials (if enabled).\n" " -c, --creds Print Aegis security credentials (if enabled).\n"
" -d, --delay SECS After invoking sleep for SECS seconds\n" " -d, --delay SECS After invoking sleep for SECS seconds\n"
@ -650,6 +657,8 @@ int main(int argc, char *argv[])
app_type = QT_APP; app_type = QT_APP;
else if (strcmp(optarg, "d") == 0) else if (strcmp(optarg, "d") == 0)
app_type = QDECL_APP; app_type = QDECL_APP;
else if (strcmp(optarg, "e") == 0)
app_type = EXEC_APP;
else else
{ {
report(report_error, "Unknown application type: %s \n", optarg); report(report_error, "Unknown application type: %s \n", optarg);

@ -298,7 +298,7 @@ void Booster::renameProcess(int parentArgc, char** parentArgv,
} }
} }
int Booster::launchProcess() void Booster::setEnvironmentBeforeLaunch()
{ {
// Possibly restore process priority // Possibly restore process priority
errno = 0; errno = 0;
@ -342,9 +342,6 @@ int Booster::launchProcess()
} }
#endif #endif
// Load the application and find out the address of main()
void* handle = loadMain();
// Duplicate I/O descriptors // Duplicate I/O descriptors
for (unsigned int i = 0; i < m_appData->ioDescriptors().size(); i++) for (unsigned int i = 0; i < m_appData->ioDescriptors().size(); i++)
{ {
@ -369,6 +366,17 @@ int Booster::launchProcess()
char * launch = const_cast<char *>(strstr(m_appData->argv()[0], ".launch")); char * launch = const_cast<char *>(strstr(m_appData->argv()[0], ".launch"));
*launch = '\0'; *launch = '\0';
} }
}
int Booster::launchProcess()
{
setEnvironmentBeforeLaunch();
// Load the application and find out the address of main()
void* handle = loadMain();
// Set dumpable flag
prctl(PR_SET_DUMPABLE, 1);
// Set dumpable flag // Set dumpable flag
prctl(PR_SET_DUMPABLE, 1); prctl(PR_SET_DUMPABLE, 1);

@ -81,7 +81,7 @@ public:
/*! /*!
* \brief Run the application to be invoked. * \brief Run the application to be invoked.
* This method causes the application binary to be loaded * By default, this method causes the application binary to be loaded
* using dlopen(). Program execution jumps to the address of * using dlopen(). Program execution jumps to the address of
* "main()" found in the newly loaded library. The Booster process * "main()" found in the newly loaded library. The Booster process
* exits with corresponding exit-code after the execution of * exits with corresponding exit-code after the execution of
@ -146,6 +146,18 @@ public:
protected: protected:
/*!
* Set process environment (UID, GID..) before launch.
* Re-implement if needed. This is automatically called by
* launchProcess().
*/
virtual void setEnvironmentBeforeLaunch();
/*! Load the library and jump to main.
* Re-implement if needed.
*/
virtual int launchProcess();
/*! /*!
* \brief Preload libraries / initialize cache etc. * \brief Preload libraries / initialize cache etc.
* Called from initialize if not in the boot mode. * Called from initialize if not in the boot mode.
@ -190,9 +202,6 @@ private:
//! and signal that a new booster can be created. //! and signal that a new booster can be created.
void sendDataToParent(); void sendDataToParent();
//! Load the library and jump to main
int launchProcess();
//! Helper method: load the library and find out address for "main". //! Helper method: load the library and find out address for "main".
void* loadMain(); void* loadMain();

@ -46,8 +46,6 @@ void Logger::closeLog()
void Logger::writeLog(const int priority, const char * format, va_list ap) void Logger::writeLog(const int priority, const char * format, va_list ap)
{ {
if (Logger::m_isOpened)
{
// In debug mode everything is printed also to stdout // In debug mode everything is printed also to stdout
if (m_debugMode) if (m_debugMode)
{ {
@ -55,6 +53,8 @@ void Logger::writeLog(const int priority, const char * format, va_list ap)
printf("\n"); printf("\n");
} }
if (Logger::m_isOpened)
{
// Print to syslog // Print to syslog
vsyslog(priority, format, ap); vsyslog(priority, format, ap);
} }

@ -64,7 +64,7 @@ public:
virtual char boosterType() const { return type(); } virtual char boosterType() const { return type(); }
/*! /*!
* \brief Return a unique character ('d') represtenting the type of MBoosters. * \brief Return a unique character ('m') represtenting the type of MBoosters.
* \return Type character. * \return Type character.
*/ */
static char type(); static char type();

Loading…
Cancel
Save