bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug 552320] Handling AT_FDCWD as EBADF in glibc's utimens() causes


From: Jim Meyering
Subject: Re: [Bug 552320] Handling AT_FDCWD as EBADF in glibc's utimens() causes tar failures
Date: Tue, 05 Jan 2010 22:07:34 +0100

address@hidden wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=552320
>
> Ondrej Vasik <address@hidden> changed:
>
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |address@hidden
>             Summary|new tar is unable to open   |Handling AT_FDCWD as EBADF
>                    |archives created with old   |in glibc's utimens() causes
>                    |tar                         |tar failures
>
> --- Comment #5 from Ondrej Vasik <address@hidden>  2010-01-05 14:29:13 EDT ---
> Ah - even the latest gnulib doesn't handle this new recent change - so touch
> from coreutils might be affected as well as mentioned in debian bugzilla from
> comment #4. Therefore adding coreutils/gnulib upstream maintainer into CC.
>
> Jim, what do you think? Is the patch from
> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=563726#66 good way to go and
> should be applied to gnulib/coreutils-8.3 to prevent touch (or better said
> futimens() with AT_FDCWD file descriptor) failures after glibc update?

Hi Ondrej,

Thanks for the heads up.  Good timing.
That does indeed look like a bug, and Aurelien Jarno's fix seems right.

Here's "git diff -w" output:

diff --git a/lib/utimens.c b/lib/utimens.c
index 4df1646..6b7716f 100644
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -264,6 +264,7 @@ fdutimens (char const *file, int fd, struct timespec const 
timespec[2])
         }
 # endif /* HAVE_UTIMENSAT */
 # if HAVE_FUTIMENS
+      if (0 <= fd)
       {
         result = futimens (fd, ts);
 #  ifdef __linux__





I expect to push the following to gnulib in the morning:

>From e7d83f123f5eed312523252c066510b5de0f7cd1 Mon Sep 17 00:00:00 2001
From: Aurelien Jarno <address@hidden>
Date: Tue, 5 Jan 2010 21:31:41 +0100
Subject: [PATCH] utimens (fdutimens): ignore a negative FD, per contract

* lib/utimens.c (fdutimens) [HAVE_FUTIMENS]: Call futimens only
when we have a valid file descriptor.  Otherwise, using a brand
new glibc (with just-patched futimes that now fails with EBADF)
would cause this function to fail with ENOSYS.
Reported by Guillaume Ayoub in http://bugs.debian.org/563726.
See also http://bugzilla.redhat.com/552320
---
 ChangeLog     |   10 ++++++++++
 lib/utimens.c |   23 ++++++++++++-----------
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2857d3d..80ba5cd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-01-05  Aurelien Jarno  <address@hidden>
+
+       utimens (fdutimens): ignore a negative FD, per contract
+       * lib/utimens.c (fdutimens) [HAVE_FUTIMENS]: Call futimens only
+       when we have a valid file descriptor.  Otherwise, using a brand
+       new glibc (with just-patched futimes that now fails with EBADF)
+       would cause this function to fail with ENOSYS.
+       Reported by Guillaume Ayoub in http://bugs.debian.org/563726.
+       See also http://bugzilla.redhat.com/552320
+
 2010-01-05  Jim Meyering  <address@hidden>

        maint: remove useless inclusions of "xalloc.h"
diff --git a/lib/utimens.c b/lib/utimens.c
index 4df1646..6b7716f 100644
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -264,19 +264,20 @@ fdutimens (char const *file, int fd, struct timespec 
const timespec[2])
         }
 # endif /* HAVE_UTIMENSAT */
 # if HAVE_FUTIMENS
-      {
-        result = futimens (fd, ts);
+      if (0 <= fd)
+       {
+         result = futimens (fd, ts);
 #  ifdef __linux__
-        /* Work around the same bug as above.  */
-        if (0 < result)
-          errno = ENOSYS;
+         /* Work around the same bug as above.  */
+         if (0 < result)
+           errno = ENOSYS;
 #  endif /* __linux__ */
-        if (result == 0 || errno != ENOSYS)
-          {
-            utimensat_works_really = 1;
-            return result;
-          }
-      }
+         if (result == 0 || errno != ENOSYS)
+           {
+             utimensat_works_really = 1;
+             return result;
+           }
+       }
 # endif /* HAVE_FUTIMENS */
     }
   utimensat_works_really = -1;
--
1.6.6.387.g2649b1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]