prevent error log flood when certain cgroup features are missing from the kernel; fixes #749
Costa Tsaousis committed
Aug 1, 2016 at 18:41 UTC
9c9a9d2910ee82e2cd966085e5fdf6ffb4ade925
1 file changed
+49
-20
src/sys_fs_cgroup.c
+49
-20
@@ -8,6 +8,7 @@
8
#include <sys/types.h>
9
#include <dirent.h>
10
#include <string.h>
11
+#include <sys/stat.h>
12
13
#include "common.h"
14
#include "appconfig.h"
@@ -923,6 +924,7 @@ void find_all_cgroups() {
924
cleanup_all_cgroups();
925
926
struct cgroup *cg;
927
+ struct stat buf;
928
for(cg = cgroup_root; cg ; cg = cg->next) {
929
// fprintf(stderr, " >>> CGROUP '%s' (%u - %s) with name '%s'\n", cg->id, cg->hash, cg->available?"available":"stopped", cg->name);
930
@@ -936,49 +938,76 @@ void find_all_cgroups() {
938
char filename[FILENAME_MAX + 1];
939
if(cgroup_enable_cpuacct_stat && !cg->cpuacct_stat.filename) {
940
snprintfz(filename, FILENAME_MAX, "%s%s/cpuacct.stat", cgroup_cpuacct_base, cg->id);
939
- cg->cpuacct_stat.filename = strdup(filename);
940
- debug(D_CGROUP, "cpuacct.stat filename for cgroup '%s': '%s'", cg->id, cg->cpuacct_stat.filename);
941
+ if(stat(filename, &buf) != -1) {
942
+ cg->cpuacct_stat.filename = strdup(filename);
943
+ debug(D_CGROUP, "cpuacct.stat filename for cgroup '%s': '%s'", cg->id, cg->cpuacct_stat.filename);
944
+ }
945
+ else debug(D_CGROUP, "cpuacct.stat file for cgroup '%s': '%s' does not exist.", cg->id, filename);
946
}
947
if(cgroup_enable_cpuacct_usage && !cg->cpuacct_usage.filename) {
948
snprintfz(filename, FILENAME_MAX, "%s%s/cpuacct.usage_percpu", cgroup_cpuacct_base, cg->id);
944
- cg->cpuacct_usage.filename = strdup(filename);
945
- debug(D_CGROUP, "cpuacct.usage_percpu filename for cgroup '%s': '%s'", cg->id, cg->cpuacct_usage.filename);
949
+ if(stat(filename, &buf) != -1) {
950
+ cg->cpuacct_usage.filename = strdup(filename);
951
+ debug(D_CGROUP, "cpuacct.usage_percpu filename for cgroup '%s': '%s'", cg->id, cg->cpuacct_usage.filename);
952
+ }
953
+ else debug(D_CGROUP, "cpuacct.usage_percpu file for cgroup '%s': '%s' does not exist.", cg->id, filename);
954
}
955
if(cgroup_enable_memory && !cg->memory.filename) {
956
snprintfz(filename, FILENAME_MAX, "%s%s/memory.stat", cgroup_memory_base, cg->id);
949
- cg->memory.filename = strdup(filename);
950
- debug(D_CGROUP, "memory.stat filename for cgroup '%s': '%s'", cg->id, cg->memory.filename);
957
+ if(stat(filename, &buf) != -1) {
958
+ cg->memory.filename = strdup(filename);
959
+ debug(D_CGROUP, "memory.stat filename for cgroup '%s': '%s'", cg->id, cg->memory.filename);
960
+ }
961
+ else debug(D_CGROUP, "memory.stat file for cgroup '%s': '%s' does not exist.", cg->id, filename);
962
}
963
if(cgroup_enable_blkio) {
964
if(!cg->io_service_bytes.filename) {
965
snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_service_bytes", cgroup_blkio_base, cg->id);
955
- cg->io_service_bytes.filename = strdup(filename);
956
- debug(D_CGROUP, "io_service_bytes filename for cgroup '%s': '%s'", cg->id, cg->io_service_bytes.filename);
966
+ if(stat(filename, &buf) != -1) {
967
+ cg->io_service_bytes.filename = strdup(filename);
968
+ debug(D_CGROUP, "io_service_bytes filename for cgroup '%s': '%s'", cg->id, cg->io_service_bytes.filename);
969
+ }
970
+ else debug(D_CGROUP, "io_service_bytes file for cgroup '%s': '%s' does not exist.", cg->id, filename);
971
}
972
if(!cg->io_serviced.filename) {
973
snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_serviced", cgroup_blkio_base, cg->id);
960
- cg->io_serviced.filename = strdup(filename);
961
- debug(D_CGROUP, "io_serviced filename for cgroup '%s': '%s'", cg->id, cg->io_serviced.filename);
974
+ if(stat(filename, &buf) != -1) {
975
+ cg->io_serviced.filename = strdup(filename);
976
+ debug(D_CGROUP, "io_serviced filename for cgroup '%s': '%s'", cg->id, cg->io_serviced.filename);
977
+ }
978
+ else debug(D_CGROUP, "io_serviced file for cgroup '%s': '%s' does not exist.", cg->id, filename);
979
}
980
if(!cg->throttle_io_service_bytes.filename) {
981
snprintfz(filename, FILENAME_MAX, "%s%s/blkio.throttle.io_service_bytes", cgroup_blkio_base, cg->id);
965
- cg->throttle_io_service_bytes.filename = strdup(filename);
966
- debug(D_CGROUP, "throttle_io_service_bytes filename for cgroup '%s': '%s'", cg->id, cg->throttle_io_service_bytes.filename);
982
+ if(stat(filename, &buf) != -1) {
983
+ cg->throttle_io_service_bytes.filename = strdup(filename);
984
+ debug(D_CGROUP, "throttle_io_service_bytes filename for cgroup '%s': '%s'", cg->id, cg->throttle_io_service_bytes.filename);
985
+ }
986
+ else debug(D_CGROUP, "throttle_io_service_bytes file for cgroup '%s': '%s' does not exist.", cg->id, filename);
987
}
988
if(!cg->throttle_io_serviced.filename) {
989
snprintfz(filename, FILENAME_MAX, "%s%s/blkio.throttle.io_serviced", cgroup_blkio_base, cg->id);
970
- cg->throttle_io_serviced.filename = strdup(filename);
971
- debug(D_CGROUP, "throttle_io_serviced filename for cgroup '%s': '%s'", cg->id, cg->throttle_io_serviced.filename);
990
+ if(stat(filename, &buf) != -1) {
991
+ cg->throttle_io_serviced.filename = strdup(filename);
992
+ debug(D_CGROUP, "throttle_io_serviced filename for cgroup '%s': '%s'", cg->id, cg->throttle_io_serviced.filename);
993
+ }
994
+ else debug(D_CGROUP, "throttle_io_serviced file for cgroup '%s': '%s' does not exist.", cg->id, filename);
995
}
996
if(!cg->io_merged.filename) {
997
snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_merged", cgroup_blkio_base, cg->id);
975
- cg->io_merged.filename = strdup(filename);
976
- debug(D_CGROUP, "io_merged filename for cgroup '%s': '%s'", cg->id, cg->io_merged.filename);
998
+ if(stat(filename, &buf) != -1) {
999
+ cg->io_merged.filename = strdup(filename);
1000
+ debug(D_CGROUP, "io_merged filename for cgroup '%s': '%s'", cg->id, cg->io_merged.filename);
1001
+ }
1002
+ else debug(D_CGROUP, "io_merged file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1003
}
1004
if(!cg->io_queued.filename) {
1005
snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_queued", cgroup_blkio_base, cg->id);
980
- cg->io_queued.filename = strdup(filename);
981
- debug(D_CGROUP, "io_queued filename for cgroup '%s': '%s'", cg->id, cg->io_queued.filename);
1006
+ if(stat(filename, &buf) != -1) {
1007
+ cg->io_queued.filename = strdup(filename);
1008
+ debug(D_CGROUP, "io_queued filename for cgroup '%s': '%s'", cg->id, cg->io_queued.filename);
1009
+ }
1010
+ else debug(D_CGROUP, "io_queued file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1011
}
1012
}
1013
}
@@ -1242,12 +1271,12 @@ void update_cgroup_charts(int update_every) {
1271
// cgroups main
1272
1273
int do_sys_fs_cgroup(int update_every, unsigned long long dt) {
1274
+ (void)dt;
1275
+
1276
static int cgroup_global_config_read = 0;
1277
static time_t last_run = 0;
1278
time_t now = time(NULL);
1279
1249
- if(dt) {};
1250
-
1280
if(unlikely(!cgroup_global_config_read)) {
1281
read_cgroup_plugin_configuration();
1282
cgroup_global_config_read = 1;