Ejemplo n.º 1
0
void reload_cmd(sock_t fd, char *options, unsigned int nb_options)
{
	char *msg;
	
	if (get_active_threads_size() > 0) {
		msg = "Threads still active, cannot reload";
		proxenet_write(fd, (void*)msg, strlen(msg));
		return;
	}

	proxy_state = SLEEPING;
	
	proxenet_destroy_plugins_vm();
	proxenet_delete_list_plugins();

	if( proxenet_initialize_plugins_list() < 0) {
		msg = "Failed to reinitilize plugins";
		proxenet_write(fd, (void*)msg, strlen(msg));
		proxy_state = INACTIVE;
		return;
	}

	proxenet_initialize_plugins();

	proxy_state = ACTIVE;

	msg = "Plugins list successfully reloaded\n";
	proxenet_write(fd, (void*)msg, strlen(msg));

	return;
}
Ejemplo n.º 2
0
int proxenet_start() 
{
	sock_t control_socket, listening_socket;
	struct sigaction saction;
	
	control_socket = listening_socket = -1;

	/* create control socket */
	control_socket = create_control_socket();
	if (control_socket < 0) {
		xlog(LOG_CRITICAL, "Cannot create control socket: %s\n", strerror(errno));
		return -1;
	}

#ifdef DEBUG
	xlog(LOG_INFO, "Control socket: %d\n", control_socket);
#endif
	
	/* create listening socket */
	listening_socket = create_bind_socket(cfg->iface, cfg->port);
	if (listening_socket < 0) {
		xlog(LOG_CRITICAL, "Cannot create bind socket: %s\n", strerror(errno));
		return -1;
	}

#ifdef DEBUG
	xlog(LOG_INFO, "Bind socket: %d\n", listening_socket);
#endif
	
	/* init everything */
	initialize_sigmask(&saction);

	plugins_list = NULL;
	proxy_state = INACTIVE;
	active_threads_bitmask = 0;
	
	/* set up plugins */
	if( proxenet_initialize_plugins_list() < 0 )
		return -1;
	
	proxenet_initialize_plugins(); // call *MUST* succeed or abort()

	/* setting request counter  */
	request_id = 0;
	get_new_request_id();
	
	/* prepare threads and start looping */
	xloop(listening_socket, control_socket);
	
	/* clean context */
	proxenet_remove_all_plugins();
	
	close_socket(listening_socket);
	close_socket(control_socket);

	unlink(CONTROL_SOCK_PATH);
	return 0;
}
Ejemplo n.º 3
0
/**
 * This function is called right after the configuration was parsed.
 * It simply:
 * - creates the main listening sockets (control and proxy)
 * - initialize the signal mask
 * - initialize all the VMs
 * - fill the plugin list with the valid plugins located in the autoload path
 * - then call the main thread loop
 * - once finished, it also cleans the structures
 *
 * @return 0 if everything went well, -1 otherwise with an error message
 */
int proxenet_start()
{
        sock_t control_socket, listening_socket;
        struct sigaction saction;

        /* create control socket */
        control_socket = proxenet_bind_control_socket();
        if (control_socket < 0) {
                xlog(LOG_CRITICAL, "Cannot create control socket: %s\n", strerror(errno));
                return -1;
        }

        if(cfg->verbose)
                xlog(LOG_INFO, "Control socket: %d\n", control_socket);

        /* create listening socket */
        listening_socket = proxenet_bind_socket(cfg->iface, cfg->port);
        if (listening_socket < 0) {
                xlog(LOG_CRITICAL, "Cannot create bind socket: %s\n", strerror(errno));
                return -1;
        }

        if(cfg->verbose)
                xlog(LOG_INFO, "Bind socket: %d\n", listening_socket);


        /* init everything */
        initialize_sigmask(&saction);

        plugins_list = NULL;
        proxy_state = INACTIVE;
        active_threads_bitmask = 0;

        /* set up plugins */
        if( proxenet_initialize_plugins_list() < 0 )
                return -1;

        /* this call *MUST* succeed or die */
        proxenet_initialize_plugins();

        /* setting request counter  */
        request_id = 0;

        /* we "artificially" allocate an ID 0 so that all new requests will be > 0 */
        /* for the child threads, a request id of 0 means not allocated */
        get_new_request_id();

        init_global_stats();

        /* prepare threads and start looping */
        xloop(listening_socket, control_socket);

        end_global_stats();

        if (cfg->verbose)
                print_global_stats();

        /* clean context */
        proxenet_destroy_plugins_vm();
        proxenet_free_all_plugins();

        proxenet_close_socket(listening_socket, NULL);
        proxenet_close_socket(control_socket, NULL);

        unlink(CFG_CONTROL_SOCK_PATH);
        return 0;
}