On Sat, Jul 27, 2013 at 6:17 PM, Glenn Fowler <[email protected]> wrote:
> the AT&T Software Technology ast alpha 2013-07-27 source release
> has been posted to the download site
>         http://www.research.att.com/sw/download/alpha/
> the package names and md5 checksums are
>             INIT  8cdf2460c146a7412ee1f2d37d19e3ce
>         ast-base  46a03d0e49840acedef8c0623cbef85c
>         ast-open  f61766d8cb1f91c960a3a2a1385adcd6
>          ast-ksh  911d28c7263e90ec1e8037ad0b6db643
> the md5 sums should match the ones listed on the download page
>
> still verifying builds on some architectures
> should be ok on linux & solaris
> for the next week or so stability/regression patches will take priority
[snip]

Attached (as "astksh20130727_cd_fix002.diff.txt") is _another_ attempt
to get cd(1) fixed. The changes should be more or less
straightforward:
- Renamed |rehash()| because it caused a namespace collision with
other libc stuff
- Fixed |errno| handling in |sh_diropenat()|
- |sh_diropenat()| no longer uses |fstat()| to verify whether a fd
represents a directory (or not) when we have the real (non-emulated)
|O_DIRECTORY| (saves one expensive (for NFS) syscall)
- Dead code removal
- Comment in shell.h about |shp->pwdfd| to make sure who is allowed to
maintain that variable

Any feedback welcome...

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
diff -r -u build_i386_64bit_debug/src/cmd/ksh93/bltins/cd_pwd.c 
build_i386_64bit_debug_patched/src/cmd/ksh93/bltins/cd_pwd.c
--- src/cmd/ksh93/bltins/cd_pwd.c       2013-07-22 20:59:06.000000000 +0200
+++ src/cmd/ksh93/bltins/cd_pwd.c       2013-07-27 21:27:06.385074247 +0200
@@ -41,7 +41,7 @@
 /*
  * Invalidate path name bindings to relative paths
  */
-static void rehash(register Namval_t *np,void *data)
+static void rehash_relpathbindings(register Namval_t *np,void *data)
 {
        Pathcomp_t *pp = (Pathcomp_t*)np->nvalue.cp;
        NOT_USED(data);
@@ -49,6 +49,10 @@
                _nv_unset(np,0);
 }
 
+#if _ast_O_LOCAL && O_DIRECTORY >= _ast_O_LOCAL
+#define O_DIRECTORY_EMULATED 1
+#endif
+
 /*
  * Obtain a file handle to the directory "path" relative to directory
  * "dir", or open a NFSv4 xattr directory handle for file dir/path.
@@ -56,8 +60,10 @@
 int sh_diropenat(Shell_t *shp, int dir, const char *path, bool xattr)
 {
        int fd,shfd;
-       int savederrno=errno;
+       int savederrno;
+#ifdef O_DIRECTORY_EMULATED
        struct stat fs;
+#endif
 #ifndef O_XATTR
        NOT_USED(xattr);
 #endif
@@ -70,7 +76,9 @@
                if((apfd = openat(dir, path, O_RDONLY|O_NONBLOCK|O_CLOEXEC))>=0)
                {
                        fd = openat(apfd, e_dot, O_XATTR|O_CLOEXEC);
+                       savederrno=errno
                        close(apfd);
+                       errno=savederrno;
                }
        }
        else
@@ -79,12 +87,15 @@
 
        if(fd < 0)
                return fd;
+/* Only stat the fd if we don't have a native O_DIRECTORY */
+#ifdef O_DIRECTORY_EMULATED
        if (!fstat(fd, &fs) && !S_ISDIR(fs.st_mode))
        {
                close(fd);
                errno = ENOTDIR;
                return -1;
        }
+#endif
 
        /* Move fd to a number > 10 and register the fd number with the shell */
        shfd = sh_fcntl(fd, F_DUPFD_CLOEXEC, 10);
@@ -418,7 +429,7 @@
        nv_putval(pwdnod,dir,NV_RDONLY);
        nv_onattr(pwdnod,NV_NOFREE|NV_EXPORT);
        shp->pwd = pwdnod->nvalue.cp;
-       nv_scan(shp->track_tree,rehash,(void*)0,NV_TAGGED,NV_TAGGED);
+       
nv_scan(shp->track_tree,rehash_relpathbindings,(void*)0,NV_TAGGED,NV_TAGGED);
        path_newdir(shp,shp->pathlist);
        path_newdir(shp,shp->cdpathlist);
        if(oldpwd)
diff -r -u build_i386_64bit_debug/src/cmd/ksh93/include/shell.h 
build_i386_64bit_debug_patched/src/cmd/ksh93/include/shell.h
--- src/cmd/ksh93/include/shell.h       2013-07-23 03:12:23.000000000 +0200
+++ src/cmd/ksh93/include/shell.h       2013-07-27 21:18:54.978877988 +0200
@@ -155,7 +155,7 @@
        char            shcomp;         /* set when runing shcomp */
        short           subshell;       /* set for virtual subshell */
        Stk_t           *stk;           /* stack poiter */
-       int             pwdfd;          /* file descriptor for pwd */
+       int             pwdfd;          /* file descriptor for pwd (must be 
from sh_diropenat()/sh_fcntl()!) */
 #ifdef _SH_PRIVATE
        _SH_PRIVATE
 #endif /* _SH_PRIVATE */
diff -r -u build_i386_64bit_debug/src/cmd/ksh93/sh/init.c 
build_i386_64bit_debug_patched/src/cmd/ksh93/sh/init.c
--- src/cmd/ksh93/sh/init.c     2013-07-22 16:43:07.000000000 +0200
+++ src/cmd/ksh93/sh/init.c     2013-07-27 21:18:17.530558925 +0200
@@ -1550,12 +1550,8 @@
                }
        }
        sh_ioinit(shp);
-#ifdef AT_FDCWD
-       shp->pwdfd = sh_diropenat(shp, AT_FDCWD, e_dot, false);
-#else
-       /* Systems without AT_FDCWD/openat() do not use the |dir| argument */
-       shp->pwdfd = sh_diropenat(shp, -1, e_dot, false);
-#endif
+       shp->pwdfd = sh_diropenat(shp, AT_FDCWD, e_dot, false);
+
 #ifdef O_SEARCH
        /* This should _never_ happen, guranteed by design and goat sacrifice */
        if(shp->pwdfd < 0)
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to