Fix minor issues 40/152440/4 accepted/tizen/4.0/unified/20170927.045605 submit/tizen_4.0/20170926.084004 tizen_4.0.IoT.p1_release
authorKichan Kwon <k_c.kwon@samsung.com>
Tue, 26 Sep 2017 06:52:37 +0000 (15:52 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Tue, 26 Sep 2017 07:32:10 +0000 (16:32 +0900)
- Prevent divided by zero
- Use pclose instead of fclose
- Notice the failure

Change-Id: I217aea7398b3634f1c44124209e5bce24ff1c2b1
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/runtime_info_usage.c
test/runtime_info_test_resourced.c
test/runtime_info_test_vconf.c

index dba663d..34beca0 100644 (file)
@@ -415,10 +415,17 @@ API int runtime_info_get_cpu_usage(runtime_cpu_usage_s *usage)
 
        total_uptime = user + nice + system + idle + iowait + irq + softirq;
 
-       usage->user = (double)user * 100 / total_uptime;
-       usage->nice = (double)nice * 100 / total_uptime;
-       usage->system = (double)system * 100 / total_uptime;
-       usage->iowait = (double)iowait * 100 / total_uptime;
+       if (total_uptime > 0) {
+               usage->user = (double)user * 100 / total_uptime;
+               usage->nice = (double)nice * 100 / total_uptime;
+               usage->system = (double)system * 100 / total_uptime;
+               usage->iowait = (double)iowait * 100 / total_uptime;
+       } else {
+               usage->user = 0;
+               usage->nice = 0;
+               usage->system = 0;
+               usage->iowait = 0;
+       }
 
        return RUNTIME_INFO_ERROR_NONE;
 }
index 292c231..15135f5 100644 (file)
@@ -101,11 +101,11 @@ void runtime_info_test_get_process_memory_info(pid_t pid)
        if (!fscanf(fp, "%*d %d %d %*d %d", &code, &data, &pss)) {
                printf("memps has invalid format\n");
                printf("  Result : %s\n", PRINT_RESULT(ERROR));
-               fclose(fp);
+               pclose(fp);
                return;
        }
 
-       fclose(fp);
+       pclose(fp);
 
        printf("  Virtual memory size   : %s\n",
                        PRINT_RESULT(check_value(info[0].vsz, BytetoKiB(vsz), 10)));
index eab55fd..8dc9e5f 100644 (file)
@@ -284,6 +284,7 @@ static gpointer runtime_info_test_cb_thread(gpointer data)
        }
 
        g_main_loop_run(mainloop);
+       g_main_loop_unref(mainloop);
 
        return NULL;
 }
@@ -345,6 +346,8 @@ void runtime_info_test_set_changed_cb(void)
                if (g_cond_wait_until(&cond, &mutex, g_get_monotonic_time() + TIME_TO_WAIT_CB)) {
                        result = SUCCESS;
                        ret = runtime_info_unset_changed_cb(key_list_bool[CB_TEST_IDX].key_r);
+                       if (ret != RUNTIME_INFO_ERROR_NONE)
+                               printf("Notice : failed to unset callback.\n");
                        break;
                }
        }
@@ -364,6 +367,8 @@ judge:
                        ret = execlp(VCONF_EXECUTABLE, VCONF_ARGV_0, VCONF_ARGV_1, VCONF_ARGV_2,
                                        VCONF_ARGV_3, key_list_bool[CB_TEST_IDX].key_v, VCONF_ARGV_5,
                                        (value_orig ? VCONF_ARGV_6_TRUE : VCONF_ARGV_6_FALSE), VCONF_ARGV_7);
+                       if (ret == -1)
+                               printf("Notice : failed to rollback vconf value.\n");
                        break;
                case -1:
                default: