net: modify sdb connection
authorMunkyu Im <munkyu.im@samsung.com>
Tue, 16 Aug 2016 10:37:49 +0000 (19:37 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 19 Aug 2016 02:24:00 +0000 (11:24 +0900)
- change the sleeping time efficiently.
- disable stderr from log by using redirection.

Change-Id: I542fe588ed468293f724acf8f1679c17f2c9f878
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
tizen/src/util/net_helper.c

index b7be35f..ff6c5c4 100644 (file)
@@ -50,7 +50,6 @@ DECLARE_DEBUG_CHANNEL(net_helper);
 #define BUF_SIZE 64
 #define MAX_TRIAL 20
 #define MAX_USER_NAME_LEN 36
-#define SLEEP_WAIT_SDB 500  /* ms */
 
 int emul_vm_base_socket;
 static bool sdb_daemon_is_initialized = false;
@@ -398,7 +397,8 @@ static void *get_user_home_path(void *args)
 {
     FILE *fp;
     char user_name[MAX_USER_NAME_LEN] = { 0, } ;
-    int index = 0;
+    int trial = 0;
+    int sleep_time = 500; // msec
 #ifndef CONFIG_WIN32
     const char *sdb_path = "../../../../../tools/sdb";
 #else
@@ -411,12 +411,17 @@ static void *get_user_home_path(void *args)
     if (get_platform_default_home()) {
         return NULL;
     }
-
-    char *cmd_root_off = g_strdup_printf("\"%s%s\" -s emulator-%d root off",
+#ifndef CONFIG_WIN32
+    char *cmd_root_off = g_strdup_printf("\"%s%s\" -s emulator-%d root off 2> /dev/null",
             bin_dir, sdb_path, get_vm_device_serial_number());
-    char *cmd_get_home = g_strdup_printf("\"%s%s\" -s emulator-%d shell id -un",
+    char *cmd_get_home = g_strdup_printf("\"%s%s\" -s emulator-%d shell id -un 2> /dev/null",
             bin_dir, sdb_path, get_vm_device_serial_number());
-
+#else
+    char *cmd_root_off = g_strdup_printf("\"%s%s\" -s emulator-%d root off 2> NUL",
+            bin_dir, sdb_path, get_vm_device_serial_number());
+    char *cmd_get_home = g_strdup_printf("\"%s%s\" -s emulator-%d shell id -un 2> NUL",
+            bin_dir, sdb_path, get_vm_device_serial_number());
+#endif
     //FIXME: (sdb) cannot check sdb root status
     fp = popen(cmd_root_off, "r");
     if (fp == NULL) {
@@ -426,12 +431,16 @@ static void *get_user_home_path(void *args)
     }
     g_free(cmd_root_off);
     pclose(fp);
-
-    while (index++ != MAX_TRIAL) {
+    while (true) {
+        if (trial >= MAX_TRIAL) {
+            sleep_time = 2000;
+        } else {
+            trial++;
+        }
 #ifdef CONFIG_WIN32
-        Sleep(SLEEP_WAIT_SDB);
+        Sleep(sleep_time);
 #else
-        usleep(SLEEP_WAIT_SDB * 1000);
+        usleep(sleep_time * 1000);
 #endif
         fp = popen(cmd_get_home, "r");
         if (fp == NULL) {
@@ -446,7 +455,6 @@ static void *get_user_home_path(void *args)
                 set_platform_default_home(path);
                 g_free(path);
                 pclose(fp);
-
                 break;
             }
         }