From: Yu Watanabe Date: Sat, 12 Jul 2025 19:52:36 +0000 (+0900) Subject: quotacheck: add quotacheck.mode credential support X-Git-Tag: v258-rc1~48^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dba4fe9a60e8876addcd6a597c9e1d5f529309ca;p=thirdparty%2Fsystemd.git quotacheck: add quotacheck.mode credential support --- diff --git a/man/systemd-quotacheck@.service.xml b/man/systemd-quotacheck@.service.xml index 503df381e0f..56397ff7bda 100644 --- a/man/systemd-quotacheck@.service.xml +++ b/man/systemd-quotacheck@.service.xml @@ -62,6 +62,32 @@ + + Credentials + + systemd-quotacheck supports the service credentials logic as implemented by + ImportCredential=/LoadCredential=/SetCredential= + (see systemd.exec5 for + details). The following credentials are used when passed in: + + + + quotacheck.mode + + + The contents of the credential is parsed as same as the kernel command line option with the + same name. See above for more details. + + + + + + + Note that by default the systemd-quotacheck@.service and + systemd-quotacheck-root.service unit files are set up to inherit + quotacheck.mode credential from the service manager. + + See Also diff --git a/man/systemd.system-credentials.xml b/man/systemd.system-credentials.xml index 0411061ca39..fd0d12320da 100644 --- a/man/systemd.system-credentials.xml +++ b/man/systemd.system-credentials.xml @@ -524,6 +524,19 @@ + + + quotacheck.* + + + Read by systemd-quotacheck@.service and + systemd-quotacheck-root.service. See + systemd-quotacheck8 + for more details. + + + + diff --git a/src/quotacheck/quotacheck.c b/src/quotacheck/quotacheck.c index 49d63d77d02..f6866213481 100644 --- a/src/quotacheck/quotacheck.c +++ b/src/quotacheck/quotacheck.c @@ -3,6 +3,7 @@ #include #include +#include "creds-util.h" #include "log.h" #include "main-func.h" #include "proc-cmdline.h" @@ -45,6 +46,20 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat return 0; } +static void parse_credentials(void) { + _cleanup_free_ char *value = NULL; + int r; + + r = read_credential("quotacheck.mode", (void**) &value, /* ret_size = */ NULL); + if (r < 0) + log_debug_errno(r, "Failed to read credential 'quotacheck.mode', ignoring: %m"); + else { + arg_mode = quota_check_mode_from_string(value); + if (arg_mode < 0) + log_warning_errno(arg_mode, "Invalid 'quotacheck.mode' credential, ignoring: %s", value); + } +} + static int run(int argc, char *argv[]) { int r; @@ -60,6 +75,8 @@ static int run(int argc, char *argv[]) { if (r < 0) log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m"); + parse_credentials(); + if (arg_mode == QUOTA_CHECK_SKIP) return 0; diff --git a/units/systemd-quotacheck-root.service.in b/units/systemd-quotacheck-root.service.in index 4792e5bdd5b..eea656c562b 100644 --- a/units/systemd-quotacheck-root.service.in +++ b/units/systemd-quotacheck-root.service.in @@ -23,3 +23,4 @@ Type=oneshot RemainAfterExit=yes ExecStart={{LIBEXECDIR}}/systemd-quotacheck / TimeoutSec=infinity +ImportCredential=quotacheck.* diff --git a/units/systemd-quotacheck@.service.in b/units/systemd-quotacheck@.service.in index b38450ed098..7569052d820 100644 --- a/units/systemd-quotacheck@.service.in +++ b/units/systemd-quotacheck@.service.in @@ -25,3 +25,4 @@ Type=oneshot RemainAfterExit=yes ExecStart={{LIBEXECDIR}}/systemd-quotacheck %f TimeoutSec=infinity +ImportCredential=quotacheck.*