+ GOptionContext *context;
+
+ GOptionEntry entries[] = {
+ { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, "Turn on debug messages", NULL },
+ { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Do not daemonize server", NULL },
+ { NULL },
+ };
+
+ context = g_option_context_new("");
+ g_option_context_add_main_entries (context, entries, NULL);
+
+ GError *err = NULL;
+ if (!g_option_context_parse (context, &argc, &argv, &err)) {
+ fprintf(stderr, "error: %s\n", err->message);
+ fprintf(stderr, "%s", g_option_context_get_help(context, FALSE, NULL));
+ g_error_free (err);
+ exit(-1);
+ }
+
+ if (optind < argc) {
+ fprintf(stderr, "error: too many arguments\n");
+ fprintf(stderr, "%s", g_option_context_get_help(context, FALSE, NULL));
+ exit(-1);
+ }
+
+ g_option_context_free(context);
+
+ if (debug) foreground = TRUE;
+