apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject Re: Bug: pool cleanups run by subprocesses
Date Wed, 23 Oct 2002 15:04:37 GMT

The problem is this line in open.c:

    if (!(flag & APR_FILE_NOCLEANUP)) {
        apr_pool_cleanup_register((*new)->pool, (void *)(*new),
                                  apr_unix_file_cleanup, 
apr_unix_file_cleanup);
    }

Notice the last argument to apr_pool_cleanup_register.  That argument
essentially means that the cleanup should be run when creating a new
process.  This should be removed from the code.  Then, if you want to
close the file before creating the child, you will have to use
apr_file_inherit_set.

I haven't looked at the exit(1) problem yet.

Ryan

On Wed, 23 Oct 2002, Greg Hudson wrote:

> The following program demonstrates a bug in APR: when a process is
> created, it explicitly runs pool cleanups.  I'm not sure what the
> motivation for that is, but it's a bad idea.  Note how "testdata\n" is
> written twice to the file "test" when the test program is run, because
> the apr_file_t output buffer is flushed twice.
> 
> A separate but similar bug is that, if the exec() fails in
> threadproc/proc.c, the "exit(1)" call will cause regular atexit
> handlers to run, including the handler which flushes stdio data.  This
> can cause stdio data to be flushed twice.  "_exit(1)" should be called
> instead.
> 
> (I'm not on this list; please cc me on replies.)
> 
> #include <apr_general.h>
> #include <apr_file_io.h>
> #include <apr_thread_proc.h>
> 
> int main()
> {
>   apr_pool_t *pool;
>   apr_file_t *file;
>   apr_size_t nbytes;
>   apr_proc_t proc;
>   apr_procattr_t *procattr;
>   const char *args[] = { "/bin/echo", "blah", NULL };
>   apr_status_t err;
> 
>   err = apr_initialize();
>   err = apr_pool_create(&pool, NULL);
>   err = apr_file_open(&file, "test",
> 		      APR_CREATE|APR_APPEND|APR_BUFFERED|APR_READ|APR_WRITE,
> 		      APR_OS_DEFAULT, pool);
>   nbytes = 9;
>   err = apr_file_write(file, "testdata\n", &nbytes);
>   err = apr_procattr_create(&procattr, pool);
>   err = apr_procattr_cmdtype_set(procattr, APR_PROGRAM_ENV);
>   err = apr_proc_create(&proc, "/bin/echo", args, NULL, procattr, pool);
>   err = apr_proc_wait(&proc, NULL, NULL, APR_WAIT);
>   apr_terminate();
>   return 0;
> }
> 

-- 

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
550 Jean St
Oakland CA 94610
-------------------------------------------------------------------------------


Mime
View raw message