]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
edit-util: do not try to recreate temp file if missing
authorMike Yuan <me@yhndnzj.com>
Sun, 11 Aug 2024 13:41:30 +0000 (15:41 +0200)
committerMike Yuan <me@yhndnzj.com>
Mon, 12 Aug 2024 14:06:37 +0000 (16:06 +0200)
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.

src/shared/edit-util.c

index 2d0129eda2791f478a6aaceadb94a98eddd5c671..b1f2aade2753c628f5a7b6216537c6f85692b160 100644 (file)
@@ -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);