示例#1
0
void t_chassis_shutdown_hooks_new(void) {
	chassis_shutdown_hooks_t *hooks;

	hooks = chassis_shutdown_hooks_new();

	chassis_shutdown_hooks_free(hooks);
}
示例#2
0
void t_chassis_shutdown_hooks_register(void) {
	chassis_shutdown_hooks_t *hooks;
	chassis_shutdown_hook_t *hook;
	int count = 0;

	hooks = chassis_shutdown_hooks_new();

	hook = chassis_shutdown_hook_new();
	hook->func = shutdown_func;
	hook->udata = &count;
	g_assert_cmpint(TRUE, ==, chassis_shutdown_hooks_register(hooks,
				C("foo"),
				hook));

	/* check that _call() only execs the shutdown hook once */	
	g_assert_cmpint(hook->is_called, ==, FALSE);
	g_assert_cmpint(*(int *)hook->udata, ==, 0);
	chassis_shutdown_hooks_call(hooks);
	g_assert_cmpint(hook->is_called, ==, TRUE);
	g_assert_cmpint(*(int *)hook->udata, ==, 1);
	chassis_shutdown_hooks_call(hooks);
	g_assert_cmpint(hook->is_called, ==, TRUE);
	g_assert_cmpint(*(int *)hook->udata, ==, 1);

	/* register a hook with the same name */
	hook = chassis_shutdown_hook_new();
	g_assert_cmpint(FALSE, ==, chassis_shutdown_hooks_register(hooks,
				C("foo"),
				hook));
	chassis_shutdown_hook_free(hook); /* as it failed, we have to free it */

	chassis_shutdown_hooks_free(hooks);
}
示例#3
0
/**
 * free the global scope
 *
 * closes all open connections, cleans up all plugins
 *
 * @param chas      global context
 */
void chassis_free(chassis *chas) {
    guint i;
#ifdef HAVE_EVENT_BASE_FREE
    const char *version;
#endif

    if (!chas) return;

    /* call the destructor for all plugins */
    for (i = 0; i < chas->modules->len; i++) {
        chassis_plugin *p = chas->modules->pdata[i];

        g_assert(p->destroy);
        p->destroy(p->config);
    }
    
    chassis_shutdown_hooks_call(chas->shutdown_hooks); /* cleanup the global 3rd party stuff before we unload the modules */

    for (i = 0; i < chas->modules->len; i++) {
        chassis_plugin *p = chas->modules->pdata[i];

        chassis_plugin_free(p);
    }
    
    g_ptr_array_free(chas->modules, TRUE);

    if (chas->base_dir) g_free(chas->base_dir);
    if (chas->log_path) g_free(chas->log_path);
    if (chas->user) g_free(chas->user);
    
    if (chas->stats) chassis_stats_free(chas->stats);

    chassis_timestamps_global_free(NULL);

    GPtrArray *threads = chas->threads;
    if (threads) {
        for (i = 0; i < threads->len; ++i) {
            chassis_event_thread_free(threads->pdata[i]);
        }

        g_ptr_array_free(threads, TRUE);
    }

    if (chas->instance_name) g_free(chas->instance_name);

#ifdef HAVE_EVENT_BASE_FREE
    /* only recent versions have this call */

    version = event_get_version();

    /* libevent < 1.3e doesn't cleanup its own fds from the event-queue in signal_init()
     * calling event_base_free() would cause a assert() on shutdown
     */
    if (version && (strcmp(version, "1.3e") >= 0)) {
        if (chas->event_base) event_base_free(chas->event_base);
    }
#endif
    g_free(chas->event_hdr_version);

    chassis_shutdown_hooks_free(chas->shutdown_hooks);

    lua_scope_free(chas->sc);

    network_backends_free(chas->backends);

    if (chas->proxy_filter != NULL) { sql_filter_free(chas->proxy_filter); }
    if (chas->proxy_reserved != NULL) { sql_reserved_query_free(chas->proxy_reserved); }

    g_free(chas);
}
示例#4
0
/**
 * free the global scope
 *
 * closes all open connections, cleans up all plugins
 *
 * @param chas      global context
 */
void chassis_free(chassis *chas) {
	guint i;
#ifdef HAVE_EVENT_BASE_FREE
	const char *version;
#endif

	if (!chas) return;

	/* init the shutdown, without freeing share structures */	
	if (chas->priv_shutdown) chas->priv_shutdown(chas, chas->priv);
	

	/* call the destructor for all plugins */
	for (i = 0; i < chas->modules->len; i++) {
		chassis_plugin *p = chas->modules->pdata[i];

		g_assert(p->destroy);
		p->destroy(p->config);
	}
	
	chassis_shutdown_hooks_call(chas->shutdown_hooks); /* cleanup the global 3rd party stuff before we unload the modules */

	for (i = 0; i < chas->modules->len; i++) {
		chassis_plugin *p = chas->modules->pdata[i];

		chassis_plugin_free(p);
	}
	
	g_ptr_array_free(chas->modules, TRUE);

	/* free the pointers _AFTER_ the modules are shutdown */
	if (chas->priv_free) chas->priv_free(chas, chas->priv);


	if (chas->base_dir) g_free(chas->base_dir);
	if (chas->user) g_free(chas->user);
	
	if (chas->stats) chassis_stats_free(chas->stats);

	chassis_timestamps_global_free(NULL);

	if (chas->threads) chassis_event_threads_free(chas->threads);

#ifdef HAVE_EVENT_BASE_FREE
	/* only recent versions have this call */

	version = event_get_version();

	/* libevent < 1.3e doesn't cleanup its own fds from the event-queue in signal_init()
	 * calling event_base_free() would cause a assert() on shutdown
	 */
	if (version && (strcmp(version, "1.3e") >= 0)) {
		if (chas->event_base) event_base_free(chas->event_base);
	}
#endif
	g_free(chas->event_hdr_version);

	chassis_shutdown_hooks_free(chas->shutdown_hooks);

	//add by vinchen/CFR
    if (chas->set_mutex) {
        g_mutex_free(chas->set_mutex);
    }
    if (chas->user_ip_set){
        g_set_destroy(chas->user_ip_set);
    }
 
	if (chas->base_dir_org)
		g_free(chas->base_dir_org);
	if (chas->lua_cpath_org)
		g_free(chas->lua_cpath_org);
	if (chas->lua_path_org)
		g_free(chas->lua_path_org);
	if (chas->log_file_name_org)
		g_free(chas->log_file_name_org);
	if (chas->plugin_dir_org)
		g_free(chas->plugin_dir_org);
	if (chas->pid_file_org)
		g_free(chas->pid_file_org);
	if (chas->default_file)
		g_free(chas->default_file);
	if(chas->ignore_user)
		g_strfreev(chas->ignore_user);
  if (chas->query_mutex)
    g_mutex_free(chas->query_mutex);
	
	g_free(chas);
}