]> Kevux Git Server - fll/commitdiff
Update: properly process and support -c/--control custom control group file path.
authorKevin Day <thekevinday@gmail.com>
Mon, 12 Apr 2021 01:57:36 +0000 (20:57 -0500)
committerKevin Day <thekevinday@gmail.com>
Mon, 12 Apr 2021 01:57:36 +0000 (20:57 -0500)
This is a directory path to the sysfs cgroups directory.
It must end in a path separator '/'.

There is existing code that needed to be updated to use the -c/--control.
It was being ignored!

level_3/controller/c/controller.c
level_3/controller/c/controller.h
level_3/controller/c/private-common.c
level_3/controller/c/private-common.h
level_3/controller/c/private-controller.c
level_3/controller/c/private-rule.c

index 77abe1b7646a0b6e5676fa86b218c77dcf808493..2c704a05bdb1c53f6f28f3d8e1b1c253bcbd2de7 100644 (file)
@@ -27,7 +27,7 @@ extern "C" {
 
     fprintf(output.stream, "%c", f_string_eol_s[0]);
 
-    fll_program_print_help_option(output, context, controller_short_control, controller_long_control, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "      Specify a custom control group file path, such as '" controller_path_control "'.");
+    fll_program_print_help_option(output, context, controller_short_control, controller_long_control, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "      Specify a custom control group file path, such as '" f_control_group_path_system_prefix f_control_group_path_system_default "'.");
     fll_program_print_help_option(output, context, controller_short_daemon, controller_long_daemon, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "       Run in daemon only mode (do not process the entry).");
     fll_program_print_help_option(output, context, controller_short_interruptable, controller_long_interruptable, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "Designate that this program can be interrupted.");
     fll_program_print_help_option(output, context, controller_short_pid, controller_long_pid, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "          Specify a custom pid file path, such as '" controller_path_pid controller_string_default controller_path_suffix "'.");
@@ -262,6 +262,24 @@ extern "C" {
             fll_error_print(data->error, F_status_set_fine(status), "fll_path_canonical", F_true);
           }
         }
+        else {
+          status = f_string_append_assure(f_path_separator, 1, &setting.path_control);
+
+          if (F_status_is_error(status)) {
+            if (data->error.verbosity != f_console_verbosity_quiet) {
+              fll_error_print(data->error, F_status_set_fine(status), "f_string_append_assure", F_true);
+            }
+          }
+          else {
+            status = f_string_dynamic_terminate_after(&setting.path_control);
+
+            if (F_status_is_error(status)) {
+              if (data->error.verbosity != f_console_verbosity_quiet) {
+                fll_error_print(data->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true);
+              }
+            }
+          }
+        }
       }
       else {
         if (data->warning.verbosity == f_console_verbosity_debug) {
@@ -305,11 +323,33 @@ extern "C" {
 
       // a control file path is required.
       if (!setting.path_control.used) {
-        status = f_string_append(controller_path_control, controller_path_control_length, &setting.path_control);
+        status = f_string_append_nulless(f_control_group_path_system_prefix, f_control_group_path_system_prefix_length, &setting.path_control);
+
+        if (F_status_is_error_not(status)) {
+          status = f_string_append_nulless(f_control_group_path_system_default, f_control_group_path_system_default_length, &setting.path_control);
+        }
 
         if (F_status_is_error(status)) {
           if (data->error.verbosity != f_console_verbosity_quiet) {
-            fll_error_print(data->error, F_status_set_fine(status), "f_string_append", F_true);
+            fll_error_print(data->error, F_status_set_fine(status), "f_string_append_nulless", F_true);
+          }
+        }
+        else {
+          status = f_string_append_assure(f_path_separator, 1, &setting.path_control);
+
+          if (F_status_is_error(status)) {
+            if (data->error.verbosity != f_console_verbosity_quiet) {
+              fll_error_print(data->error, F_status_set_fine(status), "f_string_append_assure", F_true);
+            }
+          }
+          else {
+            status = f_string_dynamic_terminate_after(&setting.path_control);
+
+            if (F_status_is_error(status)) {
+              if (data->error.verbosity != f_console_verbosity_quiet) {
+                fll_error_print(data->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true);
+              }
+            }
           }
         }
       }
index 3d35094ab193ac4f80cfc89144c903435022aec7..69be87a2e9711999b77b6b6b42d2257798388af4 100644 (file)
@@ -94,12 +94,10 @@ extern "C" {
 
   #define controller_default_program_script "bash"
 
-  #define controller_path_control  "/sys/fs/cgroup/unified"
   #define controller_path_pid      "/var/run/controller/controller-"
   #define controller_path_settings "/etc/controller"
   #define controller_path_suffix   ".pid"
 
-  #define controller_path_control_length  22
   #define controller_path_pid_length      31
   #define controller_path_settings_length 15
   #define controller_path_suffix_length   4
index efa6fd0e291a32c24cf2a56b7fef1c6d261f58bd..6eff7157fa2c8296bda397eae489c22f50d03a4b 100644 (file)
@@ -83,6 +83,19 @@ extern "C" {
   }
 #endif // _di_controller_entry_items_delete_simple_
 
+#ifndef _di_controller_error_file_print_
+  void controller_error_file_print(const fll_error_print_t print, const f_status_t status, const f_string_t function, const bool fallback, const f_string_t name, const f_string_t operation, const uint8_t type, controller_thread_t *thread) {
+
+    if (print.verbosity != f_console_verbosity_quiet) {
+      f_thread_mutex_lock(&thread->lock.print);
+
+      fll_error_file_print(print, status, function, fallback, name, operation, type);
+
+      controller_print_unlock_flush(print.to.stream, &thread->lock.print);
+    }
+  }
+#endif // _di_controller_error_file_print_
+
 #ifndef _di_controller_error_print_
   void controller_error_print(const fll_error_print_t print, const f_status_t status, const f_string_t function, const bool fallback, controller_thread_t *thread) {
 
index 74f00119b0a6a4e2800930b516b01541487f9c11..29a6be4527ed680be85ad859ca493f39e9d79bf4 100644 (file)
@@ -1251,6 +1251,35 @@ extern "C" {
 #endif // _di_controller_entry_items_delete_simple_
 
 /**
+ * Print the file error, locking the print mutex during the print.
+ *
+ * @param print
+ *   Designates how printing is to be performed.
+ * @param status
+ *   The status code to process.
+ *   Make sure this has F_status_set_fine() called if the status code has any error or warning bits.
+ * @param function
+ *   The name of the function where the error happened.
+ *   Set to 0 to disable.
+ * @param fallback
+ *   Set to F_true to print the fallback error message for unknown errors.
+ * @param name
+ *   The name of the file or directory.
+ * @param operation
+ *   The operation that fails, such as 'create' or 'access'.
+ * @param type
+ *   A valid file type code from the fll_error_file_type enum.
+ * @param thread
+ *   The thread data.
+ *
+ * @see fll_error_file_print()
+ */
+#ifndef _di_controller_error_file_print_
+  extern void controller_error_file_print(const fll_error_print_t print, const f_status_t status, const f_string_t function, const bool fallback, const f_string_t name, const f_string_t operation, const uint8_t type, controller_thread_t *thread) f_gcc_attribute_visibility_internal;
+#endif // _di_controller_error_file_print_
+
+
+/**
  * Print the error, locking the print mutex during the print.
  *
  * @param print
index 8250911f2519a310f5b4528f979bba7b8f0b3edf..3052cd92de5dbf3e39f307c23284301e4b4c5761 100644 (file)
@@ -265,7 +265,6 @@ extern "C" {
   f_status_t controller_get_id_user(const f_string_static_t buffer, const f_string_range_t range, controller_cache_t *cache, uid_t *id) {
     f_number_unsigned_t number = 0;
 
-    // @todo fix argument ordering in fl_conversion_string_to_number_unsigned().
     f_status_t status = fl_conversion_string_to_number_unsigned(buffer.string, range, &number);
 
     if (F_status_is_error(status)) {
@@ -307,7 +306,6 @@ extern "C" {
   f_status_t controller_get_id_group(const f_string_static_t buffer, const f_string_range_t range, controller_cache_t *cache, gid_t *id) {
     f_number_unsigned_t number = 0;
 
-    // @todo fix argument ordering in fl_conversion_string_to_number_unsigned().
     f_status_t status = fl_conversion_string_to_number_unsigned(buffer.string, range, &number);
 
     if (F_status_is_error(status)) {
index 804e18898e0e68d5a67edad85e331f2509cb4ab8..11f76ceaddb82ac37a2162f68b7dee66a634276e 100644 (file)
@@ -780,7 +780,7 @@ extern "C" {
         status = fll_control_group_prepare(process->rule.control_group);
 
         if (F_status_is_error(status)) {
-          controller_error_print(main.data->error, F_status_set_fine(status), "fll_control_group_prepare", F_true, main.thread);
+          controller_error_file_print(main.data->error, F_status_set_fine(status), "fll_control_group_prepare", F_true, process->rule.control_group.path.string, "prepare control groups for", fll_error_file_type_directory, main.thread);
 
           return status;
         }
@@ -3311,15 +3311,10 @@ extern "C" {
 
         rule->control_group.path.used = 0;
 
-        // @todo path prefix needs to be configurable via a parameter.
-        status = f_string_append(f_control_group_path_system_prefix, f_control_group_path_system_prefix_length, &rule->control_group.path);
-
-        if (F_status_is_error_not(status)) {
-          status = f_string_append(f_control_group_path_system_default, f_control_group_path_system_default_length, &rule->control_group.path);
-        }
+        status = f_string_dynamic_append(main.setting->path_control, &rule->control_group.path);
 
         if (F_status_is_error(status)) {
-          controller_rule_error_print(main.data->error, cache->action, F_status_set_fine(status), "f_string_append", F_true, F_false, main.thread);
+          controller_rule_error_print(main.data->error, cache->action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_false, main.thread);
         }
         else {
           rule->control_group.groups.used = 0;