From 2d3326cf449f6662b23ae7cdfb7df2d5f19f95c3 Mon Sep 17 00:00:00 2001 From: Adam Michalski Date: Tue, 9 Apr 2024 16:34:28 +0200 Subject: [PATCH] Merge isu-cleaner service into isud service According to Tizen platform pollicy, we have to reduce the number of services. Change-Id: Ie31e87085b8b724c5b4cebecf09a9c85fd985b4a --- CMakeLists.txt | 1 - packaging/isu.spec | 9 ++--- src/isu-cleaner/CMakeLists.txt | 12 ------- src/isu-cleaner/isu-cleaner.c | 65 ------------------------------------- src/isu-cleaner/isu-cleaner.service | 11 ------- src/isud/isud.c | 41 +++++++++++++++++++++++ src/isud/isud.service | 5 +++ 7 files changed, 49 insertions(+), 95 deletions(-) delete mode 100644 src/isu-cleaner/CMakeLists.txt delete mode 100644 src/isu-cleaner/isu-cleaner.c delete mode 100644 src/isu-cleaner/isu-cleaner.service diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ff904f..b511c9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,4 +6,3 @@ ADD_SUBDIRECTORY(src/isud) ADD_SUBDIRECTORY(src/pkg_manager) ADD_SUBDIRECTORY(src/pkg_maker) ADD_SUBDIRECTORY(src/plugin_parser) -ADD_SUBDIRECTORY(src/isu-cleaner) diff --git a/packaging/isu.spec b/packaging/isu.spec index e25ecad..3a217b0 100644 --- a/packaging/isu.spec +++ b/packaging/isu.spec @@ -51,8 +51,7 @@ cp packaging/isu.manifest . %cmake . \ -DCMAKE_INSTALL_PREFIX=%{_prefix} \ -DLIBISU_VERSION=%{libisu_version} \ - -DCHECK_ISU_FEATURE=OFF \ - -DSYSTEMD_DIR:PATH=%{_unitdir} + -DCHECK_ISU_FEATURE=OFF make %{?_smp_mflags} %install @@ -74,7 +73,7 @@ install -m644 config/isu.conf %{buildroot}/usr/lib/tmpfiles.d/isu.conf install -m644 config/upgrade.cfg %{buildroot}/etc/isu/upgrade.cfg install -m750 src/pkg_manager/isu %{buildroot}/%{_bindir}/isu.sh -%install_service delayed.target.wants %{name}-cleaner.service +%install_service delayed.target.wants isud.service %files %manifest isu.manifest @@ -88,9 +87,7 @@ install -m750 src/pkg_manager/isu %{buildroot}/%{_bindir}/isu.sh /etc/isu/upgrade.cfg %{_bindir}/isu.sh %{_bindir}/isu -%{_bindir}/isu-cleaner -%{_unitdir}/%{name}-cleaner.service -%{_unitdir}/delayed.target.wants/%{name}-cleaner.service +%{_unitdir}/delayed.target.wants/isud.service %files tools %manifest isu.manifest diff --git a/src/isu-cleaner/CMakeLists.txt b/src/isu-cleaner/CMakeLists.txt deleted file mode 100644 index ee2ccfd..0000000 --- a/src/isu-cleaner/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -INCLUDE(GNUInstallDirs) -FIND_PACKAGE(PkgConfig) -pkg_check_modules(deps REQUIRED "glib-2.0 gio-2.0 capi-system-info dlog") - -ADD_EXECUTABLE(isu-cleaner isu-cleaner.c) -SET_TARGET_PROPERTIES(isu-cleaner PROPERTIES OUTPUT_NAME "isu-cleaner") -TARGET_INCLUDE_DIRECTORIES(isu-cleaner PRIVATE . ${deps_INCLUDE_DIRS} ../libisu/) -TARGET_LINK_LIBRARIES(isu-cleaner PUBLIC isu -pie -larchive ${deps_LIBRARIES}) - -INSTALL(TARGETS isu-cleaner DESTINATION ${CMAKE_INSTALL_BINDIR}) - -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/isu-cleaner.service DESTINATION ${SYSTEMD_DIR}) \ No newline at end of file diff --git a/src/isu-cleaner/isu-cleaner.c b/src/isu-cleaner/isu-cleaner.c deleted file mode 100644 index ee06b27..0000000 --- a/src/isu-cleaner/isu-cleaner.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include -#include -#include -#include - -#include "libisu-internal.h" - -#define LOG_TAG "ISUCLEANER" -#include - -#define ISU_APP_PATH "/opt/usr/globalapps" -#define ISU_APP_PREFIX "org.tizen.isu." - -int main(int argc, char *argv[]) -{ - DIR *dir = opendir(ISU_APP_PATH); - - if (dir == NULL) { - SLOGE("Open dir %s error (%d): %m\n", ISU_APP_PATH, errno); - return ISU_RES_ERR_NOT_EXIST; - } - - struct dirent *entry; - int result = 0; - while ((entry = readdir(dir)) != NULL) { - if (entry->d_type != DT_DIR) continue; - - char pathbuff[PATH_MAX]; - snprintf(pathbuff, sizeof(pathbuff), "%s/%s", ISU_APP_PATH, entry->d_name); - if (strcmp(entry->d_name, ".") == 0 - || strcmp(entry->d_name, "..") == 0 - || strncmp(entry->d_name, ISU_APP_PREFIX, sizeof(ISU_APP_PREFIX)-1)) - continue; - result = remove_dir_contents(pathbuff); - if (result != 0) { - SLOGE("Can't remove unnecessary files from apps path: %s (result: %d)", pathbuff, result); - break; - } - } - - if (result == 0) - SLOGE("ISU clean-up succeded."); - else - SLOGE("ISU clean-up failed."); - - closedir(dir); - return result; -} diff --git a/src/isu-cleaner/isu-cleaner.service b/src/isu-cleaner/isu-cleaner.service deleted file mode 100644 index 80a6caf..0000000 --- a/src/isu-cleaner/isu-cleaner.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=isu clean-up service - -[Service] -Type=oneshot -SmackProcessLabel=System -ExecStart=/usr/bin/isu-cleaner -RemainAfterExit=yes - -[Install] -WantedBy=delayed.target diff --git a/src/isud/isud.c b/src/isud/isud.c index 787c94f..0936c76 100644 --- a/src/isud/isud.c +++ b/src/isud/isud.c @@ -29,6 +29,9 @@ #define TIMEOUT_INTERVAL_SEC 30 +#define ISU_APP_PATH "/opt/usr/globalapps" +#define ISU_APP_PREFIX "org.tizen.isu." + enum Action { Install, InstallDir, @@ -248,6 +251,42 @@ static bool dbus_init(void) return true; } +int perform_clean_up(void) +{ + DIR *dir = opendir(ISU_APP_PATH); + + if (dir == NULL) { + SLOGE("Open dir %s error (%d): %m\n", ISU_APP_PATH, errno); + return ISU_RES_ERR_NOT_EXIST; + } + + struct dirent *entry; + int result = 0; + while ((entry = readdir(dir)) != NULL) { + if (entry->d_type != DT_DIR) continue; + + char pathbuff[PATH_MAX]; + snprintf(pathbuff, sizeof(pathbuff), "%s/%s", ISU_APP_PATH, entry->d_name); + if (strcmp(entry->d_name, ".") == 0 + || strcmp(entry->d_name, "..") == 0 + || strncmp(entry->d_name, ISU_APP_PREFIX, sizeof(ISU_APP_PREFIX)-1)) + continue; + result = remove_dir_contents(pathbuff); + if (result != 0) { + SLOGE("Can't remove unnecessary files from apps path: %s (result: %d)", pathbuff, result); + break; + } + } + + if (result == 0) + SLOGE("ISU clean-up succeded."); + else + SLOGE("ISU clean-up failed."); + + closedir(dir); + return result; +} + int main(void) { loop = g_main_loop_new(NULL, false); @@ -271,5 +310,7 @@ int main(void) g_mutex_clear(&timeout_mutex); g_main_loop_unref(loop); + perform_clean_up(); + return EXIT_SUCCESS; } diff --git a/src/isud/isud.service b/src/isud/isud.service index b720b4c..121bba7 100644 --- a/src/isud/isud.service +++ b/src/isud/isud.service @@ -8,4 +8,9 @@ Group=system BusName=org.tizen.system.isu ExecStart=/usr/bin/isud SmackProcessLabel=System +Capabilities=cap_dac_override=i +SecureBits=keep-caps KillMode=mixed + +[Install] +WantedBy=delayed.target -- 2.7.4