!9 Fix the problem caused by the boot sequence of mate-settings-daemon and kiran-session-daemon.

From: @kylinsecos_admin 
Reviewed-by: @tangjie02 
Signed-off-by: @tangjie02
This commit is contained in:
openeuler-ci-bot 2022-03-08 10:09:57 +00:00 committed by Gitee
commit 1745c82080
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 184 additions and 255 deletions

View File

@ -0,0 +1,163 @@
From 9796c3d4224e7c5b15edca3ca0b158451809b973 Mon Sep 17 00:00:00 2001
From: kylinsecos_admin <gitee@kylinos.com.cn>
Date: Thu, 3 Mar 2022 14:46:14 +0800
Subject: [PATCH] feature(dbus): Add dbus method Setenv
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 添加dbus函数Setenv
Signed-off-by: kylinsecos_admin <gitee@kylinos.com.cn>
---
src/org.gnome.SessionManager.xml | 10 ++++++++++
src/session-manager.cpp | 12 ++++++++++++
src/session-manager.h | 3 +++
src/utils.cpp | 18 +++++++++---------
src/utils.h | 6 +++---
5 files changed, 37 insertions(+), 12 deletions(-)
diff --git a/src/org.gnome.SessionManager.xml b/src/org.gnome.SessionManager.xml
index 60827ce..9b4cec5 100644
--- a/src/org.gnome.SessionManager.xml
+++ b/src/org.gnome.SessionManager.xml
@@ -116,6 +116,16 @@
<description>Whether the user can reboot.</description>
</method>
+ <method name="Setenv">
+ <arg name="name" type="s" direction="in">
+ <summary>The environment variable name</summary>
+ </arg>
+ <arg name="value" type="s" direction="in">
+ <summary>The environment variable value</summary>
+ </arg>
+ <description>Adds the variable name to the application launch environment with the specified value. May only be used during the Session Manager initialization phase.</description>
+ </method>
+
<signal name="InhibitorAdded">
<arg name="cookie" type="u">
<summary>The inhibitor cookie.</summary>
diff --git a/src/session-manager.cpp b/src/session-manager.cpp
index 5047c59..7f57255 100644
--- a/src/session-manager.cpp
+++ b/src/session-manager.cpp
@@ -279,6 +279,18 @@ void SessionManager::CanReboot(MethodInvocation &invocation)
invocation.ret(this->power_.can_power_action(PowerAction::POWER_ACTION_REBOOT));
}
+void SessionManager::Setenv(const Glib::ustring &name, const Glib::ustring &value, MethodInvocation &invocation)
+{
+ KLOG_PROFILE("name: %s, value: %s.", name.c_str(), value.c_str());
+
+ if (this->current_phase_ > KSMPhase::KSM_PHASE_INITIALIZATION)
+ {
+ DBUS_ERROR_REPLY_AND_RET(KSMErrorCode::ERROR_MANAGER_PHASE_INVALID);
+ }
+ Utils::setenv(name, value);
+ invocation.ret();
+}
+
void SessionManager::init()
{
KLOG_PROFILE("");
diff --git a/src/session-manager.h b/src/session-manager.h
index c8cf075..9d26c57 100644
--- a/src/session-manager.h
+++ b/src/session-manager.h
@@ -88,6 +88,9 @@ protected:
virtual void RequestReboot(MethodInvocation &invocation);
virtual void CanReboot(MethodInvocation &invocation);
+ // 添加会话程序的环境变量
+ virtual void Setenv(const Glib::ustring &name, const Glib::ustring &value, MethodInvocation &invocation);
+
private:
void init();
diff --git a/src/utils.cpp b/src/utils.cpp
index e70cc98..0cbe117 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -87,13 +87,13 @@ std::vector<std::string> Utils::get_autostart_dirs()
return dirs;
}
-void Utils::setenv(const std::string &key, const std::string &value)
+void Utils::setenv(const std::string &name, const std::string &value)
{
- KLOG_DEBUG("key: %s, value: %s.", key.c_str(), value.c_str());
+ KLOG_DEBUG("name: %s, value: %s.", name.c_str(), value.c_str());
- Glib::setenv(key, value);
- Utils::setenv_to_dbus(key, value);
- Utils::setenv_to_systemd(key, value);
+ Glib::setenv(name, value);
+ Utils::setenv_to_dbus(name, value);
+ Utils::setenv_to_systemd(name, value);
}
void Utils::setenvs(const std::map<Glib::ustring, Glib::ustring> &envs)
@@ -196,7 +196,7 @@ std::string Utils::phase_enum2str(KSMPhase phase)
return std::string();
}
-void Utils::setenv_to_dbus(const std::string &key, const std::string &value)
+void Utils::setenv_to_dbus(const std::string &name, const std::string &value)
{
try
{
@@ -206,7 +206,7 @@ void Utils::setenv_to_dbus(const std::string &key, const std::string &value)
DAEMON_DBUS_INTERFACE_NAME);
using param_type = std::tuple<std::map<Glib::ustring, Glib::ustring>>;
- std::map<Glib::ustring, Glib::ustring> envs{{key, value}};
+ std::map<Glib::ustring, Glib::ustring> envs{{name, value}};
auto parameter = Glib::Variant<param_type>::create(std::make_tuple(envs));
daemon_proxy->call_sync("UpdateActivationEnvironment", parameter);
}
@@ -217,7 +217,7 @@ void Utils::setenv_to_dbus(const std::string &key, const std::string &value)
}
}
-void Utils::setenv_to_systemd(const std::string &key, const std::string &value)
+void Utils::setenv_to_systemd(const std::string &name, const std::string &value)
{
try
{
@@ -226,7 +226,7 @@ void Utils::setenv_to_systemd(const std::string &key, const std::string &value)
SYSTEMD_DBUS_OBJECT_PATH,
SYSTEMD_DBUS_INTERFACE_NAME);
using param_type = std::tuple<std::vector<Glib::ustring>>;
- auto env = fmt::format("{0}={1}", key, value);
+ auto env = fmt::format("{0}={1}", name, value);
auto parameter = Glib::Variant<param_type>::create(std::make_tuple(std::vector<Glib::ustring>{env}));
systemd_proxy->call_sync("SetEnvironment", parameter);
}
diff --git a/src/utils.h b/src/utils.h
index 2501734..d51de5b 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -32,7 +32,7 @@ public:
// 获取自动启动程序的目录列表
static std::vector<std::string> get_autostart_dirs();
// 设置环境变量
- static void setenv(const std::string &key, const std::string &value);
+ static void setenv(const std::string &name, const std::string &value);
static void setenvs(const std::map<Glib::ustring, Glib::ustring> &envs);
// 生成cookie
static uint32_t generate_cookie();
@@ -41,8 +41,8 @@ public:
static std::string phase_enum2str(KSMPhase phase);
private:
- static void setenv_to_dbus(const std::string &key, const std::string &value);
- static void setenv_to_systemd(const std::string &key, const std::string &value);
+ static void setenv_to_dbus(const std::string &name, const std::string &value);
+ static void setenv_to_systemd(const std::string &name, const std::string &value);
private:
static Glib::Rand rand_;
--
2.27.0

View File

@ -1,187 +0,0 @@
From 918aca5b83c170b229c6449c27556ad70743f728 Mon Sep 17 00:00:00 2001
From: tangjie02 <tangjie02@kylinsec.com.cn>
Date: Tue, 4 Jan 2022 17:11:31 +0800
Subject: [PATCH] fix(xinit): Fix the dbus error when the session manager is
launched by xinit
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 修复通过xinit启动会话管理时程序会卡在获取DisplayManager的dbus句柄的地方
Signed-off-by: tangjie02 <tangjie02@kylinsec.com.cn>
---
src/client/client-manager.cpp | 2 ++
src/main.cpp | 35 +++++++++++++++++++++++++++++++++
src/presence.cpp | 2 ++
src/session-manager.cpp | 2 ++
src/ui/ui-manager.cpp | 2 ++
src/wrapper/display-manager.cpp | 24 +++++++++++++++-------
src/xsmp-server.cpp | 2 ++
7 files changed, 62 insertions(+), 7 deletions(-)
diff --git a/src/client/client-manager.cpp b/src/client/client-manager.cpp
index be9a75b..e5c4df2 100644
--- a/src/client/client-manager.cpp
+++ b/src/client/client-manager.cpp
@@ -61,6 +61,8 @@ std::shared_ptr<ClientDBus> ClientManager::get_client_by_dbus_name(const std::st
void ClientManager::init()
{
+ KLOG_PROFILE("");
+
this->dbus_daemon_proxy_->signal_signal().connect(sigc::mem_fun(this, &ClientManager::on_dbus_daemon_signal_cb));
this->xsmp_server_->signal_new_client_connected().connect(sigc::mem_fun(this, &ClientManager::on_new_xsmp_client_connected_cb));
this->xsmp_server_->signal_ice_conn_status_changed().connect(sigc::mem_fun(this, &ClientManager::on_ice_conn_status_changed_cb));
diff --git a/src/main.cpp b/src/main.cpp
index a5571e9..005ae0e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -12,6 +12,7 @@
* Author: tangjie02 <tangjie02@kylinos.com.cn>
*/
+#include <glib.h>
#include <glib/gi18n.h>
#include <gtkmm.h>
#include "src/app/app-manager.h"
@@ -24,6 +25,37 @@
using namespace Kiran::Daemon;
+#define DBUS_LAUNCH_COMMAND "dbus-launch"
+
+bool start_dbus_session(int argc, char **argv)
+{
+ int i = 0;
+
+ RETURN_VAL_IF_TRUE(!Glib::getenv("DBUS_SESSION_BUS_ADDRESS").empty(), true);
+ RETURN_VAL_IF_TRUE(Kiran::StrUtils::startswith(argv[0], DBUS_LAUNCH_COMMAND), true);
+
+ char **new_argv = (char **)g_malloc(argc + 3 * sizeof(*argv));
+
+ new_argv[0] = (char *)DBUS_LAUNCH_COMMAND;
+ new_argv[1] = (char *)"--exit-with-session";
+
+ for (i = 0; i < argc; i++)
+ {
+ new_argv[i + 2] = argv[i];
+ }
+
+ new_argv[i + 2] = NULL;
+
+ KLOG_DEBUG("Start session manager by dbus-launch.");
+
+ if (!execvp(DBUS_LAUNCH_COMMAND, new_argv))
+ {
+ KLOG_WARNING("No session bus and could not exec dbus-launch: %s", g_strerror(errno));
+ return false;
+ }
+ return true;
+}
+
void init_env()
{
using param_type = std::map<Glib::ustring, Glib::ustring>;
@@ -72,6 +104,9 @@ int main(int argc, char *argv[])
{
klog_gtk3_init(std::string(), "kylinsec-session", PROJECT_NAME, PROJECT_NAME);
+ // 这里做一个兼容性处理当会话dbus-daemon没有启动时一般不会出现由会话管理进行拉起
+ start_dbus_session(argc, argv);
+
setlocale(LC_ALL, "");
bindtextdomain(PROJECT_NAME, KSM_LOCALEDIR);
bind_textdomain_codeset(PROJECT_NAME, "UTF-8");
diff --git a/src/presence.cpp b/src/presence.cpp
index 3a898d3..d0fb4ff 100644
--- a/src/presence.cpp
+++ b/src/presence.cpp
@@ -32,6 +32,8 @@ Presence::Presence() : enabled_idle_timeout_(true),
void Presence::init()
{
+ KLOG_PROFILE("");
+
this->idle_timeout_ = this->settings_->get_int(KSM_SCHEMA_KEY_IDLE_DELAY);
this->idle_xlarm_.init();
this->update_idle_xlarm();
diff --git a/src/session-manager.cpp b/src/session-manager.cpp
index d0cb95b..892c8b9 100644
--- a/src/session-manager.cpp
+++ b/src/session-manager.cpp
@@ -281,6 +281,8 @@ void SessionManager::CanReboot(MethodInvocation &invocation)
void SessionManager::init()
{
+ KLOG_PROFILE("");
+
this->power_.init();
this->presence_->init();
diff --git a/src/ui/ui-manager.cpp b/src/ui/ui-manager.cpp
index 3c5d9d2..046da89 100644
--- a/src/ui/ui-manager.cpp
+++ b/src/ui/ui-manager.cpp
@@ -32,6 +32,8 @@ void UIManager::global_init()
void UIManager::init()
{
+ KLOG_PROFILE("");
+
auto resource = Gio::Resource::create_from_file(KSM_INSTALL_DATADIR "/kiran-session-manager.gresource");
resource->register_global();
diff --git a/src/wrapper/display-manager.cpp b/src/wrapper/display-manager.cpp
index 558773d..4097056 100644
--- a/src/wrapper/display-manager.cpp
+++ b/src/wrapper/display-manager.cpp
@@ -23,15 +23,25 @@ namespace Daemon
DisplayManager::DisplayManager()
{
+ auto xdg_seat_object_path = Glib::getenv("XDG_SEAT_PATH");
+
try
{
- auto xdg_seat_object_path = Glib::getenv("XDG_SEAT_PATH");
- this->display_proxy_ = Gio::DBus::Proxy::create_for_bus_sync(Gio::DBus::BUS_TYPE_SYSTEM,
- DISPLAY_MANAGER_DBUS_NAME,
- xdg_seat_object_path,
- DISPLAY_MANAGER_DBUS_INTERFACE,
- Glib::RefPtr<Gio::DBus::InterfaceInfo>(),
- Gio::DBus::PROXY_FLAGS_DO_NOT_AUTO_START);
+ if (xdg_seat_object_path.empty())
+ {
+ KLOG_WARNING("Not found XDG_SEAT_PATH.");
+ }
+ else
+ {
+ KLOG_DEBUG("XDG_SEAT_PATH: %s.", xdg_seat_object_path.c_str());
+
+ this->display_proxy_ = Gio::DBus::Proxy::create_for_bus_sync(Gio::DBus::BUS_TYPE_SYSTEM,
+ DISPLAY_MANAGER_DBUS_NAME,
+ xdg_seat_object_path,
+ DISPLAY_MANAGER_DBUS_INTERFACE,
+ Glib::RefPtr<Gio::DBus::InterfaceInfo>(),
+ Gio::DBus::PROXY_FLAGS_DO_NOT_AUTO_START);
+ }
}
catch (const Glib::Error& e)
{
diff --git a/src/xsmp-server.cpp b/src/xsmp-server.cpp
index 35a6629..75e4173 100644
--- a/src/xsmp-server.cpp
+++ b/src/xsmp-server.cpp
@@ -58,6 +58,8 @@ void XsmpServer::global_init()
void XsmpServer::init()
{
+ KLOG_PROFILE("");
+
char error_string[BUFSIZ];
SmsSetErrorHandler(&XsmpServer::on_sms_error_handler_cb);
IceSetIOErrorHandler(&XsmpServer::on_ice_io_error_handler_cb);
--
2.27.0

View File

@ -1,56 +0,0 @@
From 3d2ec38f9c4d3bd19d707ef60fefc6243d650235 Mon Sep 17 00:00:00 2001
From: tangjie02 <tangjie02@kylinsec.com.cn>
Date: Mon, 17 Jan 2022 17:24:46 +0800
Subject: [PATCH] fix(env): Some environments are filtered because the if
statement is wrong.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 由于if语句写错导致部分环境变量被过滤
Closes #48435
Signed-off-by: tangjie02 <tangjie02@kylinsec.com.cn>
---
src/main.cpp | 8 ++++++--
src/utils.cpp | 2 +-
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/main.cpp b/src/main.cpp
index 005ae0e..eec074c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -69,10 +69,14 @@ void init_env()
for (auto key : Glib::listenv())
{
auto value = Glib::getenv(key);
- if (key_regex->match(value) && value_regex->match(value))
+ if (key_regex->match(key) && value_regex->match(value))
{
envs.emplace(key, value);
- KLOG_DEBUG("key: %s, value: %s.", key.c_str(), value.c_str());
+ KLOG_DEBUG("Add environment: %s=%s.", key.c_str(), value.c_str());
+ }
+ else
+ {
+ KLOG_WARNING("Filter environment: %s=%s.", key.c_str(), value.c_str());
}
}
Utils::setenvs(envs);
diff --git a/src/utils.cpp b/src/utils.cpp
index b2cfb29..e70cc98 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -125,7 +125,7 @@ void Utils::setenvs(const std::map<Glib::ustring, Glib::ustring> &envs)
list_env.push_back(env);
}
- KLOG_DEBUG("envs: %s.", StrUtils::join(list_env, ";").c_str());
+ KLOG_DEBUG("Set environments: %s.", StrUtils::join(list_env, ";").c_str());
auto systemd_proxy = Gio::DBus::Proxy::create_for_bus_sync(Gio::DBus::BUS_TYPE_SESSION,
SYSTEMD_DBUS_NAME,
SYSTEMD_DBUS_OBJECT_PATH,
--
2.27.0

Binary file not shown.

Binary file not shown.

View File

@ -1,15 +1,12 @@
%global on_openeuler 1
Name: kiran-session-manager
Version: 2.2.1
Release: 3.kb3
Version: 2.2.2
Release: 3
Summary: Session manager for KIRAN desktop environment
License: Mulan PSL v2
Source0: %{name}-%{version}.tar.gz
Patch1001: 0000-fix-xinit-Fix-the-dbus-error-when-the-session-manage-918aca5b.patch
Patch1002: 1002-fix-env-Some-environments-are-filtered-because-the-i-3d2ec38f.patch
Patch1000: 0000-feature-dbus-Add-dbus-method-Setenv-9796c3d4.patch
BuildRequires: cmake >= 3.2
BuildRequires: pkgconfig(giomm-2.4)
@ -24,7 +21,7 @@ BuildRequires: fmt-devel
BuildRequires: libICE-devel
BuildRequires: libSM-devel
BuildRequires: libXext-devel
BuildRequires: gdbus-codegen-glibmm
BuildRequires: gdbus-codegen-glibmm >= 1.0.2
Requires: systemd
@ -39,10 +36,10 @@ Session manager for KIRAN desktop environment
%build
%if 0%{?on_openeuler} == 1
%cmake -DSUPPORT_CAJA:BOOL=TRUE
%else
%if 0%{?kylin}
%cmake
%else
%cmake -DSUPPORT_CAJA:BOOL=TRUE
%endif
make %{?_smp_mflags}
@ -62,8 +59,20 @@ make %{?_smp_mflags}
%changelog
* Sat Jan 22 2022 tangjie02 <tangjie02@kylinsec.com.cn> - 2.2.1-3.kb3
- KYOS-F: Comptabile openeuler.
* Thu Mar 03 2022 tangjie02 <tangjie02@kylinsec.com.cn> - 2.2.2-3
- KYOS-F: Add dbus method Setenv for kiran-session-daemon.
* Thu Feb 24 2022 chendingjian <chendingjian@kylinos.com.cn> - 2.2.2-2
- rebuild for KY3.4-MATE-modules-dev
* Wed Feb 16 2022 tangjie02 <tangjie02@kylinsec.com.cn> - 2.2.2-1.kb1
- KYOS-F: Rebuild this package.
* Wed Feb 16 2022 tangjie02 <tangjie02@kylinsec.com.cn> - 2.2.1-2.kb5
- KYOS-B: Fix the problem caused by the boot sequence of mate-settings-daemon and kiran-session-daemon.
* Wed Jan 26 2022 longcheng <longcheng@kylinsec.com.cn> - 2.2.1-2.kb4
- KYOS-B: Add compile options -DSUPPORT_CAJA:BOOL=TRUE in openeuler (#49472)
* Wed Jan 19 2022 tangjie02 <tangjie02@kylinsec.com.cn> - 2.2.1-2.kb3
- KYOS-F: Rebuild because of last compile failed.