Discussion:
[ast-developers] 'command exec {n}<"." ; echo "foo" >~{n}/test1 ' doesn't work
Irek Szczesniak
2013-08-01 17:09:40 UTC
Permalink
I'm trying to create a file relative to a directory fd but it doesn't work:

ksh -c 'command exec {n}<"." ; echo "foo" >~{n}/test1 ; true '

Does anyone know what's wrong in this case?

ksh --version
version sh (AT&T Research) 93v- 2013-07-24

Irek
Roland Mainz
2013-08-01 17:44:16 UTC
Permalink
Post by Irek Szczesniak
ksh -c 'command exec {n}<"." ; echo "foo" >~{n}/test1 ; true '
Does anyone know what's wrong in this case?
ksh --version
version sh (AT&T Research) 93v- 2013-07-24
Grrr... someone broke directory fds again...

Glenn: It worked in ast-ksh.2013-07-19 and first failed in ast-ksh.2013-07-27:
-- snip --
$ (find . -name ksh -type f | sort -u | fgrep 'linux.i386-64/bin/ksh'
| while read i ; do echo "#### $i" ; "$i" -c 'command exec {n}<"." ;
echo "test123" >~{n}/test1 ; true ' ; done)
...
...
### ./ast_ksh_20130719/build_i386_64bit_debug_patched/arch/linux.i386-64/bin/ksh
#### ./ast_ksh_20130719/build_i386_64bit_debug_stpcpy/arch/linux.i386-64/bin/ksh
#### ./ast_ksh_20130727/build_fgetcwd/arch/linux.i386-64/bin/ksh
./ast_ksh_20130727/build_fgetcwd/arch/linux.i386-64/bin/ksh:
/proc/30863/fd/11/test1: cannot create [Permission denied]
#### ./ast_ksh_20130727/build_i386_64bit_debug/arch/linux.i386-64/bin/ksh
-- snip --

----

Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
Glenn Fowler
2013-08-01 19:04:43 UTC
Permalink
its in src/lib/libast/path/pathopen.c which unifies all of the
/dev/ and /proc/<pid>/<fd>/ intercepts in one place
my bad
try this patch
(your line numbers will differ because mast source doesn't have the copyright comment)

--- .../path/pathopen.c Tue Jul 23 14:51:50 2013
+++ path/pathopen.c Thu Aug 1 14:55:47 2013
@@ -162,7 +162,12 @@
return 1;
}

- /* F_GETFL must match oflags */
+ /* a trailing path component means dev.fd must be a directory */
+
+ if (b[dev.path.offset])
+ return openat(dev.fd, b + dev.path.offset, oflags, mode);
+
+ /* the path boils down to just dev.fd -- F_GETFL must match oflags */

if (!(f & O_RDWR) && (f & O_ACCMODE) != (oflags & O_ACCMODE))
{
Post by Roland Mainz
Post by Irek Szczesniak
ksh -c 'command exec {n}<"." ; echo "foo" >~{n}/test1 ; true '
Does anyone know what's wrong in this case?
ksh --version
version sh (AT&T Research) 93v- 2013-07-24
Grrr... someone broke directory fds again...
-- snip --
$ (find . -name ksh -type f | sort -u | fgrep 'linux.i386-64/bin/ksh'
| while read i ; do echo "#### $i" ; "$i" -c 'command exec {n}<"." ;
echo "test123" >~{n}/test1 ; true ' ; done)
...
...
### ./ast_ksh_20130719/build_i386_64bit_debug_patched/arch/linux.i386-64/bin/ksh
#### ./ast_ksh_20130719/build_i386_64bit_debug_stpcpy/arch/linux.i386-64/bin/ksh
#### ./ast_ksh_20130727/build_fgetcwd/arch/linux.i386-64/bin/ksh
/proc/30863/fd/11/test1: cannot create [Permission denied]
#### ./ast_ksh_20130727/build_i386_64bit_debug/arch/linux.i386-64/bin/ksh
-- snip --
Roland Mainz
2013-08-01 20:34:20 UTC
Permalink
2013/8/1 Glenn Fowler <gsf at research.att.com>:
[snip]
Post by Glenn Fowler
its in src/lib/libast/path/pathopen.c which unifies all of the
/dev/ and /proc/<pid>/<fd>/ intercepts in one place
my bad
try this patch
(your line numbers will differ because mast source doesn't have the copyright comment)
--- .../path/pathopen.c Tue Jul 23 14:51:50 2013
+++ path/pathopen.c Thu Aug 1 14:55:47 2013
@@ -162,7 +162,12 @@
return 1;
}
- /* F_GETFL must match oflags */
+ /* a trailing path component means dev.fd must be a directory */
+
+ if (b[dev.path.offset])
+ return openat(dev.fd, b + dev.path.offset, oflags, mode);
+
+ /* the path boils down to just dev.fd -- F_GETFL must match oflags */
if (!(f & O_RDWR) && (f & O_ACCMODE) != (oflags & O_ACCMODE))
{
Thanks... the patch seems to fix the issue on SuSE
12.3/Linux/AMD64/64bit... I'll test more platforms (Solaris) later
today...
... and if I find time I write a "directoryfd.sh" test module to cover
this area...

----

Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
Loading...