You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by yl...@apache.org on 2018/02/06 23:30:41 UTC

svn commit: r1823412 - /httpd/httpd/trunk/modules/slotmem/mod_slotmem_shm.c

Author: ylavic
Date: Tue Feb  6 23:30:41 2018
New Revision: 1823412

URL: http://svn.apache.org/viewvc?rev=1823412&view=rev
Log:
mod_slotmem_shm: follow up tp r1822509.

Check SHM sizes when reused, reload may have changed the needs.


Modified:
    httpd/httpd/trunk/modules/slotmem/mod_slotmem_shm.c

Modified: httpd/httpd/trunk/modules/slotmem/mod_slotmem_shm.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/slotmem/mod_slotmem_shm.c?rev=1823412&r1=1823411&r2=1823412&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/slotmem/mod_slotmem_shm.c (original)
+++ httpd/httpd/trunk/modules/slotmem/mod_slotmem_shm.c Tue Feb  6 23:30:41 2018
@@ -362,6 +362,32 @@ static apr_status_t slotmem_doall(ap_slo
     return retval;
 }
 
+static int check_slotmem(ap_slotmem_instance_t *mem, apr_size_t size,
+                         apr_size_t item_size, unsigned int item_num)
+{
+    sharedslotdesc_t *desc;
+
+    /* check size */
+    if (apr_shm_size_get(mem->shm) != size) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, APLOGNO(02599)
+                     "existing shared memory for %s could not be used "
+                     "(failed size check)",
+                     mem->name);
+        return 0;
+    }
+
+    desc = apr_shm_baseaddr_get(mem->shm);
+    if (desc->size != item_size || desc->num != item_num) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, APLOGNO(02600)
+                     "existing shared memory for %s could not be used "
+                     "(failed contents check)",
+                     mem->name);
+        return 0;
+    }
+
+    return 1;
+}
+
 static apr_status_t slotmem_create(ap_slotmem_instance_t **new,
                                    const char *name, apr_size_t item_size,
                                    unsigned int item_num,
@@ -382,13 +408,31 @@ static apr_status_t slotmem_create(ap_sl
     apr_status_t rv;
     apr_pool_t *p;
 
+    *new = NULL;
+
     if (slotmem_filenames(pool, name, &fname, persist ? &pname : NULL)) {
         /* first try to attach to existing slotmem */
         if (next) {
+            ap_slotmem_instance_t *prev = NULL;
             for (;;) {
                 if (strcmp(next->name, fname) == 0) {
+                    *new = next; /* either returned here or reused finally */
+                    if (!check_slotmem(next, size, item_size, item_num)) {
+                        apr_shm_destroy(next->shm);
+                        next = next->next;
+                        if (prev) {
+                            prev->next = next;
+                        }
+                        else {
+                            globallistmem = next;
+                        }
+                        if (next) {
+                            continue;
+                        }
+                        next = prev;
+                        break;
+                    }
                     /* we already have it */
-                    *new = next;
                     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02603)
                                  "create found %s in global list", fname);
                     return APR_SUCCESS;
@@ -396,6 +440,7 @@ static apr_status_t slotmem_create(ap_sl
                 if (!next->next) {
                      break;
                 }
+                prev = next;
                 next = next->next;
             }
         }
@@ -412,7 +457,6 @@ static apr_status_t slotmem_create(ap_sl
                  "create %s: %"APR_SIZE_T_FMT"/%u", fname, item_size,
                  item_num);
 
-
     {
         if (fbased) {
             apr_shm_remove(fname, pool);
@@ -460,10 +504,14 @@ static apr_status_t slotmem_create(ap_sl
     p = fbased ? gpool : pool;
     ptr = (char *)desc + AP_SLOTMEM_OFFSET;
 
-    /* For the chained slotmem stuff */
-    res = apr_pcalloc(p, sizeof(ap_slotmem_instance_t));
-    res->name = apr_pstrdup(p, fname);
-    res->pname = apr_pstrdup(p, pname);
+    /* For the chained slotmem stuff (*new may be reused from above) */
+    res = *new;
+    if (res == NULL) {
+        res = apr_pcalloc(p, sizeof(ap_slotmem_instance_t));
+        res->name = apr_pstrdup(p, fname);
+        res->pname = apr_pstrdup(p, pname);
+        *new = res;
+    }
     res->fbased = fbased;
     res->shm = shm;
     res->persist = (void *)ptr;
@@ -486,7 +534,6 @@ static apr_status_t slotmem_create(ap_sl
         }
     }
 
-    *new = res;
     return APR_SUCCESS;
 }