Fix error handling of dbus communication 89/255489/4 accepted/tizen/unified/20210321.225639 submit/tizen/20210319.035222
authorYunmi Ha <yunmi.ha@samsung.com>
Fri, 19 Mar 2021 01:54:40 +0000 (10:54 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Fri, 19 Mar 2021 02:25:29 +0000 (11:25 +0900)
Change-Id: I404561789b8bc3c0f22a1fdf5b5adef6de364fc0
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/runtime_info_usage.c

index d86a2de..b147f0a 100644 (file)
@@ -82,6 +82,31 @@ static GVariant *runtime_info_append_args(int *args, int size)
        return g_variant_builder_end(&builder);
 }
 
+static runtime_info_error_e errno_to_runtime_info_error(int err)
+{
+    switch (err) {
+    case 0:
+        return RUNTIME_INFO_ERROR_NONE;
+    case -EINVAL:
+        return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
+    case -ENOMEM:
+        return RUNTIME_INFO_ERROR_OUT_OF_MEMORY;
+    case -EIO:
+    case -ENOENT:
+        return RUNTIME_INFO_ERROR_IO_ERROR;
+    case -EPERM:
+    case -EACCES:
+        return RUNTIME_INFO_ERROR_PERMISSION_DENIED;
+    case -ENOTSUP:
+        return RUNTIME_INFO_ERROR_NOT_SUPPORTED;
+    case -ECOMM:
+        return RUNTIME_INFO_ERROR_REMOTE_IO;
+    default:
+        // TODO: what is the runtime-info error for this default case?
+        return RUNTIME_INFO_ERROR_NO_DATA;
+    }
+}
+
 /* Handler function which handles dbus related instructions
  * Creates the method call to resourced and receives the reply (if successful)
  * Return the received usage information (if received) else NULL to signify failed call to resourced
@@ -123,7 +148,8 @@ static GVariant *runtime_info_dbus_request_usage_info(runtime_info_usage_type_e
                //LCOV_EXCL_START : system error
                _E("INVALID_PARAMETER(0x%08x): invalid type parameter",
                                RUNTIME_INFO_ERROR_INVALID_PARAMETER);
-               *error = RUNTIME_INFO_ERROR_INVALID_PARAMETER;
+               if (error)
+                       *error = RUNTIME_INFO_ERROR_INVALID_PARAMETER;
                return NULL;
                //LCOV_EXCL_STOP
        }
@@ -139,7 +165,8 @@ static GVariant *runtime_info_dbus_request_usage_info(runtime_info_usage_type_e
                if (!args_in) {
                        //LCOV_EXCL_START : system error
                        _E("DBUS_METHOD_CALL: not able to append pid array to message");
-                       *error = RUNTIME_INFO_ERROR_IO_ERROR;
+                       if (error)
+                               *error = RUNTIME_INFO_ERROR_IO_ERROR;
                        return NULL;
                        //LCOV_EXCL_STOP
                }
@@ -163,7 +190,8 @@ static GVariant *runtime_info_dbus_request_usage_info(runtime_info_usage_type_e
        if (ret_dbus < 0) {
                //LCOV_EXCL_START : system error
                _E("DBUS_METHOD_CALL: not able to send message");
-
+               if (error)
+                       *error = errno_to_runtime_info_error(ret_dbus);
                return NULL;
                //LCOV_EXCL_STOP
        }
@@ -368,29 +396,6 @@ API int runtime_info_get_process_memory_info(int *pid, int size, process_memory_
        return RUNTIME_INFO_ERROR_NONE;
 }
 
-static runtime_info_error_e hal_error_to_runtime_info_error(int err)
-{
-       switch (err) {
-       case 0:
-               return RUNTIME_INFO_ERROR_NONE;
-       case -EINVAL:
-               return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
-       case -ENOMEM:
-               return RUNTIME_INFO_ERROR_OUT_OF_MEMORY;
-       case -EIO:
-       case -ENOENT:
-               return RUNTIME_INFO_ERROR_IO_ERROR;
-       case -EPERM:
-       case -EACCES:
-               return RUNTIME_INFO_ERROR_PERMISSION_DENIED;
-       case -ENOTSUP:
-               return RUNTIME_INFO_ERROR_NOT_SUPPORTED;
-       default:
-               // TODO: what is the runtime-info error for this default case?
-               return RUNTIME_INFO_ERROR_NO_DATA;
-       }
-}
-
 static int get_process_memory_info_direct(int *pid, int size, process_memory_info_key_e key, int **info)
 {
        int ret_hal, i;
@@ -410,7 +415,7 @@ static int get_process_memory_info_direct(int *pid, int size, process_memory_inf
                for (i = 0; i < size; ++i) {
                        ret_hal = hal_device_memory_get_gpu_info(pid[i], &gpu_info);
                        if (ret_hal != 0) {
-                               ret = hal_error_to_runtime_info_error(ret_hal);
+                               ret = errno_to_runtime_info_error(ret_hal);
                                goto out;
                        }
                        result[i] = gpu_info.used_pages;
@@ -420,8 +425,8 @@ static int get_process_memory_info_direct(int *pid, int size, process_memory_inf
        case RUNTIME_INFO_PROC_MEMORY_GEM_RSS:
                for (i = 0; i < size; ++i) {
                        ret_hal = hal_device_memory_get_gem_info(pid[i], &gem_info);
-                       if (ret != 0) {
-                               ret = hal_error_to_runtime_info_error(ret_hal);
+                       if (ret_hal != 0) {
+                               ret = errno_to_runtime_info_error(ret_hal);
                                goto out;
                        }
                        result[i] = gem_info.rss;