Пример #1
0
/**
 * free all event-threads
 *
 * frees all the registered event-threads and event-queue
 */
void chassis_event_threads_free(chassis_event_threads_t *threads) {
	guint i;
	chassis_event_op_t *op;

	if (!threads) return;

	/* all threads are running, now wait until they are down again */
	for (i = 0; i < threads->event_threads->len; i++) {
		chassis_event_thread_t *event_thread = threads->event_threads->pdata[i];

		chassis_event_thread_free(event_thread);
	}

	g_ptr_array_free(threads->event_threads, TRUE);

	/* free the events that are still in the queue */
	while ((op = g_async_queue_try_pop(threads->event_queue))) {
		chassis_event_op_free(op);
	}
	g_async_queue_unref(threads->event_queue);

	/* close the notification pipe */
	if (threads->event_notify_fds[0] != -1) {
		closesocket(threads->event_notify_fds[0]);
	}
	if (threads->event_notify_fds[1] != -1) {
		closesocket(threads->event_notify_fds[1]);
	}


	g_free(threads);
}
Пример #2
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);
}