mirror of
https://github.com/systemd/systemd.git
synced 2025-01-12 13:18:14 +03:00
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
This commit is contained in:
parent
5a65d2e535
commit
848517ddd4
@ -483,6 +483,18 @@ static int trim_edit_markers(const char *path) {
|
|||||||
strshorten(contents_start, contents_end - contents_start);
|
strshorten(contents_start, contents_end - contents_start);
|
||||||
|
|
||||||
contents_start = strstrip(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 */
|
/* Write new contents if the trimming actually changed anything */
|
||||||
if (strlen(contents) != size) {
|
if (strlen(contents) != size) {
|
||||||
|
Loading…
Reference in New Issue
Block a user