From owner-freebsd-threads@FreeBSD.ORG Thu May 26 22:20:02 2005 Return-Path: X-Original-To: freebsd-threads@hub.freebsd.org Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id F370E16A41C for ; Thu, 26 May 2005 22:20:01 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3CB2A43D4C for ; Thu, 26 May 2005 22:20:01 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j4QMK1Eq074002 for ; Thu, 26 May 2005 22:20:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j4QMK1PW074001; Thu, 26 May 2005 22:20:01 GMT (envelope-from gnats) Resent-Date: Thu, 26 May 2005 22:20:01 GMT Resent-Message-Id: <200505262220.j4QMK1PW074001@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-threads@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ed Maste Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DDF0F16A41C for ; Thu, 26 May 2005 22:18:31 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id B898A43D1D for ; Thu, 26 May 2005 22:18:31 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j4QMIVPK023571 for ; Thu, 26 May 2005 22:18:31 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id j4QMIVPc023570; Thu, 26 May 2005 22:18:31 GMT (envelope-from nobody) Message-Id: <200505262218.j4QMIVPc023570@www.freebsd.org> Date: Thu, 26 May 2005 22:18:31 GMT From: Ed Maste To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: threads/81534: [PATCH] libc_r close() will fail on any fd type that doesn't support fstat() X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 May 2005 22:20:02 -0000 >Number: 81534 >Category: threads >Synopsis: [PATCH] libc_r close() will fail on any fd type that doesn't support fstat() >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-threads >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu May 26 22:20:00 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Ed Maste >Release: 5.3-RELEASE >Organization: Sandvine Incorporated >Environment: FreeBSD bsd10.phaedrus.sandvine.com 5.3-RELEASE-p2 FreeBSD 5.3-RELEASE-p2 #2: Fri Dec 3 13:30:36 EST 2004 root@bsd10.phaedrus.sandvine.com:/usr/obj/usr/src/sys/WORKFARM i386 >Description: 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. This has been discussed in a thread at http://lists.freebsd.org/pipermail/freebsd-stable/2005-May/015234.html >How-To-Repeat: == 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); } >Fix: jmg@ has already committed a fix to have kqueue_stat not return a failure (threads/75795). I posted a libc_r patch to deal with the issue at http://lists.freebsd.org/pipermail/freebsd-stable/2005-May/015236.html As jmg points out, "Who knows what else doesn't implement _stat and can't be closed.." >Release-Note: >Audit-Trail: >Unformatted: