X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Message-ID: <4D74F4A8.2080505@redhat.com> Date: Mon, 07 Mar 2011 08:07:20 -0700 From: Eric Blake User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.7 MIME-Version: 1.0 To: cygwin AT cygwin DOT com, tar-list Subject: Re: tar --atime-preserve with an empty file triggers a warning References: <20110307152005 DOT 17292u50da242vth AT messagerie DOT si DOT c-s DOT fr> <4D74EC98 DOT 7090803 AT redhat DOT com> <20110307144349 DOT GE18640 AT calimero DOT vinschen DOT de> In-Reply-To: <20110307144349.GE18640@calimero.vinschen.de> OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig31F6AE84341E1DEA68A5B5A3" X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com --------------enig31F6AE84341E1DEA68A5B5A3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable [adding bug-tar] On 03/07/2011 07:43 AM, Corinna Vinschen wrote: >>> Of course the empty.tar is created as expected (ie identical as without >>> `--atime-preserve). The warning is not produced on Solaris, Darwin or >>> Linux, >>> therefore i contacted this list. Do you think, with your expertise, tha= t i >>> should contact bug-tar also? >> >> No, this list is correct. utime should not fail on an empty file, so >> you've probably exposed a bug in cygwin1.dll. >=20 > THis looks like a tar bug, per the strace. For some reason, if the > file is empty, tar calls futimens on file descriptor 0 (which is > connected to /dev/tty1 in my case), while it call futimens on > file descriptor 4 (connected to the file empty) if the file empty > is... well, not empty. This is indeed multiple bug reports for the price of 1 :) When I strace the same thing on Linux with tar 1.23 (actually, tar-1.23-7.fc14 of Fedora), I see: lstat("a", {st_mode=3DS_IFREG|0664, st_size=3D0, ...}) =3D 0 utimensat(AT_FDCWD, "a", {{1299509299, 962839134}, {1299509299, 962839134}}, 0) =3D 0 Empty file optimization - tar skipped opening and reading from "a", and called utimensat to adjust "a" itself. lstat("b", {st_mode=3DS_IFREG|0664, st_size=3D2, ...}) =3D 0 open("b", O_RDONLY) =3D 4 read(4, "b\n", 2) =3D 2 fstat(4, {st_mode=3DS_IFREG|0664, st_size=3D2, ...}) =3D 0 utimensat(4, NULL, {{1299509302, 688833576}, {1299509302, 688833576}}, 0) =3D 0 close(4) =3D 0 Non-empty file; tar opened "b", read it, then called futimens on the open fd. Tar should NOT be calling utimensat() on an empty file, since this is inherently racy (the file could have been made non-empty between when tar stat'ed it as empty and when tar issues the utimensat). Besides, if we _know_ the file is empty at the time we did the stat, and didn't open it, then we didn't modify the atime in the first place, so we can avoid the race entirely by avoiding the attempt to restore the atime. Then, when I upgrade to the latest tar.git, post-1.25, still on Linux, I see: newfstatat(AT_FDCWD, "a", {st_mode=3DS_IFREG|0664, st_size=3D0, ...}, AT_SYMLINK_NOFOLLOW) =3D 0 dup2(0, 0) =3D 0 fstat(0, {st_mode=3DS_IFCHR|0620, st_rdev=3Dmakedev(136, 3), ...}) =3D 0 utimensat(0, NULL, {{1299510124, 243649745}, {1299510141, 910632470}}, 0) =3D 0 newfstatat(AT_FDCWD, "b", {st_mode=3DS_IFREG|0664, st_size=3D2, ...}, AT_SYMLINK_NOFOLLOW) =3D 0 ... openat(AT_FDCWD, "b", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW|O_CLOEXEC) = =3D 4 fstat(4, {st_mode=3DS_IFREG|0664, st_size=3D2, ...}) =3D 0 read(4, "b\n", 2) =3D 2 fstat(4, {st_mode=3DS_IFREG|0664, st_size=3D2, ...}) =3D 0 dup2(4, 4) =3D 4 fstat(4, {st_mode=3DS_IFREG|0664, st_size=3D2, ...}) =3D 0 utimensat(4, NULL, {{1299510125, 985648045}, {1299510125, 985648045}}, 0) =3D 0 close(4) =3D 0 So indeed, something in the latest tar is trying to call futimens on fd 0 when encountering an empty file, which is the wrong file to be changing timestamps for. Finally, cygwin is failing with EINVAL for futimens on a pty fd. However, I don't know if that's something that we can change, since cygwin doesn't really maintain a notion of changeable times on ptys at the moment. --=20 Eric Blake eblake AT redhat DOT com +1-801-349-2682 Libvirt virtualization library http://libvirt.org --------------enig31F6AE84341E1DEA68A5B5A3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJNdPSoAAoJEKeha0olJ0Nq3rsH/1brxeDGyYZkQ8+qfYC/aUA7 XqSHr+RG3DlRsEXfn4r7d1+o2PpqKm1vAfBVG97m7A7O7iG9sF8pkT9HEyMcCZC1 jCYFPf2wJ3wYo8f9HsKt4L5HSlW+BAgZR0jUNBTDIsf7EsYJpv5J3BSU6ojKLT64 SBM/AMswLSk7GnC5Ea8AxPGCkJCf8zaLlhdgKKyWn5w3/zvAtnCLnqF5wq/qo0ym 6Mly9C47dNUq8mOYX6+uIIuHpfTFZ64S6Q5GErv8+4Bl0Ih+6pbKHBO7R1Jri3H1 2V1J1LkUDUrPufLn2beR5PG0zze0Mls+cIfvE4leqpcipPSs4cdFm0S6MtZnGxM= =qdPM -----END PGP SIGNATURE----- --------------enig31F6AE84341E1DEA68A5B5A3--