From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202606 header.b=I4TzOHEP; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 337865A0269 for ; Fri, 19 Jun 2026 17:26:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1781882789; bh=frkk4gDhIkzylHjWk34OgC5GcznzncBA/vCmE3NC06I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I4TzOHEPSBKkilwBfbGlYi9AOe1VgGDYiIyoRDzJE+t/FPxEzWGKXuhYDJLuiMeWV E+TNosJ55Uk7/eNhYF93qVMRSL3ciPdaaTrjfHLFzeWQvsvN35REQHRmRXganQo5vE GmjLwvxjboT22vQn7EznyGkGj9Bs3wn2/oqntyOeQcAw2WzEwzMFR6mgQExoIov+EM HblyDLE8Z8Bbc9tTgjWg8boFOWDlvooRCpvsh2rAYHt/N6tpmZlxSvV0Vl8/yxVsLJ 23D3kVr++3vYHbx9nXI9Ry6YDipnyA9GjcEnCDnvZHry6ipU2UHjo4FisATnpH1uLP awdWIBULTtOfQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ghhJj5Kz6z58tJ; Sat, 20 Jun 2026 01:26:29 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v3 4/6] flow, udp: Fix errno handling in udp_flow_sock() Date: Sat, 20 Jun 2026 01:26:24 +1000 Message-ID: <20260619152626.3033033-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260619152626.3033033-1-david@gibson.dropbear.id.au> References: <20260619152626.3033033-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 43RHB4HBTOPWUQXGTYNC4XNBH7ZCWF63 X-Message-ID-Hash: 43RHB4HBTOPWUQXGTYNC4XNBH7ZCWF63 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 Signed-off-by: David Gibson --- flow.c | 2 +- udp_flow.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flow.c b/flow.c index b2963396..85ac6307 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