diff options
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | acconfig.h | 1 | ||||
-rw-r--r-- | configure.in | 162 | ||||
-rw-r--r-- | include/apr.h.in | 6 | ||||
-rw-r--r-- | shmem/unix/Makefile.in | 14 | ||||
-rw-r--r-- | shmem/unix/shmem.c | 222 | ||||
-rw-r--r-- | test/Makefile.in | 3 | ||||
-rw-r--r-- | test/testshmem.c | 109 |
8 files changed, 320 insertions, 201 deletions
@@ -1,4 +1,8 @@ Changes with APR b1 + + *) Move the necessary shared memory code from MM into APR and remove + our dependency upon MM. [Justin Erenkrantz] + *) Get apr_lock_file and apr_unlock_file working on Windows 9x. [Mladen Turk, Bill Stoddard] diff --git a/acconfig.h b/acconfig.h index 22047e545..3ceb016e0 100644 --- a/acconfig.h +++ b/acconfig.h @@ -14,6 +14,7 @@ #undef HAVE_POLLIN #undef HAVE_isascii #undef HAVE_SO_ACCEPTFILTER +#undef HAVE_MAP_ANON /* Cross process serialization techniques */ #undef USE_FLOCK_SERIALIZE diff --git a/configure.in b/configure.in index 738814133..382086dc0 100644 --- a/configure.in +++ b/configure.in @@ -200,13 +200,11 @@ case "$host:$CC" in APR_ADDTO(CFLAGS,-Kthread) ;; esac -LOCAL_MM_LIB="../shmem/unix/mm/libmm.la" config_subdirs="none" +INSTALL_SUBDIRS="none" case $host in i386-ibm-aix* | *-ibm-aix[1-2].* | *-ibm-aix3.* | *-ibm-aix4.1 | *-ibm-aix4.1.* | *-ibm-aix4.2 | *-ibm-aix4.2.*) OSDIR="aix" - config_subdirs="shmem/unix/mm" - USE_MM=yes eolstr="\\n" ;; *-os2*) @@ -214,7 +212,6 @@ case $host in APR_ADDTO(CFLAGS,-Zmt) OSDIR="os2" enable_threads="system_threads" - LOCAL_MM_LIB="" eolstr="\\r\\n" file_as_socket="0" ;; @@ -234,23 +231,19 @@ case $host in file_as_socket="0" ;; esac - LOCAL_MM_LIB="" ;; *os390) OSDIR="os390" - config_subdirs="shmem/unix/mm" - USE_MM=yes eolstr="\\n" ;; *) OSDIR="unix" - config_subdirs="shmem/unix/mm" - USE_MM=yes eolstr="\\n" ;; esac AC_SUBST(eolstr) +AC_SUBST(INSTALL_SUBDIRS) dnl For some platforms we need a version string which allows easy numeric dnl comparisons. @@ -390,73 +383,100 @@ AC_CHECK_FUNCS(getgrgid_r) dnl #----------------------------- Checking for Shared Memory Support echo $ac_n "${nl}Checking for Shared Memory Support...${nl}" -# run the MM config script regardless of whether we are going to use -# it or not. When we have a much better idea of who is using MM, we can -# run this on a more conditional basis. -mm_dir=shmem/unix/mm +AC_HAVE_HEADERS(sys/mman.h) +APR_CHECK_DEFINE(MAP_ANON, sys/mman.h) +AC_HAVE_FUNCS(mmap munmap shm_open shm_unlink) +APR_CHECK_FILE(/dev/zero) +AC_HAVE_HEADERS(sys/ipc.h sys/shm.h sys/file.h) +AC_HAVE_FUNCS(shmget shmat shmdt shmctl) +AC_HAVE_HEADERS(kernel/OS.h) +AC_HAVE_FUNCS(create_area) + +dnl Now we determine which one is our preference. +APR_BEGIN_DECISION([shared memory allocation method]) +APR_IFALLYES(header:sys/mman.h func:mmap func:munmap, + APR_DECIDE(USE_SHMEM_MMAP_TMP, + [Classical mmap() on temporary file])) +APR_IFALLYES(header:sys/mman.h func:mmap func:munmap func:shm_open dnl + func:shm_unlink, + APR_DECIDE(USE_SHMEM_MMAP_SHM, + [mmap() via POSIX.1 shm_open() on temporary file])) +APR_IFALLYES(header:sys/mman.h func:mmap func:munmap file:/dev/zero, + APR_DECIDE(USE_SHMEM_MMAP_ZERO, + [SVR4-style mmap() on /dev/zero])) +APR_IFALLYES(header:sys/ipc.h header:sys/shm.h header:sys/file.h dnl + func:shmget func:shmat func:shmdt func:shmctl, + APR_DECIDE(USE_SHMEM_SHMGET, [SysV IPC shmget()])) +APR_IFALLYES(header:sys/mman.h func:mmap func:munmap define:MAP_ANON, + APR_DECIDE(USE_SHMEM_MMAP_ANON, + [4.4BSD-style mmap() via MAP_ANON])) +APR_IFALLYES(header:kernel/OS.h func:create_area, + APR_DECIDE(USE_SHMEM_BEOS, [BeOS areas])) +APR_END_DECISION +AC_DEFINE_UNQUOTED($ac_decision) -dnl #----------------------------- Prepare mm directory for VPATH support -if test "$USE_MM" = "yes"; then - if test -n "$USE_VPATH"; then - test -d $mm_dir || $MKDIR $mm_dir +usemmaptmp="0" +usemmapshm="0" +usemmapzero="0" +useshmget="0" +usemmapanon="0" +usebeosarea="0" +mem_based="0" +file_based="1" - for i in shtool config.guess config.sub fbtool ltconfig \ - ltmain.sh mm_vers.c; do - test -r $mm_dir/$i || ln -s $abs_srcdir/$mm_dir/$i $mm_dir/$i - done - fi - APR_SUBDIR_CONFIG($config_subdirs) -fi +case $ac_decision in + USE_SHMEM_MMAP_TMP ) + usemmaptmp="1" + file_based="1" + ;; + USE_SHMEM_MMAP_SHM ) + usemmapshm="1" + mem_based="1" + ;; + USE_SHMEM_MMAP_ZERO ) + usemmapzero="1" + mem_based="1" + ;; + USE_SHMEM_SHMGET ) + useshmget="1" + mem_based="1" + ;; + USE_SHMEM_MMAP_ANON ) + usemmapanon="1" + mem_based="1" + ;; + USE_SHMEM_BEOS ) + usebeosarea="1" + mem_based="1" + ;; +esac -INSTALL_SUBDIRS=$config_subdirs -AC_SUBST(INSTALL_SUBDIRS) +dnl Do we have any shared memory support? +if test "$usemmaptmp$usemmapshm$usemmapzero$useshmget$usemmapanon$usebeosarea" = "000000"; then + sharedmem="0" +else + sharedmem="1" +fi -AC_MSG_CHECKING(for Shared memory support) -AC_ARG_ENABLE(shmem, - [ --enable-shmem Enable shared memory support in APR. ], - [ ], - ac_cv_enable_shmem="mm" ) +AC_SUBST(usemmaptmp) +AC_SUBST(usemmapshm) +AC_SUBST(usemmapzero) +AC_SUBST(useshmget) +AC_SUBST(usemmapanon) +AC_SUBST(usebeosarea) +AC_SUBST(sharedmem) +AC_SUBST(file_based) +AC_SUBST(mem_based) -sharedmem="0" -anonymous_shm="0" +dnl We only support anonymous shared memory in Unix currently. +anonymous_shm="1" filebased_shm="0" keybased_shm="0" -if test "$ac_cv_enable_shmem" = "mm"; then - sharedmem="1" - anonymous_shm="1" - AC_MSG_RESULT(anonymous) - if test "$USE_MM" = "yes"; then - LIBTOOL_LIBS="$abs_builddir/shmem/unix/mm/libmm.la" - fi -elif test "$ac_cv_enable_shmem" = "file"; then - sharedmem="1" - filebased_shm="1" - AC_MSG_RESULT(file based) -elif test "$ac_cv_enable_shmem" = "key"; then - sharedmem="1" - keybased_shm="1" - AC_MSG_RESULT(key based) -else - AC_MSG_RESULT(no) -fi -AC_SUBST(sharedmem) + AC_SUBST(anonymous_shm) AC_SUBST(filebased_shm) AC_SUBST(keybased_shm) -APR_CHECK_DEFINE(MM_SHMT_MMFILE, $srcdir/shmem/unix/mm/mm_conf.h) - -if test "$ac_cv_define_MM_SHMT_MMFILE" = "yes"; then - file_based="1" - mem_based="0" -else - file_based="0" - mem_based="1" -fi - -AC_SUBST(mem_based) -AC_SUBST(file_based) - if test ".$SYS_SW" = ".AIX"; then APR_ADDTO(CPPFLAGS,-U__STR__) case "$SYS_KV" in @@ -1306,7 +1326,6 @@ AC_SUBST(OSDIR) AC_SUBST(DEFAULT_OSDIR) AC_SUBST(EXEEXT) AC_SUBST(LIBTOOL_LIBS) -AC_SUBST(LOCAL_MM_LIB) echo "${nl}Construct Makefiles and header files." MAKEFILE1="Makefile strings/Makefile passwd/Makefile tables/Makefile build/Makefile" @@ -1376,9 +1395,6 @@ dnl #----------------------------- Fixup Makefiles for VPATH support changequote({,}) if test -n "$USE_VPATH"; then - if test -n "$USE_MM"; then - MAKEFILE3="$MAKEFILE3 $mm_dir/Makefile" - fi for makefile in $MAKEFILE1 $MAKEFILE2 $MAKEFILE3; do dir=`echo $makefile|sed 's%[^/][^/]*$%%'` (cat <<EOF @@ -1394,14 +1410,6 @@ EOF > tmp cp tmp $makefile done - if test -n "$USE_MM"; then - cat $mm_dir/Makefile | \ - sed \ - -e 's#\($(CFLAGS)\)#\1 -I$(srcdir) -I.#' \ - -e '/mm_global\.c/d' \ - > tmp - cp tmp $mm_dir/Makefile - fi rm -f tmp fi diff --git a/include/apr.h.in b/include/apr.h.in index c385a3b62..8c3c2ae59 100644 --- a/include/apr.h.in +++ b/include/apr.h.in @@ -62,6 +62,12 @@ #define APR_HAVE_SYS_WAIT_H @sys_waith@ #define APR_HAVE_UNISTD_H @unistdh@ +#define APR_USE_SHMEM_MMAP_TMP @usemmaptmp@ +#define APR_USE_SHMEM_MMAP_SHM @usemmapshm@ +#define APR_USE_SHMEM_MMAP_ZERO @usemmapzero@ +#define APR_USE_SHMEM_SHMGET @useshmget@ +#define APR_USE_SHMEM_BEOS @usebeosarea@ + #define APR_USE_FLOCK_SERIALIZE @flockser@ #define APR_USE_SYSVSEM_SERIALIZE @sysvser@ #define APR_USE_FCNTL_SERIALIZE @fcntlser@ diff --git a/shmem/unix/Makefile.in b/shmem/unix/Makefile.in index dc4cdf0fb..7b8e96223 100644 --- a/shmem/unix/Makefile.in +++ b/shmem/unix/Makefile.in @@ -1,20 +1,10 @@ -TARGETS = shmem.lo build-mm +TARGETS = shmem.lo # bring in rules.mk for standard functionality @INCLUDE_RULES@ INCDIR=../../include -INCDIR1=mm -INCLUDES=-I$(INCDIR) -I$(INCDIR1) - -x-local-clean: - (cd mm && $(MAKE) clean) - -x-local-distclean: - (cd mm && $(MAKE) distclean) - -build-mm: - (cd mm && $(MAKE) libmm.la) +INCLUDES=-I$(INCDIR) # DO NOT REMOVE diff --git a/shmem/unix/shmem.c b/shmem/unix/shmem.c index 825929e9c..0cf2826ab 100644 --- a/shmem/unix/shmem.c +++ b/shmem/unix/shmem.c @@ -52,61 +52,199 @@ * <http://www.apache.org/>. */ -#include "mm.h" #include "apr_general.h" #include "apr_shmem.h" +#include "apr_lock.h" +#include "apr_portable.h" #include "apr_errno.h" +/* + * This is the Unix implementation of shared memory. + * + * Currently, this code supports the following shared memory techniques: + * + * - mmap on a temporary file + * - mmap/shm_open on a temporary file (POSIX.1) + * - mmap with MAP_ANON (4.4BSD) + * - mmap /dev/zero (SVR4) + * - shmget (SysV) + * - create_area (BeOS) + */ + +#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO || APR_USE_SHMEM_MMAP_ANON +#include <sys/mman.h> +#elif APR_USE_SHMEM_SHMGET +#include <sys/ipc.h> +#include <sys/shm.h> +#include <sys/file.h> +#elif APR_USE_SHMEM_BEOS +#include <kernel/OS.h> +#endif + struct shmem_t { - MM *mm; + void *mem; + void *curmem; + apr_size_t length; + apr_lock_t *lock; + char *filename; +#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO + apr_file_t *file; +#elif APR_USE_SHMEM_MMAP_ANON + /* Nothing else. */ +#elif APR_USE_SHMEM_SHMGET + apr_os_file_t file; +#elif APR_USE_SHMEM_BEOS + area_id areaid; +#endif }; -APR_DECLARE(apr_status_t) apr_shm_init(struct shmem_t **m, apr_size_t reqsize, const char *file, apr_pool_t *cont) +APR_DECLARE(apr_status_t) apr_shm_init(apr_shmem_t **m, apr_size_t reqsize, + const char *filename, apr_pool_t *pool) { - MM *newmm = mm_create(reqsize + sizeof(**m), file, MM_ALLOCATE_ENOUGH); - if (newmm == NULL) { - return errno; - } - (*m) = mm_malloc(newmm, sizeof(struct shmem_t)); - /* important to check this; we may be locking a lock file for the first - * time, which won't work if the file is on NFS - */ - if (!*m) { - return errno; + apr_shmem_t *new_m; + int tmpfd; + void *mem; + +#if APR_USE_SHMEM_SHMGET + struct shmid_ds shmbuf; +#else + apr_status_t stat; +#endif + + new_m = apr_palloc(pool, sizeof(apr_shmem_t)); + if (!new_m) + return APR_ENOMEM; + +/* These implementations are very similar except for opening the file. */ +#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO + /* FIXME: Ignore error for now. * + *stat = apr_file_remove(filename, pool);*/ + +#if APR_USE_SHMEM_MMAP_TMP + /* FIXME: Is APR_OS_DEFAULT sufficient? */ + stat = apr_file_open(new_m->file, filename, + APR_READ | APR_WRITE | APR_CREATE, APR_OS_DEFAULT, + pool); + if (stat != APR_SUCCESS) + return APR_EGENERAL; + + tmpfd = apr_os_file_get(&tmpfd, new_m->file); + stat = apr_file_trunc(new_m->file, reqsize); + if (stat != APR_SUCCESS) + return APR_EGENERAL; + +#elif APR_USE_SHMEM_MMAP_SHM + /* FIXME: Is APR_OS_DEFAULT sufficient? */ + tmpfd = shm_open(filename, O_RDWR | O_CREAT, APR_OS_DEFAULT); + if (tmpfd == -1) + return errno + APR_OS_START_SYSERR; + + apr_os_file_put(new_m->file, &tmpfd, pool); + stat = apr_file_trunc(new_m->file, reqsize); + if (stat != APR_SUCCESS) + { + shm_unlink(filename); + return APR_EGENERAL; } - (*m)->mm = newmm; +#elif APR_USE_SHMEM_MMAP_ZERO + stat = apr_file_open(new_m->file, "/dev/zero", APR_READ | APR_WRITE, + APR_OS_DEFAULT); + if (stat != APR_SUCCESS) + return APR_EGENERAL; + tmpfd = apr_os_file_get(&tmpfd, new_m->file); +#endif + + mem = mmap(NULL, reqsize, PROT_READ|PROT_WRITE, MAP_SHARED, tmpfd, 0); + +#elif APR_USE_SHMEM_MMAP_ANON + mem = mmap(NULL, reqsize, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); +#elif APR_USE_SHMEM_SHMGET + tmpfd = shmget(IPC_PRIVATE, reqsize, (SHM_R|SHM_W|IPC_CREAT)); + if (tmpfd == -1) + return errno + APR_OS_START_SYSERR; + + new_m->file = tmpfd; + + mem = shmat(new_m->file, NULL, 0); + + /* FIXME: Handle errors. */ + if (shmctl(new_m->file, IPC_STAT, &shmbuf) == -1) + return errno + APR_OS_START_SYSERR; + + apr_current_userid(&shmbuf.shm_perm.uid, &shmbuf.shm_perm.gid, pool); + + if (shmctl(new_m->file, IPC_SET, &shmbuf) == -1) + return errno + APR_OS_START_SYSERR; + +#elif APR_USE_SHMEM_BEOS + new_m->area_id = create_area("mm", (void*)&mem, B_ANY_ADDRESS, reqsize, + B_LAZY_LOCK, B_READ_AREA|B_WRITE_AREA); + /* FIXME: error code? */ + if (new_m->area_id < 0) + return APR_EGENERAL; + +#endif + + new_m->mem = mem; + new_m->curmem = mem; + new_m->length = reqsize; + + apr_lock_create(&new_m->lock, APR_MUTEX, APR_CROSS_PROCESS, NULL, pool); + if (!new_m->lock) + return APR_EGENERAL; + + *m = new_m; return APR_SUCCESS; } -APR_DECLARE(apr_status_t) apr_shm_destroy(struct shmem_t *m) +APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shmem_t *m) { - mm_destroy(m->mm); +#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO + munmap(m->mem); + apr_file_close(m->file); +#elif APR_USE_SHMEM_MMAP_ANON + munmap(m->mem); +#elif APR_USE_SHMEM_SHMGET + shmdt(m->mem); +#elif APR_USE_SHMEM_BEOS + delete_area(new_m->area_id); +#endif + return APR_SUCCESS; } -APR_DECLARE(void *) apr_shm_malloc(struct shmem_t *c, apr_size_t reqsize) +APR_DECLARE(void *) apr_shm_malloc(apr_shmem_t *m, apr_size_t reqsize) { - if (c->mm == NULL) { - return NULL; + void *new; + new = NULL; + + apr_lock_acquire(m->lock); + /* Do we have enough space? */ + if ((m->curmem - m->mem + reqsize) <= m->length) + { + new = m->curmem; + m->curmem += reqsize; } - return mm_malloc(c->mm, reqsize); + apr_lock_release(m->lock); + return new; } -APR_DECLARE(void *) apr_shm_calloc(struct shmem_t *shared, apr_size_t size) +APR_DECLARE(void *) apr_shm_calloc(apr_shmem_t *m, apr_size_t reqsize) { - if (shared == NULL) { - return NULL; - } - return mm_calloc(shared->mm, 1, size); + void *new = apr_shm_malloc(m, reqsize); + memset(new, '\0', reqsize); + return new; } -APR_DECLARE(apr_status_t) apr_shm_free(struct shmem_t *shared, void *entity) +APR_DECLARE(apr_status_t) apr_shm_free(apr_shmem_t *shared, void *entity) { - mm_free(shared->mm, entity); + /* Without a memory management scheme within our shared memory, it + * is impossible to implement free. */ return APR_SUCCESS; } -APR_DECLARE(apr_status_t) apr_shm_name_get(apr_shmem_t *c, apr_shm_name_t **name) +APR_DECLARE(apr_status_t) apr_shm_name_get(apr_shmem_t *c, + apr_shm_name_t **name) { #if APR_USES_ANONYMOUS_SHM *name = NULL; @@ -121,7 +259,8 @@ APR_DECLARE(apr_status_t) apr_shm_name_get(apr_shmem_t *c, apr_shm_name_t **name #endif } -APR_DECLARE(apr_status_t) apr_shm_name_set(apr_shmem_t *c, apr_shm_name_t *name) +APR_DECLARE(apr_status_t) apr_shm_name_set(apr_shmem_t *c, + apr_shm_name_t *name) { #if APR_USES_ANONYMOUS_SHM return APR_ANONYMOUS; @@ -135,12 +274,12 @@ APR_DECLARE(apr_status_t) apr_shm_name_set(apr_shmem_t *c, apr_shm_name_t *name) #endif } -APR_DECLARE(apr_status_t) apr_shm_open(struct shmem_t *c) +APR_DECLARE(apr_status_t) apr_shm_open(apr_shmem_t *c) { #if APR_USES_ANONYMOUS_SHM -/* When using MM, we don't need to open shared memory segments in child - * segments, so just return immediately. +/* we don't need to open shared memory segments in child segments, so + * just return immediately. */ return APR_SUCCESS; /* Currently, we are not supporting name based shared memory on Unix @@ -153,11 +292,18 @@ APR_DECLARE(apr_status_t) apr_shm_open(struct shmem_t *c) #endif } -APR_DECLARE(apr_status_t) apr_shm_avail(struct shmem_t *c, apr_size_t *size) +APR_DECLARE(apr_status_t) apr_shm_avail(apr_shmem_t *m, apr_size_t *size) { - *size = mm_available(c); - if (*size == 0) { - return APR_ENOSHMAVAIL; - } - return APR_SUCCESS; + apr_status_t stat; + + stat = APR_ENOSHMAVAIL; + + apr_lock_acquire(m->lock); + + *size = m->length - (m->curmem - m->mem); + if (*size) + stat = APR_SUCCESS; + + apr_lock_release(m->lock); + return stat; } diff --git a/test/Makefile.in b/test/Makefile.in index 2eb90b680..3e97ad5e3 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -35,8 +35,7 @@ TARGETS = $(PROGRAMS) # bring in rules.mk for standard functionality @INCLUDE_RULES@ -LOCAL_LIBS=../libapr.la @LOCAL_MM_LIB@ -##../shmem/unix/mm/libmm.la +LOCAL_LIBS=../libapr.la CLEAN_TARGETS = testfile.tmp testdso@EXEEXT@ mod_test.so diff --git a/test/testshmem.c b/test/testshmem.c index 6b685576c..5c705451c 100644 --- a/test/testshmem.c +++ b/test/testshmem.c @@ -85,7 +85,7 @@ static void msgwait(int boxnum) apr_sleep(0); test = boxes[boxnum].msgavail; } - fprintf(stdout, "\nreceived a message in box %d, message was: %s\n", + fprintf(stdout, "received a message in box %d, message was: %s\n", boxnum, boxes[boxnum].msg); } @@ -145,7 +145,7 @@ int main(void) printf("Smallest allocation will be %" APR_SIZE_T_FMT " bytes\n", psize[0]); printf("Largest allocation will be %" APR_SIZE_T_FMT " bytes\n", - psize[CYCLES -1]); + psize[CYCLES - 1]); printf("I will be doing it in %d steps\n", CYCLES); printf("\tAllocating via apr_shm_malloc..............."); @@ -167,45 +167,35 @@ int main(void) } printf("OK\n"); - printf("\tAllocating via apr_shm_calloc..............."); - for (cntr = CYCLES-1;cntr > -1;cntr--){ - ptrs[cntr] = apr_shm_malloc(shm, psize[cntr]); - if (ptrs[cntr] == NULL){ - printf("Failed at %" APR_SIZE_T_FMT" bytes\n", - psize[cntr]); - exit (-1); - } - } - printf("OK\n\tFreeing....................................."); - for (cntr = 0;cntr < CYCLES;cntr++){ - if (apr_shm_free(shm, ptrs[cntr]) != APR_SUCCESS){ - printf("Failed at step %d, %" APR_SIZE_T_FMT - " bytes\n", cntr, psize[cntr]); - exit (-1); - } - } - printf("OK\n"); - - printf("Checking we have all we should have remaining......."); + printf("\tDetermining how much space is remaining....."); rv = apr_shm_avail(shm, &cksize); if (rv == APR_ENOTIMPL){ - printf("Not Impl.\n"); + printf("Not Impl."); } else { if (rv != APR_SUCCESS){ printf("Failed!\n"); exit (-1); } - if (cksize == (TESTSIZE - size)){ - printf ("OK\n"); - } else { - printf ("Failed.\nShould have had %" APR_SIZE_T_FMT - " bytes, instead there are %" - APR_SIZE_T_FMT " bytes :(\n", - TESTSIZE - size, cksize); - exit(-1); - } + printf("%" APR_SIZE_T_FMT, cksize); + } + printf("\n\t%d cycles of malloc and calloc passed.", CYCLES); + + printf("\n\nClearing shmem segment.............................."); + rv = apr_shm_destroy(shm); + if (rv != APR_SUCCESS) + { + printf("Failed\n"); + exit(-1); + } + printf("OK\n"); + + printf("Recreating shared memory block (%" APR_SIZE_T_FMT " bytes)......", + TESTSIZE); + if (apr_shm_init(&shm, TESTSIZE, NULL, context) != APR_SUCCESS) { + fprintf(stderr, "Error allocating shared memory block\n"); + exit(-1); } - printf("%d cycles of malloc and calloc passed.\n\n", CYCLES); + fprintf(stdout, "OK\n"); printf("Block test.\n"); printf("\tI am about to allocate %" APR_SIZE_T_FMT @@ -223,49 +213,24 @@ int main(void) } printf ("OK\n"); - printf ("\tAbout to allocate %d blocks of %d bytes....", CYCLES, SIZE); - for (cntr = 0;cntr < CYCLES;cntr++){ - if ((ptrs[cntr] = apr_shm_malloc(shm, SIZE)) == NULL){ - printf("Failed.\n"); - printf("Couldn't allocate block %d\n", cntr + 1); - exit (-1); - } - } - printf("Complete.\n"); - - printf ("\tAbout to free %d blocks of %d bytes........", CYCLES, SIZE); - for (cntr = 0;cntr < CYCLES;cntr++){ - if ((rv = apr_shm_free(shm, ptrs[cntr])) != APR_SUCCESS){ - printf("Failed\n"); - printf("Counldn't free block %d\n", cntr + 1); - exit (-1); - } + printf("Clearing shmem segment.............................."); + rv = apr_shm_destroy(shm); + if (rv != APR_SUCCESS) + { + printf("Failed\n"); + exit(-1); } - printf("Complete.\n"); + printf("OK\n"); - printf("Checking we have all we should have remaining......."); - rv = apr_shm_avail(shm, &cksize); - if (rv == APR_ENOTIMPL){ - printf("Not Impl.\n"); - } else { - if (rv != APR_SUCCESS){ - printf("Failed!\n"); - exit (-1); - } - if (cksize == (TESTSIZE - size)){ - printf ("OK\n"); - } else { - printf ("Failed.\nShould have had %" - APR_SIZE_T_FMT " bytes, instead there are %" - APR_SIZE_T_FMT " bytes :(\n", - TESTSIZE - size, cksize); - exit(-1); - } + printf("Recreating shared memory block (%" APR_SIZE_T_FMT " bytes)......", + TESTSIZE); + if (apr_shm_init(&shm, TESTSIZE, NULL, context) != APR_SUCCESS) { + fprintf(stderr, "Error allocating shared memory block\n"); + exit(-1); } + fprintf(stdout, "OK\n"); - printf("Block test complete.\n\n"); - - printf("Creating a child process\n"); + printf("Shared Process Test (child/parent)\n"); pid = fork(); if (pid == 0) { apr_sleep(1); |