diff options
Diffstat (limited to 'src/interface-gtk')
| -rw-r--r-- | src/interface-gtk/interface.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/interface-gtk/interface.c b/src/interface-gtk/interface.c index a86e3fd..32370d9 100644 --- a/src/interface-gtk/interface.c +++ b/src/interface-gtk/interface.c @@ -19,6 +19,7 @@ #include "config.h" #endif +#include <stdlib.h> #include <string.h> #include <signal.h> @@ -27,6 +28,7 @@ #include <glib/gstdio.h> #ifdef G_OS_UNIX +#include <unistd.h> #include <glib-unix.h> #endif @@ -105,7 +107,7 @@ static struct { /* current document's name or empty string for "(Unnamed)" buffer */ teco_string_t info_current; - gboolean no_csd; + gboolean no_csd, detach; gint xembed_id; GtkWidget *info_bar_widget; @@ -132,6 +134,26 @@ static struct { void teco_interface_init(void) { +#ifdef G_OS_UNIX + if (teco_interface.detach) { + /* + * NOTE: There is also daemon() on BSD/Linux, + * but the following should be more portable. + */ + pid_t pid = fork(); + g_assert(pid >= 0); + if (pid != 0) + /* parent process */ + exit(EXIT_SUCCESS); + + setsid(); + + g_freopen("/dev/null", "r", stdin); + g_freopen("/dev/null", "a+", stdout); + g_freopen("/dev/null", "a+", stderr); + } +#endif + /* * gtk_init() is not necessary when using gtk_get_option_group(), * but this will open the default display. @@ -341,6 +363,11 @@ teco_interface_get_options(void) G_OPTION_ARG_INT, &teco_interface.xembed_id, "Embed into an existing X11 Window.", "ID"}, #endif +#ifdef G_OS_UNIX + {"detach", 'd', G_OPTION_FLAG_IN_MAIN, + G_OPTION_ARG_NONE, &teco_interface.detach, + "Detach from controlling terminal (daemonize).", NULL}, +#endif {NULL} }; |
