Skip to contentSkip to conversation

qga/commands-posix: Make ga_wait_child() return boolean

PATCH In review Zhao Liu 3 participants 3 messages Jul 16, 2024 – Jul 17, 2024

lore
Share & tools
lore

Zhao Liu

author
#0 lore raw

PATCH v2 1/1 qga/commands-posix: Make ga_wait_child() return boolean

Make ga_wait_child() return boolean and check the returned boolean in ga_run_command() instead of dereferencing @errp.

---
v2:
* Added Phil's r/b.
* Used Phil's polished words.

---
 qga/commands-posix.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
qga/commands-posix.c +4 -4
index 7f05996495a2..64bb0be94479 100644
@@ -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;
     }
 
Signature · 1 line
2.34.1
#1 lore raw

Hi Konstantin,

If there are no other patches on your guest-agent queue, I can take this patch in my next pull request.

Regards,

Phil.

Quoted 51 lines · Zhao Liu

Make ga_wait_child() return boolean and check the returned boolean in ga_run_command() instead of dereferencing @errp.

---
v2:
* Added Phil's r/b.
* Used Phil's polished words.

---
  qga/commands-posix.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
qga/commands-posix.c +4 -4
index 7f05996495a2..64bb0be94479 100644
@@ -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;
      }
 
Reviewed-by
#2 lore raw

Hi Philippe,

I plan to merge this with "Add new api 'guest-network-get-route'"
https://patchwork.kernel.org/project/qemu-devel/cover/[email protected]/
Can I ask you to review the new GuestNetworkRoute struct with IPv6 support?

Quoted 66 lines · Philippe Mathieu-Daudé

Hi Konstantin,

If there are no other patches on your guest-agent queue, I can take this patch in my next pull request.

Regards,

Phil.

qga/commands-posix.c static void ga_wait_child(pid_t pid, int *status,

Quoted 29 lines · Zhao Liu

Make ga_wait_child() return boolean and check the returned boolean in ga_run_command() instead of dereferencing @errp.

---
v2:
* Added Phil's r/b.
* Used Phil's polished words.

---
  qga/commands-posix.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
qga/commands-posix.c +1 -1
index 7f05996495a2..64bb0be94479 100644
@@ -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)

qga/commands-posix.c static void ga_wait_child(pid_t pid, int *status, · line 71

Quoted 2 lines
qga/commands-posix.c +0 -0
      if (rpid == -1) {
          error_setg_errno(errp, errno, "failed to wait for child (pid:

%d)",

qga/commands-posix.c static int ga_run_command(const char *argv[], const

Quoted 11 lines
qga/commands-posix.c +2 -1
                           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,

Quoted 9 lines
qga/commands-posix.c +1 -2
          goto out;
      }
 
-    ga_wait_child(pid, &status, errp);
-    if (*errp) {
+    if (!ga_wait_child(pid, &status, errp)) {
          goto out;
      }