| @@ -1,51 +1,57 @@ | | | @@ -1,51 +1,57 @@ |
1 | $NetBSD: patch-exp__chan.c,v 1.2 2022/06/19 14:43:28 gdt Exp $ | | 1 | $NetBSD: patch-exp__chan.c,v 1.3 2022/06/19 22:22:22 gdt Exp $ |
2 | | | 2 | |
3 | Add hack to work around deadlock situation that occurs on Solaris and | | 3 | Add hack to work around deadlock situation that occurs on Solaris and |
4 | Linux. See PR 34442. | | 4 | Linux. See PR 34442. |
5 | | | 5 | |
6 | The problem apparently does not occur on BSD, but it doesn't seem to | | 6 | The problem apparently does not occur on BSD, but it doesn't seem to |
7 | be clear why or whether that's really the case; the description of the | | 7 | be clear why or whether that's really the case; the description of the |
8 | problem as far as it's understood seems to be portable. So don't | | 8 | problem as far as it's understood seems to be portable. So don't |
9 | conditionalize it, as the check should be safe. If this turns out to | | 9 | conditionalize it, as the check should be safe. If this turns out to |
10 | cause problems, we can wrap it in ifdefs. | | 10 | cause problems, we can wrap it in ifdefs. |
11 | | | 11 | |
12 | \todo File changes upstream (but upstream is not functioning). | | 12 | \todo File changes upstream (but upstream is not functioning). |
13 | | | 13 | |
14 | --- exp_chan.c.orig 2010-07-01 00:53:49.000000000 +0000 | | 14 | --- exp_chan.c.orig 2010-07-01 00:53:49.000000000 +0000 |
15 | +++ exp_chan.c | | 15 | +++ exp_chan.c |
16 | @@ -7,6 +7,7 @@ | | 16 | @@ -7,6 +7,9 @@ |
17 | */ | | 17 | */ |
18 | | | 18 | |
19 | #include <sys/types.h> | | 19 | #include <sys/types.h> |
| | | 20 | +#if defined(linux) || defined(sunos) |
20 | +#include <sys/poll.h> | | 21 | +#include <sys/poll.h> |
| | | 22 | +#endif |
21 | #include <stdio.h> | | 23 | #include <stdio.h> |
22 | #include <signal.h> | | 24 | #include <signal.h> |
23 | #include <errno.h> | | 25 | #include <errno.h> |
24 | @@ -205,6 +206,8 @@ ExpInputProc(instanceData, buf, toRead, | | 26 | @@ -205,6 +208,10 @@ ExpInputProc(instanceData, buf, toRead, |
25 | ExpState *esPtr = (ExpState *) instanceData; | | 27 | ExpState *esPtr = (ExpState *) instanceData; |
26 | int bytesRead; /* How many bytes were actually | | 28 | int bytesRead; /* How many bytes were actually |
27 | * read from the input device? */ | | 29 | * read from the input device? */ |
| | | 30 | +#if defined(linux) || defined(sunos) |
28 | + struct pollfd fds[1]; | | 31 | + struct pollfd fds[1]; |
29 | + int pollResult; | | 32 | + int pollResult; |
| | | 33 | +#endif |
30 | | | 34 | |
31 | *errorCodePtr = 0; | | 35 | *errorCodePtr = 0; |
32 | | | 36 | |
33 | @@ -215,6 +218,18 @@ ExpInputProc(instanceData, buf, toRead, | | 37 | @@ -215,6 +222,20 @@ ExpInputProc(instanceData, buf, toRead, |
34 | * nonblocking, the read will never block. | | 38 | * nonblocking, the read will never block. |
35 | */ | | 39 | */ |
36 | | | 40 | |
| | | 41 | +#if defined(linux) || defined(sunos) |
37 | + /* Update: there isn't always, which can lead to hangs. See PR 34442. */ | | 42 | + /* Update: there isn't always, which can lead to hangs. See PR 34442. */ |
38 | + fds[0].fd = esPtr->fdin; | | 43 | + fds[0].fd = esPtr->fdin; |
39 | + fds[0].events = POLLIN | POLLERR | POLLHUP | POLLNVAL; | | 44 | + fds[0].events = POLLIN | POLLERR | POLLHUP | POLLNVAL; |
40 | + pollResult = poll(fds, 1, 0); | | 45 | + pollResult = poll(fds, 1, 0); |
41 | + if (pollResult <= 0) { | | 46 | + if (pollResult <= 0) { |
42 | + *errorCodePtr = EWOULDBLOCK; | | 47 | + *errorCodePtr = EWOULDBLOCK; |
43 | + return -1; | | 48 | + return -1; |
44 | + } else if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { | | 49 | + } else if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { |
45 | + *errorCodePtr = EBADF; | | 50 | + *errorCodePtr = EBADF; |
46 | + return -1; | | 51 | + return -1; |
47 | + } | | 52 | + } |
| | | 53 | +#endif |
48 | + | | 54 | + |
49 | bytesRead = read(esPtr->fdin, buf, (size_t) toRead); | | 55 | bytesRead = read(esPtr->fdin, buf, (size_t) toRead); |
50 | /*printf("ExpInputProc: read(%d,,) = %d\r\n",esPtr->fdin,bytesRead);*/ | | 56 | /*printf("ExpInputProc: read(%d,,) = %d\r\n",esPtr->fdin,bytesRead);*/ |
51 | if (bytesRead > -1) { | | 57 | if (bytesRead > -1) { |