aaron 02/01/22 11:31:41
Modified: shmem/unix shm.c
Log:
Add some more comments and more robust error checking.
Changed the return error from apr_shm_attach if filename == NULL. Normally
in APR input parameters are not explicitly checked, but since in apr_shm
a NULL filename has a special meaning (anonymous memory) it will now
return APR_EINVAL in that case.
Revision Changes Path
1.8 +11 -8 apr/shmem/unix/shm.c
Index: shm.c
===================================================================
RCS file: /home/cvs/apr/shmem/unix/shm.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- shm.c 17 Jan 2002 00:32:22 -0000 1.7
+++ shm.c 22 Jan 2002 19:31:41 -0000 1.8
@@ -311,13 +311,19 @@
#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM ||
APR_USE_SHMEM_MMAP_ZERO
munmap(m->base, m->realsize);
apr_file_close(m->file);
+ /* FIXME: unlink the file */
#elif APR_USE_SHMEM_MMAP_ANON
munmap(m->base, m->realsize);
#elif APR_USE_SHMEM_SHMGET || APR_USE_SHMEM_SHMGET_ANON
+ /* Indicate that the segment is to be destroyed as soon
+ * as all processes have detached. This also disallows any
+ * new attachments to the segment. */
if (shmctl(m->shmid, IPC_RMID, NULL) == -1) {
return errno;
}
- shmdt(m->base);
+ if (shmdt(m->base) == -1) {
+ return errno;
+ }
#endif
return APR_SUCCESS;
@@ -330,12 +336,9 @@
apr_status_t status;
if (filename == NULL) {
-#if APR_USE_SHMEM_MMAP_ZERO || APR_USE_SHMEM_MMAP_ANON
- /* If they want anonymous memory they shouldn't call attach. */
- return APR_EGENERAL;
-#else
- return APR_ENOTIMPL;
-#endif
+ /* It doesn't make sense to attach to a segment if you don't know
+ * the filename. */
+ return APR_EINVAL;
}
else {
#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM
@@ -420,7 +423,7 @@
/* FIXME: munmap the segment. */
return APR_ENOTIMPL;
#elif APR_USE_SHMEM_SHMGET
- if (shmdt(m->base) < 0) {
+ if (shmdt(m->base) == -1) {
return errno;
}
return APR_SUCCESS;