emul_state: cleaned-up bin path and log path
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 12 Aug 2015 07:50:07 +0000 (16:50 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 17 Aug 2015 08:25:54 +0000 (17:25 +0900)
"bin_path" is stored in global variale.
"get_log_redirection_path()" provide *real* redirection path
that is aquired by system runtime information.
(In Windows, it works on WINVER > 0x600 - vista or newer - only.
Otherwise, it still provide assembled log path using legacy method.)

Change-Id: I24e04d3238a6a6727b025f51250d8646674b9662
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
tizen/src/emul_state.c
tizen/src/emul_state.h
tizen/src/emulator_common.h
tizen/src/emulator_options.h
tizen/src/skin/maruskin_operation.c
tizen/src/ui/menu/detailedinfodialog.cpp
tizen/src/util/osutil-darwin.c
tizen/src/util/osutil-linux.c
tizen/src/util/osutil-win32.c

index 1122b12..974ccd9 100644 (file)
@@ -41,6 +41,7 @@ extern bool kvm_allowed;
 #include <windows.h>
 extern bool hax_allowed;
 #elif defined(CONFIG_DARWIN)
+#include <fcntl.h>
 extern bool hax_allowed;
 #endif
 
@@ -72,44 +73,6 @@ static EmulatorConfigState _emul_state;
 char log_path[PATH_MAX] = { 0, };
 #endif
 
-const char *get_bin_path(void)
-{
-    const char *bin_path = get_variable(KEYWORD_BIN_PATH);
-    // guarantee bin_path is not NULL
-    if (!bin_path) {
-        bin_path = "";
-    }
-    return bin_path;
-}
-
-const char *get_log_path(void)
-{
-#ifdef SUPPORT_LEGACY_ARGS
-    if (log_path[0]) {
-        return log_path;
-    }
-#endif
-    const char *log_path = get_variable("log_path");
-
-    // if "log_path" is not exist, make it first.
-    if (!log_path) {
-        char *vms_path = get_variable("vms_path");
-        char *vm_name = get_variable("vm_name");
-        if (!vms_path || !vm_name) {
-            // we can not specify log path.
-            // emulator may not be launched from emulator-manager.
-            log_path = "";
-        }
-        else {
-            log_path = g_strdup_printf("%s/%s/logs", vms_path, vm_name);
-        }
-
-        set_variable("log_path", log_path, false);
-    }
-
-    return log_path;
-}
-
 /* sdl bits per pixel */
 void set_emul_sdl_bpp(int bpp)
 {
@@ -125,26 +88,6 @@ int get_emul_sdl_bpp(void)
     return _emul_info.sdl_bpp;
 }
 
-bool is_netclient_tap_attached(void)
-{
-    NetClientState *ncs[MAX_QUEUE_NUM];
-    int queues, i;
-
-    queues = qemu_find_net_clients_except(NULL, ncs,
-                                          NET_CLIENT_OPTIONS_KIND_NIC,
-                                          MAX_QUEUE_NUM);
-    for (i = 0; i < queues; ++i) {
-        if (ncs[i]->info->type == NET_CLIENT_OPTIONS_KIND_TAP &&
-                (ncs[i]->peer->info->type == NET_CLIENT_OPTIONS_KIND_NIC ||
-                // for legacy -net option.
-                 ncs[i]->peer->info->type == NET_CLIENT_OPTIONS_KIND_HUBPORT)) {
-            return true;
-        }
-    }
-
-    return false;
-}
-
 void set_emul_guest_ip(char *ip)
 {
     strncpy(_emul_info.guest_ip, ip, strlen(ip));
@@ -411,8 +354,84 @@ bool get_emul_cpu_accel(void)
 //
 
 // launch_conf_path
+// only set by emulator.c when start up
 const char *launch_conf_file = NULL;
 
+// bin path
+// only set by osutil-{OS}.c when start up
+const char *bin_path = "";
+
+const char *get_bin_path(void)
+{
+    return bin_path;
+}
+
+// log path
+static const char *log_redirect_path;
+
+#ifdef CONFIG_WIN32
+// for Windows version
+extern OSVERSIONINFO osvi;
+#endif
+
+const char *get_log_redirect_path(void)
+{
+#ifdef SUPPORT_LEGACY_ARGS
+    if (log_path[0]) {
+        return log_path;
+    }
+#endif
+    int result = -1;
+    char log_filename[PATH_MAX];
+
+    // should we compare stdout(fd/1) and stderr(fd/2) ??
+#if defined(CONFIG_LINUX)
+    result = readlink("/proc/self/fd/1", log_filename, PATH_MAX);
+#elif defined(CONFIG_DARWIN)
+    result = fcntl(STDOUT_FILENO, F_GETPATH, log_filename);
+#elif defined(CONFIG_WIN32)
+# if WINVER >= 0x600
+    // works only vista or newer...
+    if (osvi.dwMajorVersion >= 6) {
+        char win32_log_filename_normalized[PATH_MAX];
+        HANDLE handle_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
+        DWORD ret = GetFinalPathNameByHandle(handle_stdout,
+                win32_log_filename_normalized,
+                PATH_MAX, FILE_NAME_NORMALIZED);
+        // strip "\\?\"
+        if (ret > 0) {
+            g_stpcpy(log_filename, win32_log_filename_normalized + 4);
+            result = 0;
+        } else {
+            result = -1;
+        }
+    }
+# endif
+#endif
+    if (result >= 0) {
+        log_redirect_path = g_path_get_dirname(log_filename);
+    } else {
+    // fail safe
+        LOG_WARNING("Can not identify log redirection path, "
+                "We should assume it !!!\n");
+
+        char *vms_path = get_variable("vms_path");
+        char *vm_name = get_variable("vm_name");
+        if (!vms_path || !vm_name) {
+            // we can not specify log path.
+            // emulator may not be launched from emulator-manager.
+            log_redirect_path = "";
+        }
+        else {
+            log_redirect_path = g_strdup_printf("%s/%s/logs",
+                    vms_path, vm_name);
+        }
+    }
+
+    return log_redirect_path;
+}
+
+
 // drive image file
 static const char *drive_image_file = NULL;
 
@@ -623,6 +642,27 @@ bool is_touchscreen_enabled(void)
     return is_pci_device_enabled(PCI_DEVICE_ID_VIRTIO_TOUCHSCREEN);
 }
 
+// tap attached
+bool is_netclient_tap_attached(void)
+{
+    NetClientState *ncs[MAX_QUEUE_NUM];
+    int queues, i;
+
+    queues = qemu_find_net_clients_except(NULL, ncs,
+                                          NET_CLIENT_OPTIONS_KIND_NIC,
+                                          MAX_QUEUE_NUM);
+    for (i = 0; i < queues; ++i) {
+        if (ncs[i]->info->type == NET_CLIENT_OPTIONS_KIND_TAP &&
+                (ncs[i]->peer->info->type == NET_CLIENT_OPTIONS_KIND_NIC ||
+                // for legacy -net option.
+                 ncs[i]->peer->info->type == NET_CLIENT_OPTIONS_KIND_HUBPORT)) {
+            return true;
+        }
+    }
+
+    return false;
+}
+
 // vm_data_path
 static const char *vm_data_path = NULL;
 
@@ -663,6 +703,7 @@ const char *get_vm_data_path(void)
 }
 
 // display resolution
+// only set by vl.c when start up
 int initial_resolution_width = -1;
 int initial_resolution_height = -1;
 
index e94c1ef..8f108a8 100644 (file)
@@ -127,7 +127,7 @@ extern char log_path[];
 #endif
 
 char const *get_bin_path(void);
-char const *get_log_path(void);
+char const *get_log_redirect_path(void);
 
 /* setter */
 void set_emul_win_scale(double scale);
@@ -167,7 +167,6 @@ char* get_emul_host_ip(void);
 
 bool get_emuld_connection(void);
 bool get_sdb_connection(void);
-bool is_netclient_tap_attached(void);
 int get_max_touch_point(void);
 
 /* multi-touch */
@@ -177,18 +176,22 @@ int get_multi_touch_enable(void);
 
 // cleaned-up
 extern const char *launch_conf_file;
+extern const char *bin_path;
+extern int initial_resolution_width;
+extern int initial_resolution_height;
 
 const char *get_drive_image_file(void);
 const char *get_http_proxy_addr(void);
 const char *get_vm_name(void);
 const char *get_profile_name(void);
-const char* get_host_directory_sharing_path(void);
 const char *get_vm_data_path(void);
+const char* get_host_directory_sharing_path(void);
 
 bool is_gpu_accel_enabled(void);
 bool is_pci_device_enabled(int device_id);
 bool is_mouse_enabled(void);
 bool is_touchscreen_enabled(void);
+bool is_netclient_tap_attached(void);
 
 uint64_t get_ram_size(void);
 
index 4aef167..ad88358 100644 (file)
 
 #include "config-host.h"
 
+#ifdef CONFIG_DARWIN
+#include "sys/syslimits.h"
+#endif
+
 #if !defined(PATH_MAX)
 #if defined(MAX_PATH)
 #define PATH_MAX    MAX_PATH
index cbe1895..f085f1b 100644 (file)
@@ -37,8 +37,6 @@
  #define SUPPORT_SKIN_OPTIONS
 #endif
 
-#define KEYWORD_BIN_PATH    "_BIN_PATH_"
-
 void set_variable(const char * const arg1, const char * const arg2, bool override);
 char *get_variable(const char * const name);
 void reset_variables(void);
index 398c4be..7245c17 100644 (file)
@@ -381,7 +381,7 @@ DetailInfo* get_detail_info(int qemu_argc, char** qemu_argv)
 
     /* collect log path information */
 #define LOGPATH_TEXT "log_path="
-    const char* log_path = get_log_path();
+    const char* log_path = get_log_redirect_path();
     int log_path_len = strlen(LOGPATH_TEXT) + strlen(log_path) + delimiter_len;
     total_len += (log_path_len + 1);
 
index 6c428fa..c54b4c0 100644 (file)
@@ -149,7 +149,7 @@ QTableWidget *DetailedInfoDialog::createVmInfoTable()
     }
 
     insertTableRow(vmInfoTable, QString(DETAILED_INFO_LOG_PATH),
-        QString(get_log_path()), QString(get_log_path()));
+        QString(get_log_redirect_path()), QString(get_log_redirect_path()));
 
 #if 0
     insertTableRow(vmInfoTable, DETAILED_INFO_TELNET_PORT,
index 4fc31e2..b6fcef1 100644 (file)
@@ -99,7 +99,7 @@ void remove_vm_lock_os(void)
 void set_bin_path_os(char const *const exec_argv)
 {
     char *file_name = NULL;
-    char bin_path[PATH_MAX] = { 0, };
+    char bin_path_os[PATH_MAX] = { 0, };
 
     if (!exec_argv) {
         return;
@@ -117,12 +117,12 @@ void set_bin_path_os(char const *const exec_argv)
         return;
     }
 
-    g_strlcpy(bin_path, data, strlen(data) - strlen(file_name) + 1);
-    g_strlcat(bin_path, "/", PATH_MAX);
-
-    set_variable(KEYWORD_BIN_PATH, bin_path, true);
+    g_strlcpy(bin_path_os, data, strlen(data) - strlen(file_name) + 1);
+    g_strlcat(bin_path_os, "/", PATH_MAX);
 
     free(data);
+
+    bin_path = g_strdup(bin_path_os);
 }
 
 int get_number_of_processors(void)
index 9f0ac30..e02968a 100644 (file)
@@ -144,7 +144,7 @@ void remove_vm_lock_os(void)
 void set_bin_path_os(char const *const exec_argv)
 {
     char link_path[PATH_MAX] = { 0, };
-    char bin_path[PATH_MAX] = { 0, };
+    char bin_path_os[PATH_MAX] = { 0, };
     char *file_name = NULL;
 
     ssize_t len = readlink("/proc/self/exe", link_path, sizeof(link_path) - 1);
@@ -157,11 +157,11 @@ void set_bin_path_os(char const *const exec_argv)
     link_path[len] = '\0';
 
     file_name = g_strrstr(link_path, "/");
-    g_strlcpy(bin_path, link_path, strlen(link_path) - strlen(file_name) + 1);
+    g_strlcpy(bin_path_os, link_path, strlen(link_path) - strlen(file_name) + 1);
 
-    g_strlcat(bin_path, "/", PATH_MAX);
+    g_strlcat(bin_path_os, "/", PATH_MAX);
 
-    set_variable(KEYWORD_BIN_PATH, bin_path, true);
+    bin_path = g_strdup(bin_path_os);
 }
 
 int get_number_of_processors(void)
index d01e658..f826ae0 100644 (file)
@@ -144,7 +144,7 @@ void remove_vm_lock_os(void)
 void set_bin_path_os(char const *const exec_argv)
 {
     char link_path[PATH_MAX] = { 0, };
-    char bin_path[PATH_MAX] = { 0, };
+    char bin_path_os[PATH_MAX] = { 0, };
     char *file_name = NULL;
 
     if (!GetModuleFileName(NULL, link_path, PATH_MAX)) {
@@ -152,10 +152,10 @@ void set_bin_path_os(char const *const exec_argv)
     }
 
     file_name = g_strrstr(link_path, "\\");
-    g_strlcpy(bin_path, link_path, strlen(link_path) - strlen(file_name) + 1);
-    g_strlcat(bin_path, "\\", PATH_MAX);
+    g_strlcpy(bin_path_os, link_path, strlen(link_path) - strlen(file_name) + 1);
+    g_strlcat(bin_path_os, "\\", PATH_MAX);
 
-    set_variable(KEYWORD_BIN_PATH, bin_path, true);
+    bin_path = g_strdup(bin_path_os);
 }
 
 int get_number_of_processors(void)
@@ -175,6 +175,9 @@ int get_number_of_processors(void)
     return num_processors;
 }
 
+// FIXME
+OSVERSIONINFO osvi;
+
 void print_system_info_os(void)
 {
     INFO("* Windows\n");
@@ -182,7 +185,6 @@ void print_system_info_os(void)
     INFO("* LibPNG Version : %s\n", PNG_LIBPNG_VER_STRING);
 
     /* Retrieves information about the current os */
-    OSVERSIONINFO osvi;
     ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
     osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);