bug-tar
[Top][All Lists]
Advanced

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

Re: [Bug-tar] Problem with fstatat on AIX 7.1


From: Paul Eggert
Subject: Re: [Bug-tar] Problem with fstatat on AIX 7.1
Date: Mon, 05 Sep 2011 13:12:55 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.21) Gecko/20110831 Thunderbird/3.1.13

Well then there's something I'm still not following: the AIX
openat is supposed to be called, but truss is claiming it's not
called.  Let's try to isolate the problem.  How about if you try
the following patch against the latest tarball, and then run
'truss' on the same test as before.  The output of the test should
start with something like this:

        underlying openat (-100, "a", 657664, 0) returns 4 (OK)
        underlying openat (4, "X", 657664, 0) returns 5 (OK)
        underlying openat (4, "Z", 657664, 0) returns 5 (OK)
        underlying openat (4, "Y", 657664, 0) returns 5 (OK)
        underlying openat (4, "b", 657664, 0) returns 5 (OK)
        underlying openat (5, "X", 657664, 0) returns 6 (OK)
        underlying openat (5, "Z", 657664, 0) returns 6 (OK)
        underlying openat (5, "c", 657664, 0) returns 6 (OK)
        underlying openat (6, "X", 657664, 0) returns 7 (OK)
        underlying openat (6, "d", 657664, 0) returns 7 (OK)
        underlying openat (7, "e", 657664, 0) returns 8 (OK)
        underlying openat (8, "X", 657664, 0) returns 9 (OK)
        underlying openat (8, "f", 657664, 0) returns 9 (OK)
        underlying openat (9, "X", 657664, 0) returns -1 (Too many open files)
        open_failure_recover called
        p=0x7fff7f7bd670, p->fd=7, p->parent=0x7fff7f7bd950, p->parent->fd=6
        p=0x7fff7f7bd950, p->fd=6, p->parent=0x7fff7f7bdc30, p->parent->fd=5
        p=0x7fff7f7bdc30, p->fd=5, p->parent=0x7fff7f7bdf10, p->parent->fd=4
        p=0x7fff7f7bdf10, p->fd=4, p->parent=(nil), p->parent->fd=-999999
        open_failure_recover succeeded
        underlying openat (9, "X", 657664, 0) returns 4 (OK)
        ...

but apparently something is going wrong.


diff --git a/src/create.c b/src/create.c
index 9839e1f..47af317 100644
--- a/src/create.c
+++ b/src/create.c
@@ -1251,18 +1251,27 @@ ensure_slash (char **pstr)
 static bool
 open_failure_recover (struct tar_stat_info const *dir)
 {
+  int e = errno;
+  fprintf (stderr, "open_failure_recover called\n");
   if (errno == EMFILE && dir && dir->parent)
     {
       struct tar_stat_info *p;
       for (p = dir->parent->parent; p; p = p->parent)
+       {
+       fprintf (stderr, "p=%p, p->fd=%d, p->parent=%p, p->parent->fd=%d\n",
+                p, p->fd, p->parent, p->parent ? p->parent->fd : -999999);
        if (0 < p->fd && (! p->parent || p->parent->fd <= 0))
          {
            tar_stat_close (p);
+           fprintf (stderr, "open_failure_recover succeeded\n");
            return true;
          }
+       }
       errno = EMFILE;
     }
 
+  fprintf (stderr, "open_failure_recover failed\n");
+  errno = e;
   return false;
 }
 
--- gnu/openat.c-1.26   2011-06-07 14:18:59.506314750 -0700
+++ gnu/openat.c        2011-09-05 13:08:38.047971582 -0700
@@ -18,8 +18,34 @@
 
 /* written by Jim Meyering */
 
+/* If the user's config.h happens to include <fcntl.h>, let it include only
+   the system's <fcntl.h> here, so that orig_openat doesn't recurse to
+   rpl_openat.  */
+#define __need_system_fcntl_h
 #include <config.h>
 
+/* Get the original definition of open.  It might be defined as a macro.  */
+#include <fcntl.h>
+#include <sys/types.h>
+#undef __need_system_fcntl_h
+
+#if HAVE_OPENAT
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+static inline int
+orig_openat (int fd, char const *filename, int flags, mode_t mode)
+{
+  int r = openat (fd, filename, flags, mode);
+  int e = errno;
+  long m = mode;
+  fprintf (stderr, "underlying openat (%d, \"%s\", %d, %ld) returns %d (%s)\n",
+          fd, filename, flags, m, r, r < 0 ? strerror (e) : "OK");
+  errno = e;
+  return r;
+}
+#endif
+
 #include "openat.h"
 
 #include <stdarg.h>
@@ -33,8 +59,6 @@
 
 #if HAVE_OPENAT
 
-# undef openat
-
 /* Like openat, but work around Solaris 9 bugs with trailing slash.  */
 int
 rpl_openat (int dfd, char const *filename, int flags, ...)
@@ -88,7 +112,7 @@ rpl_openat (int dfd, char const *filenam
     }
 # endif
 
-  fd = openat (dfd, filename, flags, mode);
+  fd = orig_openat (dfd, filename, flags, mode);
 
 # if OPEN_TRAILING_SLASH_BUG
   /* If the filename ends in a slash and fd does not refer to a directory,




reply via email to

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