Modify closing all open fds 91/78791/1 accepted/tizen/common/20160707.171554 accepted/tizen/ivi/20160707.043155 accepted/tizen/mobile/20160707.043234 accepted/tizen/tv/20160707.043045 accepted/tizen/wearable/20160707.043225 submit/tizen/20160707.014055
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 7 Jul 2016 01:56:06 +0000 (10:56 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 7 Jul 2016 01:56:06 +0000 (10:56 +0900)
Change-Id: I5bfc97b07e6d444860da66cadadf38f8729530e7
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/common.h
src/common.c
src/debug-launchpad.c

index 9210790..6488292 100644 (file)
@@ -70,6 +70,7 @@ char **_create_argc_argv(bundle *kb, int *margc, const char *app_path);
 int _proc_check_cmdline_bypid(int pid);
 void _prepare_listen_sock(void);
 int _delete_sock_path(int pid, uid_t uid);
+int _close_all_fds(void);
 
 #endif /* __COMMON_H__ */
 
index 0f14356..0df007d 100644 (file)
@@ -870,3 +870,39 @@ int _delete_sock_path(int pid, uid_t uid)
        return 0;
 }
 
+int _close_all_fds(void)
+{
+       DIR *dp;
+       struct dirent dentry;
+       struct dirent *result = NULL;
+       int fd;
+       int max_fd;
+
+       dp = opendir("/proc/self/fd");
+       if (dp == NULL) {
+               /* fallback */
+               max_fd = sysconf(_SC_OPEN_MAX);
+               for (fd = 3; fd < max_fd; fd++)
+                       close(fd);
+
+               return 0;
+       }
+
+       while (readdir_r(dp, &dentry, &result) == 0 && result) {
+               if (!isdigit(dentry.d_name[0]))
+                       continue;
+
+               fd = atoi(dentry.d_name);
+               if (fd < 3)
+                       continue;
+
+               if (fd == dirfd(dp))
+                       continue;
+
+               close(fd);
+       }
+       closedir(dp);
+
+       return 0;
+}
+
index 7e706f2..9c58d1b 100644 (file)
@@ -200,8 +200,6 @@ static int __start_process(const char *appid, const char *app_path,
 {
        char sock_path[PATH_MAX];
        int pid;
-       int max_fd;
-       int iter_fd;
 
        if (__prepare_fork(kb, appinfo->debug_appid) < 0)
                return -1;
@@ -214,13 +212,8 @@ static int __start_process(const char *appid, const char *app_path,
                _signal_unblock_sigchld();
                _signal_fini();
 
-               max_fd = sysconf(_SC_OPEN_MAX);
-               for (iter_fd = 3; iter_fd <= max_fd; iter_fd++)
-                       close(iter_fd);
-
-               snprintf(sock_path, sizeof(sock_path), "%s/apps/%d/%d",
-                               SOCKET_PATH, getuid(), getpid());
-               unlink(sock_path);
+               _close_all_fds();
+               _delete_sock_path(getpid(), getuid());
 
                PERF("prepare exec - fisrt done");
                _D("lock up test log(no error): prepare exec - first done");