From: Chanwoo Choi Date: Wed, 9 Apr 2025 05:00:57 +0000 (+0900) Subject: Add hal-backend-service-deviced plugin for unified system service support X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7acd7f35f54d39ce1d14a2cf9320935c2fbf184d;p=platform%2Fcore%2Fsystem%2Fdeviced.git Add hal-backend-service-deviced plugin for unified system service support Change-Id: Id85e4e27caf8299485d87570dad571cd6723a338 Signed-off-by: Chanwoo Choi --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f36ea414..ade10d9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index b69d32dc..a83ed4ce 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -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 diff --git a/src/core/main.c b/src/core/main.c index 0a20cb18..22eaa02d 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -27,6 +27,8 @@ #include #include +#include + #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, +}; diff --git a/systemd/deviced.service b/systemd/deviced.service index 817c32de..46abc616 100644 --- a/systemd/deviced.service +++ b/systemd/deviced.service @@ -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