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