From bea1b3576749c44eb94837f2a5b49e837d682a28 Mon Sep 17 00:00:00 2001 From: Kitae Kim Date: Mon, 18 Jun 2012 13:57:49 +0900 Subject: [PATCH] [Title] Remove a few compile warning and create a function 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 | 64 ++++------------------------ hw/pc.c | 45 +++++++++++--------- tizen/src/guest_server.c | 1 + tizen/src/hw/maru_codec.h | 2 + tizen/src/maru_err_table.c | 86 ++++++++++++++++++++++++++++++++++++-- tizen/src/maru_err_table.h | 1 + 6 files changed, 119 insertions(+), 80 deletions(-) diff --git a/blockdev.c b/blockdev.c index 7b26644571..98184b3900 100644 --- a/blockdev.c +++ b/blockdev.c @@ -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 4cca3283b0..ca468c7a86 100644 --- 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); diff --git a/tizen/src/guest_server.c b/tizen/src/guest_server.c index 79b7958ea2..6340706537 100644 --- a/tizen/src/guest_server.c +++ b/tizen/src/guest_server.c @@ -29,6 +29,7 @@ */ #include +#include #include #include #include diff --git a/tizen/src/hw/maru_codec.h b/tizen/src/hw/maru_codec.h index b94e242325..d1a1dec71a 100644 --- a/tizen/src/hw/maru_codec.h +++ b/tizen/src/hw/maru_codec.h @@ -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 diff --git a/tizen/src/maru_err_table.c b/tizen/src/maru_err_table.c index dd7715f4a1..b2d9d7ec84 100644 --- a/tizen/src/maru_err_table.c +++ b/tizen/src/maru_err_table.c @@ -30,7 +30,9 @@ #include "maru_err_table.h" #include +#include #include +#include #ifdef _WIN32 #include @@ -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 { diff --git a/tizen/src/maru_err_table.h b/tizen/src/maru_err_table.h index f265934785..491bd01584 100644 --- a/tizen/src/maru_err_table.h +++ b/tizen/src/maru_err_table.h @@ -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__ */ -- 2.34.1