From ff3ef35bfb351a528fd17ba77d6dd5a0e8ece95e Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Wed, 20 Sep 2017 16:08:52 -0400 Subject: [PATCH] Switch to matching cgroup mounts with zbx_regexp_sub() (#80) The string functions were failing to catch some variations in /proc/mounts formatting. --- .../zabbix_module_docker/zabbix_module_docker.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/modules/zabbix_module_docker/zabbix_module_docker.c b/src/modules/zabbix_module_docker/zabbix_module_docker.c index 1435df5..e1dfe29 100644 --- a/src/modules/zabbix_module_docker/zabbix_module_docker.c +++ b/src/modules/zabbix_module_docker/zabbix_module_docker.c @@ -23,6 +23,7 @@ #include "module.h" #include "sysinc.h" #include "zbxjson.h" +#include "zbxregexp.h" #include #include #include @@ -588,7 +589,7 @@ int zbx_docker_dir_detect() "" }, **tdriver; char path[512]; - char *temp1, *temp2; + const char *mounts_regex = "^[^[:blank:]]+[[:blank:]]+(/[^[:blank:]]+/)[^[:blank:]]+[[:blank:]]+cgroup[[:blank:]]+.*$"; FILE *fp; DIR *dir; @@ -602,12 +603,11 @@ int zbx_docker_dir_detect() { if ((strstr(path, "cpuset cgroup")) != NULL) { - temp1 = string_replace(path, "cgroup ", ""); - temp2 = string_replace(temp1, strstr(temp1, " "), ""); - free(temp1); - if (stat_dir != NULL) free(stat_dir); - stat_dir = string_replace(temp2, "cpuset", ""); - free(temp2); + if (SUCCEED != zbx_regexp_sub(path, mounts_regex, "\\1", &stat_dir) || NULL == stat_dir) + { + zabbix_log(LOG_LEVEL_WARNING, "Cannot detect docker stat directory in /proc/mounts"); + return SYSINFO_RET_FAIL; + } zabbix_log(LOG_LEVEL_DEBUG, "Detected docker stat directory: %s", stat_dir); pclose(fp);