Redirect stdout and stderr for debugging 73/81573/1 accepted/tizen/common/20160727.151423 accepted/tizen/ivi/20160727.103155 accepted/tizen/mobile/20160727.102957 accepted/tizen/tv/20160727.103025 accepted/tizen/wearable/20160727.103050 submit/tizen/20160727.081224
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 27 Jul 2016 06:25:09 +0000 (15:25 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 27 Jul 2016 06:25:24 +0000 (15:25 +0900)
Change-Id: Ib9fc85cd9e6b4359e8e228c0bc2446705bb62d74
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
packaging/debug-launchpad.spec
src/debug-launchpad.c

index b3eab40..491df68 100755 (executable)
@@ -62,7 +62,7 @@ rm -rf %{buildroot}
 %files
 %license LICENSE
 %manifest debug-launchpad.manifest
-%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/debug_launchpad_preloading_preinitializing_daemon
+%caps(cap_mac_admin,cap_setgid,cap_dac_override=ei) %{_bindir}/debug_launchpad_preloading_preinitializing_daemon
 %if 0%{?appfw_feature_socket_activation}
 %{_unitdir_user}/debug-launchpad.service
 %{_unitdir_user}/debug-launchpad.socket
index f7b7f46..30d5385 100644 (file)
@@ -166,6 +166,56 @@ static int __prepare_fork(bundle *kb, const char *appid)
        return 0;
 }
 
+static int __stdout_stderr_redirection(int caller_pid)
+{
+       char path[PATH_MAX];
+       int fd;
+       int ret = 0;
+
+       /* stdout */
+       snprintf(path, sizeof(path), "/proc/%d/fd/1", caller_pid);
+       fd = open(path, O_WRONLY);
+       if (fd < 0) {
+               _E("Failed to open %s [%s]", path, strerror(errno));
+               ret++;
+       } else {
+               dup2(fd, 1);
+               close(fd);
+       }
+
+       /* stderr */
+       snprintf(path, sizeof(path), "/proc/%d/fd/2", caller_pid);
+       fd = open(path, O_WRONLY);
+       if (fd < 0) {
+               _E("Failed to open %s [%s]", path, strerror(errno));
+               ret += 2;
+       } else {
+               dup2(fd, 2);
+               close(fd);
+       }
+
+       return ret;
+}
+
+static int __get_caller_pid(bundle *kb)
+{
+       const char *pid_str;
+       int pid;
+
+       pid_str = bundle_get_val(kb, AUL_K_ORG_CALLER_PID);
+       if (pid_str == NULL)
+               pid_str = bundle_get_val(kb, AUL_K_CALLER_PID);
+
+       if (pid_str == NULL)
+               return -1;
+
+       pid = atoi(pid_str);
+       if (pid <= 1)
+               return -1;
+
+       return pid;
+}
+
 static int __normal_fork_exec(int argc, char **argv)
 {
        _D("start real fork and exec\n");
@@ -204,7 +254,6 @@ static void __real_launch(const char *app_path, bundle *kb)
 static int __start_process(const char *appid, const char *app_path,
                bundle *kb, appinfo_t *appinfo)
 {
-       char sock_path[PATH_MAX];
        int pid;
 
        if (__prepare_fork(kb, appinfo->debug_appid) < 0)
@@ -221,6 +270,9 @@ static int __start_process(const char *appid, const char *app_path,
                _close_all_fds();
                _delete_sock_path(getpid(), getuid());
 
+               if (__stdout_stderr_redirection(__get_caller_pid(kb)))
+                       _E("__stdout_stderr_redirection() failed");
+
                PERF("prepare exec - fisrt done");
                _D("lock up test log(no error): prepare exec - first done");