prevent repeating cgroup errors when certain cgroup features are missing from the kernel
Costa Tsaousis committed
Aug 23, 2016 at 21:15 UTC
d9c264a7feef5fe1b3f00adc5cce4bee373e56e0
1 file changed
+32
-12
src/sys_fs_cgroup.c
+32
-12
@@ -799,10 +799,11 @@ void found_subdir_in_dir(const char *dir) {
799
if(cg) cg->available = 1;
800
}
801
802
-void find_dir_in_subdirs(const char *base, const char *this, void (*callback)(const char *)) {
802
+int find_dir_in_subdirs(const char *base, const char *this, void (*callback)(const char *)) {
803
debug(D_CGROUP, "searching for directories in '%s'", base);
804
805
- int enabled = -1;
805
+ int ret = 0;
806
+ int enabled = 0;
807
if(!this) this = base;
808
size_t dirlen = strlen(this), baselen = strlen(base);
809
const char *relative_path = &this[baselen];
@@ -810,8 +811,9 @@ void find_dir_in_subdirs(const char *base, const char *this, void (*callback)(co
811
DIR *dir = opendir(this);
812
if(!dir) {
813
error("Cannot read cgroups directory '%s'", base);
813
- return;
814
+ return ret;
815
}
816
+ ret = 1;
817
818
callback(relative_path);
819
@@ -846,13 +848,15 @@ void find_dir_in_subdirs(const char *base, const char *this, void (*callback)(co
848
strcpy(s, this);
849
strcat(s, "/");
850
strcat(s, de->d_name);
849
- find_dir_in_subdirs(base, s, callback);
851
+ int ret2 = find_dir_in_subdirs(base, s, callback);
852
+ if(ret2 > 0) ret += ret2;
853
freez(s);
854
}
855
}
856
}
857
858
closedir(dir);
859
+ return ret;
860
}
861
862
void mark_all_cgroups_as_not_available() {
@@ -895,17 +899,33 @@ void find_all_cgroups() {
899
900
mark_all_cgroups_as_not_available();
901
898
- if(cgroup_enable_cpuacct_stat || cgroup_enable_cpuacct_usage)
899
- find_dir_in_subdirs(cgroup_cpuacct_base, NULL, found_subdir_in_dir);
902
+ if(cgroup_enable_cpuacct_stat || cgroup_enable_cpuacct_usage) {
903
+ if (find_dir_in_subdirs(cgroup_cpuacct_base, NULL, found_subdir_in_dir) == -1) {
904
+ cgroup_enable_cpuacct_stat = cgroup_enable_cpuacct_usage = 0;
905
+ error("disabled cgroup cpu statistics.");
906
+ }
907
+ }
908
901
- if(cgroup_enable_blkio)
902
- find_dir_in_subdirs(cgroup_blkio_base, NULL, found_subdir_in_dir);
909
+ if(cgroup_enable_blkio) {
910
+ if (find_dir_in_subdirs(cgroup_blkio_base, NULL, found_subdir_in_dir) == -1) {
911
+ cgroup_enable_blkio = 0;
912
+ error("disabled cgroup blkio statistics.");
913
+ }
914
+ }
915
904
- if(cgroup_enable_memory)
905
- find_dir_in_subdirs(cgroup_memory_base, NULL, found_subdir_in_dir);
916
+ if(cgroup_enable_memory) {
917
+ if(find_dir_in_subdirs(cgroup_memory_base, NULL, found_subdir_in_dir) == -1) {
918
+ cgroup_enable_memory = 0;
919
+ error("disabled cgroup memory statistics.");
920
+ }
921
+ }
922
907
- if(cgroup_enable_devices)
908
- find_dir_in_subdirs(cgroup_devices_base, NULL, found_subdir_in_dir);
923
+ if(cgroup_enable_devices) {
924
+ if(find_dir_in_subdirs(cgroup_devices_base, NULL, found_subdir_in_dir) == -1) {
925
+ cgroup_enable_devices = 0;
926
+ error("disabled cgroup devices statistics.");
927
+ }
928
+ }
929
930
// remove any non-existing cgroups
931
cleanup_all_cgroups();