tools: lshal: Add --reset option to reset cache file 08/320508/4 accepted/tizen/unified/20250306.094544 accepted/tizen/unified/x/20250306.134918
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 08:07:46 +0000 (17:07 +0900)
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>
packaging/hal-api-common.spec
tools/lshal/lshal.c

index 50b9a10e25e8f2157c03b5414395c5c05675808d..98c448820648f660885c9972efb8d1be464e763d 100644 (file)
@@ -111,6 +111,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 daf408fac09e145078f06b6489f390f2a1d597a8..175d374a699827c685128dfcfcb8e9f489ba012e 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.
@@ -257,11 +260,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;