Add hal-backend-service-resourced plugin for unified system service support sandbox/sykwak/unified-system-service
authorSangYoun Kwak <sy.kwak@samsung.com>
Tue, 15 Apr 2025 11:24:10 +0000 (20:24 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Tue, 15 Apr 2025 12:09:09 +0000 (21:09 +0900)
Change-Id: Ia70af716871955e56e9d00f544bb6490a63fdfdf
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
packaging/resourced.spec
src/CMakeLists.txt
src/resourced/main.c
src/resourced/resourced.service

index 00cc2e066cf159c7f05a167d4a6b3b6da26ebcd5..03948a350ba466199c0a1d1819d98d63ad7deb4e 100644 (file)
@@ -48,6 +48,7 @@ BuildRequires:  pkgconfig(gio-2.0)
 BuildRequires: gperf
 BuildRequires:  pkgconfig(cynara-creds-pid)
 BuildRequires:  pkgconfig(security-manager)
+BuildRequires:  pkgconfig(hal-api-common)
 
 # for swap plugin
 Requires:      %{_sbindir}/mkswap
@@ -193,6 +194,7 @@ mv %{confdir}/optimizer-profile-tv.conf %{confdir}/optimizer.conf
 %license LICENSE
 %manifest resourced.manifest
 %{_libdir}/libresourced-private-api.so.*
+%{_libdir}/hal/libhal-backend-service-resourced.so
 %{_bindir}/resourced
 %dir %{plugindir}
 %attr(-,root, root) %{_bindir}/resourced
index 8b9f29e827839d63f94edf6012ea3f30b12853fa..abafdbcfaf158185e78871e7e80d0981aa188e4f 100644 (file)
@@ -115,6 +115,7 @@ SET(REQUIRES_LIST ${REQUIRES_LIST}
        aul
        cynara-creds-pid
        security-manager
+       hal-api-common
   )
 
 INCLUDE(FindPkgConfig)
@@ -267,3 +268,19 @@ ENDIF()
 
 INSTALL(FILES ${CONF_DIR}/process.conf
        DESTINATION ${RD_CONFIG_PATH} RENAME process.conf)
+
+
+SET(LIBRARY_NAME "hal-backend-service-resourced")
+
+ADD_LIBRARY(${LIBRARY_NAME} SHARED
+       ${RESOURCED_SOURCE_DIR}/init.c
+       ${RESOURCED_SOURCE_DIR}/main.c
+       ${SOURCES})
+
+TARGET_LINK_LIBRARIES(${LIBRARY_NAME}
+       resourced-private-api
+       ${RESOURCED_REQUIRE_PKGS_LDFLAGS}
+       "-pie -ldl -lm -Wl,-rpath=${RD_PLUGIN_PATH}")
+SET_TARGET_PROPERTIES(${LIBRARY_NAME} PROPERTIES COMPILE_FLAGS "-fvisibility=default")
+SET_TARGET_PROPERTIES(${LIBRARY_NAME} PROPERTIES SKIP_BUILD_RPATH true)
+INSTALL(TARGETS ${LIBRARY_NAME} DESTINATION ${LIB_INSTALL_DIR}/hal COMPONENT RuntimeLibraries)
index 97e0748794f9c08ec63b30e85c705a0c3f0854d2..ccdca64c82f172f752546fe382a85dca28271ae0 100644 (file)
@@ -38,6 +38,8 @@
 #include <mcheck.h>
 #include <systemd/sd-daemon.h>
 
+#include <hal/hal-common.h>
+
 int main(int argc, char **argv)
 {
        GMainLoop *mainloop = get_main_loop();
@@ -86,3 +88,68 @@ int main(int argc, char **argv)
        resourced_deinit();
        return ret_code;
 }
+
+static int resourced_module_init(void *data)
+{
+       GMainLoop *mainloop = get_main_loop();
+       int ret_code = 0;
+       struct daemon_arg darg = { 0, NULL, NULL };
+
+       assert(mainloop);
+
+       ret_code = resourced_init(&darg);
+       ret_value_msg_if(ret_code < 0, ret_code,
+                        "Resourced initialization failed\n");
+       init_modules_arg(&darg);
+       modules_check_runtime_support(NULL);
+
+       /* parse vendor specific configuration files.
+        * resourced currently supports two dirs called limiter.conf.d and process.conf.d
+        * ex) /etc/resourced/xxx.d/yyy.conf
+        */
+       resourced_parse_vendor_configs();
+       register_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, fixed_service_and_process_list_init);
+
+       if (resourced_restarted()) {
+               _I("Relaunched. Start to initialize and restore");
+               modules_init(NULL);
+               modules_restore(NULL);
+       } else {
+               _I("Initial instance: initializing all modules indiscriminately");
+               modules_init(NULL);
+       }
+
+       if (resourced_restarted()) {
+               modules_init_late(NULL);
+               resourced_notify(RESOURCED_NOTIFIER_BOOTING_DONE, NULL);
+       }
+
+       sd_notify(0, "READY=1");
+
+       g_main_loop_run(mainloop);
+
+       return 0;
+}
+
+static int resourced_module_exit(void *data)
+{
+       unregister_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, fixed_service_and_process_list_init);
+
+       /* free all allocated memory to store configuration information */
+       resourced_free_vendor_configs();
+
+       modules_exit(NULL);
+       resourced_deinit();
+
+       return 0;
+}
+
+__attribute__((visibility("default")))
+hal_backend_service hal_backend_service_resourced_data = {
+       .module         = HAL_MODULE_RESOURCED,
+       .name           = "hal-backend-service-resourced",
+       .early_init     = NULL,
+       .init           = resourced_module_init,
+       .exit           = resourced_module_exit,
+       .late_exit      = NULL,
+};
index 824352a5487e3d4ffd39fe9a86b7a76b4597cfc6..1290dbdd0f4e604fe15a5e6c5095918ca460bcb1 100644 (file)
@@ -1,21 +1,8 @@
 [Unit]
 Description=Resource management daemon
-# resourced monitors AUL (lauchpad) d-bus signals to learn about existence
-# and the state of applications.  Consequently, it has to start before
-# launchpad to have knowledge of all applications.  The Before= line below
-# refers to user-sessions, because tlm, and consequently user@.service
-# starts after user-sessions are allowed.
-Before=systemd-user-sessions.service
-DefaultDependencies=no
-Requires=resourced.socket
 
 [Service]
 Type=simple
-SmackProcessLabel=System
-ExecStart=/usr/bin/resourced
-MemoryMax=50M
-Restart=on-failure
-RestartSec=0
 
 [Install]
 WantedBy=multi-user.target