From 90a5b844294a0ae82c5a4f7323b96ffc7ad91aba Mon Sep 17 00:00:00 2001 From: SeokYeon Hwang Date: Tue, 2 Dec 2014 21:45:16 +0900 Subject: [PATCH] emulator: introduced 'keyword' variable Introduced 'keyword' variable that is provided by emulator itself. Removed redundant static functions. Change-Id: Ib007914f1e66d9da4a71aeb8cb0919aea60ff6d3 Signed-off-by: SeokYeon Hwang --- tizen/src/emul_state.c | 6 +++++- tizen/src/emul_state.h | 1 - tizen/src/emulator.c | 28 ++++------------------------ tizen/src/emulator_legacy.c | 14 ++------------ tizen/src/emulator_options.c | 3 ++- tizen/src/emulator_options.h | 2 ++ tizen/src/util/new_debug_ch.c | 9 +++------ tizen/src/util/osutil-darwin.c | 7 +++++-- tizen/src/util/osutil-linux.c | 8 ++++++-- tizen/src/util/osutil-win32.c | 8 +++++--- 10 files changed, 34 insertions(+), 52 deletions(-) diff --git a/tizen/src/emul_state.c b/tizen/src/emul_state.c index 0f47b12fd6..98ca01527a 100644 --- a/tizen/src/emul_state.c +++ b/tizen/src/emul_state.c @@ -47,7 +47,6 @@ static EmulatorConfigState _emul_state; /* misc */ char remote_bin_path[PATH_MAX] = { 0, }; -char bin_path[PATH_MAX] = { 0, }; #ifdef SUPPORT_LEGACY_ARGS // for compatibility char log_path[PATH_MAX] = { 0, }; @@ -60,6 +59,11 @@ const char *get_remote_bin_path(void) 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; } diff --git a/tizen/src/emul_state.h b/tizen/src/emul_state.h index 5c9d599651..79d9b8b8fd 100644 --- a/tizen/src/emul_state.h +++ b/tizen/src/emul_state.h @@ -114,7 +114,6 @@ typedef struct EmulatorConfigState { /* misc */ extern char remote_bin_path[]; -extern char bin_path[]; #ifdef SUPPORT_LEGACY_ARGS extern char log_path[]; #endif diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index 70257a5984..735c273c38 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -103,29 +103,9 @@ static void construct_main_window(int skin_argc, char *skin_argv[], } #endif -static void get_host_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy) -{ - get_host_proxy_os(http_proxy, https_proxy, ftp_proxy, socks_proxy); -} - -static void set_bin_path(char const *const exec_argv) -{ - set_bin_path_os(exec_argv); -} - -static void make_vm_lock(void) -{ - make_vm_lock_os(); -} - -static void remove_vm_lock(void) -{ - remove_vm_lock_os(); -} - static void emulator_notify_exit(Notifier *notifier, void *data) { - remove_vm_lock(); + remove_vm_lock_os(); int i; for (i = 0; i < _qemu_argc; ++i) { @@ -206,7 +186,7 @@ static void prepare_basic_features(gchar * const kernel_cmdline) clean_websocket_port(SIGKILL); #endif - make_vm_lock(); + make_vm_lock_os(); maru_device_hotplug_init(); @@ -214,7 +194,7 @@ static void prepare_basic_features(gchar * const kernel_cmdline) sdb_setup(get_device_serial_number() + SDB_UDP_SENSOR_INDEX); - get_host_proxy(http_proxy, https_proxy, ftp_proxy, socks_proxy); + get_host_proxy_os(http_proxy, https_proxy, ftp_proxy, socks_proxy); gchar * const tmp_str = g_strdup_printf(" sdb_port=%d," " http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s" @@ -370,7 +350,7 @@ static int emulator_main(int argc, char *argv[], char **envp) _qemu_argc = 0; _qemu_argv[_qemu_argc++] = g_strdup(argv[0]); - set_bin_path(_qemu_argv[0]); + set_bin_path_os(_qemu_argv[0]); if (!load_profile_default(conf, profile)) { return -1; diff --git a/tizen/src/emulator_legacy.c b/tizen/src/emulator_legacy.c index 3b8194c95f..32350df8f9 100644 --- a/tizen/src/emulator_legacy.c +++ b/tizen/src/emulator_legacy.c @@ -82,11 +82,6 @@ extern char **_skin_argv; extern int _qemu_argc; extern char **_qemu_argv; -static void set_bin_path(gchar * exec_argv) -{ - set_bin_path_os(exec_argv); -} - static void print_system_info(void) { #define DIV 1024 @@ -167,14 +162,9 @@ static void set_image_and_log_path(char *qemu_argv) strcat(log_path, LOGFILE); } -static void remove_vm_lock(void) -{ - remove_vm_lock_os(); -} - static void emulator_notify_exit(Notifier *notifier, void *data) { - remove_vm_lock(); + remove_vm_lock_os(); INFO("Exit emulator...\n"); } @@ -290,7 +280,7 @@ int legacy_emulator_main(int argc, char * argv[], char **envp) { legacy_parse_options(argc, argv, &_skin_argc, &_skin_argv, &_qemu_argc, &_qemu_argv); - set_bin_path(_qemu_argv[0]); + set_bin_path_os(_qemu_argv[0]); extract_qemu_info(_qemu_argc, _qemu_argv); INFO("Emulator start !!!\n"); diff --git a/tizen/src/emulator_options.c b/tizen/src/emulator_options.c index 7a5df2b48a..4507eb6c5d 100644 --- a/tizen/src/emulator_options.c +++ b/tizen/src/emulator_options.c @@ -67,6 +67,7 @@ void set_variable(const char * const arg1, const char * const arg2, break; } + // strip quotes name = g_strdup(arg1 + i); if(!arg2) { value = g_strdup(""); @@ -140,7 +141,7 @@ static char *substitute_variables(char *src) int end_index = -1; char *str; - // strip "" + // strip quotes int len = strlen(src); if (src[0] == '"' && src[len - 1] == '"') { src[len - 1] = '\0'; diff --git a/tizen/src/emulator_options.h b/tizen/src/emulator_options.h index ee9a898906..1ac865850b 100644 --- a/tizen/src/emulator_options.h +++ b/tizen/src/emulator_options.h @@ -31,6 +31,8 @@ #include "emulator_common.h" +#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/util/new_debug_ch.c b/tizen/src/util/new_debug_ch.c index 8537ee314b..22d25a994c 100644 --- a/tizen/src/util/new_debug_ch.c +++ b/tizen/src/util/new_debug_ch.c @@ -220,18 +220,15 @@ static void debug_init(void) char *debug = NULL; FILE *fp = NULL; char *tmp = NULL; + const char *bin_path = get_bin_path(); if (nb_debug_options != -1) { return; /* already initialized */ } nb_debug_options = 0; - if (0 == strlen(bin_path)) { - g_strlcpy(debugchfile, "DEBUGCH", MAX_FILE_LEN); - } else { - g_strlcat(debugchfile, bin_path, MAX_FILE_LEN); - g_strlcat(debugchfile, "DEBUGCH", MAX_FILE_LEN); - } + g_strlcpy(debugchfile, bin_path, MAX_FILE_LEN); + g_strlcat(debugchfile, "DEBUGCH", MAX_FILE_LEN); fp = fopen(debugchfile, "r"); if (fp == NULL) { diff --git a/tizen/src/util/osutil-darwin.c b/tizen/src/util/osutil-darwin.c index 39560a8d5a..d8c5ffa8e5 100644 --- a/tizen/src/util/osutil-darwin.c +++ b/tizen/src/util/osutil-darwin.c @@ -127,7 +127,8 @@ void remove_vm_lock_os(void) void set_bin_path_os(char const *const exec_argv) { - gchar *file_name = NULL; + char *file_name = NULL; + char bin_path[PATH_MAX] = { 0, }; if (!exec_argv) { return; @@ -146,8 +147,10 @@ void set_bin_path_os(char const *const exec_argv) } 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); + free(data); } diff --git a/tizen/src/util/osutil-linux.c b/tizen/src/util/osutil-linux.c index 3c253fed01..16f0e6c178 100644 --- a/tizen/src/util/osutil-linux.c +++ b/tizen/src/util/osutil-linux.c @@ -38,9 +38,9 @@ #include "osutil.h" #include "emulator.h" #include "emul_state.h" -#include "debug_ch.h" #include "maru_err_table.h" #include "sdb.h" +#include "emulator_options.h" #ifndef CONFIG_LINUX #error @@ -58,6 +58,7 @@ #include "hw/virtio/maru_virtio_evdi.h" #endif +#include "debug_ch.h" MULTI_DEBUG_CHANNEL(emulator, osutil); static int g_shmid; @@ -163,7 +164,8 @@ void remove_vm_lock_os(void) void set_bin_path_os(char const *const exec_argv) { - gchar link_path[PATH_MAX] = { 0, }; + char link_path[PATH_MAX] = { 0, }; + char bin_path[PATH_MAX] = { 0, }; char *file_name = NULL; ssize_t len = readlink("/proc/self/exe", link_path, sizeof(link_path) - 1); @@ -180,6 +182,8 @@ void set_bin_path_os(char const *const exec_argv) g_strlcat(bin_path, "/", PATH_MAX); + set_variable(KEYWORD_BIN_PATH, bin_path, true); + #ifdef CONFIG_SPICE g_strlcpy(remote_bin_path, link_path, strlen(link_path) - strlen(file_name) - 2); g_strlcat(remote_bin_path, "remote/bin/", PATH_MAX); diff --git a/tizen/src/util/osutil-win32.c b/tizen/src/util/osutil-win32.c index 96e5cc4b5e..cbcf18b6df 100644 --- a/tizen/src/util/osutil-win32.c +++ b/tizen/src/util/osutil-win32.c @@ -145,8 +145,9 @@ void remove_vm_lock_os(void) void set_bin_path_os(char const *const exec_argv) { - gchar link_path[PATH_MAX] = { 0, }; - gchar *file_name = NULL; + char link_path[PATH_MAX] = { 0, }; + char bin_path[PATH_MAX] = { 0, }; + char *file_name = NULL; if (!GetModuleFileName(NULL, link_path, PATH_MAX)) { return; @@ -154,8 +155,9 @@ 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); + + set_variable(KEYWORD_BIN_PATH, bin_path, true); } int get_number_of_processors(void) -- 2.34.1