|
|
|
|
@ -239,6 +239,9 @@ int wexecvp(
|
|
|
|
|
// Duplicate file argument to avoid manual duplication
|
|
|
|
|
_argv.insert(_argv.begin(), file.c_str());
|
|
|
|
|
|
|
|
|
|
// close all files , with the exception of the pipes
|
|
|
|
|
close_all_non_term_fd({ CHILD_READ_FD, CHILD_WRITE_FD, CHILD_WRITE_ERR, PARENT_READ_FD, PARENT_READ_ERR, PARENT_WRITE_FD});
|
|
|
|
|
|
|
|
|
|
// Copy the pipe descriptors
|
|
|
|
|
int dup_read_err = dup2(CHILD_READ_FD, STDIN_FILENO);
|
|
|
|
|
int dup_write_err = dup2(CHILD_WRITE_FD, STDOUT_FILENO);
|
|
|
|
|
@ -257,6 +260,7 @@ int wexecvp(
|
|
|
|
|
close(PARENT_READ_ERR);
|
|
|
|
|
close(PARENT_WRITE_FD);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char** args = const_cast<char**>(_argv.data());
|
|
|
|
|
child_err = execvp(file.c_str(), args);
|
|
|
|
|
|
|
|
|
|
@ -397,3 +401,32 @@ std::string generate_multi_rows_query(int rows, int params) {
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void close_all_non_term_fd(std::vector<int> excludeFDs) {
|
|
|
|
|
DIR *d;
|
|
|
|
|
struct dirent *dir;
|
|
|
|
|
d = opendir("/proc/self/fd");
|
|
|
|
|
if (d) {
|
|
|
|
|
while ((dir = readdir(d)) != NULL) {
|
|
|
|
|
if (strlen(dir->d_name) && dir->d_name[0] != '.') {
|
|
|
|
|
int fd = std::stol(std::string(dir->d_name));
|
|
|
|
|
if (fd > 2) {
|
|
|
|
|
if (std::find(excludeFDs.begin(), excludeFDs.end(), fd) == excludeFDs.end()) {
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
closedir(d);
|
|
|
|
|
} else {
|
|
|
|
|
struct rlimit nlimit;
|
|
|
|
|
int rc = getrlimit(RLIMIT_NOFILE, &nlimit);
|
|
|
|
|
if (rc == 0) {
|
|
|
|
|
for (unsigned int fd = 3; fd < nlimit.rlim_cur; fd++) {
|
|
|
|
|
if (std::find(excludeFDs.begin(), excludeFDs.end(), fd) == excludeFDs.end()) {
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|