[Title] Remove a few compile warning and create a function
authorKitae Kim <kt920.kim@samsung.com>
Mon, 18 Jun 2012 04:57:49 +0000 (13:57 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Mon, 18 Jun 2012 04:57:49 +0000 (13:57 +0900)
        to convert from relative path to absolute path.
[Type]
[Module] emulator / error handling
[Priority] normal
[CQ#]
[Redmine#]
[Problem] Error messages for bios and kernel file need to display clearly.
          This is the same issue as commit 6780773.
[Cause]
[Solution]
[TestCase]

blockdev.c
hw/pc.c
tizen/src/guest_server.c
tizen/src/hw/maru_codec.h
tizen/src/maru_err_table.c
tizen/src/maru_err_table.h

index 7b26644571f6f6a0cb432dea5ed274aab9e32261..98184b390076205bd4e840be7f924b44633f9f08 100644 (file)
@@ -218,6 +218,7 @@ static int parse_block_error_action(const char *buf, int is_read)
 
 #ifdef CONFIG_MARU
 extern int start_simple_client(char* msg);
+extern char* maru_convert_path(char* msg, const char *path);
 #endif
 
 DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
@@ -524,64 +525,13 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
                      file, strerror(-ret));
 
 #ifdef CONFIG_MARU
-        const char _msg[] = "Failed to load disk file from the following path. Check if the file was corrupted or missing.\n\n";
-        char* current_path = NULL;
-        char* err_msg = NULL;
-#ifdef _WIN32
-        char* dos_err_msg = NULL;
-#endif
-        int total_len = 0;
-        int msg_len = 0;
-        int cur_path_len = 0;
-        int disk_path_len = 0;
-        int res = -1;
-
-        res = (int)g_path_is_absolute((gchar*)file);
-        disk_path_len = (strlen(file) + 1);
-        msg_len = strlen(_msg) + 1;
-
-        if (!res) {
-            current_path = (char*)g_get_current_dir();
-            cur_path_len = strlen(current_path) + strlen("/") + 1;
-            total_len += cur_path_len;
-        }
-        total_len += (disk_path_len + msg_len);
-
-        err_msg = g_malloc0(total_len * sizeof(char));
-        if (!err_msg) {
-            printf("failed to allocate memory\n");
-        }
-
-        snprintf(err_msg, msg_len, "%s", _msg);
-        total_len = msg_len - 1;
-        if (!res) {
-            snprintf(err_msg + total_len, cur_path_len, "%s%s", current_path, "/");
-            total_len += (cur_path_len - 1);
-        }
-        snprintf(err_msg + total_len, disk_path_len, "%s", file);
-
-#ifdef _WIN32
-        {
-            int i;
-
-            dos_err_msg = strdup(err_msg);
-            if (!dos_err_msg) {
-                printf("failed to duplicate an error message from %p\n", err_msg);
-            }
-
-            for (i = (total_len - 1); dos_err_msg[i]; i++) {
-                if (dos_err_msg[i] == '/') {
-                    dos_err_msg[i] = '\\';
-                }
-            }
-            strncpy(err_msg, dos_err_msg, strlen(dos_err_msg));
-            free(dos_err_msg);
-        }
-#endif
+        const char _msg[] = "Failed to load disk file from the following path. Check if the file is corrupted or missing.\n\n";
+           char* err_msg = NULL;
+        err_msg = maru_convert_path((char*)_msg, file);
         start_simple_client(err_msg);
-
-        g_free(current_path);
-        g_free(err_msg);
+        if (err_msg) {
+            g_free(err_msg);
+        }
 #endif
 
         goto err;
diff --git a/hw/pc.c b/hw/pc.c
index 4cca3283b0e1ce3db5bdd284177c861f9899b23c..ca468c7a8672098f9de41c138f7514d7ff7d88e0 100644 (file)
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -689,16 +689,13 @@ static void load_linux(void *fw_cfg,
                kernel_filename, strerror(errno));
 
 #ifdef CONFIG_MARU
-    char* current_path = (char *)g_get_current_dir();
-    int len = strlen(current_path) + strlen(kernel_filename) + 2;
-
-    char* error_msg = g_malloc0(len * sizeof(char));
-    snprintf(error_msg, len, "%s/%s", current_path, kernel_filename);
+       char *error_msg = NULL;
 
+       error_msg = maru_convert_path(error_msg, kernel_filename);
     maru_register_exit_msg(MARU_EXIT_KERNEL_FILE_EXCEPTION, error_msg);
-
-    g_free(current_path);
-    g_free(error_msg);
+       if (error_msg) {
+           g_free(error_msg);
+       }
 #endif
 
        exit(1);
@@ -1048,18 +1045,26 @@ void pc_memory_init(MemoryRegion *system_memory,
         fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name);
 
 #ifdef CONFIG_MARU
-        char* current_path = (char *)g_get_current_dir();
-        const char* _path = qemu_get_data_dir();
-
-        int len = strlen(current_path) + strlen(_path) + strlen(bios_name) + 3;
-
-        char* error_msg = g_malloc0(len * sizeof(char));
-        snprintf(error_msg, len, "%s/%s/%s", current_path, _path, bios_name);
-
-        maru_register_exit_msg(MARU_EXIT_BIOS_FILE_EXCEPTION, error_msg);
-
-        g_free(current_path);
-        g_free(error_msg);
+        char *error_msg = NULL;
+               const char *path = qemu_get_data_dir();
+               char *bios_path = NULL;
+               int bios_len = 0;
+
+               bios_len = strlen(path) + strlen("/") + strlen(bios_name) + 1;
+               bios_path = g_malloc(bios_len * sizeof(char));
+        if (!bios_path) {
+            fprintf(stderr, "qemu: failed to allocate memory\n");
+               }
+        snprintf(bios_path, bios_len, "%s/%s", path, bios_name);
+        error_msg = maru_convert_path(error_msg, bios_path);
+           maru_register_exit_msg(MARU_EXIT_BIOS_FILE_EXCEPTION, error_msg);
+
+        if (bios_path) {
+            g_free(bios_path);
+        }
+        if (error_msg) {
+            g_free(error_msg);
+        }
 #endif
 
         exit(1);
index 79b7958ea230794be68b7382c91b9167c90b0fa9..634070653749b5ca4dc452983fb405982f4ee7ed 100644 (file)
@@ -29,6 +29,7 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdint.h>
index b94e242325b044f0cd9be75274c8c97ac3125976..d1a1dec71af95466fe154f7ceb3e7608ee7842d6 100644 (file)
@@ -132,6 +132,8 @@ void qemu_parser_init (SVCodecState *s, int ctxIndex);
 
 void qemu_restore_context (AVCodecContext *dst, AVCodecContext *src);
 
+void qemu_codec_close (SVCodecState *s, uint32_t value);
+
 void qemu_get_codec_ver (SVCodecState *s, int ctxIndex);
 /*
  *  FFMPEG APIs
index dd7715f4a156fa8f25fe33e444f4e09646d92e15..b2d9d7ec849a3f76e579d59d4ec15c4a692e2bde 100644 (file)
@@ -30,7 +30,9 @@
 
 #include "maru_err_table.h"
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include <glib.h>
 
 #ifdef _WIN32
 #include <windows.h>
@@ -40,8 +42,8 @@
 static char _maru_string_table[][JAVA_MAX_COMMAND_LENGTH] = {
     /* 0 */ "", //MARU_EXIT_UNKNOWN
     /* 1 */ "Failed to allocate memory in qemu.", //MARU_EXIT_MEMORY_EXCEPTION
-    /* 2 */ "Fail to load kernel file. Check if the file is corrupted or missing from the following path.\n\n", //MARU_EXIT_KERNEL_FILE_EXCEPTION
-    /* 3 */ "Fail to load bios file. Check if the file is corrupted or missing from the following path.\n\n", //MARU_EXIT_BIOS_FILE_EXCEPTION
+    /* 2 */ "Failed to load a kernel file the following path. Check if the file is corrupted or missing.\n\n", //MARU_EXIT_KERNEL_FILE_EXCEPTION
+    /* 3 */ "Failed to load a bios file the following path. Check if the file is corrupted or missing.\n\n", //MARU_EXIT_BIOS_FILE_EXCEPTION
     /* 4 */ "Skin process cannot be initialized. Skin server is not ready.",
     /* add here.. */
     "" //MARU_EXIT_NORMAL
@@ -91,11 +93,89 @@ void maru_register_exit_msg(int maru_exit_index, char* additional_msg)
 void maru_atexit(void)
 {
     if (maru_exit_status != MARU_EXIT_NORMAL || strlen(maru_exit_msg) != 0) {
-       maru_dump_backtrace(NULL, 0);
+        maru_dump_backtrace(NULL, 0);
         start_simple_client(maru_exit_msg);
     }
 }
 
+char* maru_convert_path(char *msg, const char *path)
+{
+       char* current_path = NULL;
+       char* err_msg = NULL;
+#ifdef _WIN32
+       char* dos_err_msg = NULL;
+#endif
+       int total_len = 0;
+       int msg_len = 0;
+       int cur_path_len = 0;
+       int path_len = 0;
+       int res = -1;
+
+       res = (int)g_path_is_absolute(path);
+       path_len = (strlen(path) + 1);
+       if (msg) {
+               msg_len = strlen(msg) + 1;
+       }
+
+       if (!res) {
+               current_path = (char*)g_get_current_dir();
+               cur_path_len = strlen(current_path) + strlen("/") + 1;
+               total_len += cur_path_len;
+       }
+       total_len += (path_len + msg_len);
+
+       err_msg = g_malloc0(total_len * sizeof(char));
+       if (!err_msg) {
+               fprintf(stderr, "failed to allocate memory\n");
+               if (current_path) {
+                       g_free(current_path);
+               }
+               return NULL;
+       }
+
+       if (msg) {
+               snprintf(err_msg, msg_len, "%s", msg);
+               total_len = msg_len - 1;
+       } else {
+               total_len = 0;
+       }
+
+       if (!res) {
+               snprintf(err_msg + total_len, cur_path_len, "%s%s", current_path, "/");
+               total_len += (cur_path_len - 1);
+       }
+       snprintf(err_msg + total_len, path_len, "%s", path);
+
+#ifdef _WIN32
+       {
+               int i;
+
+               dos_err_msg = strdup(err_msg);
+               if (!dos_err_msg) {
+                       printf(stderr, "failed to duplicate an error message from %p\n", err_msg);
+                       if (current_path) {
+                               g_free(current_path);
+                       }
+                       g_free(err_msg);
+                       return NULL;
+               }
+
+               for (i = (total_len - 1); dos_err_msg[i]; i++) {
+                       if (dos_err_msg[i] == '/') {
+                               dos_err_msg[i] = '\\';
+                       }
+               }
+               strncpy(err_msg, dos_err_msg, strlen(dos_err_msg));
+               free(dos_err_msg);
+       }
+#endif
+       if (current_path) {
+               g_free(current_path);
+       }
+
+       return err_msg;
+}
+
 // for pirnt 'backtrace'
 #ifdef _WIN32
 struct frame_layout {
index f26593478564d24f384f9fe15e2779dd02eb6367..491bd015844159cb5be39df44c587ce1a6b3b722 100644 (file)
@@ -49,6 +49,7 @@ enum { //This enum must match the table definition
 
 void maru_register_exit_msg(int maru_exit_status, char* additional_msg);
 void maru_atexit(void);
+char* maru_convert_path(char *msg, const char *path);
 void maru_dump_backtrace(void* ptr, int depth);
 
 #endif /* __EMUL_ERR_TABLE_H__ */