]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
edit-util: always create temp file
authorMike Yuan <me@yhndnzj.com>
Sun, 12 Mar 2023 10:06:02 +0000 (18:06 +0800)
committerMike Yuan <me@yhndnzj.com>
Sun, 12 Mar 2023 16:41:11 +0000 (00:41 +0800)
even if neither original_path nor comment_paths is specified.

src/shared/edit-util.c

index 734c06601ba01d68e1b84effa700817a098095f3..ab66fc1c1fde8b572c5ad6555ba620c986874ce6 100644 (file)
@@ -122,6 +122,17 @@ static int create_edit_temp_file(EditFile *e) {
         if (r < 0)
                 return log_error_errno(r, "Failed to create parent directories for \"%s\": %m", e->path);
 
+        if (!e->original_path && !e->comment_paths) {
+                r = mac_selinux_create_file_prepare(e->path, S_IFREG);
+                if (r < 0)
+                        return r;
+
+                r = touch(temp);
+                mac_selinux_create_file_clear();
+                if (r < 0)
+                        return log_error_errno(r, "Failed to create temporary file \"%s\": %m", temp);
+        }
+
         if (e->original_path) {
                 r = mac_selinux_create_file_prepare(e->path, S_IFREG);
                 if (r < 0)