my_popen: close filedescriptors before exec

This commit is contained in:
Stefan Seyfried
2013-02-20 15:20:55 +01:00
parent b5e0a7e064
commit c83a35ebfc

View File

@@ -129,6 +129,9 @@ FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type)
close(pfd[0]);
}
}
int maxfd = getdtablesize();
for(int i = 3; i < maxfd; i++)
close(i);
execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);
exit(0);
}