On Fri, 27 Sep 2013 04:24:07 -0400 Glenn Fowler wrote:
> On Fri, 27 Sep 2013 08:12:22 +0200 Roland Mainz wrote:
> > On Fri, Sep 27, 2013 at 7:53 AM, Roland Mainz <[email protected]>
> > wrote:
> > > On Fri, Sep 27, 2013 at 7:24 AM, Roland Mainz <[email protected]>
> > > wrote:
> > >> On Fri, Sep 27, 2013 at 6:48 AM, Roland Mainz <[email protected]>
> > >> wrote:
> > >>> On Fri, Sep 27, 2013 at 6:17 AM, Glenn Fowler <[email protected]>
> > >>> wrote:
> > >>>> On Fri, 27 Sep 2013 04:17:31 +0200 Roland Mainz wrote:
> > >>>>> On Fri, Sep 27, 2013 at 3:50 AM, Roland Mainz
> > >>>>> <[email protected]> wrote:
> > >>>>> > The following code from one of my test scripts no longer work in
> > >>>>> > ast-ksh.2013-09-26 on Solaris 11/AMD64/64bit:
> > >>>>> > -- snip --
> > >>>>> > $ ksh -c 'redirect {n}<. ; redirect
> > >>>>> > {m}</dev/file/flags@xattr@/dev/fd/$n '
> > >>>>> > /home/test001/bin/ksh: /dev/file/flags@xattr@/dev/fd/11: cannot open
> > >>>>> > [Invalid argument]
> > >>>>> > -- snip --
> > [snip]
> > > So basically we're back the point where the whole code within |#if
> > > O_XATTR| doesn't work... and shouldn't be used because the
> > > implementations will perform horribly performance-wise.
> > Erm... question:
> > What is wrong with the following patch to fix the original problem
> > that $ ksh -c 'redirect {n}<. ; redirect
> > {m}</dev/file/flags@xattr@/dev/fd/$n ; cd -f $m ; ls;true' # doesn't
> > work:
> > -- snip --
> > diff -r -u original/src/lib/libast/path/pathopen.c
> > build_i386_64bit_debug/src/lib/libast/path/pathopen.c
> > --- src/lib/libast/path/pathopen.c 2013-08-29 07:17:52.000000000 +0200
> > +++ src/lib/libast/path/pathopen.c 2013-09-27 08:03:03.149006810 +0200
> > @@ -222,7 +222,7 @@
> > /* preserve open() semantics if possible */
> > - if (oflags & (O_DIRECTORY|O_SEARCH))
> > + if (oflags & (O_DIRECTORY|O_SEARCH|O_XATTR))
> > return openat(dev.fd, ".",
> > oflags|O_INTERCEPT, mode);
> > #if O_XATTR
> > if ((f = openat(dev.fd, ".",
> > O_INTERCEPT|O_RDONLY|O_XATTR)) >= 0)
> > -- snip --
> that looks good but will require this at the top of the file
> #ifndef O_XATTR
> #define O_XATTR 0
> #endif
> > Looking at the output of "truss" it seems to do exactly what's
> > requested at shell code level...
> there's path corruption somewhere -- more on that later today
now I can go to bed ...
roland, here is a context diff you'll have to do manually because my line
number are off
the corruption happened in fgetcwd()
I tried to use the buffer space on the right but I forgot fgetcwd() used it for
scratch too
--- .../path/pathcanon.c Fri Sep 27 02:15:03 2013
+++ path/pathcanon.c Fri Sep 27 05:17:46 2013
@@ -560,8 +560,8 @@
{
z = x || (flags & PATH_PHYSICAL) && dev->fd >= 0 ? s :
(char*)path;
n = strlen(z) + 1;
- a = (char*)path + size - n;
- memmove(a, z, n);
+ a = fmtbuf(n);
+ memcpy(a, z, n);
}
else
{
@@ -575,10 +575,7 @@
v += strlen(v);
if ((v - z) > 1)
*v++ = '/';
- if (inplace)
- memmove(v, a, n);
- else
- memcpy(v, a, n);
+ memcpy(v, a, n);
s = v = r;
}
else if (*s != '/')
--- .../path/pathopen.c Thu Aug 29 01:17:52 2013
+++ path/pathopen.c Fri Sep 27 05:17:46 2013
@@ -19,6 +19,10 @@
#include <netinet/in.h>
#endif
+#ifndef O_XATTR
+#define O_XATTR 0
+#endif
+
#if !_lib_getaddrinfo
#if !defined(htons) && !_lib_htons
@@ -201,7 +205,7 @@
/* preserve open() semantics if possible */
- if (oflags & (O_DIRECTORY|O_SEARCH))
+ if (oflags & (O_DIRECTORY|O_SEARCH|O_XATTR))
return openat(dev.fd, ".", oflags|O_INTERCEPT,
mode);
#if O_XATTR
if ((f = openat(dev.fd, ".",
O_INTERCEPT|O_RDONLY|O_XATTR)) >= 0)
now here are 3 modified tests that show the problem is with
cd -f <FD> vs $PWD : somehow $PWD doesn't track cd -f changes
both scripts take -@ as an arg to use cd -@
they should work with/without the -@ arg
they use ast ls to list inodes after cd to verift the cd worked
first this one that shows O_XATTR working ok
--
unset CDPATH
redirect {topfd}<"."
print -u2 test#1 top $topfd $PWD $(ls --format='%(ino)d' --directory)
mkdir -p sub
cd $1 sub
redirect {subfd}<"."
print -u2 test#2 sub $subfd $PWD $(ls --format='%(ino)d' --directory)
cd ~{topfd} ; print -u2 test#3 top $topfd $PWD $(ls --format='%(ino)d'
--directory)
( cd ~{subfd} ; print -u2 test#4 sub $subfd $PWD $(ls --format='%(ino)d'
--directory) )
print -u2 test#5 top $topfd $PWD $(ls --format='%(ino)d' --directory)
( cd $1 sub ; print -u2 test#6 sub $subfd $PWD $(ls --format='%(ino)d'
--directory) )
print -u2 test#7 top $topfd $PWD $(ls --format='%(ino)d' --directory)
--
and this one shows that cd -f and $PWD get out of sync with the physical pwd
this happend betweem test#5 and test#6
running without -@ shows that it has nothing to do with O_XATTR
--
unset CDPATH
redirect {topfd}<"."
print -u2 test#1 top $topfd $PWD $(ls --format='%(ino)d' --directory)
mkdir -p sub
cd $1 sub
redirect {subfd}<"."
print -u2 test#2 sub $subfd $PWD $(ls --format='%(ino)d' --directory)
cd -f ${topfd} ; print -u2 test#3 top $topfd $PWD $(ls --format='%(ino)d'
--directory)
( cd -f ${subfd} ; print -u2 test#4 sub $subfd $PWD $(ls --format='%(ino)d'
--directory) )
print -u2 test#5 top $topfd $PWD $(ls --format='%(ino)d' --directory)
( cd $1 sub ; print -u2 test#6 sub $subfd $PWD $(ls --format='%(ino)d'
--directory) )
print -u2 test#7 top $topfd $PWD $(ls --format='%(ino)d' --directory)
--
this last test shows that the out-of-sync problem is with cd -f and (...)
subshells
--
unset CDPATH
redirect {topfd}<"."
print -u2 test#1 top $topfd $PWD $(ls --format='%(ino)d' --directory)
mkdir -p sub
cd $1 sub
redirect {subfd}<"."
print -u2 test#2 sub $subfd $PWD $(ls --format='%(ino)d' --directory)
cd -f ${topfd} ; print -u2 test#3 top $topfd $PWD $(ls --format='%(ino)d'
--directory)
cd -f ${subfd} ; print -u2 test#4 sub $subfd $PWD $(ls --format='%(ino)d'
--directory) ; cd ~-
print -u2 test#5 top $topfd $PWD $(ls --format='%(ino)d' --directory)
cd $1 sub ; print -u2 test#6 sub $subfd $PWD $(ls --format='%(ino)d'
--directory) ; cd ~-
print -u2 test#7 top $topfd $PWD $(ls --format='%(ino)d' --directory)
--
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers