From owner-freebsd-stable@FreeBSD.ORG Tue May 24 16:59:10 2005 Return-Path: X-Original-To: freebsd-stable@freebsd.org Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CAA4716A41C for ; Tue, 24 May 2005 16:59:10 +0000 (GMT) (envelope-from emaste@phaedrus.sandvine.ca) Received: from mailserver.sandvine.com (sandvine.com [199.243.201.138]) by mx1.FreeBSD.org (Postfix) with ESMTP id 22C4C43D1D for ; Tue, 24 May 2005 16:59:07 +0000 (GMT) (envelope-from emaste@phaedrus.sandvine.ca) Received: from labgw2.phaedrus.sandvine.com ([192.168.3.11]) by mailserver.sandvine.com with Microsoft SMTPSVC(5.0.2195.6713); Tue, 24 May 2005 12:59:04 -0400 Received: by labgw2.phaedrus.sandvine.com (Postfix, from userid 12627) id 5DA9213641; Tue, 24 May 2005 12:59:07 -0400 (EDT) Date: Tue, 24 May 2005 12:59:07 -0400 From: Ed Maste To: freebsd-stable@freebsd.org Message-ID: <20050524165907.GA20674@sandvine.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.1i X-OriginalArrivalTime: 24 May 2005 16:59:04.0286 (UTC) FILETIME=[E40A5FE0:01C56081] Subject: libc_r kqueue fd leak X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 May 2005 16:59:10 -0000 We discovered a kqueue leak when running one of our 4.x applications on FreeBSD 5.3 using the compat libc_r. It turns out it's caused by libc_r's close() failing. The libc_r close (in uthread_close.c) calls fstat() on the file descriptor. On 4.x this succeeds, while on 5.x the fstat() on the kqueue() fd returns -1 with errno=0. The close() in libc_r then returns this error without doing the actual close syscall. I built the test application shown below on a 4.7 and 5.3 machine and fstat returns 0 on 4.7, -1 on 5.3. If the test app is linked against libc_r then the close() fails too. fstat(2) indicates that fstat() returns a mostly-zeroed buffer for a socket fd, but gives no indication of what should happen for a kqueue fd. What is the expected behaviour here? The issue could be fixed by either having the kernel not fail the fstat, or making libc_r ignore the failure and continue on with the close. == kqueue.c == #include #include #include #include int main() { struct stat sb; int kq=kqueue(); printf("fstat returns %d (%d)\n", fstat(kq, &sb), errno); printf("close returns %d (%d)\n", close(kq), errno); } -- Ed Maste, Sandvine Incorporated