From: Kichan Kwon Date: Tue, 26 Sep 2017 06:52:37 +0000 (+0900) Subject: Fix minor issues X-Git-Tag: accepted/tizen/4.0/unified/20170927.045605^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F40%2F152440%2F4;p=platform%2Fcore%2Fapi%2Fruntime-info.git Fix minor issues - Prevent divided by zero - Use pclose instead of fclose - Notice the failure Change-Id: I217aea7398b3634f1c44124209e5bce24ff1c2b1 Signed-off-by: Kichan Kwon --- diff --git a/src/runtime_info_usage.c b/src/runtime_info_usage.c index dba663d..34beca0 100644 --- a/src/runtime_info_usage.c +++ b/src/runtime_info_usage.c @@ -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; } diff --git a/test/runtime_info_test_resourced.c b/test/runtime_info_test_resourced.c index 292c231..15135f5 100644 --- a/test/runtime_info_test_resourced.c +++ b/test/runtime_info_test_resourced.c @@ -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))); diff --git a/test/runtime_info_test_vconf.c b/test/runtime_info_test_vconf.c index eab55fd..8dc9e5f 100644 --- a/test/runtime_info_test_vconf.c +++ b/test/runtime_info_test_vconf.c @@ -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: