From okumoto@oecpc18.ucsd.edu  Thu Jan 30 16:09:40 2003
Return-Path: <okumoto@oecpc18.ucsd.edu>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 1C20937B401
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 30 Jan 2003 16:09:40 -0800 (PST)
Received: from oecpc18.ucsd.edu (oecpc18.ucsd.edu [132.239.18.178])
	by mx1.FreeBSD.org (Postfix) with ESMTP id A4D1643F3F
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 30 Jan 2003 16:09:39 -0800 (PST)
	(envelope-from okumoto@oecpc18.ucsd.edu)
Received: from oecpc18.ucsd.edu (localhost [127.0.0.1])
	by oecpc18.ucsd.edu (8.12.3/8.12.3) with ESMTP id h0V09dBe031095
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 30 Jan 2003 16:09:39 -0800 (PST)
	(envelope-from okumoto@oecpc18.ucsd.edu)
Received: (from okumoto@localhost)
	by oecpc18.ucsd.edu (8.12.3/8.12.3/Submit) id h0V09dgj031094;
	Thu, 30 Jan 2003 16:09:39 -0800 (PST)
Message-Id: <200301310009.h0V09dgj031094@oecpc18.ucsd.edu>
Date: Thu, 30 Jan 2003 16:09:39 -0800 (PST)
From: Max Okumoto <okumoto@ucsd.edu>
Reply-To: Max Okumoto <okumoto@ucsd.edu>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Inetd leaves some sockets open.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         47694
>Category:       bin
>Synopsis:       Inetd leaves some sockets open.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    dwmalone
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 30 16:10:07 PST 2003
>Closed-Date:    Sat Apr 05 05:42:10 PST 2003
>Last-Modified:  Sat Apr 05 05:42:10 PST 2003
>Originator:     Max Okumoto
>Release:        FreeBSD 4.6.2-RELEASE-p2 i386
>Organization:
>Environment:
System: FreeBSD oec-server2.ucsd.edu 4.6.2-RELEASE-p2 FreeBSD 4.6.2-RELEASE-p2 #0: Sun Sep 22 19:24:16 PDT 2002 troot@oec-server2.ucsd.edu:/usr/obj/usr/src/sys/OEC_SERVER2 i386

University of Washington IMAP toolkit
Version 2002a of IMAP toolkit
Copyright 1988-2002 University of Washington

>Description:
	Inetd is leaving file descriptors open when it execs the
	service binary.  When enabling both comsat(biff) and imap
	on the machine, I found that when I restart inetd, a syslog
	message is generated that indicates that inetd can't reopen
	port 512(comsat).  Looking at the output of sockstat will
	show same file descriptor open for all child imapd servers.

>How-To-Repeat:
	Enable comsat and imaps
	Boot machine
	Connect to imap server
	run sockstat and grep for imapd and inetd.

USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
jlgibson imapd    63720    0 tcp4   132.239.8.82:993      199.106.117.70:64452
jlgibson imapd    63720    1 tcp4   132.239.8.82:993      199.106.117.70:64452
jlgibson imapd    63720    4 udp4   *:901                 *:*
jlgibson imapd    63720   11 udp4   *:512                 *:*
jlgibson imapd    63716    0 tcp4   132.239.8.82:993      199.106.117.70:64446
jlgibson imapd    63716    1 tcp4   132.239.8.82:993      199.106.117.70:64446
jlgibson imapd    63716    4 udp4   *:905                 *:*
jlgibson imapd    63716   11 udp4   *:512                 *:*
okumoto  imapd    63710    0 tcp4   132.239.8.82:993      132.239.18.178:3870
okumoto  imapd    63710    1 tcp4   132.239.8.82:993      132.239.18.178:3870
okumoto  imapd    63710    4 udp4   *:913                 *:*
okumoto  imapd    63710   11 udp4   *:512                 *:*
oconnor  imapd    63671    0 tcp4   132.239.8.82:993      132.239.18.171:3069
oconnor  imapd    63671    1 tcp4   132.239.8.82:993      132.239.18.171:3069  
oconnor  imapd    63671    4 udp4   *:931                 *:*                  
oconnor  imapd    63671   11 udp4   *:512                 *:*                  
scottand imapd    62520    0 tcp4   132.239.8.82:993      132.239.8.27:4348    
scottand imapd    62520    1 tcp4   132.239.8.82:993      132.239.8.27:4348    
scottand imapd    62520    4 udp4   *:796                 *:*                  
ratcliff imapd    62493    0 tcp4   132.239.8.82:993      132.239.8.7:59425    
ratcliff imapd    62493    1 tcp4   132.239.8.82:993      132.239.8.7:59425    
ratcliff imapd    62493    4 udp4   *:829                 *:*                  
jpr      imapd    62492    0 tcp4   132.239.8.82:993      132.239.8.7:59424    
jpr      imapd    62492    1 tcp4   132.239.8.82:993      132.239.8.7:59424    
jpr      imapd    62492    4 udp4   *:828                 *:*                  
root     inetd    54260    4 tcp4   *:143                 *:*
root     inetd    54260    6 tcp4   *:110                 *:*
root     inetd    54260    7 tcp4   *:993                 *:*
root     inetd    54260    8 tcp4   *:995                 *:*
root     inetd    54260   11 udp4   *:512                 *:*
	
>Fix:

	


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->dwmalone 
Responsible-Changed-By: dwmalone 
Responsible-Changed-When: Wed Feb 5 03:42:24 PST 2003 
Responsible-Changed-Why:  
Inetd is my problem. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=47694 

From: David Malone <dwmalone@maths.tcd.ie>
To: Max Okumoto <okumoto@ucsd.edu>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: bin/47694: Inetd leaves some sockets open.
Date: Wed, 5 Feb 2003 11:41:30 +0000

 On Thu, Jan 30, 2003 at 04:09:39PM -0800, Max Okumoto wrote:
 > >Description:
 > 	Inetd is leaving file descriptors open when it execs the
 > 	service binary.  When enabling both comsat(biff) and imap
 > 	on the machine, I found that when I restart inetd, a syslog
 > 	message is generated that indicates that inetd can't reopen
 > 	port 512(comsat).
 
 If you kill inetd while a "wait" service is running, such as comsat,
 then that service continues to run. When the new inetd starts it
 finds that the socket is already bound and has to wait for the
 running service to exit before it can rebind.
 
 >	Looking at the output of sockstat will
 > 	show same file descriptor open for all child imapd servers.
 
 This looks like a bug in the filediscriptor tracking in inetd -
 I'll see if I can figure out what's going on. I believe NetBSD/OpenBSD
 use close-on-exec to do what we're doing by hand, so it might make sense
 to import that.
 
 	David.
State-Changed-From-To: open->feedback 
State-Changed-By: dwmalone 
State-Changed-When: Sun Feb 9 12:24:25 PST 2003 
State-Changed-Why:  
I have produced a patch which uses the idea from NetBSD of marking 
file discriptors as close on exec. If you could test this patch for 
me, that would be good. There is a version for -stable and for 
-current: 

http://www.maths.tcd.ie/~dwmalone/inetd-stable.patch 
http://www.maths.tcd.ie/~dwmalone/inetd-current.patch 

The patch also covers a memory leak and a NULL pointer dereference. 
(PRs 47313, 46845 and 46088). 

David. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=47694 
State-Changed-From-To: feedback->closed 
State-Changed-By: dwmalone 
State-Changed-When: Sat Apr 5 05:41:37 PST 2003 
State-Changed-Why:  
Should be fixed in -current and -stable. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=47694 
>Unformatted:
