From nobody Sun Nov 24 18:59:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1721036705; cv=none; d=zohomail.com; s=zohoarc; b=S7BDgt5LfnIABZ06JnYMs+j8vOH66DQHyhyMM4SaER+URxgO7Jqd4f3n4VqYnk3+R1E2zpB6Esgm1wLCyG5k9mhGLM3ci+CpoNQFax5+oaeYnGzmGI4dsyl3J7thK46SUwQm+j+rR0U1JqP2pRHAcRNyaAty4p3H41+9WbwYK4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721036705; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=f7Oe6DwsgPmSPRS238VF67Bgzy8rwqXxBmXmtrDfqyA=; b=UNiGfI04Z8/MXPYmESNXjiAnPcHzKXCd7wNUR0eMoahjTPWbZT5+gB/8iXxH1Pj4+abtohPRso+70qmboOZAP4GBNzGhZMJU+L3KhcwRME6gqYIJFoi2Jpfls/PWeSyuu5obETVP2i/DP50kNIiA9iv9tLhFiiO91H+cq2utcZg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1721036705274607.811831179195; Mon, 15 Jul 2024 02:45:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTIFt-0002k1-NE; Mon, 15 Jul 2024 05:44:25 -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 1sTIFs-0002gu-Qd for qemu-devel@nongnu.org; Mon, 15 Jul 2024 05:44:24 -0400 Received: from mgamail.intel.com ([198.175.65.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTIFr-0005Pt-7I for qemu-devel@nongnu.org; Mon, 15 Jul 2024 05:44:24 -0400 Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2024 02:44:22 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa003.fm.intel.com with ESMTP; 15 Jul 2024 02:44:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1721036663; x=1752572663; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aEt9NUuwJ/0VTGg32MzuEEaTFlLR/CAGW8RGmGngYGA=; b=EtJ/OEmF2q23sjkLtqqJTMnYmyNTIJ1XmLhiVDIiikHb6xoP83R8pWIf e+wJryULyM6cGwJ6vJzzuHws2pmIOy/Fz0kSFLf1eZmXlkEbu87XDJl/g lmH7WR6NJdquLC7Fp0E/RAA2ByEXO/aoF9dDMlpYelM13l/TTqD2EZl2W 5pty9IgMNds67SYbYWlm99xcj0leWGT8evlBOXgzLctzQfk0+NUfeRSnZ 6qYowKNLKd4BRG9ep8NNBk/v5Jl5MV/N8pJrmSVAOIe/4F3fLYNZcSe8j 9HUIjzJplmTmJoWwgTjAmBwcByhg+i8yjfkydw+VfIJkCqr1T40vdZKqB g==; X-CSE-ConnectionGUID: b+6awR79Qran8JJyicb3nA== X-CSE-MsgGUID: PbTrWlJRSGqJt0KB+JaUBw== X-IronPort-AV: E=McAfee;i="6700,10204,11133"; a="35837080" X-IronPort-AV: E=Sophos;i="6.09,210,1716274800"; d="scan'208";a="35837080" X-CSE-ConnectionGUID: G+lYKG51TdeS73unNOr37Q== X-CSE-MsgGUID: PDmVSPx4STywGl14/CU/HA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,210,1716274800"; d="scan'208";a="53854615" From: Zhao Liu To: qemu-devel@nongnu.org Cc: Zhao Liu , Michael Roth , Konstantin Kostiuk Subject: [PATCH] qga/commands-posix: Make ga_wait_child() return boolean Date: Mon, 15 Jul 2024 17:59:39 +0800 Message-Id: <20240715095939.72492-3-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240715095939.72492-1-zhao1.liu@intel.com> References: <20240715095939.72492-1-zhao1.liu@intel.com> 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=198.175.65.10; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1721036705606116600 Content-Type: text/plain; charset="utf-8" As the comment in qapi/error, dereferencing @errp requires ERRP_GUARD(): * =3D Why, when and how to use ERRP_GUARD() =3D * * Without ERRP_GUARD(), use of the @errp parameter is restricted: * - It must not be dereferenced, because it may be null. ... * ERRP_GUARD() lifts these restrictions. * * To use ERRP_GUARD(), add it right at the beginning of the function. * @errp can then be used without worrying about the argument being * NULL or &error_fatal. * * Using it when it's not needed is safe, but please avoid cluttering * the source with useless code. Though currently ga_run_command() only gets &local_err instead of NULL @errp, it's still better to follow the requirement to add the ERRP_GUARD(). But as error.h suggested, the best practice for callee is to return something to indicate success / failure. So make ga_wait_child() return boolean and check the returned boolean in ga_run_command() instead of dereferencing @errp, which eliminates the need of ERRP_GUARD(). Cc: Michael Roth Cc: Konstantin Kostiuk Signed-off-by: Zhao Liu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- qga/commands-posix.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 7f05996495a2..64bb0be94479 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -59,7 +59,7 @@ #endif #endif =20 -static void ga_wait_child(pid_t pid, int *status, Error **errp) +static bool ga_wait_child(pid_t pid, int *status, Error **errp) { pid_t rpid; =20 @@ -70,10 +70,11 @@ static void ga_wait_child(pid_t pid, int *status, Error= **errp) if (rpid =3D=3D -1) { error_setg_errno(errp, errno, "failed to wait for child (pid: %d)", pid); - return; + return false; } =20 g_assert(rpid =3D=3D pid); + return true; } =20 static ssize_t ga_pipe_read_str(int fd[2], char **str) @@ -178,8 +179,7 @@ static int ga_run_command(const char *argv[], const cha= r *in_str, goto out; } =20 - ga_wait_child(pid, &status, errp); - if (*errp) { + if (!ga_wait_child(pid, &status, errp)) { goto out; } =20 --=20 2.34.1