From nobody Fri Mar 10 13:29:20 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PY6N11Dl5z3xXHs; Fri, 10 Mar 2023 13:29:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PY6N10V4Rz3RFC; Fri, 10 Mar 2023 13:29:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678454961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0TkpEUPYgnCcYVNGONk6OctBDu9RPltKo+al+BwbpxM=; b=Qwb9Jgom0ijcHSUeVAr9k5z9SfeFTKVi2rYaphkReiQHIAB8mMMNNSAVTEgghyXxlhmwb8 epCsPxdzMtX1Muxax1U1D+tA3r+c/eVcr9WIhGMoi2P9SYMO9emAPf7AzBl8PGVQGHD4gk Wd5z9Mf5aM7BTJD8tfNLpCE7sW0kktInBjKiEqUTm7bryEAVn0Ysu/N2hWfbC6o2XpDLd3 nbUrIdwYnPOgOyY42x2Pk/YcRb7RGAxDCVS5HsfmhcthkpBFPiTW0kuRcR2YesUnflZ7Ra 8XxMb9onJ1hLke40o1NTw7bk3/lQDV/vUfMKYeQBz0R8lNZiHD+awEZI/KGJNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678454961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0TkpEUPYgnCcYVNGONk6OctBDu9RPltKo+al+BwbpxM=; b=K5SX1pvqvh5TrmhI/HHf+ue9m4At0/ySXdLNYIOBslEUvpUhlQSMoPRuAw525Ot8nRIzBl 8PpUYV4IAmGQoQ72gMQPNMKr/SS/9PRg30Z7T70sPVYnBE2IYB4zRoT+pRX8WICJNOVD6x QdI+CeGmERYgtt18rt0Gx1oYR9voitgNfedp4r2VjDq+lnryGNj/cFeemZKZbs57o1xqUz zsiihsjAj6vlu6e8/G0hXWU1Y72AiXPbf4BbunDmWaYYCqeHBaqH3jnHQLpQc/GmPFLFjn t560Xt6kpxNVSe/WGuGJRu4qgU3oswkvVa66wqVc6DUw/9hFHIVvv1r5iY1IDA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678454961; a=rsa-sha256; cv=none; b=ZqkHrtUH88AamY9NTxLZLSHsifZ/Cwo73b4yHfcJIIPPD3q0oIdRvPvbXWdArU//sYMnMc RFWXtXriunRyQBJSqsSUbbjKbwe124tG5UveTgoikcbTE3YwB3deJpFCSOb2K5EdFTx1+w j66Kbti/y3xhHMz5NQ9Hxy2I+22KgtCn9mhoQ/HK9J+g7jHIzKdWxVR25VvLUAuBk/4+Fu dRzG9Djhs1d/KiYpq2Iff41HUamJMFEV+EMkt7LOw8J+GrBtpUe4tUj2fegfEz9wxjQnb4 MG/nRcgpvQ2hlOztcLExfAFA63WXT3qOYk2DlMNhl5ZmJNOnBE6BdNGWS+nmww== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PY6N06ZyzzqSV; Fri, 10 Mar 2023 13:29:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32ADTKRp090129; Fri, 10 Mar 2023 13:29:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32ADTKWl090128; Fri, 10 Mar 2023 13:29:20 GMT (envelope-from git) Date: Fri, 10 Mar 2023 13:29:20 GMT Message-Id: <202303101329.32ADTKWl090128@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: e3b4cb1b32c0 - main - tftpd: Use poll() instead of alarm() + setjmp(). List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e3b4cb1b32c05ec668b16fe4e858e78b61fe5805 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=e3b4cb1b32c05ec668b16fe4e858e78b61fe5805 commit e3b4cb1b32c05ec668b16fe4e858e78b61fe5805 Author: Dag-Erling Smørgrav AuthorDate: 2023-03-10 13:24:36 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-03-10 13:25:16 +0000 tftpd: Use poll() instead of alarm() + setjmp(). While there, don't log an error when timing out waiting for a possible retransmit after a successful transfer. Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D38966 --- libexec/tftpd/tftp-io.c | 38 ++++++++++---------------------------- libexec/tftpd/tftp-transfer.c | 2 +- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/libexec/tftpd/tftp-io.c b/libexec/tftpd/tftp-io.c index 4504946e910f..a39b7cfe1fa3 100644 --- a/libexec/tftpd/tftp-io.c +++ b/libexec/tftpd/tftp-io.c @@ -38,8 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include -#include +#include #include #include #include @@ -377,27 +376,19 @@ send_data(int peer, uint16_t block, char *data, int size) /* * Receive a packet + * + * If timeout is negative, no error will be logged on timeout. */ -static jmp_buf timeoutbuf; - -static void -timeout(int sig __unused) -{ - - /* tftp_log(LOG_DEBUG, "Timeout\n"); Inside a signal handler... */ - longjmp(timeoutbuf, 1); -} - int receive_packet(int peer, char *data, int size, struct sockaddr_storage *from, - int thistimeout) + int timeout) { + struct pollfd pfd; struct tftphdr *pkt; struct sockaddr_storage from_local; struct sockaddr_storage *pfrom; socklen_t fromlen; int n; - static int timed_out; if (debug & DEBUG_PACKETS) tftp_log(LOG_DEBUG, @@ -405,13 +396,11 @@ receive_packet(int peer, char *data, int size, struct sockaddr_storage *from, pkt = (struct tftphdr *)data; - signal(SIGALRM, timeout); - timed_out = setjmp(timeoutbuf); - alarm(thistimeout); - - if (timed_out != 0) { - tftp_log(LOG_ERR, "receive_packet: timeout"); - alarm(0); + pfd.fd = peer; + pfd.events = POLLIN; + if (poll(&pfd, 1, 1000 * (timeout < 0 ? -timeout : timeout)) < 1) { + if (timeout > 0) + tftp_log(LOG_ERR, "receive_packet: timeout"); return (RP_TIMEOUT); } @@ -419,15 +408,8 @@ receive_packet(int peer, char *data, int size, struct sockaddr_storage *from, fromlen = sizeof(*pfrom); n = recvfrom(peer, data, size, 0, (struct sockaddr *)pfrom, &fromlen); - alarm(0); - DROPPACKETn("receive_packet", RP_TIMEOUT); - if (n < 0) { - tftp_log(LOG_ERR, "receive_packet: timeout"); - return (RP_TIMEOUT); - } - if (n < 0) { /* No idea what could have happened if it isn't a timeout */ tftp_log(LOG_ERR, "receive_packet: %s", strerror(errno)); diff --git a/libexec/tftpd/tftp-transfer.c b/libexec/tftpd/tftp-transfer.c index 91f87a1159a4..1949d00657b6 100644 --- a/libexec/tftpd/tftp-transfer.c +++ b/libexec/tftpd/tftp-transfer.c @@ -436,7 +436,7 @@ send_ack: for (i = 0; ; i++) { n_data = receive_packet(peer, (char *)rp, pktsize, - NULL, timeoutpacket); + NULL, -timeoutpacket); if (n_data <= 0) break; if (n_data > 0 &&