Wildcard !include statements fail if nothing matches
Forwarding this report from Debian bug #1068478. Please see the full report for more context. [1]
Per the documentation on "Including config files", "It’s not an error if wildcards don’t result in any matching files." [2]
However, that statement does not seem to reflect the actual behavior of the code.
Some relevant snippets of code from src/config/config-parser.c:
from config_parse_line(): if (strcmp(key, "!include") == 0) return CONFIG_LINE_TYPE_INCLUDE; if (strcmp(key, "!include_try") == 0) return CONFIG_LINE_TYPE_INCLUDE_TRY;
This return value is later handled with a case statement in config_parser_apply_line(): case CONFIG_LINE_TYPE_INCLUDE: case CONFIG_LINE_TYPE_INCLUDE_TRY: (void)settings_include(ctx, fix_relative_path(value, ctx->cur_input), type == CONFIG_LINE_TYPE_INCLUDE_TRY); break;
The result of the "type == CONFIG_LINE_TYPE_INCLUDE_TRY" statement is passed as the bool ignore_errors parameter to bool ignore_errors(), so if it evaluates to false as it does when type == CONFIG_LINE_TYPE_INCLUDE, then we return an error:
case GLOB_NOMATCH:
if (ignore_errors)
return 0;
ctx->error = "No matches";
return -1;
The code is pretty straightforward in how it handles this scenario, so maybe the documentation should be clarified?
Thanks noah
You should use !include_try instead. See https://doc.dovecot.org/ configuration_manual/config_file/#including-config-files Aki On 17/04/2024 00:00 EEST Noah Meyerhans via dovecot <dovecot@dovecot.org> wrote: Forwarding this report from Debian bug #1068478. Please see the full report for more context. [1] Per the documentation on "Including config files", "It’s not an error if wildcards don’t result in any matching files." [2] However, that statement does not seem to reflect the actual behavior of the code. Some relevant snippets of code from src/config/config-parser.c: from config_parse_line(): if (strcmp(key, "!include") == 0) return CONFIG_LINE_TYPE_INCLUDE; if (strcmp(key, "!include_try") == 0) return CONFIG_LINE_TYPE_INCLUDE_TRY; This return value is later handled with a case statement in config_parser_apply_line(): case CONFIG_LINE_TYPE_INCLUDE: case CONFIG_LINE_TYPE_INCLUDE_TRY: (void)settings_include(ctx, fix_relative_path(value, ctx->cur_input), type == CONFIG_LINE_TYPE_INCLUDE_TRY); break; The result of the "type == CONFIG_LINE_TYPE_INCLUDE_TRY" statement is passed as the bool ignore_errors parameter to bool ignore_errors(), so if it evaluates to false as it does when type == CONFIG_LINE_TYPE_INCLUDE, then we return an error: case GLOB_NOMATCH: if (ignore_errors) return 0; ctx->error = "No matches"; return -1; The code is pretty straightforward in how it handles this scenario, so maybe the documentation should be clarified? Thanks noah 1. https://bugs.debian.org/1068478 2. https://doc.dovecot.org/configuration_manual/config_file/ #including-config-files _______________________________________________ dovecot mailing list -- dovecot@dovecot.org To unsubscribe send an email to dovecot-leave@dovecot.org
On Wed, Apr 17, 2024 at 10:08:14AM +0300, Aki Tuomi via dovecot wrote:
You should use !include_try instead. See https://doc.dovecot.org/ configuration_manual/config_file/#including-config-files
Yes, I'm familiar with !include_try, and it clearly works fine. This report is about an inconsistency between the documentation for !include (not !include_try) and the behavior. The documentation for wildcards with respect to !include states that "It’s not an error if wildcards don’t result in any matching files."
Please consider updating the documentation to match the actual behavior.
noah
participants (2)
-
Aki Tuomi
-
Noah Meyerhans