lib: resource-monitor: Fix return value of pass_resource_monitor_is_resource_attr_sup... 67/277567/3
authorChanwoo Choi <cw00.choi@samsung.com>
Fri, 8 Jul 2022 07:49:57 +0000 (16:49 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 8 Jul 2022 09:03:24 +0000 (18:03 +0900)
When return minus error value, it is converted to 1. It means that
return 'true' when error happen. So that change the return value
from minus integer value to false.

Fix following issue by this patch:
[  FAILED  ] ResourceMonitorTest.pass_resource_monitor_is_resource_attr_supported_invalid

Change-Id: I437644ffbc6b55f9ff0e539ab3af1ceda6878872
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
lib/resource-monitor/resource-monitor.c

index fc70700..2a4b637 100644 (file)
@@ -348,23 +348,26 @@ bool pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u
                        REQUEST_IS_RESOURCE_ATTR_SUPPORTED, resource_id, attr_id);
        if (send(id, buffer, buffer_len, 0) < 0) {
                _E("[libpass] error occurred while sending buffer");
-               return -EIO;
+               return false;
        }
 
        /* wait for response */
        buffer_len = recv(id, buffer, GENERIC_BUFF_MAX, 0);
        if (buffer_len <= 0) {
                _E("[libpass] socket disconnected");
-               return -EIO;
+               return false;
        }
 
        buffer[buffer_len] = '\0';
        if (sscanf(buffer, "%d$%d", &response_req, &ret) < 2)
-               return -EINVAL;
+               return false;
+
+       if (ret < 0)
+               return false;
 
        if (response_req != REQUEST_IS_RESOURCE_ATTR_SUPPORTED) {
                _E("[libpass] wrong response");
-               return -EINVAL;
+               return false;
        }
 
        return (bool)ret;