From 41b283d0f1f4abd85d0bbeeb7f71bb30f87cfab9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 23 Feb 2018 20:46:38 +0100 Subject: [PATCH 1/2] conf-parser: let's explicitly deprecate .include in unit files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit .include lines are already deprecated somewhat, and for example explicitly not mentioned in the documentation for this reason. Let's get one step further and generatea warning when we encounter them (but still process them). Why are they deprecated? Because they are semantically awful — they complicate stat() based mtime checks for configuration files and they allow arbitrary loops we currently have zero protection against and really shouldn't have to have. --- src/shared/conf-parser.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 72c47150d0c..0ac63645774 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -211,6 +211,10 @@ static int parse_line( return 0; } + log_syntax(unit, LOG_WARNING, filename, line, 0, + ".include directives are deprecated, and support for them will be removed in a future version of systemd. " + "Please use drop-in files instead."); + fn = file_in_same_dir(filename, strstrip(l+9)); if (!fn) return -ENOMEM; From bdc8e623bb59dbe26179e2cd46d6c2c1915bb5b8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 23 Feb 2018 20:50:22 +0100 Subject: [PATCH 2/2] conf-parse: small prettification Let's use first_word() instead of startswith(), it's more explanatory and a bit more correct. Also, let's use the return value instead of adding +9 when looking for the second part of the directive. --- src/shared/conf-parser.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 0ac63645774..483dc1a69fc 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -180,7 +180,7 @@ static int parse_line( char *l, void *userdata) { - char *e; + char *e, *include; assert(filename); assert(line > 0); @@ -194,7 +194,8 @@ static int parse_line( if (strchr(COMMENTS "\n", *l)) return 0; - if (startswith(l, ".include ")) { + include = first_word(l, ".include"); + if (include) { _cleanup_free_ char *fn = NULL; /* .includes are a bad idea, we only support them here @@ -215,7 +216,7 @@ static int parse_line( ".include directives are deprecated, and support for them will be removed in a future version of systemd. " "Please use drop-in files instead."); - fn = file_in_same_dir(filename, strstrip(l+9)); + fn = file_in_same_dir(filename, strstrip(include)); if (!fn) return -ENOMEM;