X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fplaintcp.c;h=fb4c6ceb01dbb0de6b1f5de1b477b4d4d6c6b351;hb=cac13158ac4fdd8b7682f16f879796e9c4e339ff;hp=cf46b29fd982925d3978d7bf90b3ab514ead8b05;hpb=7595e3a4d77b7e498fa84e27d93cc9f680076561;p=ashd.git diff --git a/src/plaintcp.c b/src/plaintcp.c index cf46b29..fb4c6ce 100644 --- a/src/plaintcp.c +++ b/src/plaintcp.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -64,10 +65,11 @@ int listensock4(int port) close(fd); return(-1); } - if(listen(fd, 16) < 0) { + if(listen(fd, 128) < 0) { close(fd); return(-1); } + fcntl(fd, F_SETFD, FD_CLOEXEC); return(fd); } @@ -88,10 +90,11 @@ int listensock6(int port) close(fd); return(-1); } - if(listen(fd, 16) < 0) { + if(listen(fd, 128) < 0) { close(fd); return(-1); } + fcntl(fd, F_SETFD, FD_CLOEXEC); return(fd); } @@ -171,7 +174,8 @@ static void listenloop(struct muth *muth, va_list args) while(1) { namelen = sizeof(name); - block(tcp->fd, EV_READ, 0); + if(block(tcp->fd, EV_READ, 0) == 0) + goto out; ns = accept(tcp->fd, (struct sockaddr *)&name, &namelen); if(ns < 0) { flog(LOG_ERR, "accept: %s", strerror(errno)); @@ -212,7 +216,7 @@ void handleplain(int argc, char **argp, char **argv) omalloc(tcp); tcp->fd = fd; tcp->sport = port; - mustart(listenloop, tcp); + bufadd(listeners, mustart(listenloop, tcp)); if((fd = listensock4(port)) < 0) { if(errno != EADDRINUSE) { flog(LOG_ERR, "could not listen on IPv4 (port %i): %s", port, strerror(errno)); @@ -222,6 +226,6 @@ void handleplain(int argc, char **argp, char **argv) omalloc(tcp); tcp->fd = fd; tcp->sport = port; - mustart(listenloop, tcp); + bufadd(listeners, mustart(listenloop, tcp)); } }