On Wed, 14 Mar 2007, Steve Hay wrote:

I tried your patch with the current svn version (revision 518242), but I'm still seeing intermittent failures (usually in tests 15, 16 and/or 20) either when I run "nmake test" from the top-level, or when I run: perl -Iblib/arch -Iblib/lib t/TEST -verbose=1 t/apreq/upload.t from the glue/perl sub-directory :-( I'm running perl-5.8.8, apache-2.2.2 and mod_perl-2.0.3 (RC3, I think). Do I need to update anything there?

I don't think so - I ran the tests against essentially the
same setup, and didn't see any failures when run a number
of times.

Perhaps just to narrow things down, could you try the
attached C file (a VC++ Makefile is also attached)?
This uses the relevant parts of libapreq2 to create
and cleanup a temp file; the Makefile produces 4 .exes:
  apr_temp: don't enable APR_FILE_NOCLEANUP nor
            APR_SHARELOCK
  apr_temp_nc: enable only APR_FILE_NOCLEANUP
  apr_temp_sh: enable only APR_SHARELOCK
  apr_temp_nc_sh: enable both APR_FILE_NOCLEANUP and
                  APR_SHARELOCK
These are run, for example
  apr_temp 20
which will go in a loop and create, and then remove, 20
temp files (with no arguments, the default is 10.

Are there any problems with the cleanup in any of these?
If not, then it looks like the problem is somewhere
within the Perl glue.

--
best regards,
Randy
CC = cl
LINK = link
APACHE2 = C:\Apache2
DEF = -DWIN32
INCFLAG = -I$(APACHE2)\include
LIBFLAG = $(APACHE2)\lib\libapr-1.lib $(APACHE2)\lib\libaprutil-1.lib 

all: apr_temp apr_temp_nc apr_temp_sh apr_temp_nc_sh

apr_temp: apr_temp.c
        $(CC) -c apr_temp.c $(DEF) $(INCFLAG) /Foapr_temp.obj
        $(LINK) apr_temp.obj  $(LIBFLAG) /out:apr_temp.exe

apr_temp_nc: apr_temp.c
        $(CC) -c apr_temp.c $(DEF) -DNOCLEANUP $(INCFLAG) /Foapr_temp_nc.obj
        $(LINK) apr_temp_nc.obj  $(LIBFLAG) /out:apr_temp_nc.exe

apr_temp_sh: apr_temp.c
        $(CC) -c apr_temp.c $(DEF) -DSHARELOCK $(INCFLAG)  /Foapr_temp_sh.obj
        $(LINK) apr_temp_sh.obj  $(LIBFLAG) /out:apr_temp_sh.exe

apr_temp_nc_sh: apr_temp.c
        $(CC) -c apr_temp.c $(DEF) -DNOCLEANUP -DSHARELOCK $(INCFLAG) 
/Foapr_temp_nc_sh.obj
        $(LINK) apr_temp_nc_sh.obj $(LIBFLAG) /out:apr_temp_nc_sh.exe

clean:
        del *.obj *.tds *.exe
#include "apr.h"
#include "apr_errno.h"
#include "apr_pools.h"
#include "apr_file_io.h"

struct cleanup_data {
    const char *fname;
    apr_pool_t *pool;
};

static apr_status_t apreq_file_cleanup(void *d) {
    struct cleanup_data *data = d;
    printf("CLEANUP\n");
    return apr_file_remove(data->fname, data->pool);
}

apr_status_t apreq_file_mktemp(apr_file_t **fp,
                               apr_pool_t *pool,
                               const char *path) {
    apr_status_t rc;
    char *tmpl;
    struct cleanup_data *data;
    apr_int32_t flag;

    if (path == NULL) {
        rc = apr_temp_dir_get(&path, pool);
        if (rc != APR_SUCCESS)
            return rc;
    }
    rc = apr_filepath_merge(&tmpl, path, "apreqXXXXXX",
                            APR_FILEPATH_NOTRELATIVE, pool);

    if (rc != APR_SUCCESS)
        return rc;

    data = apr_palloc(pool, sizeof *data);
    /* cleanups are LIFO, so this one will run just after
       the cleanup set by mktemp */
    apr_pool_cleanup_register(pool, data,
                              apreq_file_cleanup, apreq_file_cleanup);

    /* NO APR_DELONCLOSE! see comment above */
    flag = APR_CREATE | APR_READ | APR_WRITE | APR_EXCL | APR_BINARY;
#ifdef NOCLEANUP
     flag |= APR_FILE_NOCLEANUP;
#endif
    /* Win32 needs the following to remove temp files */
#ifdef SHARELOCK
    flag |= APR_SHARELOCK;
#endif
    rc = apr_file_mktemp(fp, tmpl, flag, pool);

    if (rc == APR_SUCCESS) {
        apr_file_name_get(&data->fname, *fp);
        data->pool = pool;
        printf("fname=%s\n", data->fname);
    }
    else {
        apr_pool_cleanup_kill(pool, data, apreq_file_cleanup);
    }

    return rc;
}


int main(int argc, char **argv) {
  apr_status_t rc;
  apr_pool_t *p;
  apr_file_t *fp;
  int count=10, i;
  const char *path = NULL;

  if (argc == 2) count = atoi(argv[1]);

  rc = apr_app_initialize(&argc, &argv, NULL);
  for (i=0; i<count; i++) {
    rc = apr_pool_create(&p, NULL);
    rc = apreq_file_mktemp(&fp, p, path);
    if (rc != APR_SUCCESS) {
      printf("mktemp failed\n");
    }
    apr_file_printf(fp, "HAHAHAH\n");
    apr_pool_clear(p);
  }
  return 0;
}

  
  
  

Reply via email to