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=DPg2Fai+; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 16A355A026D for ; Wed, 17 Jun 2026 05:11:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1781665885; bh=mRIq0ctUXD4/s+q6e9XNbhXZboit4LPtZB7qgSRR2QM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DPg2Fai+wI+VG3QVp6nnorSrsverWqoi5haPQ9xrWRgG/RPe2znBHf0JGs7x0lGLc /Q8YRtfPNEx2QC180gqCGXmvu7359h1EgKE/SAj8KpmO2UtBxnXWoSf6ywFf5/scjO krkeOAFYbtDr9LSIWrRcZX5n7rO+MiKSa+t9kQ/hhK0KAEzTpC9ku7yPo4D3SPfxQD me0gZh6neL/79iEXhXbTtvj/qbFA4yI7lBXt7uT0qhDRRUilC//hMuT5Fz3/KPUh+o Cc32uxfAi0VwdWWlZXVw7vN+xWPR4s/71zCNtJq4T9s41YIIjVTxTBRLcfaKtbARzm l76U62GlZoIUw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gg85T0Fr5z58p0; Wed, 17 Jun 2026 13:11:25 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 4/6] flow, udp: Fix errno handling in udp_flow_sock() Date: Wed, 17 Jun 2026 13:11:20 +1000 Message-ID: <20260617031122.2086827-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260617031122.2086827-1-david@gibson.dropbear.id.au> References: <20260617031122.2086827-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: BQEZIL2YIL6ARLX75L564BOUNZELYE43 X-Message-ID-Hash: BQEZIL2YIL6ARLX75L564BOUNZELYE43 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 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