|
a/src/execmd.cpp |
|
b/src/execmd.cpp |
|
... |
|
... |
268 |
|
268 |
|
269 |
// It's apparently possible for m_pid to be > 0 and getpgid to fail. In
|
269 |
// It's apparently possible for m_pid to be > 0 and getpgid to fail. In
|
270 |
// this case, we have to conclude that the child process does
|
270 |
// this case, we have to conclude that the child process does
|
271 |
// not exist. Not too sure what causes this, but the previous code
|
271 |
// not exist. Not too sure what causes this, but the previous code
|
272 |
// definitely tried to call killpg(-1,) from time to time.
|
272 |
// definitely tried to call killpg(-1,) from time to time.
|
273 |
pid_t grp;
|
273 |
pid_t grp, w;
|
274 |
if (m_parent->m_pid > 0 && (grp = getpgid(m_parent->m_pid)) > 0) {
|
274 |
if (m_parent->m_pid > 0 && (grp = getpgid(m_parent->m_pid)) > 0) {
|
275 |
LOGDEB("ExecCmd: pid " << m_parent->m_pid << " killpg(" << grp <<
|
275 |
LOGDEB("ExecCmd: pid " << m_parent->m_pid << " killpg(" << grp <<
|
276 |
", SIGTERM)\n");
|
276 |
", SIGTERM)\n");
|
277 |
int ret = killpg(grp, SIGTERM);
|
277 |
int ret = killpg(grp, SIGTERM);
|
278 |
if (ret == 0) {
|
278 |
if (ret == 0) {
|
|
|
279 |
int status;
|
279 |
for (int i = 0; i < 3; i++) {
|
280 |
for (int i = 0; i < 3; i++) {
|
280 |
msleep(i == 0 ? 5 : (i == 1 ? 100 : 2000));
|
281 |
msleep(i == 0 ? 5 : (i == 1 ? 100 : 2000));
|
281 |
int status;
|
282 |
do {
|
282 |
(void)waitpid(m_parent->m_pid, &status, WNOHANG);
|
283 |
w = waitpid(m_parent->m_pid, &status, WNOHANG);
|
|
|
284 |
if (w == -1) {
|
|
|
285 |
LOGERR("ExecCmd: error waitpid (" <<
|
|
|
286 |
m_parent->m_pid << ")" << endl);
|
|
|
287 |
} else {
|
|
|
288 |
if (WIFEXITED(status)) {
|
|
|
289 |
LOGDEB("ExecCmd: " << m_parent->m_pid <<
|
|
|
290 |
" exited, status=" <<
|
|
|
291 |
WEXITSTATUS(status) << endl);
|
|
|
292 |
} else if (WIFSIGNALED(status)) {
|
|
|
293 |
LOGDEB("ExecCmd: " << m_parent->m_pid <<
|
|
|
294 |
" killed by signal " <<
|
|
|
295 |
WTERMSIG(status) << endl);
|
|
|
296 |
} else if (WIFSTOPPED(status)) {
|
|
|
297 |
LOGDEB("ExecCmd: " << m_parent->m_pid <<
|
|
|
298 |
" stopped by signal " <<
|
|
|
299 |
WSTOPSIG(status) << endl);
|
|
|
300 |
} else if (WIFCONTINUED(status)) {
|
|
|
301 |
LOGDEB("ExecCmd: " << m_parent->m_pid <<
|
|
|
302 |
" continued" << endl);
|
|
|
303 |
}
|
|
|
304 |
}
|
|
|
305 |
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
|
283 |
if (kill(m_parent->m_pid, 0) != 0) {
|
306 |
if (kill(m_parent->m_pid, 0) != 0) {
|
284 |
break;
|
307 |
break;
|
285 |
}
|
308 |
}
|
286 |
if (i == 2) {
|
309 |
if (i == 2) {
|
287 |
LOGDEB("ExecCmd: killpg(" << (grp) << ", SIGKILL)\n");
|
310 |
LOGDEB("ExecCmd: killpg(" << (grp) << ", SIGKILL)\n");
|