prefer the use of references in private static function in system_exec.cc
This commit is contained in:
parent
07c6df00cc
commit
aac5f4c6d6
@ -38,7 +38,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
void * interposer_thread (void *arg);
|
void * interposer_thread (void *arg);
|
||||||
|
|
||||||
static void close_fd (int* fd) { if (!fd) return; if (*fd >= 0) ::close (*fd); *fd = -1; }
|
static void close_fd (int& fd) { if (fd >= 0) ::close (fd); fd = -1; }
|
||||||
|
|
||||||
SystemExec::SystemExec (std::string c, std::string a)
|
SystemExec::SystemExec (std::string c, std::string a)
|
||||||
: cmd(c)
|
: cmd(c)
|
||||||
@ -510,18 +510,18 @@ SystemExec::start (int stderr_mode)
|
|||||||
pid=r;
|
pid=r;
|
||||||
|
|
||||||
/* check if execve was successful. */
|
/* check if execve was successful. */
|
||||||
close_fd(&pok[1]);
|
close_fd(pok[1]);
|
||||||
char buf;
|
char buf;
|
||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
ssize_t n = ::read(pok[0], &buf, 1 );
|
ssize_t n = ::read(pok[0], &buf, 1 );
|
||||||
if ( n==1 ) {
|
if ( n==1 ) {
|
||||||
/* child process returned from execve */
|
/* child process returned from execve */
|
||||||
pid=0;
|
pid=0;
|
||||||
close_fd(&pok[0]);
|
close_fd(pok[0]);
|
||||||
close_fd(&pin[1]);
|
close_fd(pin[1]);
|
||||||
close_fd(&pin[0]);
|
close_fd(pin[0]);
|
||||||
close_fd(&pout[1]);
|
close_fd(pout[1]);
|
||||||
close_fd(&pout[0]);
|
close_fd(pout[0]);
|
||||||
pin[1] = -1;
|
pin[1] = -1;
|
||||||
return -3;
|
return -3;
|
||||||
} else if ( n==-1 ) {
|
} else if ( n==-1 ) {
|
||||||
@ -530,7 +530,7 @@ SystemExec::start (int stderr_mode)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
close_fd(&pok[0]);
|
close_fd(pok[0]);
|
||||||
/* child started successfully */
|
/* child started successfully */
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -546,17 +546,17 @@ SystemExec::start (int stderr_mode)
|
|||||||
}
|
}
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
/* 2nd child process - catch stdout */
|
/* 2nd child process - catch stdout */
|
||||||
close_fd(&pin[1]);
|
close_fd(pin[1]);
|
||||||
close_fd(&pout[1]);
|
close_fd(pout[1]);
|
||||||
output_interposer();
|
output_interposer();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
close_fd(&pout[1]);
|
close_fd(pout[1]);
|
||||||
close_fd(&pin[0]);
|
close_fd(pin[0]);
|
||||||
close_fd(&pout[0]);
|
close_fd(pout[0]);
|
||||||
#else /* use pthread */
|
#else /* use pthread */
|
||||||
close_fd(&pout[1]);
|
close_fd(pout[1]);
|
||||||
close_fd(&pin[0]);
|
close_fd(pin[0]);
|
||||||
int rv = pthread_create(&thread_id_tt, NULL, interposer_thread, this);
|
int rv = pthread_create(&thread_id_tt, NULL, interposer_thread, this);
|
||||||
|
|
||||||
thread_active=true;
|
thread_active=true;
|
||||||
@ -570,15 +570,15 @@ SystemExec::start (int stderr_mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* child process - exec external process */
|
/* child process - exec external process */
|
||||||
close_fd(&pok[0]);
|
close_fd(pok[0]);
|
||||||
::fcntl(pok[1], F_SETFD, FD_CLOEXEC);
|
::fcntl(pok[1], F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
close_fd(&pin[1]);
|
close_fd(pin[1]);
|
||||||
if (pin[0] != STDIN_FILENO) {
|
if (pin[0] != STDIN_FILENO) {
|
||||||
::dup2(pin[0], STDIN_FILENO);
|
::dup2(pin[0], STDIN_FILENO);
|
||||||
}
|
}
|
||||||
close_fd(&pin[0]);
|
close_fd(pin[0]);
|
||||||
close_fd(&pout[0]);
|
close_fd(pout[0]);
|
||||||
if (pout[1] != STDOUT_FILENO) {
|
if (pout[1] != STDOUT_FILENO) {
|
||||||
::dup2(pout[1], STDOUT_FILENO);
|
::dup2(pout[1], STDOUT_FILENO);
|
||||||
}
|
}
|
||||||
@ -596,7 +596,7 @@ SystemExec::start (int stderr_mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pout[1] != STDOUT_FILENO && pout[1] != STDERR_FILENO) {
|
if (pout[1] != STDOUT_FILENO && pout[1] != STDERR_FILENO) {
|
||||||
close_fd(&pout[1]);
|
close_fd(pout[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nicelevel !=0) {
|
if (nicelevel !=0) {
|
||||||
@ -623,7 +623,7 @@ SystemExec::start (int stderr_mode)
|
|||||||
/* if we reach here something went wrong.. */
|
/* if we reach here something went wrong.. */
|
||||||
char buf = 0;
|
char buf = 0;
|
||||||
(void) ::write(pok[1], &buf, 1 );
|
(void) ::write(pok[1], &buf, 1 );
|
||||||
close_fd(&pok[1]);
|
close_fd(pok[1]);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -658,10 +658,10 @@ void
|
|||||||
SystemExec::close_stdin()
|
SystemExec::close_stdin()
|
||||||
{
|
{
|
||||||
if (pin[1]<0) return;
|
if (pin[1]<0) return;
|
||||||
close_fd(&pin[0]);
|
close_fd(pin[0]);
|
||||||
close_fd(&pin[1]);
|
close_fd(pin[1]);
|
||||||
close_fd(&pout[0]);
|
close_fd(pout[0]);
|
||||||
close_fd(&pout[1]);
|
close_fd(pout[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user