comparison src/if_cscope.c @ 1566:20b4b6a2a212 v7.1.279

updated for version 7.1-279
author vimboss
date Sat, 15 Mar 2008 11:41:07 +0000
parents b4791bb4fbff
children 4e581f1b08da
comparison
equal deleted inserted replaced
1565:1dd4e0ccd822 1566:20b4b6a2a212
2094 2094
2095 vim_free(buf); 2095 vim_free(buf);
2096 return CSCOPE_SUCCESS; 2096 return CSCOPE_SUCCESS;
2097 } 2097 }
2098 2098
2099 #if defined(UNIX) && defined(SIGALRM)
2100 /*
2101 * Used to catch and ignore SIGALRM below.
2102 */
2103 /* ARGSUSED */
2104 static RETSIGTYPE
2105 sig_handler SIGDEFARG(sigarg)
2106 {
2107 /* do nothing */
2108 SIGRETURN;
2109 }
2110 #endif
2099 2111
2100 /* 2112 /*
2101 * PRIVATE: cs_release_csp 2113 * PRIVATE: cs_release_csp
2102 * 2114 *
2103 * Does the actual free'ing for the cs ptr with an optional flag of whether 2115 * Does the actual free'ing for the cs ptr with an optional flag of whether
2106 static void 2118 static void
2107 cs_release_csp(i, freefnpp) 2119 cs_release_csp(i, freefnpp)
2108 int i; 2120 int i;
2109 int freefnpp; 2121 int freefnpp;
2110 { 2122 {
2111 #if defined(UNIX)
2112 int pstat;
2113 #else
2114 /* 2123 /*
2115 * Trying to exit normally (not sure whether it is fit to UNIX cscope 2124 * Trying to exit normally (not sure whether it is fit to UNIX cscope
2116 */ 2125 */
2117 if (csinfo[i].to_fp != NULL) 2126 if (csinfo[i].to_fp != NULL)
2118 { 2127 {
2119 (void)fputs("q\n", csinfo[i].to_fp); 2128 (void)fputs("q\n", csinfo[i].to_fp);
2120 (void)fflush(csinfo[i].to_fp); 2129 (void)fflush(csinfo[i].to_fp);
2121 } 2130 }
2131 #if defined(UNIX)
2132 {
2133 int pstat;
2134 pid_t pid;
2135
2136 # if defined(HAVE_SIGACTION)
2137 struct sigaction sa, old;
2138
2139 /* Use sigaction() to limit the waiting time to two seconds. */
2140 sa.sa_handler = sig_handler;
2141 sa.sa_flags = SA_NODEFER;
2142 sigaction(SIGALRM, &sa, &old);
2143 alarm(2); /* 2 sec timeout */
2144
2145 /* Block until cscope exits or until timer expires */
2146 pid = waitpid(csinfo[i].pid, &pstat, 0);
2147
2148 /* cancel pending alarm if still there and restore signal */
2149 alarm(0);
2150 sigaction(SIGALRM, &old, NULL);
2151 # else
2152 int waited;
2153
2154 /* Can't use sigaction(), loop for two seconds. First yield the CPU
2155 * to give cscope a chance to exit quickly. */
2156 sleep(0);
2157 for (waited = 0; waited < 40; ++waited)
2158 {
2159 pid = waitpid(csinfo[i].pid, &pstat, WNOHANG);
2160 if (pid != 0)
2161 break; /* break unless the process is still running */
2162 mch_delay(50, FALSE); /* sleep 50 ms */
2163 }
2164 # endif
2165 /*
2166 * If the cscope process is still running: kill it.
2167 * Safety check: If the PID would be zero here, the entire X session
2168 * would be killed. -1 and 1 are dangerous as well.
2169 */
2170 if (pid < 0 && csinfo[i].pid > 1)
2171 {
2172 kill(csinfo[i].pid, SIGTERM);
2173 (void)waitpid(csinfo[i].pid, &pstat, 0);
2174 }
2175 }
2176 #else /* !UNIX */
2122 if (csinfo[i].hProc != NULL) 2177 if (csinfo[i].hProc != NULL)
2123 { 2178 {
2124 /* Give cscope a chance to exit normally */ 2179 /* Give cscope a chance to exit normally */
2125 if (WaitForSingleObject(csinfo[i].hProc, 1000) == WAIT_TIMEOUT) 2180 if (WaitForSingleObject(csinfo[i].hProc, 1000) == WAIT_TIMEOUT)
2126 TerminateProcess(csinfo[i].hProc, 0); 2181 TerminateProcess(csinfo[i].hProc, 0);
2130 2185
2131 if (csinfo[i].fr_fp != NULL) 2186 if (csinfo[i].fr_fp != NULL)
2132 (void)fclose(csinfo[i].fr_fp); 2187 (void)fclose(csinfo[i].fr_fp);
2133 if (csinfo[i].to_fp != NULL) 2188 if (csinfo[i].to_fp != NULL)
2134 (void)fclose(csinfo[i].to_fp); 2189 (void)fclose(csinfo[i].to_fp);
2135
2136 /*
2137 * Safety check: If the PID would be zero here, the entire X session would
2138 * be killed. -1 and 1 are dangerous as well.
2139 */
2140 #if defined(UNIX)
2141 if (csinfo[i].pid > 1)
2142 {
2143 kill(csinfo[i].pid, SIGTERM);
2144 (void)waitpid(csinfo[i].pid, &pstat, 0);
2145 }
2146 #endif
2147 2190
2148 if (freefnpp) 2191 if (freefnpp)
2149 { 2192 {
2150 vim_free(csinfo[i].fname); 2193 vim_free(csinfo[i].fname);
2151 vim_free(csinfo[i].ppath); 2194 vim_free(csinfo[i].ppath);