From 221abbd008ed1dbfc2242552d886af25760f24ce Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Tue, 10 Feb 2009 21:19:37 +0100 Subject: [PATCH] Revert old forking code --- src/gui.c | 96 ++++-------------------------------------------------- src/main.c | 24 +++++--------- src/proto/main.pro | 1 - 3 files changed, 16 insertions(+), 105 deletions(-) diff --git a/src/gui.c b/src/gui.c index 196a55e3..fdaa2306 100644 --- a/src/gui.c +++ b/src/gui.c @@ -58,7 +58,7 @@ static int can_update_cursor = TRUE; /* can display the cursor */ gui_start() { char_u *old_term; -#if defined(UNIX) && !defined(__BEOS__) +#if defined(UNIX) && !defined(__BEOS__) && !defined(MACOS_X) # define MAY_FORK int dofork = TRUE; #endif @@ -117,82 +117,10 @@ gui_start() */ if (gui.in_use && dofork) { - pid_t pid = -1; - -# if defined MACOS_X - int i; - - /* on os x, you have to exec after a fork, otherwise calls to - * frameworks will assert (and without corefoundation, you can't start - * the gui. what fun.). See CAVEATS at -http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/fork.2.html - * - * Since we have to go through this anyways, we might as well use vfork. - * But: then we can't detach from our starting shell, so stick with - * fork. - * - * Kinda sucks to restart vim when doing :gui, so don't fork in that - * case (make sure gui.dofork is only set when interpreting argv, not - * when doing :gui. Currently, gui.dofork is set to false in ex_gui(). - * - * Also doesn't work well if vim starts cscope (or some other - * subprocess I guess), because it's not transferred to the newly - * exec'd process, leaving an orphaned process (not a zombie process) - * behind. The Right Thing is to kill all our child processes before - * calling exec. - */ - - /* stolen from http://paste.lisp.org/display/50906 */ - extern int *_NSGetArgc(void); - extern char ***_NSGetArgv(void); - - int argc = *_NSGetArgc(); - char ** argv = *_NSGetArgv(); - char * newargv[argc+2]; - - newargv[0] = argv[0]; - - /* - * make sure "-f" is in front of potential "--remote" flags, else - * they would consume it. - */ - newargv[1] = "-f"; - - for (i = 1; i < argc; i++) { - newargv[i + 1] = argv[i]; - } - newargv[argc+1] = NULL; - - /* shut down all the stuff we just started, just to start - * it again from the exec :-\ */ - prepare_getout(); - - pid = fork(); - switch(pid) { - case -1: -# ifndef NDEBUG - fprintf(stderr, "vim: Mac OS X workaround fork() failed!"); -# endif - _exit(255); - case 0: - /* Child. */ - - /* make sure we survive our shell */ - setsid(); - - /* Restarts the vim process, will not return. */ - execvp(argv[0], newargv); - - /* if we come here, exec has failed. bail. */ - _exit(255); - default: - /* Parent */ - _exit(0); - } -# else int pipefd[2]; /* pipe between parent and child */ int pipe_error; char dummy; + pid_t pid = -1; /* Setup a pipe between the child and the parent, so that the parent * knows when the child has done the setsid() call and is allowed to @@ -227,30 +155,27 @@ http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/fork.2.h _exit(0); } -# if defined(HAVE_SETSID) || defined(HAVE_SETPGID) +# if defined(HAVE_SETSID) || defined(HAVE_SETPGID) /* * Change our process group. On some systems/shells a CTRL-C in the * shell where Vim was started would otherwise kill gvim! */ if (pid == 0) /* child */ -# if defined(HAVE_SETSID) +# if defined(HAVE_SETSID) (void)setsid(); -# else +# else (void)setpgid(0, 0); -# endif # endif +# endif if (!pipe_error) { close(pipefd[0]); close(pipefd[1]); } - -# if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) +# if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) /* Tell the session manager our new PID */ gui_mch_forked(); -# endif - # endif } #else @@ -4832,13 +4757,6 @@ ex_gui(eap) { /* Clear the command. Needed for when forking+exiting, to avoid part * of the argument ending up after the shell prompt. */ - -#ifdef MACOS_X - /* os x doesn't really support fork(), so we can't fork of a gui - * in an already running vim. see gui_start() for more details. - */ - gui.dofork = FALSE; -#endif msg_clr_eos_force(); gui_start(); } diff --git a/src/main.c b/src/main.c index 80ad39e2..32f07a8a 100644 --- a/src/main.c +++ b/src/main.c @@ -1282,9 +1282,10 @@ getout_preserve_modified(exitval) #endif -/* Prepare proper exit*/ +/* Exit properly */ void -prepare_getout() +getout(exitval) + int exitval; { #ifdef FEAT_AUTOCMD buf_T *buf; @@ -1294,6 +1295,12 @@ prepare_getout() exiting = TRUE; + /* When running in Ex mode an error causes us to exit with a non-zero exit + * code. POSIX requires this, although it's not 100% clear from the + * standard. */ + if (exmode_active) + exitval += ex_exitval; + /* Position the cursor on the last screen line, below all the text */ #ifdef FEAT_GUI if (!gui.in_use) @@ -1410,20 +1417,7 @@ prepare_getout() if (garbage_collect_at_exit) garbage_collect(); #endif -} - -/* Exit properly */ - void -getout(exitval) - int exitval; -{ - /* When running in Ex mode an error causes us to exit with a non-zero exit - * code. POSIX requires this, although it's not 100% clear from the - * standard. */ - if (exmode_active) - exitval += ex_exitval; - prepare_getout(); mch_exit(exitval); } diff --git a/src/proto/main.pro b/src/proto/main.pro index 15c66ecf..2ecce795 100644 --- a/src/proto/main.pro +++ b/src/proto/main.pro @@ -1,6 +1,5 @@ /* main.c */ void main_loop __ARGS((int cmdwin, int noexmode)); -void prepare_getout __ARGS(()); void getout_preserve_modified __ARGS((int exitval)); void getout __ARGS((int exitval)); int process_env __ARGS((char_u *env, int is_viminit)); -- 2.11.4.GIT