tools: lshal: Add --reset option to reset cache file 69/320669/1 accepted/tizen/9.0/unified/20250310.161037
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 4 Mar 2025 08:48:22 +0000 (17:48 +0900)
committeryoungjae cho <y0.cho@samsung.com>
Wed, 5 Mar 2025 10:51:07 +0000 (10:51 +0000)
The lshal option --reset removes single file,
/opt/etc/hal/.hal-backend-compatibility-loaded. By that way, an access
to the /opt/etc/hal/.hal-backend-compatibility will truncate the file.
Any following call for the cache file will update it to the latest data,
and then recreate .hal-backend-compatibility-loaded to seal the updated
data.

Plus, to reset the cache for every rpm installation, the 'lshal --reset'
is added to %post script.

Change-Id: Id0a9a1390af3dcf1708028b4ad731f43f822d449
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
(cherry picked from commit 945b524b6b91227815287f6848035d653c88c13a)

packaging/hal-api-common.spec
tools/lshal/lshal.c

index f1cd3f69fbebab8472e408e6c841859907b6e405..17692a1c3a225b4da19cca86d7589bbd838fc7c7 100644 (file)
@@ -98,6 +98,7 @@ rm -rf %{buildroot}
 %post
 /sbin/ldconfig
 ln -sf %{_unitdir}/hal-compatibility-checker.service %{_unitdir}/sysinit.target.wants/
+%{_bindir}/lshal --reset
 
 %postun
 /sbin/ldconfig
index 7ce8aa415d16299e0a8d870bbdb3b165e83a5168..087e6c4511303c456474e74fc931ac0db83e8dc9 100644 (file)
@@ -25,6 +25,7 @@
 #include <signal.h>
 #include <unistd.h>
 #include <inttypes.h>
+#include <getopt.h>
 
 #include "hal-common.h"
 #include "hal-common-interface.h"
@@ -44,6 +45,8 @@
 #define LSHAL_FLAG_MANIFEST_VERSION            BIT(7)
 #define LSHAL_FLAG_COMPATIBILITY               BIT(8)
 
+#define DEFAULT_HAL_BACKEND_COMPATIBILITY_LOADED_PATH          "/opt/etc/hal/.hal-backend-compatibility-loaded"
+
 struct _hal_backend_module_data {
        /**
         * Each HAL module defines the different backend_module_data.
@@ -248,11 +251,67 @@ static void lshal(void)
        lshal_print_hal_backend_info(flags);
 }
 
+static int show_help(void)
+{
+       printf(
+               "lshal - list platform hal and associated backend information\n"
+               "\n"
+               "USAGE\n"
+               "\tlshal [OPTION]...\n"
+               "\n"
+               "OPTION\n"
+               "\t-h, --help\n"
+               "\t\tShow this help.\n"
+               "\n"
+               "\t-r, --reset\n"
+               "\t\tClear hal information cache.\n"
+         );
+
+       return 0;
+}
+
+static int reset_cache(void)
+{
+       int ret;
+
+       ret = unlink(DEFAULT_HAL_BACKEND_COMPATIBILITY_LOADED_PATH);
+       if (ret < 0) {
+               printf("Failed to reset cache, %m\n");
+               return ret;
+       }
+
+       sync();
+
+       return 0;
+}
+
 int main(int argc, char *argv[])
 {
+       const struct option lshal_long_option[] = {
+               { "help",       no_argument,    NULL,   'h' },
+               { "reset",      no_argument,    NULL,   'r' },
+               { 0, },
+       };
+       int opt;
+
        /* Register signal handler for freeing resources */
        signal(SIGINT, lshal_handle_signal);
 
+       for (;;) {
+               opt = getopt_long(argc, argv, "hr", lshal_long_option, NULL);
+               if (opt == -1)
+                       break;
+
+               switch (opt) {
+               case 'h':
+                       return show_help();
+               case 'r':
+                       return reset_cache();
+               default:
+                       break;
+               }
+       }
+
        lshal();
 
        return 0;