From 269b784c3a7162db8c7537360a37e27085e4f18f Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Wed, 1 Feb 2012 17:40:26 +0100 Subject: [PATCH] fork if --fork is given (Closes: #52) Thanks to egl209 for the patch. --- zathura.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/zathura.c b/zathura.c index 7b84a1a..31c671e 100644 --- a/zathura.c +++ b/zathura.c @@ -39,12 +39,14 @@ zathura_init(int argc, char* argv[]) /* parse command line options */ GdkNativeWindow embed = 0; gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL; + bool forkback = false; GOptionEntry entries[] = { { "reparent", 'e', 0, G_OPTION_ARG_INT, &embed, "Reparents to window specified by xid", "xid" }, { "config-dir", 'c', 0, G_OPTION_ARG_FILENAME, &config_dir, "Path to the config directory", "path" }, { "data-dir", 'd', 0, G_OPTION_ARG_FILENAME, &data_dir, "Path to the data directory", "path" }, { "plugins-dir", 'p', 0, G_OPTION_ARG_STRING, &plugin_path, "Path to the directories containing plugins", "path" }, + { "fork", '\0', 0, G_OPTION_ARG_NONE, &forkback, "Fork into the background" , NULL }, { NULL, '\0', 0, 0, NULL, NULL, NULL } }; @@ -61,6 +63,19 @@ zathura_init(int argc, char* argv[]) } g_option_context_free(context); + /* Fork into the background if the user really wants to ... */ + if (forkback == true) + { + int pid = fork(); + if (pid > 0) { /* parent */ + exit(0); + } else if (pid < 0) { /* error */ + printf("Error: couldn't fork."); + } + + setsid(); + } + zathura_t* zathura = g_malloc0(sizeof(zathura_t)); /* plugins */