privilege: Change is_privilege_supported() to return argument
authorUnsung Lee <unsung.lee@samsung.com>
Fri, 10 Jan 2025 07:26:28 +0000 (16:26 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 15 Jan 2025 01:17:06 +0000 (10:17 +0900)
Change the return type of is_privilege_supported() from bool to int
to get an error value through return value.
In addition, move privilege_supported state to function output argument.

Change-Id: I00be8b528422b42a88ce34bd367940d87bd04202
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
include/util/privilege.h
lib/resource-monitor/resource-monitor.c
src/util/privilege.c

index c1bd97fc9940beeacacb903834a695f68fa190f3..12b7f0e967f3654f0b0a89ff97a53506d2b3e073 100644 (file)
@@ -21,6 +21,6 @@
 
 #include <stdbool.h>
 
-bool is_privilege_supported(const char *privilege_name);
+int privilege_get_privilege_supported(const char *privilege_name, bool *privilege_supported);
 
 #endif
index ccf384cfdcfa401c154a4740cb85aa0b2a630572..3412741c1479ef594c25797af9c3b56bff95ac57 100644 (file)
@@ -301,8 +301,10 @@ int pass_resource_monitor_init(void)
        struct pass_resource_monitor_client *client;
        struct sockaddr_un server_addr;
        int ret = TIZEN_ERROR_NO_DATA;
+       bool privilege_supported = false;
 
-       if (!is_privilege_supported(PRIVILEGE_SYSTEMMONITOR))
+       ret = privilege_get_privilege_supported(PRIVILEGE_SYSTEMMONITOR, &privilege_supported);
+       if (ret != 0 || !privilege_supported)
                return TIZEN_ERROR_PERMISSION_DENIED;
 
        client = malloc(sizeof(struct pass_resource_monitor_client));
index d577223619f10e1c0bb6b350a9a27e1c61d6f75b..59d8dc94aa523354728edbf940d2a47803acd3dd 100644 (file)
@@ -30,7 +30,7 @@
 
 extern char *program_invocation_name;
 
-bool is_privilege_supported(const char *privilege_name)
+int privilege_get_privilege_supported(const char *privilege_name, bool *privilege_supported)
 {
        cynara *cynara = NULL;
        FILE *fp = NULL;
@@ -39,9 +39,13 @@ bool is_privilege_supported(const char *privilege_name)
        char smack_label[BUFF_MAX] = {0, };
        int ret;
 
+       if (!privilege_supported)
+               return -EINVAL;
+
        if (cynara_initialize(&cynara, NULL) != CYNARA_API_SUCCESS) {
                _E("failed to initialize cynara");
-               return false;
+               *privilege_supported = false;
+               return -EPERM;
        }
 
        fp = fopen("/proc/self/attr/current", "r");
@@ -66,10 +70,13 @@ bool is_privilege_supported(const char *privilege_name)
        if (cynara)
                cynara_finish(cynara);
        if (ret != CYNARA_API_ACCESS_ALLOWED) {
-               _E("'%s' privilege is not supported on %s",
+               _W("'%s' privilege is not supported on %s",
                                privilege_name, program_invocation_name);
-               return false;
+
+               *privilege_supported = false;
+       } else {
+               *privilege_supported = true;
        }
 
-       return true;
+       return 0;
 }