From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 1D1C85A0271 for ; Thu, 10 Aug 2023 04:33:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1691634801; bh=8wP45GmQAzfmCrQ4OCkUYDgwTCl4L+KtVdlEtD+hWKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nfSZgNpv408LUcgDJy/cYxX1Bctd+Fa0c4ushRj35Q7Ec39x9GRsaGe3r3j6CdvL0 dQTFmodLBmRSigPVnNaeEqe3eM+5PdeA7PeQ0o7EuutFs7/iHx7AhChDPNF7SO41Lj M8poMncxqCFGbUYpsDUQjuh8lmzdJvVG0ic8gnAI= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4RLrZT2CCsz4wy5; Thu, 10 Aug 2023 12:33:21 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 02/13] tap: Clean up behaviour for errors on listening Unix socket Date: Thu, 10 Aug 2023 12:33:04 +1000 Message-ID: <20230810023315.684784-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230810023315.684784-1-david@gibson.dropbear.id.au> References: <20230810023315.684784-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: I3MY3BLXOWLLSIQUWKW3NFHOOV6NUSAH X-Message-ID-Hash: I3MY3BLXOWLLSIQUWKW3NFHOOV6NUSAH 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: We call tap_sock_unix_new() to handle a new connection to the qemu socket if we get an EPOLLIN event on c->fd_tap_listen. If we get any other event on the fd, we'll fall through to the "tap reset" path. But that won't do anything relevant to the listening socket, it will just close the already connected socket. Furthermore, the only other event we're subscribed to for the listening socket is EPOLLRDHUP, which doesn't apply to a non connected socket. Change the subscribed events from EPOLLRDHUP to EPOLLERR to catch general errors - not that there's any obvious case that would cause this event on a listening socket. Since we don't really expect it, and it's not obvious how we'd recover, treat it as a fatal error if we ever do get that event. Finally, fold all this handling into the tap_sock_unix_new() function, there's no real reason to split it between there and tap_handler(). Signed-off-by: David Gibson --- tap.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tap.c b/tap.c index b4967d0..c883d7e 100644 --- a/tap.c +++ b/tap.c @@ -1108,7 +1108,7 @@ static void tap_sock_unix_init(struct ctx *c) listen(fd, 0); ev.data.fd = c->fd_tap_listen = fd; - ev.events = EPOLLIN | EPOLLET | EPOLLRDHUP; + ev.events = EPOLLIN | EPOLLERR | EPOLLET; epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap_listen, &ev); info("You can now start qemu (>= 7.2, with commit 13c6be96618c):"); @@ -1121,14 +1121,18 @@ static void tap_sock_unix_init(struct ctx *c) /** * tap_sock_unix_new() - Handle new connection on listening socket * @c: Execution context + * @events: epoll events */ -static void tap_sock_unix_new(struct ctx *c) +static void tap_sock_unix_new(struct ctx *c, uint32_t events) { struct epoll_event ev = { 0 }; int v = INT_MAX / 2; struct ucred ucred; socklen_t len; + if (events != EPOLLIN) + die("Error on listening Unix socket, exiting"); + len = sizeof(ucred); /* Another client is already connected: accept and close right away. */ @@ -1284,8 +1288,8 @@ static void tap_sock_reset(struct ctx *c) void tap_handler(struct ctx *c, int fd, uint32_t events, const struct timespec *now) { - if (fd == c->fd_tap_listen && events == EPOLLIN) { - tap_sock_unix_new(c); + if (fd == c->fd_tap_listen) { + tap_sock_unix_new(c, events); return; } -- 2.41.0