From ec51d6988ef4857d96016245cb10f89a5dbe84b9 Mon Sep 17 00:00:00 2001 From: "giwoong.kim" Date: Wed, 9 May 2012 16:57:17 +0900 Subject: [PATCH] [Title] convert sprintf to snprintf & update err table [Type] [Module] Emulator [Priority] [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- oslib-posix.c | 10 +++++++++- oslib-win32.c | 11 +++++++++-- tizen/src/emulator.c | 1 + tizen/src/maru_err_table.c | 22 ++++++++++++++++------ tizen/src/maru_err_table.h | 1 + tizen/src/skin/maruskin_client.c | 31 ++++++++++++++++++++++++++++--- tizen/src/skin/maruskin_client.h | 2 +- 7 files changed, 65 insertions(+), 13 deletions(-) diff --git a/oslib-posix.c b/oslib-posix.c index 1f3b0d1..bef0be1 100644 --- a/oslib-posix.c +++ b/oslib-posix.c @@ -74,7 +74,15 @@ void *qemu_oom_check(void *ptr) #ifdef CONFIG_MARU char _msg[] = "Failed to allocate memory in qemu."; char cmd[JAVA_MAX_COMMAND_LENGTH] = { 0, }; - sprintf(cmd, "%s %s %s %s=\"%s\"", JAVA_EXEFILE_PATH, JAVA_EXEOPTION, JAR_SKINFILE_PATH, "simple.msg", _msg); + + int len = strlen(JAVA_EXEFILE_PATH) + strlen(JAVA_EXEOPTION) + strlen(JAR_SKINFILE_PATH) + + strlen(JAVA_SIMPLEMODE_OPTION) + strlen(_msg) + 7; + if (len > JAVA_MAX_COMMAND_LENGTH) { + len = JAVA_MAX_COMMAND_LENGTH; + } + + snprintf(cmd, len, "%s %s %s %s=\"%s\"", + JAVA_EXEFILE_PATH, JAVA_EXEOPTION, JAR_SKINFILE_PATH, JAVA_SIMPLEMODE_OPTION, _msg); int ret = system(cmd); #endif diff --git a/oslib-win32.c b/oslib-win32.c index 1f6d853..30ce4c9 100644 --- a/oslib-win32.c +++ b/oslib-win32.c @@ -43,11 +43,18 @@ void *qemu_oom_check(void *ptr) #ifdef CONFIG_MARU char _msg[] = "Failed to allocate memory in qemu."; char cmd[JAVA_MAX_COMMAND_LENGTH] = { 0, }; - sprintf(cmd, "%s %s %s %s=\"%s\"", JAVA_EXEFILE_PATH, JAVA_EXEOPTION, JAR_SKINFILE_PATH, "simple.msg", _msg); + + int len = strlen(JAVA_EXEFILE_PATH) + strlen(JAVA_EXEOPTION) + strlen(JAR_SKINFILE_PATH) + + strlen(JAVA_SIMPLEMODE_OPTION) + strlen(_msg) + 7; + if (len > JAVA_MAX_COMMAND_LENGTH) { + len = JAVA_MAX_COMMAND_LENGTH; + } + + snprintf(cmd, len, "%s %s %s %s=\"%s\"", + JAVA_EXEFILE_PATH, JAVA_EXEOPTION, JAR_SKINFILE_PATH, JAVA_SIMPLEMODE_OPTION, _msg); int ret = WinExec(cmd, SW_SHOW); #endif - abort(); } return ptr; diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index 9c15f4f..e4b00e7 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -96,6 +96,7 @@ static void construct_main_window(int skin_argc, char* skin_argv[], int qemu_arg if (get_emul_skin_enable() == 1) { //this line is check for debugging, etc.. if ( 0 > start_skin_client(skin_argc, skin_argv) ) { + maru_register_exit_msg(MARU_EXIT_SKIN_SERVER_FAILED, NULL); exit( -1 ); } } diff --git a/tizen/src/maru_err_table.c b/tizen/src/maru_err_table.c index 2cdee54..66c9d89 100644 --- a/tizen/src/maru_err_table.c +++ b/tizen/src/maru_err_table.c @@ -39,6 +39,7 @@ static char _maru_string_table[][JAVA_MAX_COMMAND_LENGTH] = { /* 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 + /* 4 */ "Skin process cannot be initialized. Skin server is not ready.", /* add here.. */ "" //MARU_EXIT_NORMAL }; @@ -58,13 +59,22 @@ void maru_register_exit_msg(int maru_exit_index, char* additional_msg) maru_exit_status = maru_exit_index; if (maru_exit_status != MARU_EXIT_UNKNOWN) { - len = strlen(_maru_string_table[maru_exit_status]) + strlen(additional_msg) + 1; - if (len >= JAVA_MAX_COMMAND_LENGTH) { - len = JAVA_MAX_COMMAND_LENGTH; - } + if (additional_msg != NULL) { + len = strlen(_maru_string_table[maru_exit_status]) + strlen(additional_msg) + 1; + if (len > JAVA_MAX_COMMAND_LENGTH) { + len = JAVA_MAX_COMMAND_LENGTH; + } - snprintf(maru_exit_msg, len, "%s%s", _maru_string_table[maru_exit_status], additional_msg); - } else { + snprintf(maru_exit_msg, len, "%s%s", _maru_string_table[maru_exit_status], additional_msg); + } else { + len = strlen(_maru_string_table[maru_exit_status]) + 1; + if (len > JAVA_MAX_COMMAND_LENGTH) { + len = JAVA_MAX_COMMAND_LENGTH; + } + + snprintf(maru_exit_msg, len, "%s", _maru_string_table[maru_exit_status]); + } + } else if (additional_msg != NULL) { len = strlen(additional_msg); if (len >= JAVA_MAX_COMMAND_LENGTH) { additional_msg[JAVA_MAX_COMMAND_LENGTH - 1] = '\0'; diff --git a/tizen/src/maru_err_table.h b/tizen/src/maru_err_table.h index 5525445..3a25de6 100644 --- a/tizen/src/maru_err_table.h +++ b/tizen/src/maru_err_table.h @@ -41,6 +41,7 @@ enum { //This enum must match the table definition /* 1 */ MARU_EXIT_MEMORY_EXCEPTION, /* 2 */ MARU_EXIT_KERNEL_FILE_EXCEPTION, /* 3 */ MARU_EXIT_BIOS_FILE_EXCEPTION, + /* 4 */ MARU_EXIT_SKIN_SERVER_FAILED, /* add here.. */ MARU_EXIT_NORMAL }; diff --git a/tizen/src/skin/maruskin_client.c b/tizen/src/skin/maruskin_client.c index 101822e..ac6ee8d 100644 --- a/tizen/src/skin/maruskin_client.c +++ b/tizen/src/skin/maruskin_client.c @@ -80,7 +80,24 @@ static void* run_skin_client(void* arg) char* vm_path = tizen_target_path; //INFO( "vm_path:%s\n", vm_path ); - sprintf( cmd, "%s %s %s %s=\"%d\" %s=\"%d\" %s=\"%s\" %s=\"%d\" %s", JAVA_EXEFILE_PATH, JAVA_EXEOPTION, JAR_SKINFILE_PATH, + char buf_skin_server_port[16]; + char buf_uid[16]; + char buf_tizen_base_port[16]; + sprintf(buf_skin_server_port, "%d", skin_server_port); + sprintf(buf_uid, "%d", uid); + sprintf(buf_tizen_base_port, "%d", tizen_base_port); + + int len = strlen(JAVA_EXEFILE_PATH) + strlen(JAVA_EXEOPTION) + strlen(JAR_SKINFILE_PATH) + + strlen(OPT_SVR_PORT) + strlen(buf_skin_server_port) + strlen(OPT_UID) + strlen(buf_uid) + + strlen(OPT_VM_PATH) + strlen(vm_path) + strlen(OPT_NET_BASE_PORT) + strlen(buf_tizen_base_port) + + strlen(argv) + 20; + if (len > JAVA_MAX_COMMAND_LENGTH) { + INFO("swt command length is too long! (%d)\n", len); + len = JAVA_MAX_COMMAND_LENGTH; + } + + snprintf( cmd, len, "%s %s %s %s=\"%d\" %s=\"%d\" %s=\"%s\" %s=\"%d\" %s", + JAVA_EXEFILE_PATH, JAVA_EXEOPTION, JAR_SKINFILE_PATH, OPT_SVR_PORT, skin_server_port, OPT_UID, uid, OPT_VM_PATH, vm_path, @@ -104,7 +121,9 @@ static void* run_skin_client(void* arg) &sti, &pi)) { - ERR("Unable to generate process!error %u\n", GetLastError()); + ERR("Unable to generate process! error %u\n", GetLastError()); + maru_register_exit_msg(MARU_EXIT_UNKNOWN, + "CreateProcess function failed. Unable to generate process."); exit(1); } @@ -220,7 +239,13 @@ int start_simple_client(char* msg) { INFO("run simple client\n"); - sprintf(cmd, "%s %s %s %s=\"%s\"", JAVA_EXEFILE_PATH, JAVA_EXEOPTION, JAR_SKINFILE_PATH, "simple.msg", msg); + int len = strlen(JAVA_EXEFILE_PATH) + strlen(JAVA_EXEOPTION) + strlen(JAR_SKINFILE_PATH) + + strlen(JAVA_SIMPLEMODE_OPTION) + strlen(msg) + 7; + if (len > JAVA_MAX_COMMAND_LENGTH) { + len = JAVA_MAX_COMMAND_LENGTH; + } + + snprintf(cmd, len, "%s %s %s %s=\"%s\"", JAVA_EXEFILE_PATH, JAVA_EXEOPTION, JAR_SKINFILE_PATH, JAVA_SIMPLEMODE_OPTION, msg); INFO("command for swt : %s\n", cmd); #ifdef __WIN32 diff --git a/tizen/src/skin/maruskin_client.h b/tizen/src/skin/maruskin_client.h index fb3621c..4ebb900 100644 --- a/tizen/src/skin/maruskin_client.h +++ b/tizen/src/skin/maruskin_client.h @@ -35,10 +35,10 @@ #define JAR_SKINFILE_PATH "emulator-skin.jar" #define JAVA_EXEFILE_PATH "java" #define JAVA_EXEOPTION "-jar" +#define JAVA_SIMPLEMODE_OPTION "simple.msg" int start_skin_client(int argc, char* argv[]); int start_simple_client(char* msg); - #endif /* MARUSKIN_CLIENT_H_ */ -- 2.7.4