/*----------------------------------------------------------------------------*/ static entry_t * entry_allocate(void) { entry_t *e; e = memb_alloc(&entries_memb); if(e == NULL) { purge_flowtable(); e = memb_alloc(&entries_memb); if(e == NULL) { PRINTF("[FLT]: Failed to allocate an entry\n"); return NULL; } } entry_init(e); return e; }
int slap_init( int mode, const char *name ) { int rc; assert( mode ); if ( slapMode != SLAP_UNDEFINED_MODE ) { /* Make sure we write something to stderr */ slap_debug |= LDAP_DEBUG_NONE; Debug( LDAP_DEBUG_ANY, "%s init: init called twice (old=%d, new=%d)\n", name, slapMode, mode ); return 1; } slapMode = mode; slap_op_init(); #ifdef SLAPD_MODULES if ( module_init() != 0 ) { slap_debug |= LDAP_DEBUG_NONE; Debug( LDAP_DEBUG_ANY, "%s: module_init failed\n", name, 0, 0 ); return 1; } #endif if ( slap_schema_init( ) != 0 ) { slap_debug |= LDAP_DEBUG_NONE; Debug( LDAP_DEBUG_ANY, "%s: slap_schema_init failed\n", name, 0, 0 ); return 1; } if ( filter_init() != 0 ) { slap_debug |= LDAP_DEBUG_NONE; Debug( LDAP_DEBUG_ANY, "%s: filter_init failed\n", name, 0, 0 ); return 1; } if ( entry_init() != 0 ) { slap_debug |= LDAP_DEBUG_NONE; Debug( LDAP_DEBUG_ANY, "%s: entry_init failed\n", name, 0, 0 ); return 1; } switch ( slapMode & SLAP_MODE ) { case SLAP_SERVER_MODE: root_dse_init(); /* FALLTHRU */ case SLAP_TOOL_MODE: Debug( LDAP_DEBUG_TRACE, "%s init: initiated %s.\n", name, (mode & SLAP_MODE) == SLAP_TOOL_MODE ? "tool" : "server", 0 ); slap_name = name; ldap_pvt_thread_pool_init( &connection_pool, connection_pool_max, 0); slap_counters_init( &slap_counters ); ldap_pvt_thread_mutex_init( &slapd_rq.rq_mutex ); LDAP_STAILQ_INIT( &slapd_rq.task_list ); LDAP_STAILQ_INIT( &slapd_rq.run_list ); slap_passwd_init(); rc = slap_sasl_init(); if( rc == 0 ) { rc = backend_init( ); } if ( rc ) return rc; break; default: slap_debug |= LDAP_DEBUG_NONE; Debug( LDAP_DEBUG_ANY, "%s init: undefined mode (%d).\n", name, mode, 0 ); rc = 1; break; } if ( slap_controls_init( ) != 0 ) { slap_debug |= LDAP_DEBUG_NONE; Debug( LDAP_DEBUG_ANY, "%s: slap_controls_init failed\n", name, 0, 0 ); return 1; } if ( frontend_init() ) { slap_debug |= LDAP_DEBUG_NONE; Debug( LDAP_DEBUG_ANY, "%s: frontend_init failed\n", name, 0, 0 ); return 1; } if ( overlay_init() ) { slap_debug |= LDAP_DEBUG_NONE; Debug( LDAP_DEBUG_ANY, "%s: overlay_init failed\n", name, 0, 0 ); return 1; } if ( glue_sub_init() ) { slap_debug |= LDAP_DEBUG_NONE; Debug( LDAP_DEBUG_ANY, "%s: glue/subordinate init failed\n", name, 0, 0 ); return 1; } if ( acl_init() ) { slap_debug |= LDAP_DEBUG_NONE; Debug( LDAP_DEBUG_ANY, "%s: acl_init failed\n", name, 0, 0 ); return 1; } return rc; }
static void init(void) { game_init(); high_score_init(); entry_init(); }
/* Test driver for hashtable. */ int main(int argc, char **argv) { /* Test key_hashtable instance. */ hashtable_t *kt; hashtable_iter_t ki; key_t k1, k2; key_init(&k1, 1); key_init(&k2, 2); assert((kt = key_hashtable_new(16)) != NULL); assert(key_hashtable_add(kt, &k1) == &k1); assert(key_hashtable_find(kt, &k1) == &k1); assert(key_hashtable_find(kt, &k2) == NULL); assert(key_hashtable_iter(&ki, kt) == &k1); assert(key_hashtable_next(&ki) == NULL); /* Test hashtable instance. */ hashtable_t *t; entry_t entry[256]; entry_t e; match_t m; int i; entry_init(&e, 0); for (i = 0; i < 256; i++) entry_init(&entry[i], i); /* Test hashtable_new() */ t = hashtable_new(256); assert(t->size == 512); assert(t->count == 0); assert(t->etable != NULL); assert(t->ktable != NULL); /* Test hashtable_add() */ assert(hashtable_add(t, &e) == &e); /* Added duplicated copy. */ assert(hashtable_add(t, &entry[0]) == &entry[0]); /* Added duplicated instance. */ for (i = 0; i < 256; i++) assert(hashtable_add(t, &entry[i]) == &entry[i]); assert(t->count == 258); /* Test hashtable_find() */ match_init(&m, 0); assert(hashtable_find(t, &m) == &e); /* Finds first duplicate added. */ assert(m.value == m.source); /* match_cmp() updated m.value. */ for (i = 1; i < 256; i++) { match_init(&m, i); assert(hashtable_find(t, &m) == &entry[i]); assert(m.value == m.source); /* match_cmp() updated m.value. */ } match_init(&m, 256); assert(hashtable_find(t, &m) == NULL); /* Find missing entry. */ assert(m.value == 0); /* match_cmp() didn't update m.value. */ #ifndef HASHTABLE_NSTATS assert(t->find_count == 257); assert(t->match_count == 256); assert(t->hashcmp_count >= 256); assert(t->entrycmp_count >= 256); hashtable_stats_init(t); assert(t->find_count == 0); assert(t->match_count == 0); assert(t->hashcmp_count == 0); assert(t->entrycmp_count == 0); #endif /* Test hashtable iterators */ entry_t *p; hashtable_iter_t iter; int count = 0; for (p = hashtable_iter(&iter, t); p != NULL; p = hashtable_next(&iter)) { assert(p == &e || (&entry[0] <= p && p <= &entry[255])); count++; } assert(count == 258); hashtable_free(t); return 0; }