Fix debug mode launch 94/180294/3
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 28 May 2018 05:39:23 +0000 (14:39 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 29 May 2018 08:28:15 +0000 (17:28 +0900)
- Changes new argc size to avoid EFAULT(Badd address) error
- Redirect stdin

Change-Id: I6f875795d3b8f8deec260920e27730d4c8cf3ad3
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/launchpad_debug.c

index aab6408..9b292f5 100644 (file)
@@ -82,7 +82,7 @@ int _debug_create_extra_argv(int *argc, char ***argv)
 
 int _debug_create_argv(int *argc, char ***argv, bool *attach)
 {
-       int new_argc;
+       int new_argc = 0;
        char **new_argv;
        const char *exe;
        const char *debug_argv;
@@ -104,11 +104,13 @@ int _debug_create_argv(int *argc, char ***argv, bool *attach)
                return 0;
 
        attach_str = _debugger_info_get_attach(debugger_info);
-       if (attach_str && strcasecmp(attach_str, "true") == 0)
+       if (attach_str && strcasecmp(attach_str, "true") == 0) {
                *attach = true;
+               new_argc++;
+       }
 
        list = _debugger_info_get_default_opt_list(debugger_info);
-       new_argc = g_list_length(debug_argv_list) + g_list_length(list) + 1;
+       new_argc += g_list_length(debug_argv_list) + g_list_length(list) + 1;
        new_argv = (char **)calloc(new_argc, sizeof(char *));
        if (new_argv == NULL) {
                _E("out of memory");
@@ -193,6 +195,17 @@ static int __redirect_std_fds(bundle *kb)
                return -1;
        }
 
+       /* stdin */
+       snprintf(path, sizeof(path), "/proc/%d/fd/0", caller_pid);
+       fd = open(path, O_RDONLY);
+       if (fd < 0) {
+               _E("[DEBUG] Failed to open %s [%s]", path,
+                               strerror_r(errno, err_buf, sizeof(err_buf)));
+               return -1;
+       }
+       dup2(fd, 0);
+       close(fd);
+
        /* stdout */
        snprintf(path, sizeof(path), "/proc/%d/fd/1", caller_pid);
        fd = open(path, O_WRONLY);