diff options
author | Robin Gareus <robin@gareus.org> | 2013-04-30 03:28:11 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2013-04-30 03:28:46 +0200 |
commit | 03310a587c1157d2287c43f9f2aea97263606880 (patch) | |
tree | dc787cd60b302dd497075d61de9006d0c865c9e0 /gtk2_ardour/system_exec.cc | |
parent | 63b02a265a6d5e821198b5e3fcc1f6ba6d83a129 (diff) |
zero/reset closed file-descriptors
should fix issues with LinuxDSP plugins (X11 thread) & xjadeo
Diffstat (limited to 'gtk2_ardour/system_exec.cc')
-rw-r--r-- | gtk2_ardour/system_exec.cc | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/gtk2_ardour/system_exec.cc b/gtk2_ardour/system_exec.cc index 1f178a6c68..566c87dfbb 100644 --- a/gtk2_ardour/system_exec.cc +++ b/gtk2_ardour/system_exec.cc @@ -38,6 +38,8 @@ using namespace std; void * interposer_thread (void *arg); +static void close_fd (int* fd) { if (!fd) return; if (*fd >= 0) ::close (*fd); *fd = -1; } + SystemExec::SystemExec (std::string c, std::string a) : cmd(c) { @@ -483,18 +485,18 @@ SystemExec::start (int stderr_mode) pid=r; /* check if execve was successful. */ - ::close(pok[1]); + close_fd(&pok[1]); char buf; for ( ;; ) { ssize_t n = ::read(pok[0], &buf, 1 ); if ( n==1 ) { /* child process returned from execve */ pid=0; - ::close(pok[0]); - ::close(pin[1]); - ::close(pin[0]); - ::close(pout[1]); - ::close(pout[0]); + close_fd(&pok[0]); + close_fd(&pin[1]); + close_fd(&pin[0]); + close_fd(&pout[1]); + close_fd(&pout[0]); pin[1] = -1; return -3; } else if ( n==-1 ) { @@ -503,7 +505,7 @@ SystemExec::start (int stderr_mode) } break; } - ::close(pok[0]); + close_fd(&pok[0]); /* child started successfully */ #if 0 @@ -519,17 +521,17 @@ SystemExec::start (int stderr_mode) } if (r == 0) { /* 2nd child process - catch stdout */ - ::close(pin[1]); - ::close(pout[1]); + close_fd(&pin[1]); + close_fd(&pout[1]); output_interposer(); exit(0); } - ::close(pout[1]); - ::close(pin[0]); - ::close(pout[0]); + close_fd(&pout[1]); + close_fd(&pin[0]); + close_fd(&pout[0]); #else /* use pthread */ - ::close(pout[1]); - ::close(pin[0]); + close_fd(&pout[1]); + close_fd(&pin[0]); int rv = pthread_create(&thread_id_tt, NULL, interposer_thread, this); thread_active=true; @@ -543,15 +545,15 @@ SystemExec::start (int stderr_mode) } /* child process - exec external process */ - ::close(pok[0]); + close_fd(&pok[0]); ::fcntl(pok[1], F_SETFD, FD_CLOEXEC); - ::close(pin[1]); + close_fd(&pin[1]); if (pin[0] != STDIN_FILENO) { ::dup2(pin[0], STDIN_FILENO); } - ::close(pin[0]); - ::close(pout[0]); + close_fd(&pin[0]); + close_fd(&pout[0]); if (pout[1] != STDOUT_FILENO) { ::dup2(pout[1], STDOUT_FILENO); } @@ -569,7 +571,7 @@ SystemExec::start (int stderr_mode) } if (pout[1] != STDOUT_FILENO && pout[1] != STDERR_FILENO) { - ::close(pout[1]); + close_fd(&pout[1]); } if (nicelevel !=0) { @@ -596,7 +598,7 @@ SystemExec::start (int stderr_mode) /* if we reach here something went wrong.. */ char buf = 0; (void) ::write(pok[1], &buf, 1 ); - (void) ::close(pok[1]); + close_fd(&pok[1]); exit(-1); return -1; } @@ -631,11 +633,10 @@ void SystemExec::close_stdin() { if (pin[1]<0) return; - ::close(pin[0]); - ::close(pin[1]); - ::close(pout[0]); - ::close(pout[1]); - pin[1] = - 1; // mark as closed + close_fd(&pin[0]); + close_fd(&pin[1]); + close_fd(&pout[0]); + close_fd(&pout[1]); } int |