diff -r 20507e1e60e8 -r 7bafe52b6245 src/gui.c --- a/src/gui.c Fri May 18 16:35:21 2012 +0200 +++ b/src/gui.c Fri May 18 17:03:18 2012 +0200 @@ -270,6 +270,12 @@ } /* Child */ +#ifdef FEAT_GUI_GTK + /* Call gtk_init_check() here after fork(). See gui_init_check(). */ + if (gui_mch_init_check() != OK) + exit(1); +#endif + # if defined(HAVE_SETSID) || defined(HAVE_SETPGID) /* * Change our process group. On some systems/shells a CTRL-C in the @@ -430,7 +436,17 @@ #ifdef ALWAYS_USE_GUI result = OK; #else +# ifdef FEAT_GUI_GTK + /* + * Note: Don't call gtk_init_check() before fork, it will be called after + * the fork. When calling it before fork, it make vim hang for a while. + * See gui_do_fork(). + * Use a simpler check if the GUI window can probably be opened. + */ + result = gui.dofork ? gui_mch_early_init_check() : gui_mch_init_check(); +# else result = gui_mch_init_check(); +# endif #endif return result; } diff -r 20507e1e60e8 -r 7bafe52b6245 src/gui_gtk_x11.c --- a/src/gui_gtk_x11.c Fri May 18 16:35:21 2012 +0200 +++ b/src/gui_gtk_x11.c Fri May 18 17:03:18 2012 +0200 @@ -1414,7 +1414,29 @@ } /* - * Check if the GUI can be started. Called before gvimrc is sourced. + * Check if the GUI can be started. Called before gvimrc is sourced and + * before fork(). + * Return OK or FAIL. + */ + int +gui_mch_early_init_check(void) +{ + char_u *p; + + /* Guess that when $DISPLAY isn't set the GUI can't start. */ + p = mch_getenv((char_u *)"DISPLAY"); + if (p == NULL || *p == NUL) + { + gui.dying = TRUE; + EMSG(_((char *)e_opendisp)); + return FAIL; + } + return OK; +} + +/* + * Check if the GUI can be started. Called before gvimrc is sourced but after + * fork(). * Return OK or FAIL. */ int diff -r 20507e1e60e8 -r 7bafe52b6245 src/proto/gui_gtk_x11.pro --- a/src/proto/gui_gtk_x11.pro Fri May 18 16:35:21 2012 +0200 +++ b/src/proto/gui_gtk_x11.pro Fri May 18 17:03:18 2012 +0200 @@ -4,6 +4,7 @@ void gui_mch_set_blinking __ARGS((long waittime, long on, long off)); void gui_mch_stop_blink __ARGS((void)); void gui_mch_start_blink __ARGS((void)); +int gui_mch_early_init_check __ARGS((void)); int gui_mch_init_check __ARGS((void)); void gui_mch_show_tabline __ARGS((int showit)); int gui_mch_showing_tabline __ARGS((void));