From 1dcc6da102ca6a53620e31899b8b99f8b1dc211d Mon Sep 17 00:00:00 2001
From: Yasas Perera <yasascperera@gmail.com>
Date: Wed, 10 Feb 2021 12:57:25 +0100
Subject: [PATCH] container-plugin: add wayland socket name to container
 configs

A Unix socket is used by wayland compositor in the multi-process mode
to communicate between various windows. When starting the
QtApplication manager, a name for the Unix socket is passed via
command-line argument.  

This socket name is needed when setting up a container, to create a
file bind mount into the container. This allows containerized the
appman-launcher-qml process to access wayland.

The problem with the above approach is the socket name should be known
when starting the softwarecontainer-agent.

Since this is undesirable, wayland socket name should be made
available in to the container plugins.

Issue-ID: AUTOSUITE-1639

Signed-off-by: Yasas Perera <yasascperera@gmail.com>
---
 src/main-lib/main.cpp                | 12 +++++++-----
 src/main-lib/main.h                  |  5 +++--
 src/manager-lib/containerfactory.cpp |  6 ++++--
 src/manager-lib/containerfactory.h   |  2 +-
 4 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/main-lib/main.cpp b/src/main-lib/main.cpp
index 1c4864d..7fb81bb 100644
--- a/src/main-lib/main.cpp
+++ b/src/main-lib/main.cpp
@@ -256,8 +256,9 @@ void Main::setup(const Configuration *cfg) Q_DECL_NOEXCEPT_EXPR(false)
     setMainQmlFile(cfg->mainQmlFile());
     setupSingleOrMultiProcess(cfg->forceSingleProcess(), cfg->forceMultiProcess());
     setupRuntimesAndContainers(cfg->runtimeConfigurations(), cfg->openGLConfiguration(),
-                               cfg->containerConfigurations(), cfg->pluginFilePaths("container"),
-                               cfg->iconThemeSearchPaths(), cfg->iconThemeName());
+                               cfg->containerConfigurations(), cfg->waylandSocketName(),
+                               cfg->pluginFilePaths("container"), cfg->iconThemeSearchPaths(),
+                               cfg->iconThemeName());
 
     loadPackageDatabase(cfg->clearCache() || cfg->noCache(), cfg->singleApp());
 
@@ -427,8 +428,9 @@ void Main::setupSingleOrMultiProcess(bool forceSingleProcess, bool forceMultiPro
 }
 
 void Main::setupRuntimesAndContainers(const QVariantMap &runtimeConfigurations, const QVariantMap &openGLConfiguration,
-                                      const QVariantMap &containerConfigurations, const QStringList &containerPluginPaths,
-                                      const QStringList &iconThemeSearchPaths, const QString &iconThemeName)
+                                      const QVariantMap &containerConfigurations, const QString &waylandSocketName,
+                                      const QStringList &containerPluginPaths, const QStringList &iconThemeSearchPaths,
+                                      const QString &iconThemeName)
 {
     if (m_isSingleProcessMode) {
         RuntimeFactory::instance()->registerRuntime(new QmlInProcessRuntimeManager());
@@ -449,7 +451,7 @@ void Main::setupRuntimesAndContainers(const QVariantMap &runtimeConfigurations,
     for (auto iface : qAsConst(m_startupPlugins))
         iface->afterRuntimeRegistration();
 
-    ContainerFactory::instance()->setConfiguration(containerConfigurations);
+    ContainerFactory::instance()->setConfiguration(containerConfigurations, waylandSocketName);
     RuntimeFactory::instance()->setConfiguration(runtimeConfigurations);
     RuntimeFactory::instance()->setSystemOpenGLConfiguration(openGLConfiguration);
     RuntimeFactory::instance()->setIconTheme(iconThemeSearchPaths, iconThemeName);
diff --git a/src/main-lib/main.h b/src/main-lib/main.h
index 154d0e6..a694afb 100644
--- a/src/main-lib/main.h
+++ b/src/main-lib/main.h
@@ -116,8 +116,9 @@ protected:
     void setMainQmlFile(const QString &mainQml) Q_DECL_NOEXCEPT_EXPR(false);
     void setupSingleOrMultiProcess(bool forceSingleProcess, bool forceMultiProcess) Q_DECL_NOEXCEPT_EXPR(false);
     void setupRuntimesAndContainers(const QVariantMap &runtimeConfigurations, const QVariantMap &openGLConfiguration,
-                                    const QVariantMap &containerConfigurations, const QStringList &containerPluginPaths,
-                                    const QStringList &iconThemeSearchPaths, const QString &iconThemeName);
+                                    const QVariantMap &containerConfigurations, const QString &waylandSocketName,
+                                    const QStringList &containerPluginPaths, const QStringList &iconThemeSearchPaths,
+                                    const QString &iconThemeName);
     void loadPackageDatabase(bool recreateDatabase, const QString &singlePackage) Q_DECL_NOEXCEPT_EXPR(false);
     void setupIntents(int disambiguationTimeout, int startApplicationTimeout,
                       int replyFromApplicationTimeout, int replyFromSystemTimeout) Q_DECL_NOEXCEPT_EXPR(false);
diff --git a/src/manager-lib/containerfactory.cpp b/src/manager-lib/containerfactory.cpp
index 6e89e86..438e022 100644
--- a/src/manager-lib/containerfactory.cpp
+++ b/src/manager-lib/containerfactory.cpp
@@ -94,10 +94,12 @@ AbstractContainer *ContainerFactory::create(const QString &id, Application *app,
     return acm->create(app, stdioRedirections, debugWrapperEnvironment, debugWrapperCommand);
 }
 
-void ContainerFactory::setConfiguration(const QVariantMap &configuration)
+void ContainerFactory::setConfiguration(const QVariantMap &configuration, const QString &waylandSocketName)
 {
     for (auto it = m_containers.cbegin(); it != m_containers.cend(); ++it) {
-        it.value()->setConfiguration(configuration.value(it.key()).toMap());
+        QVariantMap configsMap = configuration.value(it.key()).toMap();
+        configsMap.insert(qSL("wayland-socket-name"), waylandSocketName);
+        it.value()->setConfiguration(configsMap);
     }
 }
 
diff --git a/src/manager-lib/containerfactory.h b/src/manager-lib/containerfactory.h
index 102c094..c43d160 100644
--- a/src/manager-lib/containerfactory.h
+++ b/src/manager-lib/containerfactory.h
@@ -69,7 +69,7 @@ public:
                               const QMap<QString, QString> &debugWrapperEnvironment = QMap<QString, QString>(),
                               const QStringList &debugWrapperCommand = QStringList());
 
-    void setConfiguration(const QVariantMap &configuration);
+    void setConfiguration(const QVariantMap &configuration, const QString &waylandSocketName);
 
     bool registerContainer(AbstractContainerManager *manager);
     bool registerContainer(AbstractContainerManager *manager, const QString &identifier);
-- 
2.7.4

