static void mpool_test002(void){ mpool_t *pool; pool = mpool_create(0); char *c1; char *c2; char *c3; char *c4; char *c5; c1 = mpool_alloc(sizeof(*c1), pool); c2 = mpool_alloc(sizeof(*c2), pool); c3 = mpool_alloc(sizeof(*c3), pool); c4 = mpool_alloc(sizeof(*c4), pool); c5 = mpool_alloc(sizeof(*c5), pool); *c1 = 'a'; *c2 = 'b'; *c3 = 'c'; *c4 = 'd'; *c5 = 'e'; CU_ASSERT(*c1 == 'a'); CU_ASSERT(*c2 == 'b'); CU_ASSERT(*c3 == 'c'); CU_ASSERT(*c4 == 'd'); CU_ASSERT(*c5 == 'e'); CU_ASSERT(IS_ALIGNED(c1)); CU_ASSERT(IS_ALIGNED(c2)); CU_ASSERT(IS_ALIGNED(c3)); CU_ASSERT(IS_ALIGNED(c4)); CU_ASSERT(IS_ALIGNED(c5)); mpool_destroy(pool); }
static void mpool_test005(void){ mpool_t *pool; pool = mpool_create(10); typedef struct st_s { int n; char c; } st_t; st_t *st; int *n; st = mpool_alloc(sizeof(*st), pool); n = mpool_alloc(sizeof(*n), pool); st->n = 5; st->c = 'a'; *n = 10; CU_ASSERT(st->n == 5); CU_ASSERT(st->c == 'a'); CU_ASSERT(*n == 10); CU_ASSERT(IS_ALIGNED(st)); CU_ASSERT(IS_ALIGNED(n)); mpool_destroy(pool); }
static void rteardown(void) { regex_list_done(&matcher); #ifdef USE_MPOOL mpool_destroy(matcher.mempool); #endif }
END_TEST START_TEST (test_bm_scanbuff) { struct cli_matcher *root; const char *virname = NULL; int ret; root = (struct cli_matcher *) cli_calloc(1, sizeof(struct cli_matcher)); fail_unless(root != NULL, "root == NULL"); #ifdef USE_MPOOL root->mempool = mpool_create(); #endif ret = cli_bm_init(root); fail_unless(ret == CL_SUCCESS, "cli_bm_init() failed"); ret = cli_parse_add(root, "Sig1", "deadbabe", 0, 0, NULL, 0, NULL, 0); fail_unless(ret == CL_SUCCESS, "cli_parse_add() failed"); ret = cli_parse_add(root, "Sig2", "deadbeef", 0, 0, NULL, 0, NULL, 0); fail_unless(ret == CL_SUCCESS, "cli_parse_add() failed"); ret = cli_parse_add(root, "Sig3", "babedead", 0, 0, NULL, 0, NULL, 0); fail_unless(ret == CL_SUCCESS, "cli_parse_add() failed"); ret = cli_bm_scanbuff("blah\xde\xad\xbe\xef", 12, &virname, root, 0, 0, -1); fail_unless(ret == CL_VIRUS, "cli_bm_scanbuff() failed"); fail_unless(!strncmp(virname, "Sig2", 4), "Incorrect signature matched in cli_bm_scanbuff()\n"); cli_bm_free(root); #ifdef USE_MPOOL mpool_destroy(root->mempool); #endif free(root); }
void dconf_teardown(void) { mpool_free(pool, dconf); #ifdef USE_MPOOL if (pool) mpool_destroy(pool); #endif }
static void mpool_test001(void){ mpool_t *pool; pool = mpool_create(0); char *c; c = mpool_alloc(sizeof(*c), pool); *c = 'a'; CU_ASSERT(*c == 'a'); CU_ASSERT(IS_ALIGNED(c)); mpool_destroy(pool); }
static void mpool_test004(void){ mpool_t *pool; pool = mpool_create(0); const char *cs[] = {"cubicdaiya", "bokko"}; char *s1; char *s2; s1 = mpool_alloc(strlen(cs[0]) + 1, pool); s2 = mpool_alloc(strlen(cs[1]) + 1, pool); strcpy(s1, cs[0]); strcpy(s2, cs[1]); CU_ASSERT(strncmp(s1, cs[0], strlen(s1)) == 0); CU_ASSERT(strncmp(s2, cs[1], strlen(s2)) == 0); CU_ASSERT(IS_ALIGNED(s1)); CU_ASSERT(IS_ALIGNED(s2)); mpool_destroy(pool); }
void bst_destroy(mpool_t *pool) { mpool_destroy(pool); }
static void mpool_test003(void){ mpool_t *pool; pool = mpool_create(16); bool *b; short *s; char *c; unsigned char *uc; int *n; unsigned int *un; long *l; unsigned long *ul; long long *ll; unsigned long long *ull; float *f; double *d; long double *ld; time_t *t; off_t *ot; intptr_t *ipt; size_t *siz; ptrdiff_t *pdt; b = mpool_alloc(sizeof(*b), pool); s = mpool_alloc(sizeof(*s), pool); c = mpool_alloc(sizeof(*c), pool); uc = mpool_alloc(sizeof(*uc), pool); n = mpool_alloc(sizeof(*n), pool); un = mpool_alloc(sizeof(*un), pool); l = mpool_alloc(sizeof(*l), pool); ul = mpool_alloc(sizeof(*ul), pool); ll = mpool_alloc(sizeof(*ll), pool); ull = mpool_alloc(sizeof(*ull), pool); f = mpool_alloc(sizeof(*f), pool); d = mpool_alloc(sizeof(*d), pool); ld = mpool_alloc(sizeof(*ld), pool); t = mpool_alloc(sizeof(*t), pool); ot = mpool_alloc(sizeof(*ot), pool); ipt = mpool_alloc(sizeof(*ipt), pool); siz = mpool_alloc(sizeof(*siz), pool); pdt = mpool_alloc(sizeof(*pdt), pool); *b = true; *s = 2; *c = 'a'; *uc = 'b'; *n = 5; *un = 255; *l = 550; *ul = 333; *ll = 950; *ull = 111; *f = 113.5; *d = 50.8; *ld = 115.3; *t = 123; *ot = 22; *ipt = 33; *siz = 55; *pdt = 150; CU_ASSERT(*b == true); CU_ASSERT(*s == 2); CU_ASSERT(*c == 'a'); CU_ASSERT(*uc == 'b'); CU_ASSERT(*n == 5); CU_ASSERT(*un == 255); CU_ASSERT(*l == 550); CU_ASSERT(*ul == 333); CU_ASSERT(*ll == 950); CU_ASSERT(*ull == 111); CU_ASSERT(*f == 113.5); CU_ASSERT(*d == 50.8); CU_ASSERT(*ld == 115.3); CU_ASSERT(*t == 123); CU_ASSERT(*ot == 22); CU_ASSERT(*ipt == 33); CU_ASSERT(*siz == 55); CU_ASSERT(*pdt == 150); CU_ASSERT(IS_ALIGNED(b)); CU_ASSERT(IS_ALIGNED(s)); CU_ASSERT(IS_ALIGNED(c)); CU_ASSERT(IS_ALIGNED(uc)); CU_ASSERT(IS_ALIGNED(n)); CU_ASSERT(IS_ALIGNED(un)); CU_ASSERT(IS_ALIGNED(l)); CU_ASSERT(IS_ALIGNED(ul)); CU_ASSERT(IS_ALIGNED(ll)); CU_ASSERT(IS_ALIGNED(ull)); CU_ASSERT(IS_ALIGNED(f)); CU_ASSERT(IS_ALIGNED(d)); CU_ASSERT(IS_ALIGNED(ld)); CU_ASSERT(IS_ALIGNED(t)); CU_ASSERT(IS_ALIGNED(ot)); CU_ASSERT(IS_ALIGNED(ipt)); CU_ASSERT(IS_ALIGNED(siz)); CU_ASSERT(IS_ALIGNED(pdt)); mpool_destroy(pool); }
int main (int argc, char *argv[]) { pthread_t th[NA_ENV_MAX]; na_env_t *env[NA_ENV_MAX]; mpool_t *env_pool; int c; int env_cnt = 0; bool is_daemon = false; struct json_object *conf_obj = NULL; struct json_object *environments_obj = NULL; while (-1 != (c = getopt(argc, argv, "f:" /* configuration file with JSON */ "t:" /* check configuration file */ "d" /* go to background */ "v" /* show version and information */ "h" /* show help */ ))) { switch (c) { case 'd': is_daemon = true; break; case 'f': ConfFile = optarg; conf_obj = na_get_conf(optarg); environments_obj = na_get_environments(conf_obj, &env_cnt); break; case 't': conf_obj = na_get_conf(optarg); environments_obj = na_get_environments(conf_obj, &env_cnt); printf("JSON configuration is OK\n"); return 0; break; case 'v': na_version(); return 0; break; case 'h': na_usage(); return 0; break; default: break; } } if (is_daemon && daemon(0, 0) == -1) { NA_DIE_WITH_ERROR(NA_ERROR_FAILED_DAEMONIZE); } if (env_cnt > NA_ENV_MAX) { NA_DIE_WITH_ERROR(NA_ERROR_TOO_MANY_ENVIRONMENTS); } StartTimestamp = time(NULL); na_setup_signals(); na_memproto_bm_skip_init(); env_pool = mpool_create(0); if (env_cnt == 0) { env_cnt = 1; env[0] = na_env_add(&env_pool); na_env_setup_default(env[0], 0); } else { for (int i=0;i<env_cnt;++i) { env[i] = na_env_add(&env_pool); na_env_setup_default(env[i], i); na_conf_env_init(environments_obj, env[i], i, false); } } json_object_put(conf_obj); for (int i=0;i<env_cnt;++i) { env[i]->current_conn = 0; env[i]->is_refused_active = false; env[i]->is_refused_accept = false; env[i]->is_worker_busy = calloc(sizeof(bool), env[i]->worker_max); for (int j=0;j<env[i]->worker_max;++j) { env[i]->is_worker_busy[j] = false; } env[i]->error_count = 0; env[i]->current_conn_max = 0; pthread_mutex_init(&env[i]->lock_connpool, NULL); pthread_mutex_init(&env[i]->lock_current_conn, NULL); pthread_mutex_init(&env[i]->lock_tid, NULL); pthread_mutex_init(&env[i]->lock_loop, NULL); pthread_mutex_init(&env[i]->lock_error_count, NULL); pthread_rwlock_init(&env[i]->lock_refused, NULL); pthread_rwlock_init(&env[i]->lock_request_bufsize_max, NULL); pthread_rwlock_init(&env[i]->lock_response_bufsize_max, NULL); pthread_rwlock_init(&LockReconf, NULL); env[i]->lock_worker_busy = calloc(sizeof(pthread_rwlock_t), env[i]->worker_max); for (int j=0;j<env[i]->worker_max;++j) { pthread_rwlock_init(&env[i]->lock_worker_busy[j], NULL); } na_connpool_create(&env[i]->connpool_active, env[i]->connpool_max); if (env[i]->is_use_backup) { na_connpool_create(&env[i]->connpool_backup, env[i]->connpool_max); } } for (int i=0;i<env_cnt;++i) { pthread_create(&th[i], NULL, na_event_loop, env[i]); } // monitoring signal while (true) { if (SigExit == 1) { break; } if (SigReconf == 1) { conf_obj = na_get_conf(ConfFile); environments_obj = na_get_environments(conf_obj, &env_cnt); pthread_rwlock_wrlock(&LockReconf); for (int i=0;i<env_cnt;++i) { na_conf_env_init(environments_obj, env[i], i, true); } pthread_rwlock_unlock(&LockReconf); json_object_put(conf_obj); SigReconf = 0; } // XXX we should sleep forever and only wake upon a signal sleep(1); } for (int i=0;i<env_cnt;++i) { na_connpool_destroy(&env[i]->connpool_active); if (env[i]->is_use_backup) { na_connpool_destroy(&env[i]->connpool_backup); } pthread_mutex_destroy(&env[i]->lock_connpool); pthread_mutex_destroy(&env[i]->lock_current_conn); pthread_mutex_destroy(&env[i]->lock_tid); pthread_mutex_destroy(&env[i]->lock_error_count); pthread_rwlock_destroy(&env[i]->lock_refused); pthread_rwlock_destroy(&env[i]->lock_request_bufsize_max); pthread_rwlock_destroy(&env[i]->lock_response_bufsize_max); pthread_rwlock_destroy(&LockReconf); for (int j=0;j<env[i]->worker_max;++j) { pthread_rwlock_destroy(&env[i]->lock_worker_busy[j]); } NA_FREE(env[i]->is_worker_busy); NA_FREE(env[i]->lock_worker_busy); pthread_detach(th[i]); } mpool_destroy(env_pool); return 0; }