Skip to content

Commit

Permalink
MessageControl: made dispatcher path as configurable (#1434)
Browse files Browse the repository at this point in the history
* MessageControl: made dispatcher path as configurable

* Review update

* Move MessageControlFolder and Path to Messaging settings

* Change type of Permission settings to uint16_t
  • Loading branch information
HaseenaSainul authored Oct 24, 2023
1 parent 3249f7c commit ddc2008
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 54 deletions.
9 changes: 0 additions & 9 deletions Source/WPEFramework/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ namespace PluginHost {
, ExitReasons()
, Latitude(51832547) // Divider 1.000.000
, Longitude(5674899) // Divider 1.000.000
, MessagingPort(0)
#ifdef PROCESSCONTAINERS_ENABLED
, ProcessContainers()
#endif
Expand Down Expand Up @@ -418,7 +417,6 @@ namespace PluginHost {
Add(_T("exitreasons"), &ExitReasons);
Add(_T("latitude"), &Latitude);
Add(_T("longitude"), &Longitude);
Add(_T("messagingport"), &MessagingPort);
#ifdef PROCESSCONTAINERS_ENABLED
Add(_T("processcontainers"), &ProcessContainers);
#endif
Expand Down Expand Up @@ -462,7 +460,6 @@ namespace PluginHost {
Core::JSON::ArrayType<Core::JSON::EnumType<PluginHost::IShell::reason>> ExitReasons;
Core::JSON::DecSInt32 Latitude;
Core::JSON::DecSInt32 Longitude;
Core::JSON::DecUInt16 MessagingPort;
#ifdef PROCESSCONTAINERS_ENABLED
ProcessContainerConfig ProcessContainers;
#endif
Expand Down Expand Up @@ -617,7 +614,6 @@ PUSH_WARNING(DISABLE_WARNING_THIS_IN_MEMBER_INITIALIZER_LIST)
, _softKillCheckWaitTime(3)
, _hardKillCheckWaitTime(10)
, _stackSize(0)
, _messagingPort()
, _inputInfo()
, _processInfo()
, _plugins()
Expand Down Expand Up @@ -676,7 +672,6 @@ PUSH_WARNING(DISABLE_WARNING_THIS_IN_MEMBER_INITIALIZER_LIST)
if( config.Latitude.IsSet() || config.Longitude.IsSet() ) {
SYSLOG(Logging::Error, (_T("Support for Latitude and Longitude moved from Thunder configuration to plugin providing ILocation support")));
}
_messagingPort = config.MessagingPort.Value();

_messagingCategoriesFile = config.DefaultMessagingCategories.IsQuoted();
if (_messagingCategoriesFile == true) {
Expand Down Expand Up @@ -875,9 +870,6 @@ POP_WARNING()
inline string EthernetCard() const {
return _ethernetCard;
}
inline uint16_t MessagingPort() const {
return (_messagingPort);
}
inline const InputInfo& Input() const {
return(_inputInfo);
}
Expand Down Expand Up @@ -1048,7 +1040,6 @@ POP_WARNING()
uint8_t _softKillCheckWaitTime;
uint8_t _hardKillCheckWaitTime;
uint32_t _stackSize;
uint16_t _messagingPort;
InputInfo _inputInfo;
ProcessInfo _processInfo;
Core::JSON::ArrayType<Plugin::Config> _plugins;
Expand Down
4 changes: 4 additions & 0 deletions Source/WPEFramework/GenericConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ set(WEBSERVER_PATH "/boot/www" CACHE STRING "Root path for the HTTP server")
set(WEBSERVER_PORT 8080 CACHE STRING "Port for the HTTP server")
set(PROXYSTUB_PATH "${CMAKE_INSTALL_PREFIX}/lib/${NAMESPACE_LIB}/proxystubs" CACHE STRING "Proxy stub path")
set(POSTMORTEM_PATH "/opt/minidumps" CACHE STRING "Core file path to do the postmortem of the crash")
set(MESSAGECONTROL_PATH "MessageDispatcher" CACHE STRING "MessageControl base path to create message files")
set(MESSAGING_PORT 0 CACHE STRING "The port for the messaging")
set(CONFIG_INSTALL_PATH "/etc/${NAMESPACE}" CACHE STRING "Install location of the configuration")
set(IPV6_SUPPORT false CACHE STRING "Controls if should application supports ipv6")
set(LEGACY_INITIALZE false CACHE STRING "Enables legacy Plugin Initialize behaviour (Deinit not called on failed Init)")
Expand Down Expand Up @@ -199,6 +201,8 @@ else(VIRTUALINPUT)
endif(NOT VIRTUALINPUT)

map()
kv(path ${MESSAGECONTROL_PATH})
kv(port ${MESSAGING_PORT})
key(logging)
key(tracing)
key(reporting)
Expand Down
2 changes: 1 addition & 1 deletion Source/WPEFramework/PluginHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ POP_WARNING()
// Time to open up, the message buffer for this process and define it for the out-of-proccess systems
// Define the environment variable for Messaging files, if it is not already set.
uint32_t messagingErrorCode = Core::ERROR_GENERAL;
messagingErrorCode = Messaging::MessageUnit::Instance().Open(_config->VolatilePath(), _config->MessagingPort(), messagingSettings, _background, options.flushMode);
messagingErrorCode = Messaging::MessageUnit::Instance().Open(_config->VolatilePath(), messagingSettings, _background, options.flushMode);

if ( messagingErrorCode != Core::ERROR_NONE){
#ifndef __WINDOWS__
Expand Down
2 changes: 2 additions & 0 deletions Source/WPEFramework/WPEFramework.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ else:

if boolean('@MESSAGING@'):
messaging = JSON()
messaging.add("path", '@MESSAGECONTROL_PATH@')
messaging.add("port", '@MESSAGING_PORT@')

__notification = {
"category" : "Notification",
Expand Down
4 changes: 2 additions & 2 deletions Source/core/AccessControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ namespace Core {
return result;
}

static uint32_t Permission(const string& node, const uint32_t modeFlags){
static uint32_t Permission(const string& node, const uint16_t modeFlags){
uint32_t result(Core::ERROR_NONE);

#ifdef __POSIX__
// Lucky us we mapped File::Mode 1:1 to POSIX mode,
// so we only have to filter some values :-).
mode_t mode = modeFlags & 0x0FFFFF;
mode_t mode = modeFlags & 0xFFFF;

if (::chmod(node.c_str(), mode) != 0) {
result = Core::ERROR_GENERAL;
Expand Down
2 changes: 1 addition & 1 deletion Source/core/CyclicBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ namespace Core {
{
return (_buffer.Group(groupName));
}
inline uint32_t Permission(uint32_t mode) const
inline uint32_t Permission(uint16_t mode) const
{
return (_buffer.Permission(mode));
}
Expand Down
2 changes: 1 addition & 1 deletion Source/core/DataElementFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace Core {

if ((type & File::CREATE) != 0) {
m_File.Create(type);
m_File.Permission(type & ~(File::CREATE | Core::File::SHAREABLE));
m_File.Permission(type & 0xFFFF);
} else {
m_File.Open((type & File::USER_WRITE) == 0);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/core/DataElementFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace Core {
{
return (m_File.Group(groupName));
}
inline uint32_t Permission(uint32_t mode) const
inline uint32_t Permission(uint16_t mode) const
{
return (m_File.Permission(mode));
}
Expand Down
4 changes: 2 additions & 2 deletions Source/core/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ namespace Core {
return AccessControl::OwnerShip(_name, "", groupName);
}

uint32_t File::Permission(uint32_t flags) const
uint32_t File::Permission(uint16_t flags) const
{
return AccessControl::Permission(_name, flags);
}
Expand Down Expand Up @@ -395,7 +395,7 @@ namespace Core {
return AccessControl::OwnerShip(_name, "", groupName);
}

uint32_t Directory::Permission(uint32_t flags) const
uint32_t Directory::Permission(uint16_t flags) const
{
return AccessControl::Permission(_name, flags);
}
Expand Down
20 changes: 18 additions & 2 deletions Source/core/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define __FILESYSTEM_H

#include "Portability.h"
#include "Number.h"
#include "Time.h"

#ifdef __POSIX__
Expand All @@ -35,6 +36,21 @@

namespace WPEFramework {
namespace Core {

PUSH_WARNING(DISABLE_WARNING_UNUSED_FUNCTIONS)

static void ParsePathInfo(const string& pathInfo, string& path, uint16_t& permission)
{
size_t position = pathInfo.find("|");
if (position != string::npos) {
Core::NumberType<uint16_t> number(pathInfo.substr(position + 1).c_str(), (pathInfo.length() - position));
permission = number.Value();
}
path = pathInfo.substr(0, position);
}

POP_WARNING()

class EXTERNAL File {
public:
#ifdef __WINDOWS__
Expand Down Expand Up @@ -563,7 +579,7 @@ POP_WARNING()

uint32_t User(const string& userName) const;
uint32_t Group(const string& groupName) const;
uint32_t Permission(uint32_t flags) const;
uint32_t Permission(uint16_t flags) const;

private:
inline static uint32_t ExtensionOffset(const string& name)
Expand Down Expand Up @@ -772,7 +788,7 @@ POP_WARNING()

uint32_t User(const string& userName) const;
uint32_t Group(const string& groupName) const;
uint32_t Permission(uint32_t flags) const;
uint32_t Permission(uint16_t flags) const;

private:
string _name;
Expand Down
13 changes: 3 additions & 10 deletions Source/core/NodeId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//
//////////////////////////////////////////////////////////////////////

#include "FileSystem.h"
#include "Portability.h"
#include "Serialization.h"
#include "TextFragment.h"
Expand Down Expand Up @@ -370,16 +371,8 @@ static bool IsIPv6Address(const TCHAR hostname[]) {
hostName = hostName.substr(0, position);
}

position = hostName.find("|");
if (position != string::npos) {
//string number = hostName.substr(position + 1);
Core::NumberType<uint16_t> number(hostName.substr(position + 1).c_str(), (hostName.length() - position));
m_structInfo.DomainSocket.un_access = number.Value();
m_hostName = hostName.substr(0, position);
} else {
m_structInfo.DomainSocket.un_access = static_cast<uint16_t>(~0);
m_hostName = hostName;
}
m_structInfo.DomainSocket.un_access = static_cast<uint16_t>(~0);
Core::ParsePathInfo(hostName, m_hostName, m_structInfo.DomainSocket.un_access);

m_structInfo.DomainSocket.sun_family = AF_UNIX;
strncpy(m_structInfo.DomainSocket.sun_path, m_hostName.c_str(), sizeof(m_structInfo.DomainSocket.sun_path) - 1);
Expand Down
2 changes: 1 addition & 1 deletion Source/core/NodeId.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ namespace Core {
return (m_structInfo.Extension());
}

inline uint32_t Rights() const
inline uint16_t Rights() const
{
#ifndef __WINDOWS__
return (Type() == TYPE_DOMAIN ? m_structInfo.DomainSocket.un_access : 0);
Expand Down
2 changes: 1 addition & 1 deletion Source/core/SharedBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ namespace Core {

return result;
}
uint32_t Permission(uint32_t mode) const
uint32_t Permission(uint16_t mode) const
{
uint32_t result = _administrationBuffer.Permission(mode);

Expand Down
2 changes: 1 addition & 1 deletion Source/extensions/localtracer/example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ int main(int /*argc*/, const char* argv[])
WPEFramework::Core::Singleton::Dispose();

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace Messaging {

Core::Directory(Path.c_str()).CreatePath();

Messaging::MessageUnit::Instance().Open(Path, 0, "", false, Messaging::MessageUnit::OFF);
Messaging::MessageUnit::Instance().Open(Path, "", false, Messaging::MessageUnit::OFF);

singleton = new LocalTracer(Path);
}
Expand Down
25 changes: 13 additions & 12 deletions Source/messaging/MessageUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,32 +139,33 @@ namespace WPEFramework {
* - create buffer where all InProcess components will write
*
* @param pathName volatile path (/tmp/ by default)
* @param socketPort triggers the use of using a IP socket in stead of a domain socket (in pathName) if the port value is not 0.
*/
uint32_t MessageUnit::Open(const string& pathName, const uint16_t socketPort, const string& configuration, const bool background, const flush flushMode)
uint32_t MessageUnit::Open(const string& pathName, const string& configuration, const bool background, const flush flushMode)
{
uint32_t result = Core::ERROR_OPENING_FAILED;

string basePath = Core::Directory::Normalize(pathName) + _T("MessageDispatcher");
string identifier = _T("md");
_settings.Configure(pathName, identifier, configuration, background, flushMode);

ASSERT(_dispatcher == nullptr);

if (Core::File(basePath).IsDirectory() == true) {
if (Core::File(_settings.BasePath()).IsDirectory() == true) {
//if directory exists remove it to clear data (eg. sockets) that can remain after previous run
Core::Directory(basePath.c_str()).Destroy();
}

if (Core::Directory(basePath.c_str()).CreatePath() == false) {
TRACE_L1("Unable to create MessageDispatcher directory");
Core::Directory(_settings.BasePath().c_str()).Destroy();
} else {
if (Core::Directory(_settings.BasePath().c_str()).CreatePath() == false) {
TRACE_L1("Unable to create MessageDispatcher directory");
} else {
if (_settings.Permission()) {
Core::Directory(_settings.BasePath().c_str()).Permission(_settings.Permission());
}
}
}

_settings.Configure(basePath, identifier, socketPort, configuration, background, flushMode);

// Store it on an environment variable so other instances can pick this info up..
_settings.Save();

_dispatcher.reset(new MessageDispatcher(*this, identifier, 0, basePath, socketPort));
_dispatcher.reset(new MessageDispatcher(*this, identifier, 0, _settings.BasePath().c_str(), _settings.SocketPort()));
ASSERT(_dispatcher != nullptr);

if ((_dispatcher != nullptr) && (_dispatcher->IsValid() == true)) {
Expand Down
28 changes: 22 additions & 6 deletions Source/messaging/MessageUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,14 @@ namespace WPEFramework {
, Tracing()
, Logging()
, Reporting()
, Port(0)
, Path(_T("MessageDispatcher"))
{
Add(_T("tracing"), &Tracing);
Add(_T("logging"), &Logging);
Add(_T("reporting"), &Reporting);
Add(_T("path"), &Path);
Add(_T("port"), &Port);
}
~Config() = default;
Config(const Config& other) = delete;
Expand All @@ -346,6 +350,8 @@ namespace WPEFramework {
TracingSection Tracing;
LoggingSection Logging;
ReportingSection Reporting;
Core::JSON::DecUInt16 Port;
Core::JSON::String Path;
};

public:
Expand All @@ -358,6 +364,7 @@ namespace WPEFramework {
, _path()
, _identifier()
, _socketPort()
, _permission(0)
, _mode()
{
}
Expand All @@ -376,6 +383,10 @@ namespace WPEFramework {
return (_socketPort);
}

uint16_t Permission() const {
return (_permission);
}

bool IsBackground() const {
return ((_mode & mode::BACKGROUND) != 0);
}
Expand All @@ -397,16 +408,20 @@ namespace WPEFramework {
return (abbreviate);
}

void Configure (const string& path, const string& identifier, const uint16_t socketPort, const string& config, const bool background, const flush flushMode)
void Configure (const string& basePath, const string& identifier, const string& config, const bool background, const flush flushMode)
{
Config jsonParsed;
jsonParsed.FromString(config);

_settings.clear();
_path = path;
string messagingFolder;
Core::ParsePathInfo(jsonParsed.Path.Value(), messagingFolder, _permission);

_path = Core::Directory::Normalize(basePath) + messagingFolder;
_identifier = identifier;
_socketPort = socketPort;
_socketPort = jsonParsed.Port.Value();
_mode = (background ? mode::BACKGROUND : 0) | (flushMode != flush::OFF ? mode::DIRECT : 0) | (flushMode == FLUSH_ABBREVIATED ? mode::ABBREVIATED : 0);

Config jsonParsed;
jsonParsed.FromString(config);
FromConfig(jsonParsed);
}

Expand Down Expand Up @@ -606,6 +621,7 @@ namespace WPEFramework {
string _path;
string _identifier;
uint16_t _socketPort;
uint16_t _permission;
uint8_t _mode;
};

Expand Down Expand Up @@ -842,7 +858,7 @@ namespace WPEFramework {
return (_settings.SocketPort());
}

uint32_t Open(const string& pathName, const uint16_t doorbell, const string& configuration, const bool background, const flush flushMode);
uint32_t Open(const string& pathName, const string& configuration, const bool background, const flush flushMode);
uint32_t Open(const uint32_t instanceId);
void Close();

Expand Down
Loading

0 comments on commit ddc2008

Please sign in to comment.