From: наб Date: Tue, 8 Nov 2022 20:30:01 +0000 (+0100) Subject: systemctl: edit: write override files as text files X-Git-Tag: v253-rc1~476 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=848517ddd4c9b957828aa21dca1e6bc5dd3fb2cf;p=thirdparty%2Fsystemd.git systemctl: edit: write override files as text files Instead of stripping the newline off the final would-be line; continue to reduce an empty-line-only file to an empty file, though Closes #25303 --- diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c index fe47f73d4a7..e8e6eeda290 100644 --- a/src/systemctl/systemctl-edit.c +++ b/src/systemctl/systemctl-edit.c @@ -483,6 +483,18 @@ static int trim_edit_markers(const char *path) { strshorten(contents_start, contents_end - contents_start); contents_start = strstrip(contents_start); + if (*contents_start && !endswith(contents_start, "\n")) { + char *tmp = contents_start; + if (MALLOC_SIZEOF_SAFE(contents) - (contents_start - contents) - strlen(contents_start) < 2) { + if ((tmp = realloc(contents, size + 1))) { + contents_start = tmp + (contents_start - contents); + contents = tmp; + } + } + + if (tmp) + strcat(contents_start, "\n"); + } /* Write new contents if the trimming actually changed anything */ if (strlen(contents) != size) {