void ssl_scache_shmht_init(server_rec *s, pool *p) { SSLModConfigRec *mc = myModConfig(); AP_MM *mm; table_t *ta; int ta_errno; int avail; int n; /* * Create shared memory segment */ if (mc->szSessionCacheDataFile == NULL) { ssl_log(s, SSL_LOG_ERROR, "SSLSessionCache required"); ssl_die(); } if ((mm = ap_mm_create(mc->nSessionCacheDataSize, mc->szSessionCacheDataFile)) == NULL) { ssl_log(s, SSL_LOG_ERROR, "Cannot allocate shared memory: %s", ap_mm_error()); ssl_die(); } mc->pSessionCacheDataMM = mm; /* * Make sure the childs have access to the underlaying files */ ap_mm_permission(mm, SSL_MM_FILE_MODE, ap_user_id, -1); /* * Create hash table in shared memory segment */ avail = ap_mm_available(mm); n = (avail/2) / 1024; n = n < 10 ? 10 : n; if ((ta = table_alloc(n, &ta_errno, ssl_scache_shmht_malloc, ssl_scache_shmht_calloc, ssl_scache_shmht_realloc, ssl_scache_shmht_free )) == NULL) { ssl_log(s, SSL_LOG_ERROR, "Cannot allocate hash table in shared memory: %s", table_strerror(ta_errno)); ssl_die(); } table_attr(ta, TABLE_FLAG_AUTO_ADJUST|TABLE_FLAG_ADJUST_DOWN); table_set_data_alignment(ta, sizeof(char *)); table_clear(ta); mc->tSessionCacheDataTable = ta; /* * Log the done work */ ssl_log(s, SSL_LOG_INFO, "Init: Created hash-table (%d buckets) " "in shared memory (%d bytes) for SSL session cache", n, avail); return; }
int main(int argc, char ** argv) { table_t *tab; int ret, iter_n = ITERATIONS, alignment = 0; long seed; argc--, argv++; /* set default seed */ seed = time(NULL); /* process the args */ for (; *argv != NULL; argv++, argc--) { if (**argv != '-') { continue; } switch (*(*argv + 1)) { case 'a': auto_adjust_b = 1; break; case 'A': if (argc > 0) { argv++, argc--; if (argc == 0) { usage(); } alignment = atoi(*argv); } break; case 'i': if (argc > 0) { argv++, argc--; if (argc == 0) { usage(); } iter_n = atoi(*argv); } break; case 'l': large_b = 1; break; case 's': if (argc > 0) { argv++, argc--; if (argc == 0) { usage(); } seed = atol(*argv); } break; case 'v': verbose_b = 1; break; default: usage(); break; } } if (argc > 0) { usage(); } (void)srandom(seed); (void)printf("Seed for random is %ld\n", seed); /* alloc the test table */ call_c++; tab = table_alloc(0, &ret); if (tab == NULL) { (void)printf("table_alloc returned: %s\n", table_strerror(ret)); exit(1); } if (auto_adjust_b) { ret = table_attr(tab, TABLE_FLAG_AUTO_ADJUST); if (ret != TABLE_ERROR_NONE) { (void)fprintf(stderr, "ERROR: could not set table for auto-adjust: %s\n", table_strerror(ret)); exit(1); } } if (alignment > 0) { ret = table_set_data_alignment(tab, alignment); if (ret != TABLE_ERROR_NONE) { (void)fprintf(stderr, "ERROR: could not set data alignment to %d: %s\n", alignment, table_strerror(ret)); exit(1); } } basic(tab); stress(tab, iter_n, 0); io_test(tab); order_test(tab); call_c++; ret = table_free(tab); if (ret != TABLE_ERROR_NONE) { (void)fprintf(stderr, "ERROR in table_free: %s\n", table_strerror(ret)); } (void)fputc('\n', stdout); (void)printf("Test program performed %d table calls\n", call_c); exit(0); }
void ssl_scache_shmht_init(server_rec *s, apr_pool_t *p) { SSLModConfigRec *mc = myModConfig(s); table_t *ta; int ta_errno; apr_size_t avail; int n; apr_status_t rv; /* * Create shared memory segment */ if (mc->szSessionCacheDataFile == NULL) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "SSLSessionCache required"); ssl_die(); } if ((rv = apr_shm_create(&(mc->pSessionCacheDataMM), mc->nSessionCacheDataSize, mc->szSessionCacheDataFile, mc->pPool)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, "Cannot allocate shared memory"); ssl_die(); } if ((rv = apr_rmm_init(&(mc->pSessionCacheDataRMM), NULL, apr_shm_baseaddr_get(mc->pSessionCacheDataMM), mc->nSessionCacheDataSize, mc->pPool)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, "Cannot initialize rmm"); ssl_die(); } ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "initialize MM %pp RMM %pp", mc->pSessionCacheDataMM, mc->pSessionCacheDataRMM); /* * Create hash table in shared memory segment */ avail = mc->nSessionCacheDataSize; n = (avail/2) / 1024; n = n < 10 ? 10 : n; /* * Passing server_rec as opt_param to table_alloc so that we can do * logging if required ssl_util_table. Otherwise, mc is sufficient. */ if ((ta = table_alloc(n, &ta_errno, ssl_scache_shmht_malloc, ssl_scache_shmht_calloc, ssl_scache_shmht_realloc, ssl_scache_shmht_free, s )) == NULL) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "Cannot allocate hash table in shared memory: %s", table_strerror(ta_errno)); ssl_die(); } table_attr(ta, TABLE_FLAG_AUTO_ADJUST|TABLE_FLAG_ADJUST_DOWN); table_set_data_alignment(ta, sizeof(char *)); table_clear(ta); mc->tSessionCacheDataTable = ta; /* * Log the done work */ ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, "Init: Created hash-table (%d buckets) " "in shared memory (%" APR_SIZE_T_FMT " bytes) for SSL session cache", n, avail); return; }