From nobody Fri Nov 1 00:17:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666865753364661.5658475559425; Thu, 27 Oct 2022 03:15:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onzuz-0003Tq-14; Thu, 27 Oct 2022 06:15:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onzuv-0002kO-L6 for qemu-devel@nongnu.org; Thu, 27 Oct 2022 06:15:17 -0400 Received: from proxmox-new.maurer-it.com ([94.136.29.106]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onzur-000610-Mh for qemu-devel@nongnu.org; Thu, 27 Oct 2022 06:15:17 -0400 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 31D0044038; Thu, 27 Oct 2022 12:14:59 +0200 (CEST) From: Fiona Ebner To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, hreitz@redhat.com, t.lamprecht@proxmox.com, d.csapak@proxmox.com Subject: [PATCH] vl: change PID file path resolve error to warning Date: Thu, 27 Oct 2022 12:14:43 +0200 Message-Id: <20221027101443.118049-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=94.136.29.106; envelope-from=f.ebner@proxmox.com; helo=proxmox-new.maurer-it.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1666865754956100003 Content-Type: text/plain; charset="utf-8" Commit 85c4bf8aa6 ("vl: Unlink absolute PID file path") made it a critical error when the PID file path cannot be resolved. Before this commit, it was possible to invoke QEMU when the PID file was a file created with mkstemp that was already unlinked at the time of the invocation. There might be other similar scenarios. It should not be a critical error when the PID file unlink notifier can't be registered, because the path can't be resolved. Turn it into a warning instead. Fixes: 85c4bf8aa6 ("vl: Unlink absolute PID file path") Reported-by: Dominik Csapak Suggested-by: Thomas Lamprecht Signed-off-by: Fiona Ebner Reviewed-by: Hanna Reitz --- For completeness, here is a reproducer based on our actual invocation written in Rust (depends on the "nix" crate). It works fine with QEMU 7.0, but not anymore with 7.1. use std::fs::File; use std::io::Read; use std::os::unix::io::{AsRawFd, FromRawFd}; use std::path::{Path, PathBuf}; use std::process::Command; fn make_tmp_file>(path: P) -> (File, PathBuf) { let path =3D path.as_ref(); let mut template =3D path.to_owned(); template.set_extension("tmp_XXXXXX"); match nix::unistd::mkstemp(&template) { Ok((fd, path)) =3D> (unsafe { File::from_raw_fd(fd) }, path), Err(err) =3D> panic!("mkstemp {:?} failed: {}", template, err), } } fn main() -> Result<(), Box> { let (mut pidfile, pid_path) =3D make_tmp_file("/tmp/unlinked.pid.tmp"); nix::unistd::unlink(&pid_path)?; let mut qemu_cmd =3D Command::new("./qemu-system-x86_64"); qemu_cmd.args([ "-daemonize", "-pidfile", &format!("/dev/fd/{}", pidfile.as_raw_fd()), ]); let res =3D qemu_cmd.spawn()?.wait_with_output()?; if res.status.success() { let mut pidstr =3D String::new(); pidfile.read_to_string(&mut pidstr)?; println!("got PID {}", pidstr); } else { panic!("QEMU command unsuccessful"); } Ok(()) } softmmu/vl.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index b464da25bc..10dfe773a7 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2432,10 +2432,9 @@ static void qemu_maybe_daemonize(const char *pid_fil= e) =20 pid_file_realpath =3D g_malloc0(PATH_MAX); if (!realpath(pid_file, pid_file_realpath)) { - error_report("cannot resolve PID file path: %s: %s", - pid_file, strerror(errno)); - unlink(pid_file); - exit(1); + warn_report("not removing PID file on exit: cannot resolve PID= file" + " path: %s: %s", pid_file, strerror(errno)); + return; } =20 qemu_unlink_pidfile_notifier =3D (struct UnlinkPidfileNotifier) { --=20 2.30.2