public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH v2 4/6] flow, udp: Fix errno handling in udp_flow_sock()
Date: Wed, 17 Jun 2026 13:11:20 +1000	[thread overview]
Message-ID: <20260617031122.2086827-5-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20260617031122.2086827-1-david@gibson.dropbear.id.au>

flowside_connect() behaves much like connect(2) itself, returning -1 on
error with errno set to the error code.  One of the callers, in
udp_flow_sock(), uses the errno code with flow_dbg_perror() *after* it's
called epoll_del() and close() either of which could clobber errno.

Fix that by moving the debug message earlier: there's no reason it has to
wait until the epoll_del() and close().

While we're at it, adjust the comment on flowside_connect() to clarify
that it sets errno (rather than, say, returning an error code).

Suggested-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 flow.c     | 2 +-
 udp_flow.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/flow.c b/flow.c
index 596a4722..20938034 100644
--- a/flow.c
+++ b/flow.c
@@ -258,7 +258,7 @@ int flowside_sock_l4(const struct ctx *c, enum epoll_type type, uint8_t pif,
  *
  * Connect @s to the endpoint address and port from @tgt.
  *
- * Return: 0 on success, negative on error
+ * Return: 0 on success, negative on error (setting errno)
  */
 int flowside_connect(const struct ctx *c, int s,
 		     uint8_t pif, const struct flowside *tgt)
diff --git a/udp_flow.c b/udp_flow.c
index 35417bc4..31e2f8a7 100644
--- a/udp_flow.c
+++ b/udp_flow.c
@@ -90,11 +90,11 @@ static int udp_flow_sock(const struct ctx *c,
 
 	if (flowside_connect(c, s, pif, side) < 0) {
 		rc = -errno;
+		flow_dbg_perror(uflow, "Couldn't connect flow socket");
 
 		epoll_del(flow_epollfd(&uflow->f), s);
 		close(s);
 
-		flow_dbg_perror(uflow, "Couldn't connect flow socket");
 		return rc;
 	}
 	uflow->s[sidei] = s;
-- 
2.54.0


  parent reply	other threads:[~2026-06-17  3:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-17  3:11 [PATCH v2 0/6] Improvements to flow specific logging David Gibson
2026-06-17  3:11 ` [PATCH v2 1/6] flow: Regularise flow specific logging helpers David Gibson
2026-06-17  3:11 ` [PATCH v2 2/6] flow: Indent flow details messages David Gibson
2026-06-17  3:11 ` [PATCH v2 3/6] flow: Include flow details with higher priority log messages David Gibson
2026-06-17  3:11 ` David Gibson [this message]
2026-06-17  3:11 ` [PATCH v2 5/6] flow, treewide: Promote priority of selected flow-linked messages David Gibson
2026-06-17  5:23   ` Stefano Brivio
2026-06-17  3:11 ` [PATCH v2 6/6] udp: Improve messages for errors getting errors David Gibson

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=20260617031122.2086827-5-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

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 IMAP folder(s).