Lines 90-95
Link Here
|
90 |
{ |
90 |
{ |
91 |
DIR *procdir; |
91 |
DIR *procdir; |
92 |
struct dirent *entry; |
92 |
struct dirent *entry; |
|
|
93 |
FILE *fp; |
94 |
bool container_pid = false; |
95 |
bool openvz_host = false; |
96 |
char *line = NULL; |
97 |
size_t len = 0; |
93 |
pid_t p; |
98 |
pid_t p; |
94 |
char buffer[PATH_MAX]; |
99 |
char buffer[PATH_MAX]; |
95 |
struct stat sb; |
100 |
struct stat sb; |
Lines 117-122
Link Here
|
117 |
runscript_pid = 0; |
122 |
runscript_pid = 0; |
118 |
} |
123 |
} |
119 |
|
124 |
|
|
|
125 |
/* |
126 |
If /proc/self/status contains EnvID: 0, then we are an OpenVZ host, |
127 |
and we will need to filter out processes that are inside containers |
128 |
from our list of pids. |
129 |
*/ |
130 |
|
131 |
if (exists("/proc/self/status")) { |
132 |
fp = fopen("/proc/self/status", "r"); |
133 |
if (fp) { |
134 |
while(! feof(fp)) { |
135 |
rc_getline(&line, &len, fp); |
136 |
if (strncmp(line, "envID:\t0", 8) == 0) { |
137 |
openvz_host = true; |
138 |
break; |
139 |
} |
140 |
} |
141 |
fclose(fp); |
142 |
} |
143 |
} |
144 |
|
120 |
while ((entry = readdir(procdir)) != NULL) { |
145 |
while ((entry = readdir(procdir)) != NULL) { |
121 |
if (sscanf(entry->d_name, "%d", &p) != 1) |
146 |
if (sscanf(entry->d_name, "%d", &p) != 1) |
122 |
continue; |
147 |
continue; |
Lines 134-139
Link Here
|
134 |
if (argv && |
159 |
if (argv && |
135 |
!pid_is_argv(p, (const char *const *)argv)) |
160 |
!pid_is_argv(p, (const char *const *)argv)) |
136 |
continue; |
161 |
continue; |
|
|
162 |
// We are on an OpenVZ host -- filter out container processes: |
163 |
if (openvz_host) { |
164 |
snprintf(buffer, sizeof(buffer), "/proc/%d/status", p); |
165 |
if (exists(buffer)) { |
166 |
fp = fopen(buffer, "r"); |
167 |
if (! fp) |
168 |
continue; |
169 |
while (! feof(fp)) { |
170 |
rc_getline(&line, &len, fp); |
171 |
if (strncmp(line, "envID:", 6) == 0) { |
172 |
container_pid = ! (strncmp(line, "envID:\t0", 8) == 0); |
173 |
break; |
174 |
} |
175 |
} |
176 |
fclose(fp); |
177 |
} |
178 |
} |
179 |
if (container_pid) |
180 |
continue; |
137 |
if (!pids) { |
181 |
if (!pids) { |
138 |
pids = xmalloc(sizeof(*pids)); |
182 |
pids = xmalloc(sizeof(*pids)); |
139 |
LIST_INIT(pids); |
183 |
LIST_INIT(pids); |
Lines 142-147
Link Here
|
142 |
pi->pid = p; |
186 |
pi->pid = p; |
143 |
LIST_INSERT_HEAD(pids, pi, entries); |
187 |
LIST_INSERT_HEAD(pids, pi, entries); |
144 |
} |
188 |
} |
|
|
189 |
if (line != NULL) |
190 |
free(line); |
145 |
closedir(procdir); |
191 |
closedir(procdir); |
146 |
return pids; |
192 |
return pids; |
147 |
} |
193 |
} |