Example #1
0
File: proxy.c Project: fbbs/fbbs
int main(int argc, char **argv)
{
	const char *socket_path = getenv("FBBS_SOCKET_PATH");
	server_path = getenv("FBBS_SERVER_PATH");
	if (!socket_path || !server_path)
		return EXIT_FAILURE;

	start_daemon();

	const char *fbbs_max_servers = getenv("FBBS_MAX_SERVERS");
	if (fbbs_max_servers)
		max_servers = strtol(fbbs_max_servers, NULL, 10);
	if (max_servers <= 0)
		max_servers = DEFAULT_MAX_SERVERS;
	servers = malloc(sizeof(*servers) * max_servers);
	if (!servers)
		return EXIT_FAILURE;
	for (int i = 0; i < max_servers; ++i) {
		servers[i].pid = -1;
		servers[i].fd = -1;
	}

	int max_clients = 0;
	const char *fbbs_max_clients = getenv("FBBS_MAX_CLIENTS");
	if (fbbs_max_clients)
		max_clients = strtol(fbbs_max_clients, NULL, 10);
	max_clients = check_max_clients(max_clients);
	if (max_clients <= 0)
		return EXIT_FAILURE;

	if (setgid(BBSGID) != 0)
		return EXIT_FAILURE;
	if (setuid(BBSUID) != 0)
		return EXIT_FAILURE;

	int fd = bind_unix_path(socket_path);
	if (fd < 0)
		return EXIT_FAILURE;

	fb_signal(SIGPIPE, SIG_IGN);
	fb_signal(SIGCHLD, reap_child);
	fb_signal(SIGTERM, shutdown_backend);

	for (int i = 0; i < max_servers; ++i) {
		if (!spawn_server(servers + i)) {
			kill_servers();
			return EXIT_FAILURE;
		}
	}

	ev_run(EV_DEFAULT_ 0);
	return EXIT_SUCCESS;
}
Example #2
0
void client_shutdown()
{
	console_print("Shutting down...\n");
	
	kill_servers();
	kill_download();
	kill_key();
	kill_openssl();
	kill_sound();
	kill_game();
	kill_network();
	kill_render();
//	kill_input();
	dump_console();
	kill_console();
	kill_control();
	write_config_file();
	
	SDL_Quit();

	terminate_process();
}
Example #3
0
File: proxy.c Project: fbbs/fbbs
static void shutdown_backend(int signum)
{
	proxy_shutdown = true;
	kill_servers();
}