Karsten Hopp 930f58
To: vim-dev@vim.org
Karsten Hopp 930f58
Subject: Patch 7.1.288
Karsten Hopp 930f58
Fcc: outbox
Karsten Hopp 930f58
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 930f58
Mime-Version: 1.0
Karsten Hopp 930f58
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp 930f58
Content-Transfer-Encoding: 8bit
Karsten Hopp 930f58
------------
Karsten Hopp 930f58
Karsten Hopp 930f58
Patch 7.1.288 (after 7.1.281)
Karsten Hopp 930f58
Problem:    Cscope still leaves behind temp files when using gvim.
Karsten Hopp 930f58
Solution:   When getting the ECHILD error loop for a while until cscope exits.
Karsten Hopp 930f58
	    (Dominique Pelle)
Karsten Hopp 930f58
Files:	    if_cscope.c
Karsten Hopp 930f58
Karsten Hopp 930f58
Karsten Hopp 930f58
*** ../vim-7.1.287/src/if_cscope.c	Sun Mar 16 16:02:47 2008
Karsten Hopp 930f58
--- src/if_cscope.c	Tue Mar 25 21:34:23 2008
Karsten Hopp 930f58
***************
Karsten Hopp 930f58
*** 2130,2135 ****
Karsten Hopp 930f58
--- 2130,2136 ----
Karsten Hopp 930f58
      }
Karsten Hopp 930f58
  #if defined(UNIX)
Karsten Hopp 930f58
      {
Karsten Hopp 930f58
+ 	int waitpid_errno;
Karsten Hopp 930f58
  	int pstat;
Karsten Hopp 930f58
  	pid_t pid;
Karsten Hopp 930f58
  
Karsten Hopp 930f58
***************
Karsten Hopp 930f58
*** 2145,2150 ****
Karsten Hopp 930f58
--- 2146,2152 ----
Karsten Hopp 930f58
  
Karsten Hopp 930f58
  	/* Block until cscope exits or until timer expires */
Karsten Hopp 930f58
  	pid = waitpid(csinfo[i].pid, &pstat, 0);
Karsten Hopp 930f58
+ 	waitpid_errno = errno;
Karsten Hopp 930f58
  
Karsten Hopp 930f58
  	/* cancel pending alarm if still there and restore signal */
Karsten Hopp 930f58
  	alarm(0);
Karsten Hopp 930f58
***************
Karsten Hopp 930f58
*** 2158,2163 ****
Karsten Hopp 930f58
--- 2160,2166 ----
Karsten Hopp 930f58
  	for (waited = 0; waited < 40; ++waited)
Karsten Hopp 930f58
  	{
Karsten Hopp 930f58
  	    pid = waitpid(csinfo[i].pid, &pstat, WNOHANG);
Karsten Hopp 930f58
+ 	    waitpid_errno = errno;
Karsten Hopp 930f58
  	    if (pid != 0)
Karsten Hopp 930f58
  		break;  /* break unless the process is still running */
Karsten Hopp 930f58
  	    mch_delay(50, FALSE); /* sleep 50 ms */
Karsten Hopp 930f58
***************
Karsten Hopp 930f58
*** 2170,2177 ****
Karsten Hopp 930f58
  	 */
Karsten Hopp 930f58
  	if (pid < 0 && csinfo[i].pid > 1)
Karsten Hopp 930f58
  	{
Karsten Hopp 930f58
! 	    kill(csinfo[i].pid, SIGKILL);
Karsten Hopp 930f58
! 	    (void)waitpid(csinfo[i].pid, &pstat, 0);
Karsten Hopp 930f58
  	}
Karsten Hopp 930f58
      }
Karsten Hopp 930f58
  #else  /* !UNIX */
Karsten Hopp 930f58
--- 2173,2212 ----
Karsten Hopp 930f58
  	 */
Karsten Hopp 930f58
  	if (pid < 0 && csinfo[i].pid > 1)
Karsten Hopp 930f58
  	{
Karsten Hopp 930f58
! # ifdef ECHILD
Karsten Hopp 930f58
! 	    int alive = TRUE;
Karsten Hopp 930f58
! 
Karsten Hopp 930f58
! 	    if (waitpid_errno == ECHILD)
Karsten Hopp 930f58
! 	    {
Karsten Hopp 930f58
! 		/*
Karsten Hopp 930f58
! 		 * When using 'vim -g', vim is forked and cscope process is
Karsten Hopp 930f58
! 		 * no longer a child process but a sibling.  So waitpid()
Karsten Hopp 930f58
! 		 * fails with errno being ECHILD (No child processes).
Karsten Hopp 930f58
! 		 * Don't send SIGKILL to cscope immediately but wait
Karsten Hopp 930f58
! 		 * (polling) for it to exit normally as result of sending
Karsten Hopp 930f58
! 		 * the "q" command, hence giving it a chance to clean up
Karsten Hopp 930f58
! 		 * its temporary files.
Karsten Hopp 930f58
! 		 */
Karsten Hopp 930f58
! 		int waited;
Karsten Hopp 930f58
! 
Karsten Hopp 930f58
! 		sleep(0);
Karsten Hopp 930f58
! 		for (waited = 0; waited < 40; ++waited)
Karsten Hopp 930f58
! 		{
Karsten Hopp 930f58
! 		    /* Check whether cscope process is still alive */
Karsten Hopp 930f58
! 		    if (kill(csinfo[i].pid, 0) != 0)
Karsten Hopp 930f58
! 		    {
Karsten Hopp 930f58
! 			alive = FALSE; /* cscope process no longer exists */
Karsten Hopp 930f58
! 			break;
Karsten Hopp 930f58
! 		    }
Karsten Hopp 930f58
! 		    mch_delay(50, FALSE); /* sleep 50ms */
Karsten Hopp 930f58
! 		}
Karsten Hopp 930f58
! 	    }
Karsten Hopp 930f58
! 	    if (alive)
Karsten Hopp 930f58
! # endif
Karsten Hopp 930f58
! 	    {
Karsten Hopp 930f58
! 		kill(csinfo[i].pid, SIGKILL);
Karsten Hopp 930f58
! 		(void)waitpid(csinfo[i].pid, &pstat, 0);
Karsten Hopp 930f58
! 	    }
Karsten Hopp 930f58
  	}
Karsten Hopp 930f58
      }
Karsten Hopp 930f58
  #else  /* !UNIX */
Karsten Hopp 930f58
*** ../vim-7.1.287/src/version.c	Tue Apr  1 13:10:45 2008
Karsten Hopp 930f58
--- src/version.c	Tue Apr  1 14:28:42 2008
Karsten Hopp 930f58
***************
Karsten Hopp 930f58
*** 668,669 ****
Karsten Hopp 930f58
--- 668,671 ----
Karsten Hopp 930f58
  {   /* Add new patch number below this line */
Karsten Hopp 930f58
+ /**/
Karsten Hopp 930f58
+     288,
Karsten Hopp 930f58
  /**/
Karsten Hopp 930f58
Karsten Hopp 930f58
-- 
Karsten Hopp 930f58
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 930f58
204. You're being audited because you mailed your tax return to the IRC.
Karsten Hopp 930f58
Karsten Hopp 930f58
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 930f58
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 930f58
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 930f58
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///