diff options
author | наб <nabijaczleweli@nabijaczleweli.xyz> | 2022-11-08 21:30:01 +0100 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2022-11-22 01:45:50 +0100 |
commit | 848517ddd4c9b957828aa21dca1e6bc5dd3fb2cf (patch) | |
tree | 9427ac9648feced37b8979e0a66d37bb0a83ed6f /src | |
parent | bootctl: use grey-and-slash prefix for source in list too (diff) | |
download | systemd-848517ddd4c9b957828aa21dca1e6bc5dd3fb2cf.tar.xz systemd-848517ddd4c9b957828aa21dca1e6bc5dd3fb2cf.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/systemctl/systemctl-edit.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c index fe47f73d4a..e8e6eeda29 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) { |