Page MenuHomeFreeBSD

D38966.id.diff
No OneTemporary

D38966.id.diff

diff --git a/libexec/tftpd/tftp-io.c b/libexec/tftpd/tftp-io.c
--- a/libexec/tftpd/tftp-io.c
+++ b/libexec/tftpd/tftp-io.c
@@ -38,8 +38,7 @@
#include <assert.h>
#include <errno.h>
-#include <setjmp.h>
-#include <signal.h>
+#include <poll.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -377,27 +376,19 @@
/*
* 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 @@
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 @@
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
--- a/libexec/tftpd/tftp-transfer.c
+++ b/libexec/tftpd/tftp-transfer.c
@@ -436,7 +436,7 @@
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 &&

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 8, 2:27 AM (18 m, 2 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29391491
Default Alt Text
D38966.id.diff (2 KB)

Event Timeline