Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 May 2005 22:18:31 GMT
From:      Ed Maste <emaste@phaedrus.sandvine.ca>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   threads/81534: [PATCH] libc_r close() will fail on any fd type that doesn't support fstat()
Message-ID:  <200505262218.j4QMIVPc023570@www.freebsd.org>
Resent-Message-ID: <200505262220.j4QMK1PW074001@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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 <sys/types.h>
#include <sys/stat.h>
#include <sys/event.h>
#include <errno.h>

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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200505262218.j4QMIVPc023570>