|
a/src/utils/execmd.cpp |
|
b/src/utils/execmd.cpp |
|
... |
|
... |
25 |
#include <sys/wait.h>
|
25 |
#include <sys/wait.h>
|
26 |
#include <sys/select.h>
|
26 |
#include <sys/select.h>
|
27 |
#include <fcntl.h>
|
27 |
#include <fcntl.h>
|
28 |
#include <errno.h>
|
28 |
#include <errno.h>
|
29 |
#include <signal.h>
|
29 |
#include <signal.h>
|
|
|
30 |
#include <time.h>
|
30 |
|
31 |
|
31 |
#include <vector>
|
32 |
#include <vector>
|
32 |
#include <string>
|
33 |
#include <string>
|
33 |
#include <sstream>
|
34 |
#include <sstream>
|
34 |
#include <iostream>
|
35 |
#include <iostream>
|
|
... |
|
... |
98 |
}
|
99 |
}
|
99 |
|
100 |
|
100 |
void ExecCmd::putenv(const string &ea)
|
101 |
void ExecCmd::putenv(const string &ea)
|
101 |
{
|
102 |
{
|
102 |
m_env.push_back(ea);
|
103 |
m_env.push_back(ea);
|
|
|
104 |
}
|
|
|
105 |
static void msleep(int millis)
|
|
|
106 |
{
|
|
|
107 |
struct timespec spec;
|
|
|
108 |
spec.tv_sec = millis / 1000;
|
|
|
109 |
spec.tv_nsec = (millis % 1000) * 1000000;
|
|
|
110 |
nanosleep(&spec, 0);
|
103 |
}
|
111 |
}
|
104 |
|
112 |
|
105 |
/** A resource manager to ensure that execcmd cleans up if an exception is
|
113 |
/** A resource manager to ensure that execcmd cleans up if an exception is
|
106 |
* raised in the callback, or at different places on errors occurring
|
114 |
* raised in the callback, or at different places on errors occurring
|
107 |
* during method executions */
|
115 |
* during method executions */
|
|
... |
|
... |
132 |
if (m_parent->m_pid > 0 && (grp = getpgid(m_parent->m_pid)) > 0) {
|
140 |
if (m_parent->m_pid > 0 && (grp = getpgid(m_parent->m_pid)) > 0) {
|
133 |
LOGDEB(("ExecCmd: killpg(%d, SIGTERM)\n", grp));
|
141 |
LOGDEB(("ExecCmd: killpg(%d, SIGTERM)\n", grp));
|
134 |
int ret = killpg(grp, SIGTERM);
|
142 |
int ret = killpg(grp, SIGTERM);
|
135 |
if (ret == 0) {
|
143 |
if (ret == 0) {
|
136 |
for (int i = 0; i < 3; i++) {
|
144 |
for (int i = 0; i < 3; i++) {
|
|
|
145 |
msleep(i == 0 ? 5 : (i == 1 ? 100 : 2000));
|
137 |
int status;
|
146 |
int status;
|
138 |
(void)waitpid(m_parent->m_pid, &status, WNOHANG);
|
147 |
(void)waitpid(m_parent->m_pid, &status, WNOHANG);
|
139 |
if (kill(m_parent->m_pid, 0) != 0)
|
148 |
if (kill(m_parent->m_pid, 0) != 0)
|
140 |
break;
|
149 |
break;
|
141 |
sleep(1);
|
|
|
142 |
if (i == 2) {
|
150 |
if (i == 2) {
|
143 |
LOGDEB(("ExecCmd: killpg(%d, SIGKILL)\n", grp));
|
151 |
LOGDEB(("ExecCmd: killpg(%d, SIGKILL)\n", grp));
|
144 |
killpg(grp, SIGKILL);
|
152 |
killpg(grp, SIGKILL);
|
145 |
(void)waitpid(m_parent->m_pid, &status, WNOHANG);
|
153 |
(void)waitpid(m_parent->m_pid, &status, WNOHANG);
|
146 |
}
|
154 |
}
|