]> Kevux Git Server - fll/commitdiff
Update: Improve robustness of the fll_control_group_prepare() function.
authorKevin Day <Kevin@kevux.org>
Wed, 11 Sep 2024 05:21:13 +0000 (00:21 -0500)
committerKevin Day <Kevin@kevux.org>
Wed, 11 Sep 2024 05:21:13 +0000 (00:21 -0500)
Add additional existence checks before attempting to create a directory within the cgroup path.

level_2/fll_control_group/c/control_group.c

index 65b2cae34039d22f520987f6b73db10fc2d6813c..ff3d6a682336203995c345bc2fe4b2c768def2bd 100644 (file)
@@ -33,11 +33,15 @@ extern "C" {
       memcpy(path.string + control_group.path.used, control_group.groups.array[i].string, sizeof(f_char_t) * control_group.groups.array[i].used);
       path.string[path.used] = 0;
 
-      status = fl_directory_create(path, F_file_mode_all_rwx_d);
-      if (F_status_is_error(status)) break;
-    } // for
+      status = f_directory_exists(path);
+      if (status == F_false) return F_status_set_error(F_directory_not);
+      if (F_status_is_error(status)) return status;
 
-    if (F_status_is_error(status)) return status;
+      if (status == F_file_found_not) {
+        status = fl_directory_create(path, F_file_mode_all_rwx_d);
+        if (F_status_is_error(status)) return status;
+      }
+    } // for
 
     return F_okay;
   }