From owner-freebsd-bugs@FreeBSD.ORG Sat Apr 10 10:20:20 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 31F0016A4CE for ; Sat, 10 Apr 2004 10:20:20 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 140E043D55 for ; Sat, 10 Apr 2004 10:20:20 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i3AHKJbv051894 for ; Sat, 10 Apr 2004 10:20:19 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.10/8.12.10/Submit) id i3AHKJue051893; Sat, 10 Apr 2004 10:20:19 -0700 (PDT) (envelope-from gnats) Resent-Date: Sat, 10 Apr 2004 10:20:19 -0700 (PDT) Resent-Message-Id: <200404101720.i3AHKJue051893@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Radim Kolar Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9A31D16A4CE for ; Sat, 10 Apr 2004 10:19:00 -0700 (PDT) Received: from mail.tiscali.cz (stateless1.tiscali.cz [213.235.135.70]) by mx1.FreeBSD.org (Postfix) with ESMTP id CBBB843D4C for ; Sat, 10 Apr 2004 10:18:59 -0700 (PDT) (envelope-from hsn@netmag.cz) Received: from asura.bsd (213.235.70.71) by mail.tiscali.cz (6.7.021) id 40292FFD00F3B06C for FreeBSD-gnats-submit@freebsd.org; Sat, 10 Apr 2004 19:18:58 +0200 Received: from hsn@localhost by asura.bsd (Exim 4.30_2 FreeBSD) id 1BCKYi-0000X1-RK for ; Sat, 10 Apr 2004 17:38:16 +0200 Message-Id: Date: Sat, 10 Apr 2004 17:38:16 +0200 From: Radim Kolar To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: kern/65402: patch: fflush() should not return error on readonly files X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Radim Kolar List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Apr 2004 17:20:20 -0000 >Number: 65402 >Category: kern >Synopsis: patch: fflush() should not return error on readonly files >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Apr 10 10:20:19 PDT 2004 >Closed-Date: >Last-Modified: >Originator: Radim Kolar >Release: FreeBSD 5.2.1-RELEASE-p3 i386 >Organization: Sanatana Dharma >Environment: System: FreeBSD asura.bsd 5.2.1-RELEASE-p3 FreeBSD 5.2.1-RELEASE-p3 #6: Mon Apr 5 17:41:24 CEST 2004 root@asura.bsd:/usr/src/sys/i386/compile/UP i386 >Description: When fflush() function is called on file which is opened for read-only, the call fails with bad file descriptor error. This behaviour is different from fsync() kernel function which correctly do not return any error. I have checked different operation systems (linux, cygwin, msvc++, hpux) and everywhere fflush() on r/o files works correctly. I have found this problem while trying to port some application to freebsd, fixing the application is difficult, since it uses the same set classes for read and write access to datafiles. There is no reason for returning error to user. If there are no data to write, simply do nothing. This patch do not breaks any existing application. >How-To-Repeat: #include int main (int argc,const char *argv[]) { FILE *f; char buf[2222]; f=fopen("/etc/passwd","r"); fread(buf, 10, 1, f); printf("ff rc %d\n",fflush(f)); /* check errno here */ fclose(f); } >Fix: --- /usr/src/lib/libc/stdio/fflush.c Fri Mar 22 22:53:04 2002 +++ fflush.c Sat Apr 10 17:22:01 2004 @@ -62,8 +62,7 @@ return (_fwalk(sflush_locked)); FLOCKFILE(fp); if ((fp->_flags & (__SWR | __SRW)) == 0) { - errno = EBADF; - retval = EOF; + return (0); } else retval = __sflush(fp); FUNLOCKFILE(fp); @@ -82,8 +81,7 @@ if (fp == NULL) return (_fwalk(sflush_locked)); if ((fp->_flags & (__SWR | __SRW)) == 0) { - errno = EBADF; - retval = EOF; + return (0); } else retval = __sflush(fp); return (retval); >Release-Note: >Audit-Trail: >Unformatted: