Add hal-backend-service-deviced plugin for unified system service support
authorChanwoo Choi <cw00.choi@samsung.com>
Wed, 9 Apr 2025 05:00:57 +0000 (14:00 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 9 Apr 2025 11:08:51 +0000 (20:08 +0900)
Change-Id: Id85e4e27caf8299485d87570dad571cd6723a338
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
CMakeLists.txt
packaging/deviced.spec
src/core/main.c
systemd/deviced.service

index f36ea414550a80d6daba55eedd07eb14c815decf..ade10d9e90672e1ca09152ef50c5b5dc925140fd 100644 (file)
@@ -6,6 +6,7 @@ PROJECT(deviced C)
 ########################################################
 
 SET(CMAKE_VERBOSE_MAKEFILE OFF)
+SET(LIBRARY_NAME "hal-backend-service-deviced")
 
 IF("${ARCH}" STREQUAL "arm")
        OPTION(USE_ARM "Use Arm" ON)
@@ -254,6 +255,10 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
 
 INSTALL(DIRECTORY DESTINATION ${MAKE_INSTALL_PREFIX}${DD_PLUGIN_PATH})
 
+ADD_LIBRARY(${LIBRARY_NAME} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${REQUIRED_PKGS_LDFLAGS} "-lrt -ldl -lm" deviced-common-private)
+INSTALL(TARGETS ${LIBRARY_NAME} DESTINATION ${LIB_INSTALL_DIR}/hal COMPONENT RuntimeLibraries)
+
 IF(POWER_MODULE STREQUAL on)
        ADD_EXECUTABLE(deviced-shutdown src/power-shutdown/shutdown.c src/shared/common.c)
        SET(deviced-shutdown_LDFLAGS ${REQUIRED_PKGS_LDFLAGS})
index b69d32dc84315fa3a1b9b5a05e2c6650b7de3216..a83ed4ceb62c8ea1ba40c95a080ab8878c33493d 100644 (file)
@@ -48,6 +48,7 @@ BuildRequires:  pkgconfig(cmocka)
 BuildRequires:  pkgconfig(gtest)
 BuildRequires:  pkgconfig(gmock)
 BuildRequires:  pkgconfig(security-manager)
+BuildRequires:  pkgconfig(hal-api-common)
 
 Requires: %{name}-tools = %{version}-%{release}
 %{?systemd_requires}
@@ -306,6 +307,7 @@ mv %{_libdir}/tv-display.so %{_libdir}/deviced/display.so
 %{_sysconfdir}/mtp-responder-dummy/descs
 %{_unitdir}/mtp-responder-dummy.socket
 %{_unitdir}/mtp-responder-dummy.service
+%{_libdir}/hal/libhal-backend-service-deviced.so
 
 # Assume power module is on (-DPOWER_MODULE=on)
 %{_unitdir}/deviced-request-shutdown@.service
index 0a20cb18cd9059355a6986287ee488dad3f0c832..22eaa02dfd4fd1f85eeb20d6784e42f5ae83f57c 100644 (file)
@@ -27,6 +27,8 @@
 #include <device/board-internal.h>
 #include <argos.h>
 
+#include <hal/hal-common.h>
+
 #include "core.h"
 #include "log.h"
 #include "resource.h"
@@ -176,3 +178,90 @@ int main(int argc, char **argv)
        writepid(PIDFILE_PATH);
        return deviced_main(argc, argv);
 }
+
+
+static int deviced_init (void *data)
+{
+       int ret;
+       dbus_handle_h handle = NULL;
+       guint timer;
+       char bootmode[32] = "normal";
+       int retval;
+
+       writepid(PIDFILE_PATH);
+
+       CRITICAL_LOG("Initializing deviced.");
+       //mainloop = g_main_loop_new(NULL, FALSE);
+
+       ret = poweroff_check_revived();
+       if (is_poweroff_state(ret)) {
+               /* Restarted: deviced was terminated
+                * in middle of reboot/poweroff - resume procedure
+                */
+               poweroff_request_shutdown(ret);
+               return 0;
+       }
+
+       handle = gdbus_get_connection(G_BUS_TYPE_SYSTEM, FALSE);
+       if (!handle)
+               _E("Failed to get dbus connection.");
+
+       load_plugins();
+
+       retval = device_board_get_boot_mode(bootmode, sizeof(bootmode));
+       if (retval < 0)
+               _W("Cannot get boot mode, ret(%d)", retval);
+
+       if (retval == 0) {
+               ret = power_boot_load_silent_boot();
+               if (ret < 0)
+                       _W("Cannot set silent_boot, ret(%d)", ret);
+       }
+
+       CRITICAL_LOG("bootmode=%s", bootmode);
+
+       resource_init();
+       devices_init(NULL);
+
+       ret = gdbus_request_name(handle, DEVICED_BUS_NAME, deviced_dbus_name_acquired, NULL);
+       if (ret <= 0) {
+               _E("Failed to request bus name.");
+               gdbus_check_name_owner(NULL, DEVICED_BUS_NAME);
+       }
+
+       g_unix_signal_add(SIGTERM, handle_sigterm, (gpointer) SIGTERM);
+       g_unix_signal_add(SIGUSR1, handle_sigusr1, (gpointer) SIGUSR1);
+
+       timer = g_timeout_add_seconds_full(G_PRIORITY_HIGH, WATCHDOG_REFRESH_TIME, watchdog_cb, NULL, NULL);
+       if (timer) {
+               ret = aw_register(WATCHDOG_TIMEOUT);
+               if (ret < 0)
+                       _E("aw_register failed.");
+       }
+
+       /* g_main_loop */
+       CRITICAL_LOG("Starting deviced.");
+       //g_main_loop_run(mainloop);
+       //g_main_loop_unref(mainloop);
+
+       devices_exit(NULL);
+       resource_exit();
+
+       unload_plugins();
+
+       return 0;
+}
+
+static int deviced_exit(void *data)
+{
+       return 0;
+}
+
+hal_backend_service hal_backend_service_deviced_data = {
+       .module         = HAL_MODULE_DEVICED,
+       .name           = "hal-backend-service-deviced",
+       .early_init     = NULL,
+       .init           = deviced_init,
+       .exit           = deviced_exit,
+       .late_exit      = NULL,
+};
index 817c32decd49d0fde65264adaacf7c1cfe5f684c..46abc616a81d707eba68e6058f0c1e94b79aca10 100644 (file)
@@ -1,5 +1,7 @@
 [Unit]
 Description=System device daemon
+Requires=local-fs.target tizen-system-env.service systemd-tmpfiles-setup.service wait-mount@opt-usr.service dbus.socket
+After=wait-mount@opt-usr.service dbus.service local-fs.target tizen-system-env.service systemd-tmpfiles-setup.service
 
 # Caution: never uncomment belwo "Wants=" and "After=" entries.
 # Just information, deviced internally wait for /run/.wm_ready
@@ -10,10 +12,12 @@ Description=System device daemon
 Type=notify
 SmackProcessLabel=System::Privileged
 Environment=XDG_RUNTIME_DIR=/run
-ExecStart=/usr/bin/deviced
-Restart=on-failure
+EnvironmentFile=/run/xdg-root-env
+ExecStart=/usr/bin/hal/hal-backend-service storaged deviced
+Restart=always
 RestartSec=0
 KillSignal=SIGUSR1
+MemoryMax=20M
 
 [Install]
 WantedBy=multi-user.target