From owner-freebsd-questions@FreeBSD.ORG Fri Jul 16 06:39:33 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CE6D1106566C for ; Fri, 16 Jul 2010 06:39:33 +0000 (UTC) (envelope-from rehsack@googlemail.com) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id 62C9B8FC12 for ; Fri, 16 Jul 2010 06:39:32 +0000 (UTC) Received: by wwc33 with SMTP id 33so910727wwc.31 for ; Thu, 15 Jul 2010 23:39:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=WeIWpuB4RXBJgnSVgKho99qPhnmV6VpI18nh2zVBVlE=; b=alAhAFLydrMr61X8jeXV/0urN+zDrL8f6sLAuz3s0ymp/YE1MxmYZh31khflJ7Tcie 26vyum3GgfiRBDpBkDi9/d/49o20d7gmNkvQxxv8O5qTS517phm/xLtqRC2K/LZV96wn 5zpM5WwINEAft1nM0rg/M1F9Kg/+ywje3/mGg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=xrPVZXstcBYtBSJJ2oJI2NonET15gwhQ/Drynj5yLFn2EpRCeaId0QVnV45lbGM+ss jTVyEwFs9SImD6UUbUoenH6LvLETIhy2Jz9Y/AM9aZTWGPHDCU1fA5tyjf+AxGpYePa4 xErOn+UozDsEX4qQSrxkXkXf1zWrQIuf+1ihA= MIME-Version: 1.0 Received: by 10.227.127.202 with SMTP id h10mr496244wbs.202.1279262372034; Thu, 15 Jul 2010 23:39:32 -0700 (PDT) Received: by 10.216.89.66 with HTTP; Thu, 15 Jul 2010 23:39:31 -0700 (PDT) In-Reply-To: <20100716043056.GF5485@dan.emsphone.com> References: <20100715172615.GC5485@dan.emsphone.com> <86tyo0qd19.fsf@chateau.d.if> <20100716043056.GF5485@dan.emsphone.com> Date: Fri, 16 Jul 2010 08:39:31 +0200 Message-ID: From: Jens Rehsack To: Dan Nelson Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Ashish SHUKLA , freebsd-questions@freebsd.org Subject: Re: getpwent bug? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Jul 2010 06:39:34 -0000 2010/7/16 Dan Nelson : > In the last episode (Jul 16), Ashish SHUKLA said: >> Dan Nelson writes: >> > In the last episode (Jul 15), Jens Rehsack said: >> >> Hi all, >> >> >> >> I detected an issue with getpwent on my FreeBSD test box: >> >> >> >> perl -MData::Dumper -e 'my @e =3D getpwent(); print Dumper(\@e); endp= went(); @e =3D getpwent(); print Dumper(\@e); endpwent(); @e =3D getpwent()= ; print Dumper(\@e); endpwent();' >> >> $VAR1 =3D [ 'root', '', 0, 0, 0, '', 'Charlie &', '/root', '/bin/csh'= , 0 ]; >> >> $VAR1 =3D [ 'toor', '*', 0, 0, 0, '', 'Bourne-again Superuser', '/roo= t', '', 0 ]; >> >> $VAR1 =3D [ 'daemon', '*', 1, 1, 0, '', 'Owner of many system process= es', '/root', '/usr/sbin/nologin', 0 ]; >> >> >> >> I'm using FreeBSD waldorf.muppets.liwing.de 7.3-PRERELEASE FreeBSD 7.= 3-PRERELEASE #0: Fri Mar 12 11:31:18 UTC 2010 root@waldorf.muppets.liwing.d= e:/usr/obj/usr/src/sys/WALDORF =A0amd64 >> >> > The above output looks perfect, and should match the top three lines i= n >> > /your etc/passwd files. >> >> Well, OP is also invoking 'endpwent()' after every 'getpwent()' invocati= on >> which according to GNU/Linux's glibc and NetBSD's libc (as OP mentioned) >> should rewind the position in passwd database to the beginning. > > Ah. I missed the endpwent calls. Was difficult for me to format the single liner ;) >> To me it definitely looks like a bug in FreeBSD's getpw*() family of >> functions. >> >> As tested using sysutils/lsof, in the following program in FreeBSD, the >> descriptor corresponding to '/etc/pwd.db' is closed on endpwent(3) but >> position in database is never rewinded as shown in the output. > > It looks like the *pwent functions keep an internal counter that endpwent > doesn't reset. Could you please take a look to my other mail (getgrent related) - there se= ems another bug ... > Try the following patch: Can I do this without a full world rebuild? (I do not develop in FBSD activ= ely). Otherwise I recommend (the test case was in OP) that someone with a separate test box tries it out and commit it etc. I had to develop a workaround for all other boxes anyway. Thank you very much, Jens > Index: gen/getpwent.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- gen/getpwent.c =A0 =A0 =A0(revision 210157) > +++ gen/getpwent.c =A0 =A0 =A0(working copy) > @@ -794,6 +794,7 @@ files_setpwent(void *retval, void *mdata, va_list > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(void)st->db->close(st->db= ); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0st->db =3D NULL; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 st->keynum =3D 0; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > =A0 =A0 =A0 =A0default: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > > > -- > =A0 =A0 =A0 =A0Dan Nelson > =A0 =A0 =A0 =A0dnelson@allantgroup.com >