Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit b5b02ba5 authored by Deucе's avatar Deucе 👌🏾

More closely reproduce select() behaviour when using poll()

Specifically, have errors mean the fd is "ready".

Also, fix some extra revent clearing and a spy socket issue while
we're looking at this code.

Should fix issues with CGI scripts that close stdin/stdout but do
not terminate, and maybe deal with some other corner cases at the
same time.
parent dbed4f1a
Pipeline #1846 passed with stage
in 13 minutes and 27 seconds
......@@ -1931,12 +1931,10 @@ void input_thread(void *arg)
#ifdef PREFER_POLL
fds[0].fd = sbbs->client_socket;
fds[0].events = POLLIN;
fds[0].revents = 0;
nfds = 1;
if (uspy_socket[sbbs->cfg.node_num-1] != INVALID_SOCKET) {
fds[0].fd = uspy_socket[sbbs->cfg.node_num-1];
fds[0].events = POLLIN;
fds[0].revents = 0;
fds[1].fd = uspy_socket[sbbs->cfg.node_num-1];
fds[1].events = POLLIN;
nfds++;
}
......
......@@ -2083,7 +2083,7 @@ void services_thread(void* arg)
continue;
for(j=0; j<service[i].set->sock_count; j++) {
if ((fds[nfdsi + j].revents & POLLIN) == 0)
if ((fds[nfdsi + j].revents) == 0)
continue;
#else
/* Setup select() parms */
......
......@@ -4192,9 +4192,9 @@ static int cgi_read_wait_timeout(void *arg)
cd->fds[1].events = POLLIN;
if (poll(cd->fds, 2, startup->max_cgi_inactivity * 1000) > 0) {
if (cd->fds[0].revents & POLLIN)
if (cd->fds[0].revents)
ret |= CGI_OUTPUT_READY;
if (cd->fds[1].revents & POLLIN)
if (cd->fds[1].revents)
ret |= CGI_ERROR_READY;
}
......@@ -4778,7 +4778,7 @@ static BOOL exec_cgi(http_session_t *session)
cd.fds[0].events = POLLOUT;
while(sent < session->req.post_len) {
if (poll(cd.fds, 1, 1000) > 0) {
if (cd.fds[0].revents & POLLIN)
if (cd.fds[0].revents)
i = write(in_pipe[1], &session->req.post_data[sent], session->req.post_len - sent);
else
i = 0;
......@@ -4835,7 +4835,7 @@ static BOOL exec_cgi(http_session_t *session)
close(in_pipe[1]); /* close excess file descriptor */
/* Drain STDERR & STDOUT */
while(poll(cd.fds, 2, 1000) > 0) {
if(cd.fds[1].revents & POLLIN) {
if(cd.fds[1].revents) {
i=read(err_pipe[0],buf,sizeof(buf)-1);
if(i!=-1 && i!=0) {
buf[i]=0;
......@@ -4843,7 +4843,7 @@ static BOOL exec_cgi(http_session_t *session)
}
}
if(cd.fds[0].revents & POLLIN) {
if(cd.fds[0].revents) {
i=read(cd.fds[0].fd, buf, sizeof(buf));
if(i!=-1 && i!=0) {
int snt=0;
......
......@@ -1692,7 +1692,6 @@ int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
if(!(mode&EX_NOLOG)) {
fds[1].fd = err_pipe[0];
fds[1].events = POLLIN;
fds[1].revents = 0;
}
while(!terminated) {
if(waitpid(pid, &i, WNOHANG)!=0) /* child exited */
......@@ -1717,7 +1716,7 @@ int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
if(mode&EX_NOLOG)
poll(fds, 1, 1);
else {
while (poll(fds, 2, 1) > 0 && (fds[1].revents & POLLIN)
while (poll(fds, 2, 1) > 0 && (fds[1].revents)
&& (i < (int)sizeof(buf) - 1)) {
if((rd=read(err_pipe[0],bp,1))>0) {
i+=rd;
......@@ -1744,7 +1743,7 @@ int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
}
}
data_waiting=fds[0].revents & POLLIN;
data_waiting=fds[0].revents;
if(i==0 && data_waiting==0)
continue;
......
......@@ -364,7 +364,7 @@ SOCKET xpms_accept(struct xpms_set *xpms_set, union xp_sockaddr * addr,
for(i=0; i<xpms_set->sock_count; i++) {
if(xpms_set->socks[i].sock == INVALID_SOCKET)
continue;
if (fds[scnt].revents & (POLLERR | POLLNVAL)) {
if (fds[scnt].revents & ~(POLLIN)) {
scnt++;
closesocket(xpms_set->socks[i].sock);
xpms_set->lprintf(LOG_ERR, "%04d * Listening socket went bad", xpms_set->socks[i].sock);
......
......@@ -305,7 +305,7 @@ BOOL socket_check(SOCKET sock, BOOL* rd_p, BOOL* wr_p, DWORD timeout)
if (pfd.revents & (POLLERR | POLLNVAL))
return FALSE;
if(pfd.revents & (POLLIN | POLLHUP) && (rd_p !=NULL || wr_p==NULL)) {
if(pfd.revents & ~(POLLOUT) && (rd_p !=NULL || wr_p==NULL)) {
rd=recv(sock,&ch,1,MSG_PEEK);
if(rd==1 || (rd==SOCKET_ERROR && ERROR_VALUE==EMSGSIZE)) {
if(rd_p!=NULL)
......@@ -483,7 +483,7 @@ BOOL socket_recvdone(SOCKET sock, int timeout)
switch (poll(&pfd, 1, timeout)) {
case 1:
if (pfd.revents & (POLLIN | POLLHUP)) {
if (pfd.revents) {
rd = recv(sock,&ch,1,MSG_PEEK);
if (rd == 1 || (rd==SOCKET_ERROR && ERROR_VALUE==EMSGSIZE))
return FALSE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment