From: Mike Yuan Date: Sun, 11 Aug 2024 13:41:30 +0000 (+0200) Subject: edit-util: do not try to recreate temp file if missing X-Git-Tag: v257-rc1~712^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b5b2ff8fa6413afc2e5a058ea8281a58a4c691d;p=thirdparty%2Fsystemd.git edit-util: do not try to recreate temp file if missing We initially read from temp file, then strip it, and write back to it. If the file suddenly disappeared during the process, it indicates someone else is touching our temp file behind our back. Let's not silently continue. --- diff --git a/src/shared/edit-util.c b/src/shared/edit-util.c index 2d0129eda27..b1f2aade275 100644 --- a/src/shared/edit-util.c +++ b/src/shared/edit-util.c @@ -356,7 +356,7 @@ static int strip_edit_temp_file(EditFile *e) { return 1; /* Contents have real changes */ r = write_string_file(e->temp, new_contents, - WRITE_STRING_FILE_CREATE | WRITE_STRING_FILE_TRUNCATE | WRITE_STRING_FILE_AVOID_NEWLINE); + WRITE_STRING_FILE_TRUNCATE | WRITE_STRING_FILE_AVOID_NEWLINE); if (r < 0) return log_error_errno(r, "Failed to strip temporary file '%s': %m", e->temp);