From: SeokYeon Hwang Date: Thu, 10 Jul 2014 06:06:16 +0000 (+0900) Subject: emulator: clean-up sources and headers X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~228^2^2~75^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=745233f7322b485e0686fd663c0a4a1c97289fd2;p=sdk%2Femulator%2Fqemu.git emulator: clean-up sources and headers emulator.*: remove unnecessary "DEFINE". new_debug_ch.*: use GLIB functions. osutil*: fix redundant stack usage. Change-Id: I2f0d53342e2cb96ec136e89f3637e4d50dbabf03 Signed-off-by: SeokYeon Hwang --- diff --git a/include/qemu-common.h b/include/qemu-common.h index a96b89c33e..8ddb0cb669 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -475,7 +475,7 @@ int parse_debug_env(const char *name, int max, int initial); const char *qemu_ether_ntoa(const MACAddr *mac); #if defined(CONFIG_MARU) && defined(CONFIG_WIN32) -#include "../tizen/src/maru_common.h" +#include "../tizen/src/emulator_common.h" int is_wow64(void); bool get_java_path(char **java_path); diff --git a/tizen/src/display/maru_shm.c b/tizen/src/display/maru_shm.c index 57eecfa58f..77a9cbae17 100644 --- a/tizen/src/display/maru_shm.c +++ b/tizen/src/display/maru_shm.c @@ -36,8 +36,8 @@ #include "emul_state.h" #include "hw/pci/maru_brightness.h" #include "skin/maruskin_server.h" +#include "util/maru_err_table.h" #include "debug_ch.h" -#include "maru_err_table.h" MULTI_DEBUG_CHANNEL(tizen, maru_shm); diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index 76be82f698..c115991df4 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -56,6 +56,7 @@ #endif #ifdef CONFIG_DARWIN +#include #include "ns_event.h" int thread_running = 1; /* Check if we need exit main */ #endif @@ -181,8 +182,6 @@ static Notifier emulator_exit = { .notify = emulator_notify_exit }; static void print_system_info(void) { -#define DIV 1024 - LOG_INFO("* Board name : %s\n", build_version); LOG_INFO("* Package %s\n", pkginfo_version); LOG_INFO("* Package %s\n", pkginfo_maintainer); diff --git a/tizen/src/emulator.h b/tizen/src/emulator.h index 0403a22573..7198e4cf7d 100644 --- a/tizen/src/emulator.h +++ b/tizen/src/emulator.h @@ -3,7 +3,7 @@ * * Copyright (C) 2011, 2012 Samsung Electronics Co., Ltd. All rights reserved. * - * Contact: + * Contact: * SeokYeon Hwang * MunKyu Im * GiWoong Kim @@ -42,10 +42,6 @@ #include "qemu/option.h" #include "sysemu/sysemu.h" -#define MAXLEN 512 -#define MAXPACKETLEN 60 -//#define SHMKEY 26099 - extern gchar bin_path[]; extern gchar log_path[]; diff --git a/tizen/src/skin/maruskin_operation.c b/tizen/src/skin/maruskin_operation.c index bca9fd08ca..383343a61a 100644 --- a/tizen/src/skin/maruskin_operation.c +++ b/tizen/src/skin/maruskin_operation.c @@ -52,8 +52,6 @@ #include "ecs/ecs.h" #ifdef CONFIG_HAX -#include "guest_debug.h" - #include "target-i386/hax-i386.h" #endif diff --git a/tizen/src/util/new_debug_ch.c b/tizen/src/util/new_debug_ch.c index 89c0782f35..e27abdef08 100644 --- a/tizen/src/util/new_debug_ch.c +++ b/tizen/src/util/new_debug_ch.c @@ -30,15 +30,14 @@ * */ -#include - #include "qemu-common.h" #include "emulator.h" #include "util/new_debug_ch.h" #include "util/osutil.h" -static char debugchfile[512] = {0, }; +#define MAX_FILE_LEN 512 +static char debugchfile[MAX_FILE_LEN] = {0, }; static int fd = STDOUT_FILENO; static const char * const debug_classes[] = @@ -58,7 +57,7 @@ static int cmp_name(const void *p1, const void *p2) const char *name = p1; const struct _debug_channel *chan = p2; - return strcmp(name, chan->name); + return g_strcmp0(name, chan->name); } /* get the flags to use for a given channel, possibly setting them too in case of lazy init */ @@ -104,7 +103,7 @@ static void add_option(const char *name, unsigned char set, unsigned char clear) while (min <= max) { pos = (min + max) / 2; - res = strcmp(name, debug_options[pos].name); + res = g_strcmp0(name, debug_options[pos].name); if (!res) { debug_options[pos].flags = (debug_options[pos].flags & ~clear) | set; return; @@ -127,7 +126,7 @@ static void add_option(const char *name, unsigned char set, unsigned char clear) (nb_debug_options - pos) * sizeof(debug_options[0])); } - strcpy(debug_options[pos].name, name); + g_strlcpy(debug_options[pos].name, name, MAX_NAME_LEN); debug_options[pos].flags = (default_flags & ~clear) | set; nb_debug_options++; } @@ -138,7 +137,7 @@ static void parse_options(const char *str) char *opt, *next, *options; unsigned int i; - if (!(options = strdup(str))) { + if (!(options = g_strdup(str))) { return; } @@ -227,10 +226,10 @@ static void debug_init(void) } if (0 == strlen(bin_path)) { - strcpy(debugchfile, "DEBUGCH"); + g_strlcpy(debugchfile, "DEBUGCH", MAX_FILE_LEN); } else { - strcat(debugchfile, bin_path); - strcat(debugchfile, "DEBUGCH"); + g_strlcat(debugchfile, bin_path, MAX_FILE_LEN); + g_strlcat(debugchfile, "DEBUGCH", MAX_FILE_LEN); } fp = fopen(debugchfile, "r"); @@ -261,7 +260,7 @@ static void debug_init(void) } if (debug != NULL) { - if (!strcmp(debug, "help")) { + if (!g_strcmp0(debug, "help")) { debug_usage(); } parse_options(debug); @@ -295,11 +294,11 @@ int dbg_log(enum _debug_class cls, struct _debug_channel *channel, return -1; } - ret = snprintf(buf_msg, sizeof(buf_msg), "%s [%s:%s] ", + ret = g_snprintf(buf_msg, sizeof(buf_msg), "%s [%s:%s] ", get_timeofday(), debug_classes[cls], channel->name); va_start(valist, format); - ret += vsnprintf(buf_msg + ret, sizeof(buf_msg) - ret, format, valist); + ret += g_vsnprintf(buf_msg + ret, sizeof(buf_msg) - ret, format, valist); va_end(valist); ret_write = qemu_write_full(fd, buf_msg, ret); diff --git a/tizen/src/util/new_debug_ch.h b/tizen/src/util/new_debug_ch.h index 72238d3b14..a0e0e2340d 100644 --- a/tizen/src/util/new_debug_ch.h +++ b/tizen/src/util/new_debug_ch.h @@ -35,6 +35,7 @@ #include +#define MAX_NAME_LEN 15 // #define NO_DEBUG #ifdef __cplusplus @@ -56,11 +57,10 @@ enum _debug_class struct _debug_channel { unsigned char flags; - char name[15]; + char name[MAX_NAME_LEN]; }; #ifndef NO_DEBUG -#define MSGSIZE_MAX 2048 #define __GET_DEBUGGING_SEVERE(dbch) ((dbch)->flags & (1 << __DBCL_SEVERE)) #define __GET_DEBUGGING_WARNING(dbch) ((dbch)->flags & (1 << __DBCL_WARNING)) #define __GET_DEBUGGING_INFO(dbch) ((dbch)->flags & (1 << __DBCL_INFO)) diff --git a/tizen/src/util/osutil-darwin.c b/tizen/src/util/osutil-darwin.c index 74a418234a..a4f483cda3 100644 --- a/tizen/src/util/osutil-darwin.c +++ b/tizen/src/util/osutil-darwin.c @@ -34,9 +34,10 @@ @brief Collection of utilities for darwin */ -#include "maru_common.h" +#include "emulator_common.h" #include "osutil.h" #include "emulator.h" +#include "emul_state.h" #include "debug_ch.h" #include "maru_err_table.h" #include "sdb.h" @@ -46,6 +47,7 @@ #endif #include +#include #include #include #include @@ -93,7 +95,7 @@ void make_vm_lock_os(void) char *shared_memory; int base_port; base_port = get_emul_vm_base_port(); - g_shmid = shmget((key_t)base_port, MAXLEN, 0666|IPC_CREAT); + g_shmid = shmget((key_t)base_port, getpagesize(), 0666|IPC_CREAT); if (g_shmid == -1) { ERR("shmget failed\n"); perror("osutil-darwin: "); @@ -178,7 +180,7 @@ void print_system_info_os(void) /* uname */ INFO("* Host machine uname :\n"); - char uname_cmd[MAXLEN] = "uname -a"; + char const *const uname_cmd = "uname -a"; if(system(uname_cmd) < 0) { INFO("system function command '%s' \ returns error !", uname_cmd); @@ -227,7 +229,7 @@ void print_system_info_os(void) /* java version */ INFO("* Java version :\n"); - char lspci_cmd[MAXLEN] = "java -version"; + char const *const lspci_cmd = "java -version"; fflush(stdout); if(system(lspci_cmd) < 0) { @@ -251,16 +253,16 @@ char *get_timeofday(void) static int get_auto_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy) { - char type[MAXLEN]; - char proxy[MAXLEN]; - char line[MAXLEN]; + char type[DEFAULTBUFLEN]; + char proxy[DEFAULTBUFLEN]; + char line[DEFAULTBUFLEN]; FILE *fp_pacfile; char *p = NULL; CFStringRef pacURL = (CFStringRef)CFDictionaryGetValue(proxySettings, kSCPropNetProxiesProxyAutoConfigURLString); if (pacURL) { - char url[MAXLEN] = {}; + char url[DEFAULTBUFLEN] = {}; CFStringGetCString(pacURL, url, sizeof url, kCFStringEncodingASCII); INFO("pac address: %s\n", (char*)url); download_url(url); @@ -268,7 +270,7 @@ static int get_auto_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, fp_pacfile = fopen(pac_tempfile, "r"); if(fp_pacfile != NULL) { - while(fgets(line, MAXLEN, fp_pacfile) != NULL) { + while(fgets(line, DEFAULTBUFLEN, fp_pacfile) != NULL) { if( (strstr(line, "return") != NULL) && (strstr(line, "if") == NULL)) { INFO("line found %s", line); sscanf(line, "%*[^\"]\"%s %s", type, proxy); @@ -326,7 +328,7 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPPort); port = cfnumber_to_int(proxyPort); // Save hostname & port - snprintf(http_proxy, MAXLEN, "%s:%d", hostname, port); + snprintf(http_proxy, DEFAULTBUFLEN, "%s:%d", hostname, port); free(hostname); } else { @@ -342,7 +344,7 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPSPort); port = cfnumber_to_int(proxyPort); // Save hostname & port - snprintf(https_proxy, MAXLEN, "%s:%d", hostname, port); + snprintf(https_proxy, DEFAULTBUFLEN, "%s:%d", hostname, port); free(hostname); } else { @@ -358,7 +360,7 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesFTPPort); port = cfnumber_to_int(proxyPort); // Save hostname & port - snprintf(ftp_proxy, MAXLEN, "%s:%d", hostname, port); + snprintf(ftp_proxy, DEFAULTBUFLEN, "%s:%d", hostname, port); free(hostname); } else { @@ -374,7 +376,7 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSPort); port = cfnumber_to_int(proxyPort); // Save hostname & port - snprintf(socks_proxy, MAXLEN, "%s:%d", hostname, port); + snprintf(socks_proxy, DEFAULTBUFLEN, "%s:%d", hostname, port); free(hostname); } else { diff --git a/tizen/src/util/osutil-linux.c b/tizen/src/util/osutil-linux.c index d9b3032d6b..866355ba23 100644 --- a/tizen/src/util/osutil-linux.c +++ b/tizen/src/util/osutil-linux.c @@ -127,7 +127,7 @@ void make_vm_lock_os(void) base_port = get_emul_vm_base_port(); - g_shmid = shmget((key_t)base_port, MAXLEN, 0666|IPC_CREAT); + g_shmid = shmget((key_t)base_port, getpagesize(), 0666|IPC_CREAT); if (g_shmid == -1) { ERR("shmget failed\n"); perror("osutil-linux: "); @@ -223,7 +223,7 @@ void print_system_info_os(void) /* get linux distribution information */ INFO("* Linux distribution infomation :\n"); - const gchar lsb_release_cmd[MAXLEN] = "lsb_release -d -r -c"; + char const *const lsb_release_cmd = "lsb_release -d -r -c"; gchar *buffer = NULL; gint buffer_size = strlen(lsb_release_cmd) + 1; @@ -239,7 +239,7 @@ void print_system_info_os(void) /* pci device description */ INFO("* Host PCI devices :\n"); - const gchar lspci_cmd[MAXLEN] = "lspci"; + char const *const lspci_cmd = "lspci"; buffer_size = strlen(lspci_cmd) + 1; buffer = g_malloc(buffer_size); @@ -269,25 +269,25 @@ char *get_timeofday(void) static void process_string(char *buf) { - char tmp_buf[MAXLEN]; + char tmp_buf[DEFAULTBUFLEN]; /* remove single quotes of strings gotten by gsettings */ if (gproxytool == GSETTINGS) { remove_string(buf, tmp_buf, "\'"); - memset(buf, 0, MAXLEN); + memset(buf, 0, DEFAULTBUFLEN); strncpy(buf, tmp_buf, strlen(tmp_buf)-1); } } static int get_auto_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy) { - char type[MAXLEN]; - char proxy[MAXLEN]; - char line[MAXLEN]; + char type[DEFAULTBUFLEN]; + char proxy[DEFAULTBUFLEN]; + char line[DEFAULTBUFLEN]; FILE *fp_pacfile; char *p = NULL; FILE *output; - char buf[MAXLEN]; + char buf[DEFAULTBUFLEN]; output = popen(gproxycmds[GNOME_PROXY_AUTOCONFIG_URL][gproxytool], "r"); if (fscanf(output, "%s", buf) > 0) { @@ -299,7 +299,7 @@ static int get_auto_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, pclose(output); fp_pacfile = fopen(pac_tempfile, "r"); if (fp_pacfile != NULL) { - while (fgets(line, MAXLEN, fp_pacfile) != NULL) { + while (fgets(line, DEFAULTBUFLEN, fp_pacfile) != NULL) { if ((strstr(line, "return") != NULL) && (strstr(line, "if") == NULL)) { INFO("line found %s", line); sscanf(line, "%*[^\"]\"%s %s", type, proxy); @@ -340,18 +340,18 @@ static int get_auto_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy) { - char buf[MAXLEN] = {0,}; + char buf[DEFAULTBUFLEN] = {0,}; char buf_port[MAXPORTLEN] = {0,}; - char buf_proxy[MAXLEN] = {0,}; + char buf_proxy[DEFAULTBUFLEN] = {0,}; char *buf_proxy_bak; char *proxy; FILE *output; - int MAXPROXYLEN = MAXLEN + MAXPORTLEN; + int MAXPROXYLEN = DEFAULTBUFLEN + MAXPORTLEN; output = popen(gproxycmds[GNOME_PROXY_HTTP_HOST][gproxytool], "r"); if(fscanf(output, "%s", buf) > 0) { process_string(buf); - snprintf(buf_proxy, MAXLEN, "%s", buf); + snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf); } pclose(output); @@ -361,7 +361,7 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char buf_proxy_bak = getenv("http_proxy"); INFO("http_proxy from env: %s\n", buf_proxy_bak); if(buf_proxy_bak != NULL) { - proxy = malloc(MAXLEN); + proxy = malloc(DEFAULTBUFLEN); remove_string(buf_proxy_bak, proxy, HTTP_PREFIX); strncpy(http_proxy, proxy, strlen(proxy)-1); INFO("final http_proxy value: %s\n", http_proxy); @@ -376,17 +376,17 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char } else { snprintf(http_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf_port); - memset(buf_proxy, 0, MAXLEN); + memset(buf_proxy, 0, DEFAULTBUFLEN); INFO("http_proxy: %s\n", http_proxy); } pclose(output); - memset(buf, 0, MAXLEN); + memset(buf, 0, DEFAULTBUFLEN); output = popen(gproxycmds[GNOME_PROXY_HTTPS_HOST][gproxytool], "r"); if(fscanf(output, "%s", buf) > 0) { process_string(buf); - snprintf(buf_proxy, MAXLEN, "%s", buf); + snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf); } pclose(output); @@ -395,14 +395,14 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char snprintf(https_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf); } pclose(output); - memset(buf, 0, MAXLEN); - memset(buf_proxy, 0, MAXLEN); + memset(buf, 0, DEFAULTBUFLEN); + memset(buf_proxy, 0, DEFAULTBUFLEN); INFO("https_proxy : %s\n", https_proxy); output = popen(gproxycmds[GNOME_PROXY_FTP_HOST][gproxytool], "r"); if(fscanf(output, "%s", buf) > 0) { process_string(buf); - snprintf(buf_proxy, MAXLEN, "%s", buf); + snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf); } pclose(output); @@ -411,14 +411,14 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char snprintf(ftp_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf); } pclose(output); - memset(buf, 0, MAXLEN); - memset(buf_proxy, 0, MAXLEN); + memset(buf, 0, DEFAULTBUFLEN); + memset(buf_proxy, 0, DEFAULTBUFLEN); INFO("ftp_proxy : %s\n", ftp_proxy); output = popen(gproxycmds[GNOME_PROXY_SOCKS_HOST][gproxytool], "r"); if(fscanf(output, "%s", buf) > 0) { process_string(buf); - snprintf(buf_proxy, MAXLEN, "%s", buf); + snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf); } pclose(output); @@ -433,7 +433,7 @@ static void get_proxy(char *http_proxy, char *https_proxy, char *ftp_proxy, char void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy) { - char buf[MAXLEN]; + char buf[DEFAULTBUFLEN]; FILE *output; int ret; diff --git a/tizen/src/util/osutil-win32.c b/tizen/src/util/osutil-win32.c index 33661e8f11..fc2349a913 100644 --- a/tizen/src/util/osutil-win32.c +++ b/tizen/src/util/osutil-win32.c @@ -35,9 +35,10 @@ */ #include -#include "maru_common.h" +#include "emulator_common.h" #include "osutil.h" #include "emulator.h" +#include "emul_state.h" #include "debug_ch.h" #include "maru_err_table.h" #include "sdb.h" @@ -225,9 +226,9 @@ char *get_timeofday(void) static int get_auto_proxy(BYTE *url, char *http_proxy, char *https_proxy, char *ftp_proxy, char *socks_proxy) { - char type[MAXLEN]; - char proxy[MAXLEN]; - char line[MAXLEN]; + char type[DEFAULTBUFLEN]; + char proxy[DEFAULTBUFLEN]; + char line[DEFAULTBUFLEN]; FILE *fp_pacfile; char *p = NULL; @@ -236,7 +237,7 @@ static int get_auto_proxy(BYTE *url, char *http_proxy, char *https_proxy, char * fp_pacfile = fopen(pactempfile, "r"); if (fp_pacfile != NULL) { - while(fgets(line, MAXLEN, fp_pacfile) != NULL) { + while(fgets(line, DEFAULTBUFLEN, fp_pacfile) != NULL) { if ( (strstr(line, "return") != NULL) && (strstr(line, "if") == NULL)) { INFO("line found %s", line); sscanf(line, "%*[^\"]\"%s %s", type, proxy); @@ -369,7 +370,7 @@ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, cha } INFO("proxy value: %s\n", (char *)proxyserver); - real_proxy = malloc(MAXLEN); + real_proxy = malloc(DEFAULTBUFLEN); if (real_proxy == NULL) { ERR("Failed to allocate a buffer\n"); free(proxyserver); diff --git a/tizen/src/util/osutil.h b/tizen/src/util/osutil.h index ffa0596c5d..566f4a3034 100644 --- a/tizen/src/util/osutil.h +++ b/tizen/src/util/osutil.h @@ -43,6 +43,7 @@ #define DIRECT "DIRECT" #define PROXY "PROXY" #define MAXPORTLEN 6 +#define DEFAULTBUFLEN 512 #define GNOME_PROXY_MODE 0 #define GNOME_PROXY_AUTOCONFIG_URL 1