Add isu-cleaner service 61/308661/6
authorAdam Michalski <a.michalski2@partner.samsung.com>
Thu, 28 Mar 2024 10:24:20 +0000 (11:24 +0100)
committerAdam Michalski <a.michalski2@partner.samsung.com>
Fri, 29 Mar 2024 09:53:17 +0000 (10:53 +0100)
isu-cleaner adds two components to the Individual Service Upgrade:
* isu-cleaner tool - cleans up the /opt/usr/globalapps/org.tizen.isu.*
                     subdirectories from the remanants that may have
                     remained after removing duplicate install files
* isu-cleaner service - starts from delayed.target and executes the
                        isu-cleaner. This way we assure that all
                        possible remanents in globalapps are cleaned
                        up.

Change-Id: I7e4e5f7b6138095681b9a9fe73eb5a2430425c09

CMakeLists.txt
packaging/isu.spec
src/isu-cleaner/CMakeLists.txt [new file with mode: 0644]
src/isu-cleaner/isu-cleaner.c [new file with mode: 0644]
src/isu-cleaner/isu-cleaner.service [new file with mode: 0644]

index b511c9e..7ff904f 100644 (file)
@@ -6,3 +6,4 @@ ADD_SUBDIRECTORY(src/isud)
 ADD_SUBDIRECTORY(src/pkg_manager)
 ADD_SUBDIRECTORY(src/pkg_maker)
 ADD_SUBDIRECTORY(src/plugin_parser)
+ADD_SUBDIRECTORY(src/isu-cleaner)
index d7e29ca..e25ecad 100644 (file)
@@ -51,7 +51,8 @@ cp packaging/isu.manifest .
 %cmake . \
        -DCMAKE_INSTALL_PREFIX=%{_prefix} \
        -DLIBISU_VERSION=%{libisu_version} \
-       -DCHECK_ISU_FEATURE=OFF
+       -DCHECK_ISU_FEATURE=OFF \
+       -DSYSTEMD_DIR:PATH=%{_unitdir}
 make %{?_smp_mflags}
 
 %install
@@ -73,6 +74,8 @@ 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
+
 %files
 %manifest isu.manifest
 %license LICENSE.MIT
@@ -85,6 +88,9 @@ 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
 
 %files tools
 %manifest isu.manifest
diff --git a/src/isu-cleaner/CMakeLists.txt b/src/isu-cleaner/CMakeLists.txt
new file mode 100644 (file)
index 0000000..ee2ccfd
--- /dev/null
@@ -0,0 +1,12 @@
+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
new file mode 100644 (file)
index 0000000..ee06b27
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * 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 <assert.h>
+#include <dirent.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "libisu-internal.h"
+
+#define LOG_TAG "ISUCLEANER"
+#include <dlog/dlog.h>
+
+#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
new file mode 100644 (file)
index 0000000..80a6caf
--- /dev/null
@@ -0,0 +1,11 @@
+[Unit]
+Description=isu clean-up service
+
+[Service]
+Type=oneshot
+SmackProcessLabel=System
+ExecStart=/usr/bin/isu-cleaner
+RemainAfterExit=yes
+
+[Install]
+WantedBy=delayed.target