]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
quotacheck: introduce string table for quota check mode
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Jul 2025 19:46:22 +0000 (04:46 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 15 Jul 2025 20:47:38 +0000 (05:47 +0900)
No functional change, just refactoring.

src/quotacheck/quotacheck.c

index b98819f0efec4db52ac3fdf3f820b19a90ca9e5b..49d63d77d025684c12a29582ffc489646067bd47 100644 (file)
@@ -7,10 +7,26 @@
 #include "main-func.h"
 #include "proc-cmdline.h"
 #include "process-util.h"
+#include "string-table.h"
 #include "string-util.h"
 
-static bool arg_skip = false;
-static bool arg_force = false;
+typedef enum QuotaCheckMode {
+        QUOTA_CHECK_AUTO,
+        QUOTA_CHECK_FORCE,
+        QUOTA_CHECK_SKIP,
+        _QUOTA_CHECK_MODE_MAX,
+        _QUOTA_CHECK_MODE_INVALID = -EINVAL,
+} QuotaCheckMode;
+
+static QuotaCheckMode arg_mode = QUOTA_CHECK_AUTO;
+
+static const char * const quota_check_mode_table[_QUOTA_CHECK_MODE_MAX] = {
+        [QUOTA_CHECK_AUTO]  = "auto",
+        [QUOTA_CHECK_FORCE] = "force",
+        [QUOTA_CHECK_SKIP]  = "skip",
+};
+
+DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(quota_check_mode, QuotaCheckMode);
 
 static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
 
@@ -19,17 +35,12 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
                 if (proc_cmdline_value_missing(key, value))
                         return 0;
 
-                if (streq(value, "auto"))
-                        arg_force = arg_skip = false;
-                else if (streq(value, "force"))
-                        arg_force = true;
-                else if (streq(value, "skip"))
-                        arg_skip = true;
-                else
-                        log_warning("Invalid quotacheck.mode= value, ignoring: %s", value);
+                arg_mode = quota_check_mode_from_string(value);
+                if (arg_mode < 0)
+                        log_warning_errno(arg_mode, "Invalid quotacheck.mode= value, ignoring: %s", value);
 
         } else if (streq(key, "forcequotacheck") && !value)
-                arg_force = true;
+                arg_mode = QUOTA_CHECK_FORCE;
 
         return 0;
 }
@@ -49,10 +60,10 @@ static int run(int argc, char *argv[]) {
         if (r < 0)
                 log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
 
-        if (!arg_force) {
-                if (arg_skip)
-                        return 0;
+        if (arg_mode == QUOTA_CHECK_SKIP)
+                return 0;
 
+        if (arg_mode == QUOTA_CHECK_AUTO) {
                 /* This is created by systemd-fsck when fsck detected and corrected errors. In normal
                  * operations quotacheck is not needed. */
                 if (access("/run/systemd/quotacheck", F_OK) < 0) {