From 3b8dffb16591e6d4a8c04e99416a2aaa8562b9ac Mon Sep 17 00:00:00 2001 From: SeokYeon Hwang Date: Wed, 12 Aug 2015 16:50:07 +0900 Subject: [PATCH] emul_state: cleaned-up bin path and log path "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 --- tizen/src/emul_state.c | 157 ++++++++++++++--------- tizen/src/emul_state.h | 9 +- tizen/src/emulator_common.h | 4 + tizen/src/emulator_options.h | 2 - tizen/src/skin/maruskin_operation.c | 2 +- tizen/src/ui/menu/detailedinfodialog.cpp | 2 +- tizen/src/util/osutil-darwin.c | 10 +- tizen/src/util/osutil-linux.c | 8 +- tizen/src/util/osutil-win32.c | 12 +- 9 files changed, 127 insertions(+), 79 deletions(-) diff --git a/tizen/src/emul_state.c b/tizen/src/emul_state.c index 1122b12e68..974ccd9b2a 100644 --- a/tizen/src/emul_state.c +++ b/tizen/src/emul_state.c @@ -41,6 +41,7 @@ extern bool kvm_allowed; #include extern bool hax_allowed; #elif defined(CONFIG_DARWIN) +#include 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; diff --git a/tizen/src/emul_state.h b/tizen/src/emul_state.h index e94c1ef501..8f108a823c 100644 --- a/tizen/src/emul_state.h +++ b/tizen/src/emul_state.h @@ -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); diff --git a/tizen/src/emulator_common.h b/tizen/src/emulator_common.h index 4aef16733f..ad88358a21 100644 --- a/tizen/src/emulator_common.h +++ b/tizen/src/emulator_common.h @@ -49,6 +49,10 @@ #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 diff --git a/tizen/src/emulator_options.h b/tizen/src/emulator_options.h index cbe18954eb..f085f1bc48 100644 --- a/tizen/src/emulator_options.h +++ b/tizen/src/emulator_options.h @@ -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); diff --git a/tizen/src/skin/maruskin_operation.c b/tizen/src/skin/maruskin_operation.c index 398c4bebe8..7245c175e7 100644 --- a/tizen/src/skin/maruskin_operation.c +++ b/tizen/src/skin/maruskin_operation.c @@ -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); diff --git a/tizen/src/ui/menu/detailedinfodialog.cpp b/tizen/src/ui/menu/detailedinfodialog.cpp index 6c428faab0..c54b4c0388 100644 --- a/tizen/src/ui/menu/detailedinfodialog.cpp +++ b/tizen/src/ui/menu/detailedinfodialog.cpp @@ -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, diff --git a/tizen/src/util/osutil-darwin.c b/tizen/src/util/osutil-darwin.c index 4fc31e28e0..b6fcef1011 100644 --- a/tizen/src/util/osutil-darwin.c +++ b/tizen/src/util/osutil-darwin.c @@ -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) diff --git a/tizen/src/util/osutil-linux.c b/tizen/src/util/osutil-linux.c index 9f0ac30787..e02968a124 100644 --- a/tizen/src/util/osutil-linux.c +++ b/tizen/src/util/osutil-linux.c @@ -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) diff --git a/tizen/src/util/osutil-win32.c b/tizen/src/util/osutil-win32.c index d01e658e86..f826ae08c2 100644 --- a/tizen/src/util/osutil-win32.c +++ b/tizen/src/util/osutil-win32.c @@ -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); -- 2.34.1