4 char dirName[] =
"/proc/self/fd/";
5 char buf[256], fullName[256];
6 DIR *dir = opendir(dirName);
10 struct dirent *entry = NULL;
11 while((entry = readdir(dir)) != NULL)
13 if(entry->d_name[0] <=
'9' && entry->d_name[0] >=
'0')
15 int fd = atoi(entry->d_name);
16 if(fd > 2 && fd != dfd)
18 sprintf(fullName,
"%s%s", dirName, entry->d_name);
19 int l = readlink(fullName, buf,
sizeof(buf) - 1);
21 printf(
"close %s\n",buf);
30 printf(
"Can't open /proc/self/fd/\n");
32 int l = readlink(
"/proc/self/exe", buf,
sizeof(buf) - 1);
34 if(execv(buf, argv) < 0)