sessiond: Apply systemd-based dbus activation 49/276649/6
authorAdam Michalski <a.michalski2@partner.samsung.com>
Wed, 22 Jun 2022 12:43:13 +0000 (14:43 +0200)
committerAdam Michalski <a.michalski2@partner.samsung.com>
Wed, 29 Jun 2022 09:31:02 +0000 (11:31 +0200)
Change-Id: I7c5323eef839ead0fb9e3ae066310c3b50aa357e

packaging/sessiond.spec
sessiond/CMakeLists.txt
sessiond/sessiond.service
sessiond/src/main.cpp
sessiond/systemd/org.tizen.system.sessiond.service [new file with mode: 0644]

index ec277ff..da5485b 100644 (file)
@@ -67,14 +67,12 @@ pushd build
 %make_install
 popd
 
-%install_service multi-user.target.wants sessiond.service
-
 %files
 %manifest sessiond.manifest
 %license LICENSE.MIT
 %{_bindir}/sessiond
-%{_unitdir}/multi-user.target.wants/sessiond.service
 %{_unitdir}/sessiond.service
+%{_datadir}/dbus-1/system-services/org.tizen.system.sessiond.service
 /etc/dbus-1/system.d/org.tizen.sessiond.conf
 
 %files -n libsessiond
index f8ad357..88111e0 100644 (file)
@@ -16,4 +16,5 @@ target_link_libraries(sessiond PRIVATE PkgConfig::DEPS sessiond_common)
 install(TARGETS sessiond)
 
 INSTALL(FILES sessiond.service DESTINATION /usr/lib/systemd/system)
+INSTALL(FILES systemd/org.tizen.system.sessiond.service DESTINATION /usr/share/dbus-1/system-services)
 INSTALL(FILES org.tizen.sessiond.conf DESTINATION /etc/dbus-1/system.d)
index 1e213d9..10f26a0 100644 (file)
@@ -13,4 +13,4 @@ ExecStart=/usr/bin/sessiond
 Restart=on-failure
 
 [Install]
-WantedBy=multi-user.target
+WantedBy=delayed.target
index 7081bf3..182d153 100644 (file)
@@ -72,11 +72,14 @@ struct introspection_data {
 };
 
 struct owner_id {
-       owner_id(std::string_view name, GBusAcquiredCallback on_connect, GBusNameLostCallback on_error,
-                gpointer user_data)
+       owner_id() : inner(0) {}
+
+       void own_name_on_connection(GDBusConnection *connection, std::string_view name,
+               GBusNameAcquiredCallback on_name_acquired, GBusNameLostCallback on_name_lost, gpointer user_data)
        {
-               inner = g_bus_own_name(G_BUS_TYPE_SYSTEM, name.data(), G_BUS_NAME_OWNER_FLAGS_NONE, on_connect,
-                                      nullptr, on_error, user_data, nullptr);
+               inner = g_bus_own_name_on_connection(connection, name.data(), G_BUS_NAME_OWNER_FLAGS_NONE,
+                       on_name_acquired, on_name_lost, user_data, nullptr);
+               std::cout << "Acquiring " << name << std::endl;
        }
 
        ~owner_id()
@@ -115,8 +118,18 @@ struct sessiond_context {
         * before any sub session is switched to. */
        static constexpr int INITIAL_SUB_SESSION_ID = 0;
 
-       sessiond_context() : data(xml), id(bus_name, glib_bus_connected, glib_name_lost, this), loop()
+       sessiond_context() : data(xml), id(), loop()
        {
+               connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
+               if (!connection)
+                       throw std::runtime_error("Cannot connect to the system bus");
+
+               guint registration_id = g_dbus_connection_register_object(
+                       connection, bus_object.data(), data.inner->interfaces[0], &table, this, nullptr, nullptr);
+               if (registration_id <= 0)
+                       throw std::runtime_error("Couldn't register bus ID");
+
+               id.own_name_on_connection(connection, bus_name, glib_name_acquired, glib_name_lost, this);
        }
 
        void run()
@@ -124,13 +137,9 @@ struct sessiond_context {
                g_main_loop_run(loop.inner);
        }
 
-       void on_bus_connected(GDBusConnection *conn)
+       void on_name_acquired()
        {
-               connection = conn;
-               guint registration_id = g_dbus_connection_register_object(
-                   connection, bus_object.data(), data.inner->interfaces[0], &table, this, nullptr, nullptr);
-               if (registration_id <= 0)
-                       throw std::runtime_error("Couldn't register bus ID");
+               std::cout << "Bus name acquired" << std::endl;
        }
 
        void on_name_lost()
@@ -373,11 +382,12 @@ struct sessiond_context {
                g_dbus_method_invocation_return_value(invocation, ret);
        }
 
-       static void glib_bus_connected(GDBusConnection *conn, const gchar *name, gpointer user_data)
+       static void glib_name_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data)
        {
                auto self = static_cast<sessiond_context *>(user_data);
-               self->on_bus_connected(conn);
+               self->on_name_acquired();
        }
+
        static void glib_name_lost(GDBusConnection *conn, const gchar *name, gpointer user_data)
        {
                auto self = static_cast<sessiond_context *>(user_data);
diff --git a/sessiond/systemd/org.tizen.system.sessiond.service b/sessiond/systemd/org.tizen.system.sessiond.service
new file mode 100644 (file)
index 0000000..5a7a4d3
--- /dev/null
@@ -0,0 +1,4 @@
+[D-BUS Service]
+Name=org.tizen.sessiond
+Exec=/bin/false
+SystemdService=sessiond.service