Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 50157 invoked by uid 500); 23 Oct 2001 20:15:59 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 50146 invoked from network); 23 Oct 2001 20:15:59 -0000 X-Authentication-Warning: rdu88-250-106.nc.rr.com: trawick set sender to trawick@attglobal.net using -f Sender: trawick@rdu88-250-106.nc.rr.com To: dev@apr.apache.org Subject: [PATCH] fd issue with apr_proc_create() and cleanup for exec From: Jeff Trawick Date: 23 Oct 2001 16:15:55 -0400 Message-ID: Lines: 60 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N scenario: . create a child process and enable pipes for the standard descriptors (0-2) . have registered cleanups for files which use any of the standard descriptors problem: the dup2() calls in the child to set up the pipes on the standard descriptors close whatever was on those descriptors before cleanup for exec closes not what was on those descriptors before but instead closes the pipes child process gets EBADF when reading from stdin or writing to stdout/stderr quick hack: tweak the order of processing in the child so that the cleanup happens before we set up our pipes on the standard descriptors This patch is barely tested; it gets my silly apache module to work, but I can't make any other promises. Index: srclib/apr/threadproc/unix/proc.c =================================================================== RCS file: /home/cvs/apr/threadproc/unix/proc.c,v retrieving revision 1.50 diff -u -r1.50 proc.c --- srclib/apr/threadproc/unix/proc.c 2001/10/23 17:30:08 1.50 +++ srclib/apr/threadproc/unix/proc.c 2001/10/23 20:00:40 @@ -289,6 +289,12 @@ else if (new->pid == 0) { int status; /* child process */ + + /* do exec cleanup before duping pipes to fds 0-2; otherwise, + * any files cleaned up with those fds will hose our pipes + */ + apr_pool_cleanup_for_exec(); + if (attr->child_in) { apr_file_close(attr->parent_in); dup2(attr->child_in->filedes, STDIN_FILENO); @@ -312,8 +318,6 @@ exit(-1); /* We have big problems, the child should exit. */ } } - - apr_pool_cleanup_for_exec(); if ((status = limit_proc(attr)) != APR_SUCCESS) { return status; -- Jeff Trawick | trawick@attglobal.net | PGP public key at web site: http://www.geocities.com/SiliconValley/Park/9289/ Born in Roswell... married an alien...