From bc03868a55d081601f8bad2315ce8fe791b8dfc8 Mon Sep 17 00:00:00 2001 From: SeokYeon Hwang Date: Fri, 4 Jul 2014 19:08:42 +0900 Subject: [PATCH] emulator: some error reporting routine is refactored maru_register_exit_msg() can accept variable arguments. Remove maru_convert_path(), Add get_canonical_path(). Change-Id: I7975510cfb34a0bbb633df5a74ffce21922c0c92 Signed-off-by: SeokYeon Hwang Signed-off-by: Sooyoung Ha --- blockdev.c | 22 ++-- hw/9pfs/virtio-9p-device.c | 15 +-- hw/i386/pc.c | 11 +- hw/i386/pc_sysfw.c | 2 +- tizen/src/Makefile.objs | 5 +- tizen/src/emulator.c | 2 +- tizen/src/emulator_legacy.c | 2 +- tizen/src/skin/maruskin_client.c | 2 +- tizen/src/skin/maruskin_server.c | 2 +- tizen/src/util/Makefile.objs | 3 + tizen/src/{ => util}/maru_err_table.c | 170 ++++++++------------------ tizen/src/{ => util}/maru_err_table.h | 8 +- vl.c | 2 +- 13 files changed, 84 insertions(+), 162 deletions(-) rename tizen/src/{ => util}/maru_err_table.c (67%) rename tizen/src/{ => util}/maru_err_table.h (90%) diff --git a/blockdev.c b/blockdev.c index 0144f04113..f8c63c902a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -46,6 +46,10 @@ #include "trace.h" #include "sysemu/arch_init.h" +#ifdef CONFIG_MARU +#include "tizen/src/util/maru_err_table.h" +#endif + static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives); static const char *const if_name[IF_COUNT] = { @@ -288,11 +292,6 @@ static int parse_block_error_action(const char *buf, bool is_read, Error **errp) } } -#ifdef CONFIG_MARU -extern int start_simple_client(char* msg); -extern char* maru_convert_path(char* msg, const char *path); -#endif - static bool check_throttle_config(ThrottleConfig *cfg, Error **errp) { if (throttle_conflicting(cfg)) { @@ -513,14 +512,13 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts, if (ret < 0) { #ifdef CONFIG_MARU - 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; + char *path = get_canonical_path(file); + char *msg = g_strdup_printf("Failed to load disk file from the following path. Check if the file is corrupted or missing.\n\n%s", path); - err_msg = maru_convert_path((char*)_msg, file); - if (err_msg) { - start_simple_client(err_msg); - g_free(err_msg); - } + start_simple_client(msg); + + g_free(path); + g_free(msg); #endif error_setg(errp, "could not open disk image %s: %s", diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index 24ef874944..519b6e3c83 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -21,8 +21,7 @@ #include "virtio-9p-coth.h" #ifdef CONFIG_MARU -#include "../tizen/src/maru_err_table.h" -// extern char* maru_convert_path(char* msg, const char *path); +#include "tizen/src/util/maru_err_table.h" #endif static uint32_t virtio_9p_get_features(VirtIODevice *vdev, uint32_t features) @@ -108,13 +107,11 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp) error_setg(errp, "Virtio-9p Failed to initialize fs-driver with id:%s" " and export path:%s", s->fsconf.fsdev_id, s->ctx.fs_root); #ifdef CONFIG_MARU - const char _msg[] = "Failed to find the file sharing path. Check if the path is correct or not.\n\n"; - char* err_msg = NULL; - err_msg = maru_convert_path((char*)_msg, s->ctx.fs_root); - maru_register_exit_msg(MARU_EXIT_UNKNOWN, err_msg); - if (err_msg) { - g_free(err_msg); - } + char *path = get_canonical_path(s->ctx.fs_root); + maru_register_exit_msg(MARU_EXIT_UNKNOWN, "Failed to find the file sharing path." + " Check if the path is correct or not.\n\n%s", path); + + g_free(path); #endif goto out; } diff --git a/hw/i386/pc.c b/hw/i386/pc.c index f48baeea8e..612bde2f2c 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -60,7 +60,7 @@ #include "acpi-build.h" #ifdef CONFIG_MARU -#include "../../tizen/src/maru_err_table.h" +#include "tizen/src/util/maru_err_table.h" #endif /* debug PC/ISA interrupts */ //#define DEBUG_IRQ @@ -734,13 +734,10 @@ static void load_linux(FWCfgState *fw_cfg, kernel_filename, strerror(errno)); #ifdef CONFIG_MARU - char *error_msg = NULL; + char *path = get_canonical_path(kernel_filename); + maru_register_exit_msg(MARU_EXIT_KERNEL_FILE_EXCEPTION, path); - error_msg = maru_convert_path(error_msg, kernel_filename); - maru_register_exit_msg(MARU_EXIT_KERNEL_FILE_EXCEPTION, error_msg); - if (error_msg) { - g_free(error_msg); - } + g_free(path); #endif exit(1); } diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index 7819b21601..61e54ddc10 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -35,7 +35,7 @@ #include "sysemu/kvm.h" #ifdef CONFIG_MARU -#include "../../tizen/src/maru_err_table.h" +#include "tizen/src/util/maru_err_table.h" #endif #define BIOS_FILENAME "bios.bin" diff --git a/tizen/src/Makefile.objs b/tizen/src/Makefile.objs index 44bddfa55b..ba3ff7859a 100644 --- a/tizen/src/Makefile.objs +++ b/tizen/src/Makefile.objs @@ -3,14 +3,11 @@ QEMU_CFLAGS += -I$(SRC_PATH)/tizen/src # emulator base -obj-y += emulator.o emulator_legacy.o emulator_options.o emul_state.o maru_err_table.o +obj-y += emulator.o emulator_legacy.o emulator_options.o emul_state.o # utils obj-y += util/ -# mloop event -#obj-y += mloop_event.o - # maru display obj-y += display/ diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index a659db802d..2243b3ef47 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -40,7 +40,7 @@ #include "emulator_options.h" #include "util/sdb_noti_server.h" #include "util/check_gl.h" -#include "maru_err_table.h" +#include "util/maru_err_table.h" #include "util/osutil.h" #include "util/sdb.h" #include "skin/maruskin_server.h" diff --git a/tizen/src/emulator_legacy.c b/tizen/src/emulator_legacy.c index 85fa9d55e4..47b87de6b2 100644 --- a/tizen/src/emulator_legacy.c +++ b/tizen/src/emulator_legacy.c @@ -41,7 +41,7 @@ #include "guest_debug.h" #include "hw/virtio/maru_virtio_touchscreen.h" #include "util/check_gl.h" -#include "maru_err_table.h" +#include "util/maru_err_table.h" #include "display/maru_display.h" #include "util/osutil.h" #include "util/sdb.h" diff --git a/tizen/src/skin/maruskin_client.c b/tizen/src/skin/maruskin_client.c index 243037a0a6..0c6fc22b22 100644 --- a/tizen/src/skin/maruskin_client.c +++ b/tizen/src/skin/maruskin_client.c @@ -46,7 +46,7 @@ #ifdef CONFIG_WIN32 #include -#include "maru_err_table.h" +#include "util/maru_err_table.h" #endif MULTI_DEBUG_CHANNEL(qemu, skin_client); diff --git a/tizen/src/skin/maruskin_server.c b/tizen/src/skin/maruskin_server.c index 0264db0e52..5c94ada3c8 100644 --- a/tizen/src/skin/maruskin_server.c +++ b/tizen/src/skin/maruskin_server.c @@ -34,7 +34,7 @@ #include "maruskin_server.h" #include "maruskin_operation.h" #include "display/maru_display.h" -#include "maru_err_table.h" +#include "util/maru_err_table.h" #include "ecs/ecs.h" #include "emul_state.h" diff --git a/tizen/src/util/Makefile.objs b/tizen/src/util/Makefile.objs index 2234ec0ade..762e715f6e 100644 --- a/tizen/src/util/Makefile.objs +++ b/tizen/src/util/Makefile.objs @@ -20,4 +20,7 @@ obj-$(CONFIG_DARWIN) += check_gl_cgl.o # hotplug obj-y += maru_device_hotplug.o +# error table +obj-y += maru_err_table.o + $(obj)/osutil.o: QEMU_CFLAGS += $(CURL_CFLAGS) diff --git a/tizen/src/maru_err_table.c b/tizen/src/util/maru_err_table.c similarity index 67% rename from tizen/src/maru_err_table.c rename to tizen/src/util/maru_err_table.c index 01f6dd1f07..62c834de5f 100644 --- a/tizen/src/maru_err_table.c +++ b/tizen/src/util/maru_err_table.c @@ -50,20 +50,20 @@ MULTI_DEBUG_CHANNEL(qemu, backtrace); static char _maru_string_table[][JAVA_MAX_COMMAND_LENGTH] = { /* 0 */ "", /* 1 */ "Failed to allocate memory in qemu.", - /* 2 */ "Failed to load a kernel file the following path.\ -Check if the file is corrupted or missing.\n\n", - /* 3 */ "Failed to load a bios file in bios path that mentioned on document.\ -Check if the file is corrupted or missing.\n\n", + /* 2 */ "Failed to load a kernel file the following path." + " Check if the file is corrupted or missing.\n\n", + /* 3 */ "Failed to load a bios file in bios path that mentioned on document." + " Check if the file is corrupted or missing.\n\n", /* 4 */ "Skin process cannot be initialized. Skin server is not ready.", - /* 5 */ "Emulator has stopped working.\n\ -A problem caused the program to stop working correctly.", + /* 5 */ "Emulator has stopped working.\n" + "A problem caused the program to stop working correctly.", /* add here.. */ "" }; static int maru_exit_status = MARU_EXIT_NORMAL; -static char maru_exit_msg[JAVA_MAX_COMMAND_LENGTH] = { 0, }; +static char *maru_exit_msg; #ifdef CONFIG_WIN32 static LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter; @@ -74,54 +74,61 @@ static pthread_spinlock_t siglock; void maru_sighandler(int sig); #endif +char *get_canonical_path(char const *const path) +{ + if ((int)g_path_is_absolute(path)) { + return (char *)path; + } + + char *canonical_path; + +#ifndef _WIN32 + char *current_dir = g_get_current_dir(); + canonical_path = g_strdup_printf("%s/%s", current_dir, path); + g_free(current_dir); +#else + canonical_path = g_malloc(MAX_PATH); + GetFullPathName(path, MAX_PATH, canonical_path, NULL); +#endif -void maru_register_exit_msg(int maru_exit_index, char const *const additional_msg) + return canonical_path; +} + +void maru_register_exit_msg(int maru_exit_index, char const *format, ...) { - int len = 0; + va_list args; if (maru_exit_index >= MARU_EXIT_NORMAL) { - fprintf(stderr, "Invalid error message index = %d\n", maru_exit_index); + fprintf(stderr, "Invalid error message index = %d\n", + maru_exit_index); return; } if (maru_exit_status != MARU_EXIT_NORMAL) { - fprintf(stderr, "The error message is already registered = %d\n", maru_exit_status); + fprintf(stderr, "The error message is already registered = %d\n", + maru_exit_status); return; } maru_exit_status = maru_exit_index; - if (maru_exit_status != MARU_EXIT_UNKNOWN) { - if (maru_exit_status == MARU_EXIT_HB_TIME_EXPIRED) { - fprintf(stderr, "Skin client could not connect to Skin server.\ -The time of internal heartbeat has expired.\n"); - } - - 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; - } + if (maru_exit_status == MARU_EXIT_HB_TIME_EXPIRED) { + fprintf(stderr, "Skin client could not connect to Skin server." + " The time of internal heartbeat has expired.\n"); + } - 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; - } + if (!format) { + format = ""; + } - snprintf(maru_exit_msg, len, - "%s", _maru_string_table[maru_exit_status]); - } - } else if (additional_msg != NULL) { /* MARU_EXIT_UNKNOWN */ - len = strlen(additional_msg); - if (len >= JAVA_MAX_COMMAND_LENGTH) { - len = JAVA_MAX_COMMAND_LENGTH - 1; - } + va_start(args, format); + char *additional = g_strdup_vprintf(format, args); + va_end(args); + maru_exit_msg = g_strdup_printf("%s%s", _maru_string_table[maru_exit_status], + additional); + g_free(additional); - pstrcpy(maru_exit_msg, len + 1, additional_msg); - maru_exit_msg[len] = '\0'; + if (strlen(maru_exit_msg) >= JAVA_MAX_COMMAND_LENGTH) { + maru_exit_msg[JAVA_MAX_COMMAND_LENGTH - 1] = '\0'; } fprintf(stdout, "The error message is registered = %d : %s\n", @@ -131,93 +138,16 @@ The time of internal heartbeat has expired.\n"); void maru_atexit(void) { - if (maru_exit_status != MARU_EXIT_NORMAL || strlen(maru_exit_msg) != 0) { + if (maru_exit_status != MARU_EXIT_NORMAL || maru_exit_msg) { start_simple_client(maru_exit_msg); } + g_free(maru_exit_msg); + INFO("normal exit called\n"); // dump backtrace log no matter what maru_dump_backtrace(NULL, 0); } -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; - - if (!path) { - path = "NULL"; - res = 1; - } - else { - 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 a buffer for an error massage\n"); - 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 = g_strdup(err_msg); - if (!dos_err_msg) { - fprintf(stderr, - "failed to duplicate an error message from %p\n", err_msg); - 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] = '\\'; - } - } - pstrcpy(err_msg, strlen(dos_err_msg) + 1, dos_err_msg); - g_free(dos_err_msg); - } -#endif - g_free(current_path); - - return err_msg; -} - /* Print 'backtrace' */ #ifdef _WIN32 struct frame_layout { diff --git a/tizen/src/maru_err_table.h b/tizen/src/util/maru_err_table.h similarity index 90% rename from tizen/src/maru_err_table.h rename to tizen/src/util/maru_err_table.h index 8ad2bac01a..f27dc91013 100644 --- a/tizen/src/maru_err_table.h +++ b/tizen/src/util/maru_err_table.h @@ -32,8 +32,7 @@ #ifndef __EMUL_ERR_TABLE_H__ #define __EMUL_ERR_TABLE_H__ -#include "skin/maruskin_client.h" - +#include "tizen/src/skin/maruskin_client.h" /* TODO: define macro for fair of definition */ /* This enum must match the table definition */ @@ -49,9 +48,10 @@ enum { }; -void maru_register_exit_msg(int maru_exit_status, char const *const additional_msg); +char *get_canonical_path(char const *const path); +void maru_register_exit_msg(int maru_exit_status, char const *format, ...); void maru_atexit(void); -char *maru_convert_path(char *msg, const char *path); + void maru_dump_backtrace(void *ptr, int depth); void maru_register_exception_handler(void); diff --git a/vl.c b/vl.c index 7c0d432da1..3cf5854d2b 100644 --- a/vl.c +++ b/vl.c @@ -132,7 +132,7 @@ int qemu_main(int argc, char **argv, char **envp); #ifdef CONFIG_MARU #include "tizen/src/maru_common.h" #include "tizen/src/emulator.h" -#include "tizen/src/maru_err_table.h" +#include "tizen/src/util/maru_err_table.h" #include "tizen/src/emul_state.h" #include "tizen/src/display/maru_display.h" #include "tizen/src/skin/maruskin_operation.h" -- 2.34.1