qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Zhao Liu <zhao1.liu@intel.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>,
	Michael Roth <michael.roth@amd.com>,
	Konstantin Kostiuk <kkostiuk@redhat.com>
Subject: [PATCH] qga/commands-posix: Make ga_wait_child() return boolean
Date: Mon, 15 Jul 2024 17:59:39 +0800	[thread overview]
Message-ID: <20240715095939.72492-3-zhao1.liu@intel.com> (raw)
In-Reply-To: <20240715095939.72492-1-zhao1.liu@intel.com>

As the comment in qapi/error, dereferencing @errp requires
ERRP_GUARD():

* = Why, when and how to use ERRP_GUARD() =
*
* 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 <michael.roth@amd.com>
Cc: Konstantin Kostiuk <kkostiuk@redhat.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 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
 
-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;
 
@@ -70,10 +70,11 @@ static void ga_wait_child(pid_t pid, int *status, Error **errp)
     if (rpid == -1) {
         error_setg_errno(errp, errno, "failed to wait for child (pid: %d)",
                          pid);
-        return;
+        return false;
     }
 
     g_assert(rpid == pid);
+    return true;
 }
 
 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 char *in_str,
         goto out;
     }
 
-    ga_wait_child(pid, &status, errp);
-    if (*errp) {
+    if (!ga_wait_child(pid, &status, errp)) {
         goto out;
     }
 
-- 
2.34.1



  parent reply	other threads:[~2024-07-15  9:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-15  9:59 [PATCH] hw/nubus/nubus-virtio-mmio: Fix missing ERRP_GUARD() in nubus_virtio_mmio_realize() Zhao Liu
2024-07-15  9:59 ` [PATCH] hw/virtio/vdpa-dev: Check returned value instead of dereferencing @errp Zhao Liu
2024-07-15 21:01   ` Eugenio Perez Martin
2024-07-16  3:21     ` Zhao Liu
2024-07-16 16:02       ` Eugenio Perez Martin
2024-07-15  9:59 ` Zhao Liu [this message]
2024-07-15  9:59   ` [PATCH] qga/commands-posix: Make ga_wait_child() return boolean Philippe Mathieu-Daudé
2024-07-15 13:06     ` Zhao Liu
2024-07-17 11:27 ` [PATCH] hw/nubus/nubus-virtio-mmio: Fix missing ERRP_GUARD() in nubus_virtio_mmio_realize() Zhao Liu
2024-07-22 21:21   ` Philippe Mathieu-Daudé
2024-07-23 10:21 ` Markus Armbruster
2024-07-23 14:30   ` Zhao Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240715095939.72492-3-zhao1.liu@intel.com \
    --to=zhao1.liu@intel.com \
    --cc=kkostiuk@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).