X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fhugepages.c;h=ac9441d092ecc9227e977f9971a3c0d323c614c3;hb=4d370741101aeb037ae52f3529a4a0869e0dc08a;hp=e7b98da47d62e8658eefda7424a83bcd0da0c2e9;hpb=26c9dd08034c325d8a20ab80e9fba3d2c164f933;p=collectd.git diff --git a/src/hugepages.c b/src/hugepages.c index e7b98da4..ac9441d0 100644 --- a/src/hugepages.c +++ b/src/hugepages.c @@ -187,6 +187,7 @@ static int read_syshugepages(const char* path, const char* node) while ((result = readdir(dir)) != NULL) { if (strncmp(result->d_name, hugepages_dir, sizeof(hugepages_dir)-1)) { /* not node dir */ + errno = 0; continue; } @@ -196,10 +197,17 @@ static int read_syshugepages(const char* path, const char* node) e_info.d_name = result->d_name; e_info.node = node; walk_directory(path2, read_hugepage_entry, &e_info, 0); + errno = 0; } - closedir(dir); + /* Check if NULL return from readdir() was an error */ + if (errno != 0) { + ERROR("%s: readdir failed", g_plugin_name); + closedir(dir); + return -1; + } + closedir(dir); return 0; } @@ -220,7 +228,7 @@ static int read_nodes(void) } errno = 0; - if ((lim = pathconf(path, _PC_NAME_MAX)) == -1) { + if ((lim = pathconf(sys_node, _PC_NAME_MAX)) == -1) { /* Limit not defined if errno == 0, otherwise error */ if (errno != 0) { ERROR("%s: pathconf failed", g_plugin_name); @@ -234,15 +242,23 @@ static int read_nodes(void) while ((result = readdir(dir)) != NULL) { if (strncmp(result->d_name, node_string, sizeof(node_string)-1)) { /* not node dir */ + errno = 0; continue; } ssnprintf(path, (size_t) lim, sys_node_hugepages, result->d_name); read_syshugepages(path, result->d_name); + errno = 0; } - closedir(dir); + /* Check if NULL return from readdir() was an error */ + if (errno != 0) { + ERROR("%s: readdir failed", g_plugin_name); + closedir(dir); + return -1; + } + closedir(dir); return 0; }