- memset(pfd, 0, sizeof(pfd));
-
- pfd[FROM_CGI].fd = fromCgi_rd;
- pfd[FROM_CGI].events = POLLIN;
-
- if (toCgi_wr) {
- pfd[TO_CGI].fd = toCgi_wr;
- if (hdr_cnt > 0) {
- pfd[TO_CGI].events = POLLOUT;
- } else if (post_len > 0) {
- pfd[0].events = POLLIN;
+ /* Note: even pfd[0].events == 0 won't prevent
+ * revents == POLLHUP|POLLERR reports from closed stdin.
+ * Setting fd to -1 works: */
+ pfd[0].fd = -1;
+ pfd[0].events = POLLIN;
+ pfd[0].revents = 0; /* probably not needed, paranoia */
+
+ /* We always poll this fd, thus kernel always sets revents: */
+ /*pfd[FROM_CGI].events = POLLIN; - moved out of loop */
+ /*pfd[FROM_CGI].revents = 0; - not needed */
+
+ /* gcc-4.8.0 still doesnt fill two shorts with one insn :( */
+ /* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47059 */
+ /* hopefully one day it will... */
+ pfd[TO_CGI].events = POLLOUT;
+ pfd[TO_CGI].revents = 0; /* needed! */
+
+ if (toCgi_wr && hdr_cnt <= 0) {
+ if (post_len > 0) {
+ /* Expect more POST data from network */
+ pfd[0].fd = 0;