summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f91506b)
raw | patch | inline | side by side (parent: f91506b)
author | Kim Jones <kim-marie.jones@intel.com> | |
Tue, 16 Aug 2016 15:00:27 +0000 (16:00 +0100) | ||
committer | Kim Jones <kim-marie.jones@intel.com> | |
Tue, 16 Aug 2016 16:50:32 +0000 (17:50 +0100) |
Fix typo in .pod file.
Change char * strings to static const char [].
Change INFO() to DEBUG() in 1 place.
Removed unnecessary initialisations & casts.
Fixed ignored error returns from some funcs.
Actually use result returned from pathconf().
Change-Id: I0b59af4eb8afd29141abfa9233ca1d4a8d19d0d1
Signed-off-by: Kim Jones <kim-marie.jones@intel.com>
Change char * strings to static const char [].
Change INFO() to DEBUG() in 1 place.
Removed unnecessary initialisations & casts.
Fixed ignored error returns from some funcs.
Actually use result returned from pathconf().
Change-Id: I0b59af4eb8afd29141abfa9233ca1d4a8d19d0d1
Signed-off-by: Kim Jones <kim-marie.jones@intel.com>
src/collectd.conf.pod | patch | blob | history | |
src/hugepages.c | patch | blob | history |
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 65fdc53d2f099f4d13cac929ffaa9c1df7aa63db..b6d04ca2b6ce5b1f520630f5169e77f5fc0cb92f 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
To collect B<hugepages> information, collectd reads directories
"/sys/devices/system/node/*/hugepages" and
"/sys/kernel/mm/hugepages".
-Reading of these directories can be disabled by following
-options. Default is enabled.
+Reading of these directories can be disabled by the following
+options (default is enabled).
=over 4
diff --git a/src/hugepages.c b/src/hugepages.c
index ee43237032955608270bb662c7f39737cddc4afd..e7b98da47d62e8658eefda7424a83bcd0da0c2e9 100644 (file)
--- a/src/hugepages.c
+++ b/src/hugepages.c
struct entry_info {
char *d_name;
- char *node;
+ const char *node;
};
static int huge_config_callback(const char *key, const char *val)
{
- INFO("%s: HugePages config key='%s', val='%s'", g_plugin_name, key, val);
+ DEBUG("%s: HugePages config key='%s', val='%s'", g_plugin_name, key, val);
if (strcasecmp(key, g_cfg_rpt_numa) == 0) {
g_flag_rpt_numa = IS_TRUE(val);
void *e_info)
{
char path2[PATH_MAX];
- char *type = "hugepages";
- char *partial_type_inst = "free_used";
+ static const char type[] = "hugepages";
+ static const char partial_type_inst[] = "free_used";
char type_instance[PATH_MAX];
- char *strin = NULL;
- struct entry_info *hpsize_plinst = (struct entry_info *) e_info;
+ char *strin;
+ struct entry_info *hpsize_plinst = e_info;
static int flag = 0;
static double used_hp = 0;
static double free_hp = 0;
static int read_syshugepages(const char* path, const char* node)
{
- const char hugepages_dir[] = "hugepages";
- DIR *dir = NULL;
- struct dirent *result = NULL;
+ static const char hugepages_dir[] = "hugepages";
+ DIR *dir;
+ struct dirent *result;
char path2[PATH_MAX];
struct entry_info e_info;
+ long lim;
dir = opendir(path);
if (dir == NULL) {
return -1;
}
- if (pathconf(path, _PC_NAME_MAX) == -1) {
- /* Limit not defined, or error */
- ERROR("%s: pathconf failed", g_plugin_name);
- closedir(dir);
- return -1;
+ errno = 0;
+ if ((lim = pathconf(path, _PC_NAME_MAX)) == -1) {
+ /* Limit not defined if errno == 0, otherwise error */
+ if (errno != 0) {
+ ERROR("%s: pathconf failed", g_plugin_name);
+ closedir(dir);
+ return -1;
+ } else {
+ lim = PATH_MAX;
+ }
}
/* read "hugepages-XXXXXkB" entries */
}
/* /sys/devices/system/node/node?/hugepages/ */
- ssnprintf(path2, sizeof(path2), "%s/%s", path, result->d_name);
+ ssnprintf(path2, (size_t) lim, "%s/%s", path, result->d_name);
e_info.d_name = result->d_name;
- e_info.node = (char *) node;
- walk_directory(path2, read_hugepage_entry, (void *) &e_info, 0);
+ e_info.node = node;
+ walk_directory(path2, read_hugepage_entry, &e_info, 0);
}
closedir(dir);
static int read_nodes(void)
{
- const char sys_node[] = "/sys/devices/system/node";
- const char node_string[] = "node";
- const char sys_node_hugepages[] = "/sys/devices/system/node/%s/hugepages";
- DIR *dir = NULL;
- struct dirent *result = NULL;
+ static const char sys_node[] = "/sys/devices/system/node";
+ static const char node_string[] = "node";
+ static const char sys_node_hugepages[] = "/sys/devices/system/node/%s/hugepages";
+ DIR *dir;
+ struct dirent *result;
char path[PATH_MAX];
+ long lim;
dir = opendir(sys_node);
if (dir == NULL) {
return -1;
}
- if (pathconf(sys_node, _PC_NAME_MAX) == -1) {
- /* Limit not defined, or error */
- ERROR("%s: pathconf failed", g_plugin_name);
- closedir(dir);
- return -1;
+ errno = 0;
+ if ((lim = pathconf(path, _PC_NAME_MAX)) == -1) {
+ /* Limit not defined if errno == 0, otherwise error */
+ if (errno != 0) {
+ ERROR("%s: pathconf failed", g_plugin_name);
+ closedir(dir);
+ return -1;
+ } else {
+ lim = PATH_MAX;
+ }
}
while ((result = readdir(dir)) != NULL) {
continue;
}
- ssnprintf(path, sizeof(path), sys_node_hugepages, result->d_name);
+ ssnprintf(path, (size_t) lim, sys_node_hugepages, result->d_name);
read_syshugepages(path, result->d_name);
}
static int huge_read(void)
{
- const char sys_mm_hugepages[] = "/sys/kernel/mm/hugepages";
+ static const char sys_mm_hugepages[] = "/sys/kernel/mm/hugepages";
if (g_flag_rpt_mm) {
- read_syshugepages(sys_mm_hugepages, "mm");
+ if (read_syshugepages(sys_mm_hugepages, "mm") != 0) {
+ return -1;
+ }
}
if (g_flag_rpt_numa) {
- read_nodes();
+ if (read_nodes() != 0) {
+ return -1;
+ }
}
return 0;