From owner-freebsd-standards@FreeBSD.ORG Tue Jul 10 15:22:15 2012 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 562B9106566C; Tue, 10 Jul 2012 15:22:15 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id CD1A48FC14; Tue, 10 Jul 2012 15:22:14 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q6AFMLXA027827; Tue, 10 Jul 2012 18:22:21 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q6AFM8r7053679; Tue, 10 Jul 2012 18:22:08 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q6AFM8Hn053678; Tue, 10 Jul 2012 18:22:08 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 10 Jul 2012 18:22:08 +0300 From: Konstantin Belousov To: Volodymyr Kostyrko Message-ID: <20120710152208.GF2338@deviant.kiev.zoral.com.ua> References: <4FFC1D2D.4020405@gmail.com> <20120710140203.GA2338@deviant.kiev.zoral.com.ua> <4FFC39D9.6080809@gmail.com> <20120710142746.GD2338@deviant.kiev.zoral.com.ua> <4FFC441A.2010500@gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ZSoWtPk5XaIUnOQI" Content-Disposition: inline In-Reply-To: <4FFC441A.2010500@gmail.com> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: "freebsd-hackers@freebsd.org" , freebsd-standards@freebsd.org Subject: Re: kern/149857: [kqueue] kqueue not reporting EOF under certain circumstances X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Jul 2012 15:22:15 -0000 --ZSoWtPk5XaIUnOQI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jul 10, 2012 at 06:02:50PM +0300, Volodymyr Kostyrko wrote: > Konstantin Belousov wrote: > >>So you mean this is just my false assumption that EOF _should_ occur on > >>stdin? And it actually occurs only if source is a process which can send > >>EOF? > > > >'Source' cannot be a process. Read filter on pipes can return EV_EOF. > >Read filter on vnodes (read: regular files) does not return EV_EOF, > >except in situation that is created by manual intervention of > >administrator. >=20 > This keeps me puzzled. How then I can tell that file at stdin is already= =20 > at EOF? You mean I should treat stdin like normal vnode-backed file? >=20 > off_t pos =3D 0, endpos; >=20 > lseek(fileno(stdin), 0, SEEK_END); > endpos =3D ftell(stdin); > lseek(fileno(stdin), 0, SEEK_SET); >=20 > ... and then later check it with: >=20 > if(endpos !=3D -1) { > pos +=3D kev.data; > if(pos >=3D endpos) { > printf("end reached\n"); > return(0); > } > } >=20 > Is this a correct way to detect EOF? I'm letting besides that I should=20 > also detect vnode changes and update max file size accordingly. >=20 > >It should have been clear from my previous response. >=20 > Please excuse me, I'm a bit new to this things... Why do you use kqueue there at all ? Just read from stdin, and decide that you hit EOF when read returned 0 bytes. If insisting on using kqueue, which may be ligitimate if you process other sources besides stdin, you should first investigate the nature of the fd 0 using fstat, and then use appropriate code for regular file, pipe and probably socket (e.g. for the case if code allows to run under inetd(8)). --ZSoWtPk5XaIUnOQI Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAk/8SJwACgkQC3+MBN1Mb4jqSgCdHgVPqhHwmfHo6xP3bSVIj7LU OoIAnRa30uNLPclEEcXgk17m6VXbU7JG =c8s9 -----END PGP SIGNATURE----- --ZSoWtPk5XaIUnOQI--