On Wed, Sep 19, 2001 at 12:16:24PM -0700, Ryan Bloom wrote:
> On Wednesday 19 September 2001 11:37 am, William A. Rowe, Jr. wrote:
> > From: "Greg Stein" <[EMAIL PROTECTED]>
> > Sent: Wednesday, September 19, 2001 1:26 PM
> >
> > > On Wed, Sep 19, 2001 at 01:52:12PM -0400, Rodent of Unusual Size wrote:
> > > > Greg Stein wrote:
> > > > > It isn't a bug. Cleanups are for just wrapping things up,
> > > > > not doing work.
> > > >
> > > > If that's the authoritative answer, then we need to provide
> > > > a supported way for 'doing work' at cleanup time.
> > > >
> > > > > You might not even be able to open and use that file if
> > > > > your pool is n the process of being destroyed.
> > > >
> > > > That sounds like utter tripe.  If you can't depend on the
> > > > pool lasting at least until your cleanup routine ends,
> > > > then the whole cleanup mechanism is seriously borked.  AFAIK
> > > > it isn't, so I think the above assertion *is*.
> > >
> > > The problem is cross-dependency between the cleanup actions. One can
> > > destroy something another cleanup needs. If you restrict their actions to
> > > "simple" things, then the cross-dependencies are (hopefully!) removed.
> >
> > Really?  No.  Cleanups are run as a LIFO stack.  Anything that existed when
> > something was added to the pool must exist when that something is removed
> > from the pool.
> >
> > IMHO, we need to make subpool scrubbing an actual LIFO cleanup as well, so
> > that will also be true of subpools.
> >
> > Considering how we use pools for dynamic libraries and the rest, it's
> > absolutely vital that they are unspun from the pool in LIFO order of their
> > creation.
> 
> I agree with Bill.  Having reviewed the code quite deeply yesterday, pool
> cleanups follow a very clean rule, and registering a cleanup from within
> a cleanup will always work if done correctly.  If you have data in a pool

BZzzzt.  The attached code registers a cleanup from within a cleanup, and
does so 'correctly'.  See the program attached at the bottom, which behaves 
incorrectly.  It is simple code, but not knowing that a given
function registers a cleanup can cause major problems (leaking
file descriptors, etc. eventually).  The file should contain 'Cleanup',
because the cleanup of the file should flush the buffer -- that
cleanup is never run, though.

> when the cleanup is registered, it is gauranteed to be there when the cleanup
> is run.
> 
> Anything else is completely broken.


#include "apr.h"
#include "apr_file_io.h"

static apr_status_t my_cleanup(void *cbdata){
    apr_pool_t *p = cbdata;
    apr_file_t *file;

    apr_file_open(&file, "/tmp/bonk", 
                  APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BUFFERED,
                  APR_OS_DEFAULT, p);
    apr_file_printf(file, "Cleanup");
    return APR_SUCCESS;
}

int main(int argc, char *argv[]){
    apr_pool_t *pool;

    apr_initialize();
    apr_pool_create(&pool, NULL);
    apr_pool_cleanup_register(pool, pool, my_cleanup, NULL);
    apr_pool_destroy(pool);
    apr_terminate();
    return 0;
}

Reply via email to