summaryrefslogtreecommitdiffstats
path: root/web/attachments/339420-check_procs_openvz.patch
blob: 2a2a28ca823740f35a7fa9750c5f17eb16bcf7e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 937c0ad..d1d5378 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -203,6 +203,9 @@ main (int argc, char **argv)
 
 			/* Ignore self */
 			if (mypid == procpid) continue;
+			
+			/* Ignore child containers if we're on an OpenVZ hardware node */
+			if (read_openvz_id(1) == 0 && read_openvz_id(procpid) != 0) continue;
 
 			if ((options & STAT) && (strstr (statopts, procstat)))
 				resultsum |= STAT;
@@ -666,6 +669,26 @@ convert_to_seconds(char *etime) {
 	return total;
 }
 
+/* Returns the OpenVZ enviroment ID of the specified process, or -1 if we're not on OpenVZ */
+int
+read_openvz_id(int procid) {
+	FILE *file;
+	char *filename = strdup("");
+	char line[64];
+	int result = -1;
+	
+	asprintf(&filename, "/proc/%d/status", procid);
+	
+	if ((file = fopen(filename, "r")) == NULL) return -1;
+	
+	while (fgets(line, sizeof(line), file) != NULL) {
+		sscanf(line, "envID:\t%d", &result);
+	}
+	
+	fclose(file);
+	return result;
+}
+
 
 void
 print_help (void)