On Wed, Jun 19, 2013 at 5:49 PM, Cedric Blancher
<[email protected]> wrote:
> On 19 June 2013 16:16, David Korn <[email protected]> wrote:
>> cc: [email protected]
>> Subject: Re: [ast-developers] When will the tree reopen for normal patches?
>> --------
>>
>>> cd /dev/fd/$d no longer works
>>
>> What do you mean that it no longer works, I just did
>>         exec 9< /tmp
>> and was able to do
>>         cd /dev/fd/9/foo
>> to change to /tmp/foo.
>>
>
> /bin/ksh -c 'exec {n}</etc ; cd /dev/fd/$n/ ; true'
> /bin/ksh: cd: /dev/fd/11/: [Bad address]
>
> This has been reported to [email protected] several
> times. Search for '[Bad address]'.
>
> There were also requests for cd -f $n relative_path to allow relative
> paths which go above the starting point of fd, e.g. cd -f $n ../../a/b
> The other reason for cd -f $fd relative_path was that POSIX does not
> standardise absolute paths and that bash and dash developers see it as
> a cleaner API to openat() than using /dev/fd

Attached (as "astksh_20130613_cd_f_dirfd_002.diff.txt") is the patch
to add $ cd -f $fd # ... it's more or less the same solution which was
proposed for bash4&&dash, too.

----

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_cd_f/src/cmd/ksh93/bltins/cd_pwd.c
--- src/cmd/ksh93/bltins/cd_pwd.c       2013-05-16 16:36:14.000000000 +0200
+++ src/cmd/ksh93/bltins/cd_pwd.c       2013-06-20 12:49:48.032595845 +0200
@@ -19,8 +19,8 @@
 ***********************************************************************/
 #pragma prototyped
 /*
- * cd [-LP@]  [dirname]
- * cd [-LP@]  [old] [new]
+ * cd [-LP@] [-f dirfd] [dirname]
+ * cd [-LP@] [-fdirfd] [old] [new]
  * pwd [-LP]
  *
  *   David Korn
@@ -171,12 +171,21 @@
        int rval;
        bool flag=false,xattr=false;
        char *oldpwd;
+       int dirfd = shp->pwdfd;
        int newdirfd;
        Namval_t *opwdnod, *pwdnod;
        if(sh_isoption(shp,SH_RESTRICTED))
                errormsg(SH_DICT,ERROR_exit(1),e_restricted+4);
        while((rval = optget(argv,sh_optcd))) switch(rval)
        {
+#ifdef AT_FDCWD
+              case 'f':
+                      errno = 0;
+                      dirfd = strtol(opt_info.arg, (char **)NULL, 10);        
+                      if ((errno != 0) || (dirfd < 0))
+                      errormsg(SH_DICT, ERROR_system(1), "%s: invalid dir fd", 
opt_info.arg);
+                      break;
+#endif
                case 'L':
                        flag = false;
                        break;
@@ -307,7 +316,7 @@
                                        continue;
 #endif /* SHOPT_FS_3D */
                }
-               rval = newdirfd = sh_diropenat(shp, shp->pwdfd,
+               rval = newdirfd = sh_diropenat(shp, dirfd,
                        path_relative(shp,stakptr(PATH_OFFSET)), xattr);
                if(newdirfd >=0)
                {
@@ -346,7 +355,7 @@
        if(rval<0 && *dir=='/' && 
*(path_relative(shp,stakptr(PATH_OFFSET)))!='/')
        {
                rval = newdirfd = sh_diropenat(shp,
-                       shp->pwdfd,
+                       dirfd,
                        dir, xattr);
                if(newdirfd >=0)
                {
diff -r -u build_i386_64bit_debug/src/cmd/ksh93/data/builtins.c 
build_i386_64bit_debug_cd_f/src/cmd/ksh93/data/builtins.c
--- src/cmd/ksh93/data/builtins.c       2013-05-30 05:34:48.000000000 +0200
+++ src/cmd/ksh93/data/builtins.c       2013-06-20 12:52:28.993198173 +0200
@@ -446,7 +446,7 @@
 ;
 
 const char sh_optcd[] =
-"[-1c?\n@(#)$Id: cd (AT&T Research) 2012-07-10 $\n]"
+"[-1c?\n@(#)$Id: cd (AT&T Research) 2013-06-20 $\n]"
 USAGE_LICENSE
 "[+NAME?cd - change working directory ]"
 "[+DESCRIPTION?\bcd\b changes the current working directory of the "
@@ -482,6 +482,9 @@
        "\bPATH_RESOLVE\b.  If \bPATH_RESOLVE\b is \bphysical\b, "
        "then the behavior will be as if \b-P\b were specified.  Otherwise, "
        "the behavior will be as if  \b-L\b were specified.]"
+#ifdef AT_FDCWD
+"[f]#[dirfd?Path is relative to this directory fd.]"
+#endif
 "[L?Handle each pathname component \b..\b in a logical fashion by moving "
        "up one level by name in the present working directory.]"
 "[P?The present working directory is first converted to an absolute pathname "
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to