From: Youngjae Cho Date: Tue, 4 Mar 2025 08:48:22 +0000 (+0900) Subject: tools: lshal: Add --reset option to reset cache file X-Git-Tag: accepted/tizen/unified/20250306.094544^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=945b524b6b91227815287f6848035d653c88c13a;p=platform%2Fhal%2Fapi%2Fcommon.git tools: lshal: Add --reset option to reset cache file 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 --- diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index 50b9a10..98c4488 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -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 diff --git a/tools/lshal/lshal.c b/tools/lshal/lshal.c index daf408f..175d374 100644 --- a/tools/lshal/lshal.c +++ b/tools/lshal/lshal.c @@ -25,6 +25,7 @@ #include #include #include +#include #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;