From: Yu Watanabe Date: Sat, 12 Jul 2025 19:46:22 +0000 (+0900) Subject: quotacheck: introduce string table for quota check mode X-Git-Tag: v258-rc1~48^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d73691c64e05650d838aaeb7da94fd8bdfb60907;p=thirdparty%2Fsystemd.git quotacheck: introduce string table for quota check mode No functional change, just refactoring. --- diff --git a/src/quotacheck/quotacheck.c b/src/quotacheck/quotacheck.c index b98819f0efe..49d63d77d02 100644 --- a/src/quotacheck/quotacheck.c +++ b/src/quotacheck/quotacheck.c @@ -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) {