From owner-freebsd-questions@FreeBSD.ORG Fri Jul 16 04:14:03 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 85B511065673 for ; Fri, 16 Jul 2010 04:14:03 +0000 (UTC) (envelope-from wahjava@gmail.com) Received: from mail-px0-f182.google.com (mail-px0-f182.google.com [209.85.212.182]) by mx1.freebsd.org (Postfix) with ESMTP id 34F438FC0A for ; Fri, 16 Jul 2010 04:14:02 +0000 (UTC) Received: by pxi8 with SMTP id 8so853990pxi.13 for ; Thu, 15 Jul 2010 21:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:received:from:to:cc :subject:organization:references:x-face:x-uptime:x-url :x-operating-system:x-openpgp-id:x-openpgp-fingerprint:x-mailer :x-mail-morse:x-attribution:organisation:date:in-reply-to:message-id :user-agent:face:mime-version:content-type; bh=1/IMROli697dpo+luW1/D3Gwvb8b6m0Bs6PiOl0ayYA=; b=jDGfZo35edkofIW9A4MSEKBBOzmcsF6vkwglPmuzJ4T6Pc3XRFYooB8zr1bfdRoRBQ u22c3H5CB2hl8A8l3/A14avGawtSe9343xu1rt73acWH6xIvFsrcokg8pdHYpXLwWm3h 4P+Qd9iZBWazJZqTnxe+6NddtjiomIJe0lTK0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:organization:references:x-face:x-uptime :x-url:x-operating-system:x-openpgp-id:x-openpgp-fingerprint :x-mailer:x-mail-morse:x-attribution:organisation:date:in-reply-to :message-id:user-agent:face:mime-version:content-type; b=xoIK/x4xWZKcsxwVQiYh6IFfdOadVUoan61tMIzPysJvjHXsUEFRBYlNAFmRabIQiM ivtAtudKyaQVXkujAGhsziN9BNUmcw42rsjz8vv//GDicICOOmgEi856btohbI6nF6hZ DRDDXZwlK+AfpEVnUQeyUK1UQuQMenbQn4Tdc= Received: by 10.142.140.16 with SMTP id n16mr618789wfd.45.1279253642560; Thu, 15 Jul 2010 21:14:02 -0700 (PDT) Received: from chateau.d.if ([122.163.158.28]) by mx.google.com with ESMTPS id z1sm2113348wfd.15.2010.07.15.21.13.59 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 15 Jul 2010 21:14:01 -0700 (PDT) Sender: Ashish SHUKLA Received: from chateau.d.if (chateau.d.if [127.0.0.1]) by chateau.d.if (Postfix) with ESMTP id 89E832D8027; Fri, 16 Jul 2010 09:43:54 +0530 (IST) From: ashish@FreeBSD.org (Ashish SHUKLA) To: Dan Nelson Organization: The FreeBSD Project References: <20100715172615.GC5485@dan.emsphone.com> X-Face: )vGQ9yK7Y$Flebu1C>(B\gYBm)[$zfKM+p&TT[[JWl6:]S>cc$%-z7-`46Zf0B*syL.C]oCq[upTG~zuS0.$"_%)|Q@$hA=9{3l{%u^h3jJ^Zl; t7 X-Uptime: 09:27:09 up 1:57, 1 user, load average: 0.10, 0.06, 0.01 X-URL: http://762e5e74.wordpress.com/ X-Operating-System: GNU/Linux/Linux 2.6.34-ARCH/x86_64 X-OpenPGP-ID: E74FA4B0 X-OpenPGP-Fingerprint: F682 CDCC 39DC 0FEA E116 20B6 C746 CFA9 E74F A4B0 X-Mailer: Gnus v5.13 X-Mail-Morse: .-- .- .... .--- .- ...- .- .--.-. --. -- .- .. .-.. .-.-.- -.-. --- -- X-Attribution: =?utf-8?B?4KSG4KS24KWA4KS3?= Organisation: The FreeBSD Project Date: Fri, 16 Jul 2010 09:43:54 +0530 In-Reply-To: <20100715172615.GC5485@dan.emsphone.com> (Dan Nelson's message of "Thu, 15 Jul 2010 12:26:15 -0500") Message-ID: <86tyo0qd19.fsf@chateau.d.if> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (x86_64-unknown-linux-gnu) Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJ1BMVEWpqal/f39tbW1jY2Md HR2goKCenp6UlJROTk7////9/f35+fnT09ORJdieAAACVklEQVQ4jXXUP2vbQBQA8AvUTkgz5OzY Z0iGWhpS6BSrkECn0mvx0MEJ6AjtYrfoBCVDlD8naJYmNlRfwZq8+mkKlIZaGpJSYmP7Q/XkJDrJ Td8i/H68u3vHPaPufwLdf32AMA4A6GcAgvAamY1pOJiDIFqicTwLswDhfr3uxfFtkAY/GFHPMwzD 8zpnACmIOnE6js7rQb+v4NJrG9od0C+QgpHMy5jBewV+UDSMWiw1Y4fWfyV7+NGFzDsYa3pth9LJ Q4XvXxFHcJRvHOmygn5NAEabnDcQQguarnfoiwSCJ99jmKKcphsZONmWsDK9Ro7cvZOCtQdg8nje egLhc2LNlkLmsezzTFUUy5w18ocox/f0LaLgJy0zO75zk+9pp85GAj36xjqhdI0y3tq2m4dqqcWX zQWBTz8L1irvolXV4J+3q7eCDgVnttjNq6X8H+9KOZsuNk1uCzx8pSp+E9HImfJOTLdcGqo+YKnG EIovizkEn48V7BO+ch2DXcD4ENSpWiU+q8hjjbgTBZCXnZtyj0Ws4Q1Q0B2WXFtYZo65Bbyeeldw RS6qFueM80LlLA29YlVwGRYvFD+kwI/0O+A2PlpOP9GwslUVciHuYGechuBTp922YiDZCrghTknm XSyOM+D3aoRZlo0Jb42zY7DN4p2x4AeZ+QAYutx1sHwTHzMT5cMNduQ9yW3GczN4KZ86kb0c9O8T yXDeFqpl2fryPEAYGXIlezAPXYh2NgVr/gvdoHIuDwuPwOhcWE8f8mmICq41eATkn8x0kuRTIKcB wE9+/QUtiiAnYcaN7wAAAABJRU5ErkJggg== MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Cc: Jens Rehsack , 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 04:14:03 -0000 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Dan Nelson writes: > In the last episode (Jul 15), Jens Rehsack said: >> Hi all, >>=20 >> I detected an issue with getpwent on my FreeBSD test box: >>=20 >> perl -MData::Dumper -e 'my @e =3D getpwent(); print Dumper(\@e); endpwen= t(); @e =3D getpwent(); print Dumper(\@e); endpwent(); @e =3D getpwent(); p= rint Dumper(\@e); endpwent();' >> $VAR1 =3D [ 'root', '', 0, 0, 0, '', 'Charlie &', '/root', '/bin/csh', 0= ]; >> $VAR1 =3D [ 'toor', '*', 0, 0, 0, '', 'Bourne-again Superuser', '/root',= '', 0 ]; >> $VAR1 =3D [ 'daemon', '*', 1, 1, 0, '', 'Owner of many system processes'= , '/root', '/usr/sbin/nologin', 0 ]; >>=20 >> I'm using FreeBSD waldorf.muppets.liwing.de 7.3-PRERELEASE FreeBSD 7.3-P= RERELEASE #0: Fri Mar 12 11:31:18 UTC 2010 root@waldorf.muppets.liwing.de:/= usr/obj/usr/src/sys/WALDORF amd64 > The above output looks perfect, and should match the top three lines in y= our > /etc/passwd files. Well, OP is also invoking 'endpwent()' after every 'getpwent()' invocation which according to GNU/Linux's glibc and NetBSD's libc (as OP mentioned) should rewind the position in passwd database to the beginning. 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. #v+ #include #include int main() { struct passwd* pw; int i; char ch; for(i =3D 0; i < 3; i++) { printf("Doing getpwent(). Press any key to continue..."); while(getchar() !=3D '\n'); pw =3D getpwent(); printf("%s:%d:%d\n", pw->pw_name, pw->pw_uid, pw->pw_gid); endpwent(); } } #v- Output on FreeBSD 8.1-RC2: #v+ %./pwent=20 Doing getpwent(). Press any key to continue... root:0:0 Doing getpwent(). Press any key to continue... toor:0:0 Doing getpwent(). Press any key to continue... daemon:1:1 #v- Output on GNU/Linux: #v+ % ./pwent Doing getpwent(). Press any key to continue... root:0:0 Doing getpwent(). Press any key to continue... root:0:0 Doing getpwent(). Press any key to continue... root:0:0 #v- HTH =2D-=20 Ashish SHUKLA | GPG: F682 CDCC 39DC 0FEA E116 20B6 C746 CFA9 E74F A4B0 freebsd.org!ashish | http://people.freebsd.org/~ashish/ =E2=80=9CHow can I possibly put a new idea into your heads, if I do not fir= st remove your delusions?=E2=80=9D (Robert A. Heinlein, "Life-Line", 1939) --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) iQIcBAEBCgAGBQJMP9yCAAoJEMdGz6nnT6SwBMMP/2V01XdDlQmypmtHhK7bavKg MXerodcCXsK1whk1YBHdfzlXj464w6PAlXa4g1LVIqTpcBXjQ5MLApofnO+eqtgh aitgL9J21ZZGxZeMvvI1Ykdsq7UsxMYj6KwAg3fdifPQz/y0mZIZH/YAFiykoO1e jq4+yVwDQ2gf0zHf/g1eQtn/MpnokEyb1WxrxLL3rKD0JVFAGjoVSGGS4lVScjhI x5QpoVMaa8Y5W5lwwjvfmktw/0Ei6sZkiZOskvmrQtCExn7Jt8wWApRNKWjppmdd UODNLoFlflMmrpYEqjkVBROJMMRqwCRjxG5wPa6lXolysE2JNrfgfwUVvtSv8AtQ UI+9mcszWSRJSM+HIgeK1mNQ8jvcOitRIUQO+grj8dvfaJqyO4ocyZej4Airg9ad lKc1haBsqf+hyRG0+/LmunG/vLXHAcDq90M9PqgvRXn33d+X2sC+I4euCGyBSdDl TSMxlMIbHr7sxAgSyK/FY9WpZJTWc+vcNZyNkNKZUR4kgrET9Jyh0Oip5Q06RaxD pgTUuLYkUHfzwSETZolbCcu0MymlJDQkOkWI0/XKOc6jBYiGqDVp8uDpY0iOT/Oh XQiJod/53hbgUyXGqEjpYEs+5jzdMlC9b2t1zNIhgLoPd+haXs6mItd+xvwdUWNS JUf6sT7dDUvQWF0Fbwpx =c9wh -----END PGP SIGNATURE----- --=-=-=--