Ejemplo n.º 1
0
/*!
  \brief main() is the typical main function in a C program, it performs
  all core initialization, loading of all main parameters, initializing handlers
  and entering gtk_main to process events until program close
  \param argc is the count of command line arguments
  \param argv is the array of command line args
  \returns TRUE
  */
gint main(gint argc, gchar ** argv)
{
	Serial_Params *serial_params = NULL;
	GAsyncQueue *queue = NULL;
	GCond *cond = NULL;
	GMutex *mutex = NULL;
	gint id = 0;
	setlocale(LC_ALL,"");
#ifdef __WIN32__
	bindtextdomain(PACKAGE, "C:\\Program Files\\MegaTunix\\dist\\locale");
#else
	bindtextdomain(PACKAGE, LOCALEDIR);
#endif
	textdomain (PACKAGE);

#ifdef DEBUG
	printf("This is a debug release, Git hash: %s\n",MTX_GIT_HASH);
#endif
	if(!g_thread_supported())
		g_thread_init(NULL);
	gdk_threads_init();
	gtk_init(&argc, &argv);
	glade_init();

	gdk_gl_init_check(&argc, &argv);
	gl_ability = gtk_gl_init_check(&argc, &argv);

	global_data = g_new0(gconstpointer, 1);

	/* Condition variables */
	cond = g_cond_new();
	DATA_SET(global_data,"statuscounts_cond",cond);
	cond = g_cond_new();
	DATA_SET(global_data,"io_dispatch_cond",cond);
	cond = g_cond_new();
	DATA_SET(global_data,"gui_dispatch_cond",cond);
	cond = g_cond_new();
	DATA_SET(global_data,"pf_dispatch_cond",cond);
	cond = g_cond_new();
	DATA_SET(global_data,"rtv_thread_cond",cond);

	/* Mutexes */
	mutex = g_mutex_new();
	DATA_SET(global_data,"serio_mutex",mutex);
	mutex = g_mutex_new();
	DATA_SET(global_data,"rtt_mutex",mutex);
	mutex = g_mutex_new();
	DATA_SET(global_data,"rtv_mutex",mutex);
	mutex = g_mutex_new();
	DATA_SET(global_data,"dash_mutex",mutex);
	mutex = g_mutex_new();
	DATA_SET(global_data,"statuscounts_mutex",mutex);
	mutex = g_mutex_new();
	DATA_SET(global_data,"io_dispatch_mutex",mutex);
	mutex = g_mutex_new();
	DATA_SET(global_data,"gui_dispatch_mutex",mutex);
	mutex = g_mutex_new();
	DATA_SET(global_data,"pf_dispatch_mutex",mutex);
	mutex = g_mutex_new();
	DATA_SET(global_data,"rtv_thread_mutex",mutex);

	/* For testing if gettext works
	   printf(_("Hello World!\n"));
	 */

	/* Build table of strings to enum values */
	build_string_2_enum_table();
	serial_params = (Serial_Params *)g_malloc0(sizeof(Serial_Params));
	DATA_SET(global_data,"serial_params",serial_params);

	handle_args(argc,argv);	/* handle CLI arguments */

	/* This will exit mtx if the locking fails! */
	create_mtx_lock();
	open_debug();		/* Open debug log */
	/* Allocate memory  */
	init();			/* Initialize global vars */
	make_mtx_dirs();	/* Create config file dirs if missing */

	/* Create Message passing queues */
	queue = g_async_queue_new();
	DATA_SET_FULL(global_data,"io_data_queue",queue,g_async_queue_unref);
	queue = g_async_queue_new();
	DATA_SET_FULL(global_data,"slave_msg_queue",queue,g_async_queue_unref);
	queue = g_async_queue_new();
	DATA_SET_FULL(global_data,"pf_dispatch_queue",queue,g_async_queue_unref);
	queue = g_async_queue_new();
	DATA_SET_FULL(global_data,"gui_dispatch_queue",queue,g_async_queue_unref);
	queue = g_async_queue_new();
	DATA_SET_FULL(global_data,"io_repair_queue",queue,g_async_queue_unref);

	read_config();
	setup_gui();		

	gtk_rc_parse_string("style \"override\"\n{\n\tGtkTreeView::horizontal-separator = 0\n\tGtkTreeView::vertical-separator = 0\n}\nwidget_class \"*\" style \"override\"");

	id = g_timeout_add_full(-50,16,(GSourceFunc)pf_dispatcher,NULL,NULL);
	DATA_SET(global_data,"pf_dispatcher_id",GINT_TO_POINTER(id));
	id = g_timeout_add_full(-35,35,(GSourceFunc)gui_dispatcher,NULL,NULL);
	DATA_SET(global_data,"gui_dispatcher_id",GINT_TO_POINTER(id));
	id = g_timeout_add(1000,(GSourceFunc)flush_binary_logs,NULL);
        DATA_SET(global_data,"binlog_flush_id",GINT_TO_POINTER(id));

	sleep_calib();
	/* Check for first_time flag, if so, run first tiem wizard, otherwise
	   load personality choice
	   */
	gdk_threads_add_timeout(500,(GSourceFunc)check_for_first_time,NULL);
	

	DATA_SET(global_data,"ready",GINT_TO_POINTER(TRUE));
	gdk_threads_enter();
	gtk_main();
	gdk_threads_leave();
	return (0) ;
}
Ejemplo n.º 2
0
int main(int argc, char * argv[])
{
#ifdef DEBUG
  open_debug();
#endif
  init_static_control_simple();
  void ask(addr_t addr)
    {
      char str[DEFAULT_TRANSFER];
      struct args args = { .log_addr = addr, .log_len = DEFAULT_TRANSFER, .phys_addr = (unsigned long)str, .direction = direct_read };
      root_strategy->ops[0][opcode_trans]((void*)root_strategy, &args, "");
      if(args.success) {
	 printf("%s", str);
      }
    }
  bool cmd(addr_t addr, char * str, char * param)
    {
      struct args args = { .log_addr = addr, .log_len = strlen(str), .phys_addr = (unsigned long)str, .direction = direct_write };
      root_strategy->ops[0][opcode_trans]((void*)root_strategy, &args, param);
      return args.success;
    }
  addr_t boot(char * str, char * param)
    {
      struct args args = { .log_len = DEFAULT_TRANSFER, .reader = FALSE, .exclu = TRUE, .action = action_wait, .melt = TRUE, .try_len = DEFAULT_TRANSFER, .op_code = opcode_gadr };
      root_strategy->ops[0][opcode_gadr]((void*)root_strategy, &args, param);
      if(!args.success) {
        printf("!!!!! gadrcreateget failed\n");
	exit(-1);
      }
      args.log_len = strlen(str);
      args.phys_addr = (unsigned long)str;
      args.direction = direct_write;
      args.op_code = opcode_trans;
      root_strategy->ops[0][opcode_trans]((void*)root_strategy, &args, param);
      if(!args.success) {
        printf("!!!!! trans '%s' failed\n", str);
	exit(-1);
      }
      return args.log_addr;
    }
  char str[256];
  addr_t control = DEFAULT_TRANSFER;
  cmd(control, "output:=control\n", "");
  // basic level
#if 0
  addr_t dev = boot("brick:=device_dummy_linux\n output:=out", "testfile");
  sprintf(str, "brick:=buffer_dummy_linux\n \n connect dev:=%llx:out\n output:=out {\n", dev);
  addr_t buffer = boot(str, "");
  sprintf(str, "brick:=map_simple\n connect in:=%llx:out\noutput:=out", buffer);
#else
  sprintf(str, "brick:=map_dummy\n output:=out{\n");
#endif
  addr_t map = boot(str, "");
  sprintf(str, "brick:=adapt_meta\n connect in:=%llx:out\n output:=out\n", map);
  addr_t meta = boot(str, "");
#if 0
  sprintf(str, "brick:=spy_trace\n connect in:=%llx:out\n output:=out\n", meta);
  meta = boot(str, "spylog");
#endif
  // create root hook
  cmd(0, "output:=_root", "");
  cmd(meta, "connect hook:=0:_root", "");
  // strategy level
  sprintf(str, "brick:=fs_simple\n connect strat:=%llx:control\n output:=control{\n", control);
  addr_t fs = boot(str, "_root");
  // testing
  sprintf(str, "brick:=bench_fs\n connect strat:=%llx:control\n", fs);
  addr_t bench = boot(str, "");
#if 1
  ask(0);
  ask(DEFAULT_TRANSFER);
  ask(0x3000);
#endif
  printf("================== STARTING BENCH ================\n");
  cmd(bench, "output:=dummy", "1000");
  printf("================== END BENCH ================\n");
#ifdef MOVE_COUNT
  extern void print_counts(void);
  print_counts();
  printf("------------------------------------\n");
  printf("_makespace: shortcuts: %d count1: %d count2: %d\n", count_0, count_1, count_2);
  printf("creates (count_c1) = %d, triggering creates (count_c2) = %d\n", count_c1, count_c2);
#endif
  cmd(meta, "brick/=adapt_meta", "");
  cmd(map, "brick/=map_dummy", "");
#ifdef DEBUG
  close_debug();
#endif
  return 0;
}
Ejemplo n.º 3
0
/*!
  \brief main() is the typical main function in a C program, it performs
  all core initialization, loading of all main parameters, initializing handlers
  and entering gtk_main to process events until program close
  \param argc is the count of command line arguments
  \param argv is the array of command line args
  \returns TRUE
  */
gint main(gint argc, gchar ** argv)
{
	Serial_Params *serial_params = NULL;
	GAsyncQueue *queue = NULL;
	GTimer *timer = NULL;
	GCond *rtv_thread_cond = NULL;
	GMutex *dash_mutex = NULL;
	GMutex *rtt_mutex = NULL;
	GMutex *rtv_mutex = NULL;
	GMutex *rtv_thread_mutex = NULL;
	GMutex *serio_mutex = NULL;
	gint id = 0;
	setlocale(LC_ALL,"");
#ifdef __WIN32__
	bindtextdomain(PACKAGE, "C:\\Program Files\\MegaTunix\\dist\\locale");
#else
	bindtextdomain(PACKAGE, LOCALEDIR);
#endif
	textdomain (PACKAGE);

#ifdef DEBUG
	printf("This is a debug release, Git hash: %s\n",GIT_HASH);
#endif
	// Not needed?
//	gdk_threads_init();
	gtk_init(&argc, &argv);
	glade_init();

	/* Check if OpenGL is supported. */
	if (gdk_gl_query() == FALSE) {
		g_print("OpenGL not supported\n");
		return 0;
	}
	else
		gl_ability = TRUE;

//	gdk_gl_init_check(&argc, &argv);
//	gl_ability = gtk_gl_init_check(&argc, &argv);

	global_data = g_new0(gconstpointer, 1);

	/* Condition Variables */
	rtv_thread_cond = g_new0(GCond,1);
	g_cond_init(rtv_thread_cond);
	DATA_SET(global_data,"rtv_thread_cond",rtv_thread_cond);
	/* Mutexes */
	dash_mutex = g_new0(GMutex, 1);
	g_mutex_init(dash_mutex);
	DATA_SET(global_data,"dash_mutex",dash_mutex);
	rtt_mutex = g_new0(GMutex, 1);
	g_mutex_init(rtt_mutex);
	DATA_SET(global_data,"rtt_mutex",rtt_mutex);
	rtv_mutex = g_new0(GMutex, 1);
	g_mutex_init(rtv_mutex);
	DATA_SET(global_data,"rtv_mutex",rtv_mutex);
	rtv_thread_mutex = g_new0(GMutex, 1);
	g_mutex_init(rtv_thread_mutex);
	DATA_SET(global_data,"rtv_thread_mutex",rtv_thread_mutex);
	serio_mutex = g_new0(GMutex, 1);
	g_mutex_init(serio_mutex);
	DATA_SET(global_data,"serio_mutex",serio_mutex);

	/* For testing if gettext works
	   printf(_("Hello World!\n"));
	 */

	/* Build table of strings to enum values */
	build_string_2_enum_table();
	serial_params = (Serial_Params *)g_malloc0(sizeof(Serial_Params));
	DATA_SET(global_data,"serial_params",serial_params);

	handle_args(argc,argv);	/* handle CLI arguments */

	/* This will exit mtx if the locking fails! */
	/* Prevents multiple instances  but stops esoteric usess too 
	 * create_mtx_lock();
	 * */
	open_debug();		/* Open debug log */

	ENTER();
	/* Allocate memory  */
	init();			/* Initialize global vars */
	make_mtx_dirs();	/* Create config file dirs if missing */

	/* Create Message passing queues */
	queue = g_async_queue_new();
	DATA_SET_FULL(global_data,"io_data_queue",queue,g_async_queue_unref);
	queue = g_async_queue_new();
	DATA_SET_FULL(global_data,"slave_msg_queue",queue,g_async_queue_unref);
	queue = g_async_queue_new();
	DATA_SET_FULL(global_data,"io_repair_queue",queue,g_async_queue_unref);

	read_config();
	setup_gui();		

	gtk_rc_parse_string("style \"override\"\n{\n\tGtkTreeView::horizontal-separator = 0\n\tGtkTreeView::vertical-separator = 0\n}\nwidget_class \"*\" style \"override\"");

	/* This doesn't do any GUI stuff so can run as is... */
	id = g_timeout_add(2000,(GSourceFunc)flush_binary_logs,NULL);
    DATA_SET(global_data,"binlog_flush_id",GINT_TO_POINTER(id));

	sleep_calib();
	/* Check for first_time flag, if so, run first time wizard, otherwise
	   load personality choice
	   */
	timer = g_timer_new();
	DATA_SET_FULL(global_data,"mtx_uptime_timer",timer,g_timer_destroy);
	g_idle_add((GSourceFunc)check_for_first_time,NULL);
	
	DATA_SET(global_data,"ready",GINT_TO_POINTER(TRUE));

	gdk_threads_enter();
	gtk_main();
	gdk_threads_leave();
	EXIT();
	return (0);
}
Ejemplo n.º 4
0
/*
 * IMAPFilter: an IMAP mail filtering utility.
 */
int
main(int argc, char *argv[])
{
	int c;
	char *cafile = NULL, *capath = NULL;

	setlocale(LC_CTYPE, "");

	opts.verbose = 0;
	opts.interactive = 0;
	opts.log = NULL;
	opts.config = NULL;
	opts.oneline = NULL;
	opts.debug = NULL;

	opts.truststore = NULL;
	if (exists_dir("/etc/ssl/certs"))
		opts.truststore = "/etc/ssl/certs";
	else if (exists_file("/etc/ssl/cert.pem"))
		opts.truststore = "/etc/ssl/cert.pem";

	env.home = NULL;
	env.pathmax = -1;

	while ((c = getopt(argc, argv, "Vc:d:e:il:t:v?")) != -1) {
		switch (c) {
		case 'V':
			version();
			/* NOTREACHED */
			break;
		case 'c':
			opts.config = optarg;
			break;
		case 'd':
			opts.debug = optarg;
			break;
		case 'e':
			opts.oneline = optarg;
			break;
		case 'i':
			opts.interactive = 1;
			break;
		case 'l':
			opts.log = optarg;
			break;
		case 't':
			opts.truststore = optarg;
			break;
		case 'v':
			opts.verbose = 1;
			break;
		case '?':
		default:
			usage();
			/* NOTREACHED */
			break;
		}
	}

	get_pathmax();
	open_debug();
	create_homedir();
	catch_signals();
	open_log();
	if (opts.config == NULL)
		opts.config = get_filepath("config.lua");

	buffer_init(&ibuf, INPUT_BUF);
	buffer_init(&obuf, OUTPUT_BUF);
	buffer_init(&nbuf, NAMESPACE_BUF);
	buffer_init(&cbuf, CONVERSION_BUF);

	regexp_compile(responses);

	SSL_library_init();
	SSL_load_error_strings();
	ssl3ctx = SSL_CTX_new(SSLv3_client_method());
	ssl23ctx = SSL_CTX_new(SSLv23_client_method());
	tls1ctx = SSL_CTX_new(TLSv1_client_method());
#if OPENSSL_VERSION_NUMBER >= 0x01000100fL
	tls11ctx = SSL_CTX_new(TLSv1_1_client_method());
	tls12ctx = SSL_CTX_new(TLSv1_2_client_method());
#endif
	if (exists_dir(opts.truststore))
		capath = opts.truststore;
	else if (exists_file(opts.truststore))
		cafile = opts.truststore;
	SSL_CTX_load_verify_locations(ssl3ctx, cafile, capath);
	SSL_CTX_load_verify_locations(ssl23ctx, cafile, capath);
	SSL_CTX_load_verify_locations(tls1ctx, cafile, capath);
#if OPENSSL_VERSION_NUMBER >= 0x01000100fL
	SSL_CTX_load_verify_locations(tls11ctx, cafile, capath);
	SSL_CTX_load_verify_locations(tls12ctx, cafile, capath);
#endif

	start_lua();
#if LUA_VERSION_NUM < 502
	{
		list *l;
		session *s;

		l = sessions;
		while (l != NULL) {
			s = l->data;
			l = l->next;

			request_logout(s);
		}
	}
#endif
	stop_lua();

	SSL_CTX_free(ssl3ctx);
	SSL_CTX_free(ssl23ctx);
	SSL_CTX_free(tls1ctx);
#if OPENSSL_VERSION_NUMBER >= 0x01000100fL
	SSL_CTX_free(tls11ctx);
	SSL_CTX_free(tls12ctx);
#endif
	ERR_free_strings();

	regexp_free(responses);

	buffer_free(&ibuf);
	buffer_free(&obuf);
	buffer_free(&nbuf);
	buffer_free(&cbuf);

	xfree(env.home);

	close_log();
	close_debug();

	exit(0);
}
Ejemplo n.º 5
0
int main(int argc, char * argv[])
{
#ifdef DEBUG
  open_debug();
#endif
  init_static_control_simple();
  bool cmd(addr_t addr, char * str, char * param)
    {
      struct args args = { .log_addr = addr, .log_len = strlen(str), .phys_addr = (unsigned long)str, .direction = direct_write };
      root_strategy->ops[0][opcode_trans]((void*)root_strategy, &args, param);
      return args.success;
    }
  addr_t boot(char * str, char * param)
    {
      struct args args = { .log_len = DEFAULT_TRANSFER, .reader = FALSE, .exclu = TRUE, .action = action_wait, .melt = TRUE, .try_len = DEFAULT_TRANSFER, .op_code = opcode_gadr };
      root_strategy->ops[0][opcode_gadr]((void*)root_strategy, &args, param);
      if(!args.success) {
        printf("!!!!! gadr failed\n");
	exit(-1);
      }
      args.log_len = strlen(str);
      args.phys_addr = (unsigned long)str;
      args.direction = direct_write;
      args.op_code = opcode_trans;
      root_strategy->ops[0][opcode_trans]((void*)root_strategy, &args, param);
      if(!args.success) {
        printf("!!!!! trans '%s' failed\n", str);
	exit(-1);
      }
      return args.log_addr;
    }
  char str[256];
  addr_t control = DEFAULT_TRANSFER;
  // basic level
#if 0
  addr_t dev = boot("brick:=device_dummy_linux\n output:=out", "testfile");
  sprintf(str, "brick:=buffer_dummy_linux\n \n connect dev:=%llx:out\n output:=out {\n", dev);
  addr_t buffer = boot(str, "");
  sprintf(str, "brick:=map_simple\n connect in:=%llx:out\noutput:=out", buffer);
#else
  sprintf(str, "brick:=map_dummy\n output:=out{\n");
#endif
  addr_t map = boot(str, "");
  sprintf(str, "brick:=adapt_meta\n connect in:=%llx:out\n output:=out\n", map);
  addr_t meta = boot(str, "");
  // create root hook
  cmd(0, "output:=_root", "");
  cmd(meta, "connect hook:=0:_root", "");
  // strategy level
  sprintf(str, "brick:=fs_simple\n connect strat:=%llx:control\n output:=control{\n", control);
  addr_t fs = boot(str, "_root");
  // testing

  sprintf(str, "brick:=bench_fs\n connect strat:=%llx:control\n", fs);
  addr_t bench = boot(str, "");

  printf("================== STARTING BENCH ================\n");
  cmd(bench, "output:=dummy", "1");
  printf("================== END BENCH ================\n");

  cmd(meta, "brick/=adapt_meta", "");
  printf("------------------------------------\n");
  printf("size_input=%u\n", (unsigned) sizeof(struct input));
  printf("size_output=%u\n", (unsigned) sizeof(struct output));
  printf("size_conn=%u\n", (unsigned) sizeof(struct connector_header));
  printf("size_brick=%u\n", (unsigned) sizeof(struct brick_header));

  struct timespec t0, t1;
  printf("------------------------------------\n");

  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t0);
  int i;
  for(i = 0; i < 1000000; i++) {
	  getpid();
	  getpid();
  }
  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t1);
  printf("getpid time=%11lld\n", ((long long)t1.tv_sec-(long long)t0.tv_sec)*1000LL + ((long long)t1.tv_nsec-(long long)t0.tv_nsec)/1000000LL);
  printf("------------------------------------\n");

  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t0);
  for(i = 0; i < 1000000; i++) {
	  int fd = open("/etc/passwd", O_RDONLY);
	  close(fd);
  }
  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t1);
  printf("open   time=%11lld\n", ((long long)t1.tv_sec-(long long)t0.tv_sec)*1000LL + ((long long)t1.tv_nsec-(long long)t0.tv_nsec)/1000000LL);
  printf("------------------------------------\n");

  int fd = open("/etc/services", O_RDONLY);
  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t0);
  for(i = 0; i < 1000000; i++) {
	  char buf[4096];
	  lseek(fd, 0, SEEK_SET);
	  read(fd, buf, 4096);
  }
  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t1);
  close(fd);
  printf("read   time=%11lld\n", ((long long)t1.tv_sec-(long long)t0.tv_sec)*1000LL + ((long long)t1.tv_nsec-(long long)t0.tv_nsec)/1000000LL);
  printf("------------------------------------\n");
  sprintf(str, "brick:=adapt_meta\n connect in:=%llx:out\n", map);
  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t0);
  for(i = 0; i < 1000000; i++) {
    struct conn_info conn1 = { .conn_addr = meta, .conn_name = "in" };
    struct conn_info conn2 = { .conn_addr = map, .conn_name = "out" };
    struct args args = { .log_addr = meta, .name = "adapt_meta", .conn1 = &conn1, .conn2 = &conn2 };
    root_strategy->ops[0][opcode_instbrick]((void*)root_strategy, &args, "");
    root_strategy->ops[0][opcode_connect]((void*)root_strategy, &args, "");
    root_strategy->ops[0][opcode_deinstbrick]((void*)root_strategy, &args, "");
#if 0
	  addr_t adr = cmd(meta, str, "");
	  cmd(meta, "brick/=adapt_meta\n", "");
#endif
  }
  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t1);
  printf("inst   time=%11lld\n", ((long long)t1.tv_sec-(long long)t0.tv_sec)*1000LL + ((long long)t1.tv_nsec-(long long)t0.tv_nsec)/1000000LL);
  printf("------------------------------------\n");
  cmd(map, "brick/=map_dummy", "");
#ifdef DEBUG
  close_debug();
#endif
  return 0;
}
Ejemplo n.º 6
0
/*
 * IMAPFilter: an IMAP mail filtering utility.
 */
int
main(int argc, char *argv[])
{
	int c;

	setlocale(LC_CTYPE, "");

	opts.verbose = 0;
	opts.interactive = 0;
	opts.log = NULL;
	opts.config = NULL;
	opts.oneline = NULL;
	opts.debug = NULL;

	env.home = NULL;
	env.pathmax = -1;

	while ((c = getopt(argc, argv, "Vc:d:e:il:v?")) != -1) {
		switch (c) {
		case 'V':
			version();
			/* NOTREACHED */
			break;
		case 'c':
			opts.config = optarg;
			break;
		case 'd':
			opts.debug = optarg;
			break;
		case 'e':
			opts.oneline = optarg;
			break;
		case 'i':
			opts.interactive = 1;
			break;
		case 'l':
			opts.log = optarg;
			break;
		case 'v':
			opts.verbose = 1;
			break;
		case '?':
		default:
			usage();
			/* NOTREACHED */
			break;
		}
	}

	get_pathmax();
	open_debug();
	create_homedir();
	catch_signals();
	open_log();
	if (opts.config == NULL)
		opts.config = get_filepath("config.lua");

	buffer_init(&ibuf, INPUT_BUF);
	buffer_init(&obuf, OUTPUT_BUF);
	buffer_init(&nbuf, NAMESPACE_BUF);
	buffer_init(&cbuf, CONVERSION_BUF);

	regexp_compile(responses);

	SSL_library_init();
	SSL_load_error_strings();

	start_lua();
#if LUA_VERSION_NUM < 502
	{
		list *l;
		session *s;

		l = sessions;
		while (l != NULL) {
			s = l->data;
			l = l->next;

			request_logout(s);
		}
	}
#endif
	stop_lua();

	ERR_free_strings();

	regexp_free(responses);

	buffer_free(&ibuf);
	buffer_free(&obuf);
	buffer_free(&nbuf);
	buffer_free(&cbuf);

	xfree(env.home);

	close_log();
	close_debug();

	exit(0);
}