emulator: clean-up sources and headers 95/24295/6
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 10 Jul 2014 06:06:16 +0000 (15:06 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 10 Jul 2014 06:53:26 +0000 (15:53 +0900)
emulator.*: remove unnecessary "DEFINE".
new_debug_ch.*: use GLIB functions.
osutil*: fix redundant stack usage.

Change-Id: I2f0d53342e2cb96ec136e89f3637e4d50dbabf03
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
include/qemu-common.h
tizen/src/display/maru_shm.c
tizen/src/emulator.c
tizen/src/emulator.h
tizen/src/skin/maruskin_operation.c
tizen/src/util/new_debug_ch.c
tizen/src/util/new_debug_ch.h
tizen/src/util/osutil-darwin.c
tizen/src/util/osutil-linux.c
tizen/src/util/osutil-win32.c
tizen/src/util/osutil.h

index a96b89c33e93edf7f855747d6352ad8c5aa0a8f2..8ddb0cb669458114c9c301323d68ccef8c0f0e65 100644 (file)
@@ -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);
index 57eecfa58f723be075c3178245264146a7f7501f..77a9cbae170ab0c5ff2e95367f7816e84e86ab1f 100644 (file)
@@ -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);
 
index 76be82f6986ff2cf1f8fecbaa4fd6b3ac996f6c5..c115991df457b4a6bb92773c89c8b62acc276db5 100644 (file)
@@ -56,6 +56,7 @@
 #endif
 
 #ifdef CONFIG_DARWIN
+#include <libgen.h>
 #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);
index 0403a2257312b51227978df6d67ba6e4dafaa322..7198e4cf7d37f7319c6e079d88b9bda2b2ec82c5 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2011, 2012 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: 
+ * Contact:
  * SeokYeon Hwang <syeon.hwang@samsung.com>
  * MunKyu Im <munkyu.im@samsung.com>
  * GiWoong Kim <giwoong.kim@samsung.com>
 #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[];
 
index bca9fd08ca111c21187a7a45db7bf825d6c6c2a0..383343a61afa0e957080881fcc3f88d3ce574ac3 100644 (file)
@@ -52,8 +52,6 @@
 #include "ecs/ecs.h"
 
 #ifdef CONFIG_HAX
-#include "guest_debug.h"
-
 #include "target-i386/hax-i386.h"
 #endif
 
index 89c0782f358a812a1f780dec37f528fd4d8c1868..e27abdef08b985e9a8e9c60338fac9e96f17819a 100644 (file)
  *
  */
 
-#include <stdio.h>
-
 #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);
index 72238d3b14cb057a762bac8ccb8da4abea02c671..a0e0e2340dcb1f6e2118b5006ce8108646288cd6 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <sys/types.h>
 
+#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))
index 74a418234a0efcd449314a7d0ef181f768f90278..a4f483cda36d32284aeeb1ea1099529102c8994d 100644 (file)
   @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 <string.h>
+#include <unistd.h>
 #include <sys/shm.h>
 #include <sys/sysctl.h>
 #include <SystemConfiguration/SystemConfiguration.h>
@@ -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 {
index d9b3032d6be165672ebbdb0ed7c2635897bae507..866355ba23b0c8e7ec14739bdb2fe86a478bda89 100644 (file)
@@ -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;
 
index 33661e8f1127f4bdada4b1b87c1294001964145e..fc2349a913710143e646a41d77c5bc8f7ceb8b84 100644 (file)
  */
 
 #include <png.h>
-#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);
index ffa0596c5daeeff4afb230ef961db4fa32353adb..566f4a303426317d45b8f98b53225e3c069c2db9 100644 (file)
@@ -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