From: Aaron Sethman In-Reply-To: <200302080347.h183lrf20924@...41...> Message-ID: References: <200302080347.h183lrf20924@...41...> MIME-Version: 1.0 Subject: Re: [Openvpn-devel] Opened file descriptors in script calls Sender: openvpn-devel-admin@lists.sourceforge.net Errors-To: openvpn-devel-admin@lists.sourceforge.net List-Help: List-Post: List-Subscribe: , List-Id: List-Unsubscribe: , List-Archive: Date: Sun Feb 9 17:04:03 2003 Content-Type: TEXT/PLAIN; charset=US-ASCII Content-Transfer-Encoding: 8bit To: James Yonan Cc: Alberto Gonzalez Iniesta , openvpn-devel@lists.sourceforge.net Here is a simple little replacement for system() that does close file descriptors. The main issue with it is though, it ends up picking an arbitrary number of fds to close. I picked closing 0 to 99. Aaron int s_system(const char *string) { pid_t pid; int x; pid = fork() if(pid == -1) { return -1; } if(pid > 0) { int status; wait(&status); return(status); } for(x = 0; x < 100; x++) { close(x); } execlp("/bin/sh", "-c", string); }