From owner-freebsd-ports Sun Aug 11 12:57:22 2002 Delivered-To: freebsd-ports@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 46B9537B400 for ; Sun, 11 Aug 2002 12:57:18 -0700 (PDT) Received: from mta1.rcsntx.swbell.net (mta1.rcsntx.swbell.net [151.164.30.25]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8A44F43E72 for ; Sun, 11 Aug 2002 12:57:17 -0700 (PDT) (envelope-from jwlundy@swbell.net) Received: from swbell.net ([65.70.180.253]) by mta1.rcsntx.swbell.net (Sun Internet Mail Server sims.3.5.2000.03.23.18.03.p10) with ESMTP id <0H0P00JMO36ZNE@mta1.rcsntx.swbell.net> for ports@FreeBSD.org; Sun, 11 Aug 2002 14:52:12 -0500 (CDT) Date: Sun, 11 Aug 2002 14:47:54 -0500 From: Jerry Lundy Subject: FreeBSD Port: netsed-0.01 To: roman@xpert.com Cc: ports@FreeBSD.org Message-id: <3D56BF6A.F71C5F20@swbell.net> MIME-version: 1.0 X-Mailer: Mozilla 4.76 [en] (X11; U; FreeBSD 4.5-RELEASE i386) Content-type: multipart/mixed; boundary="------------4C8B423034AD1BB86C3CE093" X-Accept-Language: en Sender: owner-freebsd-ports@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org This is a multi-part message in MIME format. --------------4C8B423034AD1BB86C3CE093 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Greetings. The netsed-0.01 port uses System V / Unix 98 methods to catch SIGCHLD and prevent zombies. The method doesn't work under FreeBSD. The attached patch adds a waitpid signal handler to the code to prevent the accumulation of zombie child processes. (The patch is to the original, unpatched netsed.c source. No additional changes were made to the Makefile.) If I need to submit this elsewhere or in another format, please let me know. Cheers, Jerry Lundy --------------4C8B423034AD1BB86C3CE093 Content-Type: text/plain; charset=us-ascii; name="netsed-bsd.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="netsed-bsd.patch" --- netsed.c.orig Fri Jan 5 18:58:22 2001 +++ netsed.c Sun Aug 11 14:32:29 2002 @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -45,11 +46,11 @@ ERR("This will replace all occurences of pat1 with pat2 in matching packets.\n"); ERR("Additional parameter (count) can be used to expire rule after 'count'\n"); ERR("succesful substitutions. Eight-bit characters, including NULL and '/', can\n"); - ERR("be passed using HTTP-alike hex escape sequences (eg. %%0a%%0d). Single '%%'\n"); - ERR("can be reached by using '%%%%'. Examples:\n\n"); - ERR(" 's/anrew/mike/1' - replace 'andrew' with 'mike' (once)\n"); - ERR(" 's/anrew/mike' - replace all occurences of 'andrew' with 'mike'\n"); - ERR(" 's/anrew/mike%%00' - replace 'andrew' with 'mike\\x00' (to keep orig. size)\n"); + ERR("be passed using HTTP-alike hex escape sequences (eg. CRLF -> %%0a%%0d).\n"); + ERR("Single '%%' can be reached by using '%%%%'. Examples:\n\n"); + ERR(" 's/andrew/mike/1' - replace 'andrew' with 'mike' (once)\n"); + ERR(" 's/andrew/mike' - replace all occurences of 'andrew' with 'mike'\n"); + ERR(" 's/andrew/mike%%00' - replace 'andrew' with 'mike\\x00' (to keep orig. size)\n"); ERR(" 's/%%%%/%%2f/20' - replace '%%' with '/' in first 20 packets\n\n"); ERR("Rules are not working on cross-packet boundaries and are evaluated from\n"); ERR("first to last not expired rule.\n"); @@ -134,8 +135,10 @@ void bind_and_listen(int tcp,int port) { + int on=1; struct sockaddr_in laddr; lsock=socket(PF_INET,tcp ? SOCK_STREAM:SOCK_DGRAM,0); + setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); fcntl(lsock,F_SETFL,O_NONBLOCK); laddr.sin_family = PF_INET; laddr.sin_port = htons (port); @@ -186,7 +189,6 @@ rd=read(s1,buf,sizeof(buf)); if (rd<0 && errno!=EAGAIN) return 0; // s1 not connected if (rd>0) { - fcntl(s2,F_SETFL,O_SYNC); printf("[+] Caught server -> client packet.\n"); rd=sed_the_buffer(rd); if (write(s2,b2,rd)<=0) return 0; // not able to send @@ -195,7 +197,6 @@ rd=read(s2,buf,sizeof(buf)); if (rd<0 && errno!=EAGAIN) return 0; // s2 not connected if (rd>0) { - fcntl(s1,F_SETFL,O_SYNC); printf("[+] Caught client -> server packet.\n"); rd=sed_the_buffer(rd); if (write(s1,b2,rd)<=0) return 0; // not able to send @@ -204,6 +205,14 @@ return 1; } +void sig_chld(int signo) +{ + pid_t pid; + int stat; + while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0) + printf("child %d terminated\n", pid); + return; +} int main(int argc,char* argv[]) { int i; @@ -242,7 +251,7 @@ if (fixedhost && fixedport) printf("[+] Using fixed forwarding to %s:%s.\n",argv[3],argv[4]); else printf("[+] Using dynamic (transparent proxy) forwarding.\n"); signal(SIGPIPE,SIG_IGN); - signal(SIGCHLD,SIG_IGN); + signal(SIGCHLD,sig_chld); // Am I bad coder?;> --------------4C8B423034AD1BB86C3CE093-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message