Mirror of the Vim source from https://github.com/vim/vim
Révision | 0e3e601e66cf233986924652f7801dc8d2568a84 (tree) |
---|---|
l'heure | 2008-04-01 21:31:14 |
Auteur | vimboss |
Commiter | vimboss |
updated for version 7.1-288
@@ -2130,6 +2130,7 @@ | ||
2130 | 2130 | } |
2131 | 2131 | #if defined(UNIX) |
2132 | 2132 | { |
2133 | + int waitpid_errno; | |
2133 | 2134 | int pstat; |
2134 | 2135 | pid_t pid; |
2135 | 2136 |
@@ -2145,6 +2146,7 @@ | ||
2145 | 2146 | |
2146 | 2147 | /* Block until cscope exits or until timer expires */ |
2147 | 2148 | pid = waitpid(csinfo[i].pid, &pstat, 0); |
2149 | + waitpid_errno = errno; | |
2148 | 2150 | |
2149 | 2151 | /* cancel pending alarm if still there and restore signal */ |
2150 | 2152 | alarm(0); |
@@ -2158,6 +2160,7 @@ | ||
2158 | 2160 | for (waited = 0; waited < 40; ++waited) |
2159 | 2161 | { |
2160 | 2162 | pid = waitpid(csinfo[i].pid, &pstat, WNOHANG); |
2163 | + waitpid_errno = errno; | |
2161 | 2164 | if (pid != 0) |
2162 | 2165 | break; /* break unless the process is still running */ |
2163 | 2166 | mch_delay(50, FALSE); /* sleep 50 ms */ |
@@ -2170,8 +2173,40 @@ | ||
2170 | 2173 | */ |
2171 | 2174 | if (pid < 0 && csinfo[i].pid > 1) |
2172 | 2175 | { |
2173 | - kill(csinfo[i].pid, SIGKILL); | |
2174 | - (void)waitpid(csinfo[i].pid, &pstat, 0); | |
2176 | +# ifdef ECHILD | |
2177 | + int alive = TRUE; | |
2178 | + | |
2179 | + if (waitpid_errno == ECHILD) | |
2180 | + { | |
2181 | + /* | |
2182 | + * When using 'vim -g', vim is forked and cscope process is | |
2183 | + * no longer a child process but a sibling. So waitpid() | |
2184 | + * fails with errno being ECHILD (No child processes). | |
2185 | + * Don't send SIGKILL to cscope immediately but wait | |
2186 | + * (polling) for it to exit normally as result of sending | |
2187 | + * the "q" command, hence giving it a chance to clean up | |
2188 | + * its temporary files. | |
2189 | + */ | |
2190 | + int waited; | |
2191 | + | |
2192 | + sleep(0); | |
2193 | + for (waited = 0; waited < 40; ++waited) | |
2194 | + { | |
2195 | + /* Check whether cscope process is still alive */ | |
2196 | + if (kill(csinfo[i].pid, 0) != 0) | |
2197 | + { | |
2198 | + alive = FALSE; /* cscope process no longer exists */ | |
2199 | + break; | |
2200 | + } | |
2201 | + mch_delay(50, FALSE); /* sleep 50ms */ | |
2202 | + } | |
2203 | + } | |
2204 | + if (alive) | |
2205 | +# endif | |
2206 | + { | |
2207 | + kill(csinfo[i].pid, SIGKILL); | |
2208 | + (void)waitpid(csinfo[i].pid, &pstat, 0); | |
2209 | + } | |
2175 | 2210 | } |
2176 | 2211 | } |
2177 | 2212 | #else /* !UNIX */ |
@@ -667,6 +667,8 @@ | ||
667 | 667 | static int included_patches[] = |
668 | 668 | { /* Add new patch number below this line */ |
669 | 669 | /**/ |
670 | + 288, | |
671 | +/**/ | |
670 | 672 | 287, |
671 | 673 | /**/ |
672 | 674 | 286, |