Skip to contentSkip to conversation

Error-handling fixes for passt

PATCH Superseded Peter Foley 3 participants 6 messages Feb 23 – Mar 4 Networking

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Error-handling fixes for passt

Some fixes for passt error handling that showed up when trying to enable support with an internal Google framework.

---
Peter Foley (2):
Only kill passt if it wrote a pidfile Don't try to read the pidfile if passt got a signal

 net/passt.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

---
base-commit: afe653676dc6dfd49f0390239ff90b2f0052c2b8
change-id: 20260223-passt-0708603dc495

Best regards,

Signature · 1 line
Peter Foley <[email protected]>
#1 lore raw

PATCH 1/2 Only kill passt if it wrote a pidfile

Avoid killing qemu if passt failed before writing a pidfile.

pid is initialized to 0, so calling pid in this scenario would kill the entire process group.

---
 net/passt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/passt.c +3 -1
index 9ed811a514..b3d4b71314 100644
@@ -102,7 +102,9 @@ static void net_passt_cleanup(NetClientState *nc)
     }
 #endif
 
-    kill(s->pid, SIGTERM);
+    if (s->pid > 0) {
+        kill(s->pid, SIGTERM);
+    }
     if (g_remove(s->pidfile) != 0) {
         warn_report("Failed to remove passt pidfile %s: %s",
                     s->pidfile, strerror(errno));
Signature · 1 line
2.53.0.371.g1d285c8824-goog
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] Only kill passt if it wrote a pidfile

Quoted 16 lines · Peter Foley

Avoid killing qemu if passt failed before writing a pidfile.

pid is initialized to 0, so calling pid in this scenario would kill the entire process group.

---
  net/passt.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
net/passt.c +0 -0
index 9ed811a514..b3d4b71314 100644

net/passt.c static void net_passt_cleanup(NetClientState *nc) · line 110

Quoted 10 lines
net/passt.c +3 -1
@@ -102,7 +102,9 @@ static void net_passt_cleanup(NetClientState *nc)
      }
  #endif
 
-    kill(s->pid, SIGTERM);
+    if (s->pid > 0) {
+        kill(s->pid, SIGTERM);
+    }
      if (g_remove(s->pidfile) != 0) {
          warn_report("Failed to remove passt pidfile %s: %s",
                      s->pidfile, strerror(errno));
#3 lore raw

PATCH 2/2 Don't try to read the pidfile if passt got a signal

In reply to Peter Foley

g_subprocess_get_if_exited returns false if passt was killed by a signal, so we fall through to trying to read the pidfile.

Update the error when passt exits to include the exit code.

---
 net/passt.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
net/passt.c +11 -2
index b3d4b71314..053c2f5f57 100644
@@ -270,8 +270,17 @@ static int net_passt_start_daemon(NetPasstState *s, int sock, Error **errp)
         return -1;
     }
 
-    if (g_subprocess_get_if_exited(daemon) &&
-        g_subprocess_get_exit_status(daemon)) {
+    if (g_subprocess_get_if_exited(daemon)) {
+        gint status = g_subprocess_get_exit_status(daemon);
+        if (status) {
+            error_setg(errp, "Passt exited with code %d", status);
+            return -1;
+      }
+    }
+
+    if (g_subprocess_get_if_signaled(daemon)) {
+        error_setg(errp, "Passt killed with signal %d",
+                   g_subprocess_get_term_sig(daemon));
         return -1;
     }
 
Signature · 1 line
2.53.0.371.g1d285c8824-goog
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] Don't try to read the pidfile if passt got a signal

Quoted 15 lines · Peter Foley

g_subprocess_get_if_exited returns false if passt was killed by a signal, so we fall through to trying to read the pidfile.

Update the error when passt exits to include the exit code.

---
  net/passt.c | 13 +++++++++++--
  1 file changed, 11 insertions(+), 2 deletions(-)
net/passt.c +0 -0
index b3d4b71314..053c2f5f57 100644
@@ -270,8 +270,17 @@ static int net_passt_start_daemon(NetPasstState *s, int sock, Error **errp)
          return -1;

net/passt.c static int net_passt_start_daemon(NetPasstState *s, int sock, Error **errp) · line 278

Quoted 10 lines
net/passt.c +6 -2
      }
 
-    if (g_subprocess_get_if_exited(daemon) &&
-        g_subprocess_get_exit_status(daemon)) {
+    if (g_subprocess_get_if_exited(daemon)) {
+        gint status = g_subprocess_get_exit_status(daemon);
+        if (status) {
+            error_setg(errp, "Passt exited with code %d", status);
+            return -1;
+      }
       ^^^

Indentation problem (6 spaces instead of 8)

net/passt.c static int net_passt_start_daemon(NetPasstState *s, int sock, Error **errp) · line 286

Quoted 9 lines
net/passt.c +5 -0
+    }
+
+    if (g_subprocess_get_if_signaled(daemon)) {
+        error_setg(errp, "Passt killed with signal %d",
+                   g_subprocess_get_term_sig(daemon));
          return -1;
      }
 
#5 lore raw
In reply to Peter Foley

Adding Laurent.

Quoted 20 lines · Peter Foley

Some fixes for passt error handling that showed up when trying to enable support with an internal Google framework.

---
Peter Foley (2):
Only kill passt if it wrote a pidfile Don't try to read the pidfile if passt got a signal

 net/passt.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

---
base-commit: afe653676dc6dfd49f0390239ff90b2f0052c2b8
change-id: 20260223-passt-0708603dc495

Best regards,
--
Peter Foley <[email protected]>