Skip to content

Commit

Permalink
Switch to matching cgroup mounts with zbx_regexp_sub() (#80)
Browse files Browse the repository at this point in the history
The string functions were failing to catch some variations in /proc/mounts formatting.
  • Loading branch information
overhacked authored and jangaraj committed Sep 20, 2017
1 parent c8792f2 commit ff3ef35
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/modules/zabbix_module_docker/zabbix_module_docker.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "module.h"
#include "sysinc.h"
#include "zbxjson.h"
#include "zbxregexp.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit ff3ef35

Please sign in to comment.