Lines 26-31
Link Here
|
26 |
#include "httpd.h" |
26 |
#include "httpd.h" |
27 |
#include "http_main.h" |
27 |
#include "http_main.h" |
28 |
#include "http_core.h" |
28 |
#include "http_core.h" |
|
|
29 |
#include "ap_mpm.h" |
29 |
|
30 |
|
30 |
#define AP_SLOTMEM_IS_PREGRAB(t) (t->desc->type & AP_SLOTMEM_TYPE_PREGRAB) |
31 |
#define AP_SLOTMEM_IS_PREGRAB(t) (t->desc->type & AP_SLOTMEM_TYPE_PREGRAB) |
31 |
#define AP_SLOTMEM_IS_PERSIST(t) (t->desc->type & AP_SLOTMEM_TYPE_PERSIST) |
32 |
#define AP_SLOTMEM_IS_PERSIST(t) (t->desc->type & AP_SLOTMEM_TYPE_PERSIST) |
Lines 42-48
typedef struct {
Link Here
|
42 |
#define AP_UNSIGNEDINT_OFFSET (APR_ALIGN_DEFAULT(sizeof(unsigned int))) |
43 |
#define AP_UNSIGNEDINT_OFFSET (APR_ALIGN_DEFAULT(sizeof(unsigned int))) |
43 |
|
44 |
|
44 |
struct ap_slotmem_instance_t { |
45 |
struct ap_slotmem_instance_t { |
45 |
char *name; /* file based SHM path/name */ |
46 |
char *name; /* file based SHM name (immutable) */ |
|
|
47 |
char *fname; /* file based SHM path/name */ |
46 |
char *pname; /* persisted file path/name */ |
48 |
char *pname; /* persisted file path/name */ |
47 |
int fbased; /* filebased? */ |
49 |
int fbased; /* filebased? */ |
48 |
void *shm; /* ptr to memory segment (apr_shm_t *) */ |
50 |
void *shm; /* ptr to memory segment (apr_shm_t *) */ |
Lines 320-326
static apr_status_t cleanup_slotmem(void *is_start
Link Here
|
320 |
* unlink, thus call destroy() first. |
322 |
* unlink, thus call destroy() first. |
321 |
*/ |
323 |
*/ |
322 |
apr_shm_destroy(mem->shm); |
324 |
apr_shm_destroy(mem->shm); |
323 |
apr_shm_remove(mem->name, mem->pool); |
325 |
apr_shm_remove(mem->fname, mem->pool); |
324 |
} |
326 |
} |
325 |
} |
327 |
} |
326 |
|
328 |
|
Lines 368-386
static int check_slotmem(ap_slotmem_instance_t *me
Link Here
|
368 |
|
370 |
|
369 |
/* check size */ |
371 |
/* check size */ |
370 |
if (apr_shm_size_get(mem->shm) != size) { |
372 |
if (apr_shm_size_get(mem->shm) != size) { |
371 |
ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, APLOGNO(02599) |
373 |
ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf, APLOGNO(02599) |
372 |
"existing shared memory for %s could not be used " |
374 |
"existing shared memory for %s could not be reused " |
373 |
"(failed size check)", |
375 |
"(failed size check)", |
374 |
mem->name); |
376 |
mem->fname); |
375 |
return 0; |
377 |
return 0; |
376 |
} |
378 |
} |
377 |
|
379 |
|
378 |
desc = apr_shm_baseaddr_get(mem->shm); |
380 |
desc = apr_shm_baseaddr_get(mem->shm); |
379 |
if (desc->size != item_size || desc->num != item_num) { |
381 |
if (desc->size != item_size || desc->num != item_num) { |
380 |
ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, APLOGNO(02600) |
382 |
ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf, APLOGNO(02600) |
381 |
"existing shared memory for %s could not be used " |
383 |
"existing shared memory for %s could not be reused " |
382 |
"(failed contents check)", |
384 |
"(failed contents check)", |
383 |
mem->name); |
385 |
mem->fname); |
384 |
return 0; |
386 |
return 0; |
385 |
} |
387 |
} |
386 |
|
388 |
|
Lines 387-392
static int check_slotmem(ap_slotmem_instance_t *me
Link Here
|
387 |
return 1; |
389 |
return 1; |
388 |
} |
390 |
} |
389 |
|
391 |
|
|
|
392 |
static apr_status_t slotmem_attach_shm(apr_shm_t **shm, const char **fname, |
393 |
int generation, apr_pool_t *pool) |
394 |
{ |
395 |
for (; generation > 0; --generation) { |
396 |
const char *gname = apr_psprintf(pool, "%s.%i", *fname, generation); |
397 |
if (apr_shm_attach(shm, gname, pool) == APR_SUCCESS) { |
398 |
*fname = gname; |
399 |
return APR_SUCCESS; |
400 |
} |
401 |
} |
402 |
return apr_shm_attach(shm, *fname, pool); |
403 |
} |
404 |
|
390 |
static apr_status_t slotmem_create(ap_slotmem_instance_t **new, |
405 |
static apr_status_t slotmem_create(ap_slotmem_instance_t **new, |
391 |
const char *name, apr_size_t item_size, |
406 |
const char *name, apr_size_t item_size, |
392 |
unsigned int item_num, |
407 |
unsigned int item_num, |
Lines 404-413
static apr_status_t slotmem_create(ap_slotmem_inst
Link Here
|
404 |
apr_size_t size = AP_SLOTMEM_OFFSET + AP_UNSIGNEDINT_OFFSET + |
419 |
apr_size_t size = AP_SLOTMEM_OFFSET + AP_UNSIGNEDINT_OFFSET + |
405 |
(item_num * sizeof(char)) + basesize; |
420 |
(item_num * sizeof(char)) + basesize; |
406 |
int persist = (type & AP_SLOTMEM_TYPE_PERSIST) != 0; |
421 |
int persist = (type & AP_SLOTMEM_TYPE_PERSIST) != 0; |
|
|
422 |
int generation = 0; |
407 |
apr_status_t rv; |
423 |
apr_status_t rv; |
408 |
apr_pool_t *p; |
424 |
apr_pool_t *p; |
409 |
|
425 |
|
410 |
*new = NULL; |
426 |
*new = NULL; |
|
|
427 |
ap_mpm_query(AP_MPMQ_GENERATION, &generation); |
411 |
|
428 |
|
412 |
if (slotmem_filenames(pool, name, &fname, persist ? &pname : NULL)) { |
429 |
if (slotmem_filenames(pool, name, &fname, persist ? &pname : NULL)) { |
413 |
/* first try to attach to existing slotmem */ |
430 |
/* first try to attach to existing slotmem */ |
Lines 414-423
static apr_status_t slotmem_create(ap_slotmem_inst
Link Here
|
414 |
if (next) { |
431 |
if (next) { |
415 |
ap_slotmem_instance_t *prev = NULL; |
432 |
ap_slotmem_instance_t *prev = NULL; |
416 |
for (;;) { |
433 |
for (;;) { |
417 |
if (strcmp(next->name, fname) == 0) { |
434 |
if (strcmp(next->name, name) == 0) { |
418 |
*new = next; /* either returned here or reused finally */ |
435 |
*new = next; /* either returned here or reused finally */ |
419 |
if (!check_slotmem(next, size, item_size, item_num)) { |
436 |
if (!check_slotmem(next, size, item_size, item_num)) { |
|
|
437 |
/* Can't reuse this SHM, a new one is needed with its |
438 |
* own filename (including generation number) because |
439 |
* the previous one may still be used by the previous |
440 |
* generation. Persisted file (if any) can't be reused |
441 |
* either. |
442 |
*/ |
420 |
apr_shm_destroy(next->shm); |
443 |
apr_shm_destroy(next->shm); |
|
|
444 |
apr_shm_remove(next->fname, pool); |
445 |
fname = apr_psprintf(pool, "%s.%i", fname, generation); |
446 |
persist = 0; |
447 |
|
421 |
next = next->next; |
448 |
next = next->next; |
422 |
if (prev) { |
449 |
if (prev) { |
423 |
prev->next = next; |
450 |
prev->next = next; |
Lines 463-469
static apr_status_t slotmem_create(ap_slotmem_inst
Link Here
|
463 |
* parent exist in the children already; only attach them. |
490 |
* parent exist in the children already; only attach them. |
464 |
*/ |
491 |
*/ |
465 |
if (is_child_process()) { |
492 |
if (is_child_process()) { |
466 |
rv = apr_shm_attach(&shm, fname, gpool); |
493 |
rv = slotmem_attach_shm(&shm, &fname, generation, pool); |
467 |
} |
494 |
} |
468 |
else { |
495 |
else { |
469 |
apr_shm_remove(fname, pool); |
496 |
apr_shm_remove(fname, pool); |
Lines 516-525
static apr_status_t slotmem_create(ap_slotmem_inst
Link Here
|
516 |
res = *new; |
543 |
res = *new; |
517 |
if (res == NULL) { |
544 |
if (res == NULL) { |
518 |
res = apr_pcalloc(p, sizeof(ap_slotmem_instance_t)); |
545 |
res = apr_pcalloc(p, sizeof(ap_slotmem_instance_t)); |
519 |
res->name = apr_pstrdup(p, fname); |
546 |
res->name = apr_pstrdup(p, name); |
520 |
res->pname = apr_pstrdup(p, pname); |
547 |
res->pname = apr_pstrdup(p, pname); |
521 |
*new = res; |
548 |
*new = res; |
522 |
} |
549 |
} |
|
|
550 |
res->fname = apr_pstrdup(p, fname); |
523 |
res->fbased = fbased; |
551 |
res->fbased = fbased; |
524 |
res->shm = shm; |
552 |
res->shm = shm; |
525 |
res->persist = (void *)ptr; |
553 |
res->persist = (void *)ptr; |
Lines 554-563
static apr_status_t slotmem_attach(ap_slotmem_inst
Link Here
|
554 |
ap_slotmem_instance_t *res; |
582 |
ap_slotmem_instance_t *res; |
555 |
ap_slotmem_instance_t *next = globallistmem; |
583 |
ap_slotmem_instance_t *next = globallistmem; |
556 |
sharedslotdesc_t *desc; |
584 |
sharedslotdesc_t *desc; |
|
|
585 |
int generation = 0; |
557 |
const char *fname; |
586 |
const char *fname; |
558 |
apr_shm_t *shm; |
587 |
apr_shm_t *shm; |
559 |
apr_status_t rv; |
588 |
apr_status_t rv; |
560 |
|
589 |
|
|
|
590 |
*new = NULL; |
591 |
ap_mpm_query(AP_MPMQ_GENERATION, &generation); |
592 |
|
561 |
if (!slotmem_filenames(pool, name, &fname, NULL)) { |
593 |
if (!slotmem_filenames(pool, name, &fname, NULL)) { |
562 |
return APR_ENOSHMAVAIL; |
594 |
return APR_ENOSHMAVAIL; |
563 |
} |
595 |
} |
Lines 568-574
static apr_status_t slotmem_attach(ap_slotmem_inst
Link Here
|
568 |
/* first try to attach to existing slotmem */ |
600 |
/* first try to attach to existing slotmem */ |
569 |
if (next) { |
601 |
if (next) { |
570 |
for (;;) { |
602 |
for (;;) { |
571 |
if (strcmp(next->name, fname) == 0) { |
603 |
if (strcmp(next->name, name) == 0) { |
572 |
/* we already have it */ |
604 |
/* we already have it */ |
573 |
*new = next; |
605 |
*new = next; |
574 |
*item_size = next->desc->size; |
606 |
*item_size = next->desc->size; |
Lines 587-593
static apr_status_t slotmem_attach(ap_slotmem_inst
Link Here
|
587 |
} |
619 |
} |
588 |
|
620 |
|
589 |
/* next try to attach to existing shared memory */ |
621 |
/* next try to attach to existing shared memory */ |
590 |
rv = apr_shm_attach(&shm, fname, pool); |
622 |
rv = slotmem_attach_shm(&shm, &fname, generation, pool); |
591 |
if (rv != APR_SUCCESS) { |
623 |
if (rv != APR_SUCCESS) { |
592 |
return rv; |
624 |
return rv; |
593 |
} |
625 |
} |
Lines 598-604
static apr_status_t slotmem_attach(ap_slotmem_inst
Link Here
|
598 |
|
630 |
|
599 |
/* For the chained slotmem stuff */ |
631 |
/* For the chained slotmem stuff */ |
600 |
res = apr_pcalloc(pool, sizeof(ap_slotmem_instance_t)); |
632 |
res = apr_pcalloc(pool, sizeof(ap_slotmem_instance_t)); |
601 |
res->name = apr_pstrdup(pool, fname); |
633 |
res->name = apr_pstrdup(pool, name); |
|
|
634 |
res->fname = apr_pstrdup(pool, fname); |
602 |
res->fbased = 1; |
635 |
res->fbased = 1; |
603 |
res->shm = shm; |
636 |
res->shm = shm; |
604 |
res->persist = (void *)ptr; |
637 |
res->persist = (void *)ptr; |