|
a/src/utils/execmd.cpp |
|
b/src/utils/execmd.cpp |
|
... |
|
... |
34 |
|
34 |
|
35 |
#include <vector>
|
35 |
#include <vector>
|
36 |
#include <string>
|
36 |
#include <string>
|
37 |
#include <sstream>
|
37 |
#include <sstream>
|
38 |
#include <iostream>
|
38 |
#include <iostream>
|
|
|
39 |
using namespace std;
|
39 |
|
40 |
|
40 |
#include "execmd.h"
|
41 |
#include "execmd.h"
|
41 |
#include "pathut.h"
|
42 |
#include "pathut.h"
|
42 |
#include "debuglog.h"
|
43 |
#include "debuglog.h"
|
43 |
#include "smallut.h"
|
44 |
#include "smallut.h"
|
44 |
#include "netcon.h"
|
45 |
#include "netcon.h"
|
45 |
#include "closefrom.h"
|
46 |
#include "closefrom.h"
|
46 |
#include "ptmutex.h"
|
47 |
#include "ptmutex.h"
|
47 |
|
48 |
|
48 |
#ifndef NO_NAMESPACES
|
|
|
49 |
using namespace std;
|
|
|
50 |
#endif /* NO_NAMESPACES */
|
|
|
51 |
|
|
|
52 |
#ifndef MAX
|
|
|
53 |
#define MAX(A,B) ((A) > (B) ? (A) : (B))
|
|
|
54 |
#endif
|
|
|
55 |
#ifndef MIN
|
|
|
56 |
#define MIN(A,B) ((A) < (B) ? (A) : (B))
|
|
|
57 |
#endif
|
|
|
58 |
|
49 |
|
59 |
/* From FreeBSD's which command */
|
50 |
/* From FreeBSD's which command */
|
60 |
static bool
|
|
|
61 |
exec_is_there(const char *candidate)
|
51 |
static bool exec_is_there(const char *candidate)
|
62 |
{
|
52 |
{
|
63 |
struct stat fin;
|
53 |
struct stat fin;
|
64 |
|
54 |
|
65 |
/* XXX work around access(2) false positives for superuser */
|
55 |
/* XXX work around access(2) false positives for superuser */
|
66 |
if (access(candidate, X_OK) == 0 &&
|
56 |
if (access(candidate, X_OK) == 0 &&
|
|
... |
|
... |
133 |
close(m_parent->m_pipein[1]);
|
123 |
close(m_parent->m_pipein[1]);
|
134 |
if (m_parent->m_pipeout[0] >= 0)
|
124 |
if (m_parent->m_pipeout[0] >= 0)
|
135 |
close(m_parent->m_pipeout[0]);
|
125 |
close(m_parent->m_pipeout[0]);
|
136 |
if (m_parent->m_pipeout[1] >= 0)
|
126 |
if (m_parent->m_pipeout[1] >= 0)
|
137 |
close(m_parent->m_pipeout[1]);
|
127 |
close(m_parent->m_pipeout[1]);
|
138 |
int status;
|
128 |
|
139 |
if (m_parent->m_pid > 0) {
|
129 |
// It's apparently possible for m_pid to be > 0 and getpgid to fail. In
|
140 |
pid_t grp = getpgid(m_parent->m_pid);
|
130 |
// this case, we have to conclude that the child process does
|
|
|
131 |
// not exist. Not too sure what causes this, but the previous code
|
|
|
132 |
// definitely tried to call killpg(-1,) from time to time.
|
|
|
133 |
pid_t grp;
|
|
|
134 |
if (m_parent->m_pid > 0 && (grp = getpgid(m_parent->m_pid)) > 0) {
|
141 |
LOGDEB(("ExecCmd: killpg(%d, SIGTERM)\n", grp));
|
135 |
LOGDEB(("ExecCmd: killpg(%d, SIGTERM)\n", grp));
|
142 |
int ret = killpg(grp, SIGTERM);
|
136 |
int ret = killpg(grp, SIGTERM);
|
143 |
if (ret == 0) {
|
137 |
if (ret == 0) {
|
144 |
for (int i = 0; i < 3; i++) {
|
138 |
for (int i = 0; i < 3; i++) {
|
|
|
139 |
int status;
|
145 |
(void)waitpid(m_parent->m_pid, &status, WNOHANG);
|
140 |
(void)waitpid(m_parent->m_pid, &status, WNOHANG);
|
146 |
if (kill(m_parent->m_pid, 0) != 0)
|
141 |
if (kill(m_parent->m_pid, 0) != 0)
|
147 |
break;
|
142 |
break;
|
148 |
sleep(1);
|
143 |
sleep(1);
|
149 |
if (i == 2) {
|
144 |
if (i == 2) {
|