From: Mike Yuan Date: Sun, 12 Mar 2023 10:06:02 +0000 (+0800) Subject: edit-util: always create temp file X-Git-Tag: v254-rc1~1056^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=52073ba24773841a77aab1b91fc4541bdc94cc70;p=thirdparty%2Fsystemd.git edit-util: always create temp file even if neither original_path nor comment_paths is specified. --- diff --git a/src/shared/edit-util.c b/src/shared/edit-util.c index 734c06601ba..ab66fc1c1fd 100644 --- a/src/shared/edit-util.c +++ b/src/shared/edit-util.c @@ -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)