View | Details | Raw Unified | Return to bug 62308
Collapse All | Expand All

(-)modules/slotmem/mod_slotmem_shm.c (-54 / +15 lines)
Lines 361-392 static apr_status_t slotmem_doall(ap_slotmem_insta Link Here
361
    return retval;
361
    return retval;
362
}
362
}
363
363
364
static int check_slotmem(ap_slotmem_instance_t *mem, apr_size_t size,
365
                         apr_size_t item_size, unsigned int item_num)
366
{
367
    sharedslotdesc_t *desc;
368
369
    /* check size */
370
    if (apr_shm_size_get(mem->shm) != size) {
371
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, APLOGNO(02599)
372
                     "existing shared memory for %s could not be used "
373
                     "(failed size check)",
374
                     mem->name);
375
        return 0;
376
    }
377
378
    desc = apr_shm_baseaddr_get(mem->shm);
379
    if (desc->size != item_size || desc->num != item_num) {
380
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, APLOGNO(02600)
381
                     "existing shared memory for %s could not be used "
382
                     "(failed contents check)",
383
                     mem->name);
384
        return 0;
385
    }
386
387
    return 1;
388
}
389
390
static apr_status_t slotmem_create(ap_slotmem_instance_t **new,
364
static apr_status_t slotmem_create(ap_slotmem_instance_t **new,
391
                                   const char *name, apr_size_t item_size,
365
                                   const char *name, apr_size_t item_size,
392
                                   unsigned int item_num,
366
                                   unsigned int item_num,
Lines 412-445 static apr_status_t slotmem_create(ap_slotmem_inst Link Here
412
    if (slotmem_filenames(pool, name, &fname, persist ? &pname : NULL)) {
386
    if (slotmem_filenames(pool, name, &fname, persist ? &pname : NULL)) {
413
        /* first try to attach to existing slotmem */
387
        /* first try to attach to existing slotmem */
414
        if (next) {
388
        if (next) {
415
            ap_slotmem_instance_t *prev = NULL;
416
            for (;;) {
389
            for (;;) {
417
                if (strcmp(next->name, fname) == 0) {
390
                if (strcmp(next->name, fname) == 0) {
418
                    *new = next; /* either returned here or reused finally */
391
                    desc = apr_shm_baseaddr_get(next->shm);
419
                    if (!check_slotmem(next, size, item_size, item_num)) {
392
                    if (desc->size != item_size) {
420
                        apr_shm_destroy(next->shm);
393
                        ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, APLOGNO(02599)
421
                        next = next->next;
394
                                     "existing shared memory for %s could not be reused "
422
                        if (prev) {
395
                                     "(failed size check)",
423
                            prev->next = next;
396
                                     next->name);
424
                        }
397
                        return APR_EINVAL;
425
                        else {
426
                            globallistmem = next;
427
                        }
428
                        if (next) {
429
                            continue;
430
                        }
431
                        next = prev;
432
                        break;
433
                    }
398
                    }
434
                    /* we already have it */
399
                    /* we already have it */
435
                    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02603)
400
                    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02603)
436
                                 "create found %s in global list", fname);
401
                                 "create found %s in global list", fname);
402
                    *new = next;
437
                    return APR_SUCCESS;
403
                    return APR_SUCCESS;
438
                }
404
                }
439
                if (!next->next) {
405
                if (!next->next) {
440
                     break;
406
                     break;
441
                }
407
                }
442
                prev = next;
443
                next = next->next;
408
                next = next->next;
444
            }
409
            }
445
        }
410
        }
Lines 512-525 static apr_status_t slotmem_create(ap_slotmem_inst Link Here
512
    p = fbased ? gpool : pool;
477
    p = fbased ? gpool : pool;
513
    ptr = (char *)desc + AP_SLOTMEM_OFFSET;
478
    ptr = (char *)desc + AP_SLOTMEM_OFFSET;
514
479
515
    /* For the chained slotmem stuff (*new may be reused from above) */
480
    /* For the chained slotmem stuff */
516
    res = *new;
481
    *new = res = apr_pcalloc(p, sizeof(ap_slotmem_instance_t));
517
    if (res == NULL) {
482
    res->name = apr_pstrdup(p, fname);
518
        res = apr_pcalloc(p, sizeof(ap_slotmem_instance_t));
483
    res->pname = apr_pstrdup(p, pname);
519
        res->name = apr_pstrdup(p, fname);
520
        res->pname = apr_pstrdup(p, pname);
521
        *new = res;
522
    }
523
    res->fbased = fbased;
484
    res->fbased = fbased;
524
    res->shm = shm;
485
    res->shm = shm;
525
    res->persist = (void *)ptr;
486
    res->persist = (void *)ptr;
Lines 534-544 static apr_status_t slotmem_create(ap_slotmem_inst Link Here
534
    res->next = NULL;
495
    res->next = NULL;
535
    res->inuse = ptr + basesize;
496
    res->inuse = ptr + basesize;
536
    if (fbased) {
497
    if (fbased) {
537
        if (globallistmem == NULL) {
498
        if (next) {
538
            globallistmem = res;
499
            next->next = res;
539
        }
500
        }
540
        else {
501
        else {
541
            next->next = res;
502
            globallistmem = res;
542
        }
503
        }
543
    }
504
    }
544
505

Return to bug 62308