Discussion:
[ast-developers] Patch to add pwdfd to shcmd.h
ольга крыжановская
2012-08-15 18:10:04 UTC
Permalink
Glenn, I have attached a patch which makes the directory fd to the
current working directory available as Shbltin_t* context->pwdfd, so
that builtins like ls, grep, find, mv, cp and so on can use it in the
future for openat().

Olga
--
, _ _ ,
{ \/`o;====- Olga Kryzhanovska -====;o`\/ }
.----'-/`-/ olga.kryzhanovska at gmail.com \-`\-'----.
`'-..-| / http://twitter.com/fleyta \ |-..-'`
/\/\ Solaris/BSD//C/C++ programmer /\/\
`--` `--`
-------------- next part --------------
diff -r -u original/src/cmd/ksh93/bltins/typeset.c build_errormap/src/cmd/ksh93/bltins/typeset.c
--- src/cmd/ksh93/bltins/typeset.c 2012-08-03 21:58:29.000000000 +0200
+++ src/cmd/ksh93/bltins/typeset.c 2012-08-15 19:23:51.687699342 +0200
@@ -906,6 +906,7 @@
Shbltin_t *sp = &shp->bltindata;

sp->nosfio = 0;
+ sp->pwdfd = shp->pwdfd;
for (n = r = 0; n < nlib; n++)
{
if (r)
diff -r -u original/src/cmd/ksh93/sh/init.c build_errormap/src/cmd/ksh93/sh/init.c
--- src/cmd/ksh93/sh/init.c 2012-08-10 23:18:24.000000000 +0200
+++ src/cmd/ksh93/sh/init.c 2012-08-15 19:26:19.966884367 +0200
@@ -1406,6 +1406,7 @@
break;
nopt = optctx(0, 0);
oopt = optctx(nopt, 0);
+ shp->bltindata.pwdfd=shp->pwdfd;
b___regress__(2, regress, &shp->bltindata);
optctx(oopt, nopt);
}
@@ -1621,6 +1622,7 @@
shp->gd->login_files = login_files;
shp->bltindata.version = SH_VERSION;
shp->bltindata.shp = shp;
+ shp->bltindata.pwdfd = -1;
#if 1
# undef sh_run
# undef sh_trap
diff -r -u original/src/cmd/ksh93/sh/macro.c build_errormap/src/cmd/ksh93/sh/macro.c
--- src/cmd/ksh93/sh/macro.c 2012-08-10 20:07:28.000000000 +0200
+++ src/cmd/ksh93/sh/macro.c 2012-08-15 19:31:05.670724431 +0200
@@ -2627,7 +2627,10 @@
if(np)
sh_fun(shp,np, (Namval_t*)0, av);
else
+ {
+ shp->bltindata.pwdfd = shp->pwdfd;
sh_btilde(2, av, &shp->bltindata);
+ }
sfstdout = save;
stkset(shp->stk,ptr, offset);
sfseek(iop,(Sfoff_t)0,SEEK_SET);
diff -r -u original/src/cmd/ksh93/sh/xec.c build_errormap/src/cmd/ksh93/sh/xec.c
--- src/cmd/ksh93/sh/xec.c 2012-08-07 22:13:08.000000000 +0200
+++ src/cmd/ksh93/sh/xec.c 2012-08-15 19:29:57.095402357 +0200
@@ -994,7 +994,9 @@
shp->xargexit = 0;
while(np==SYSCOMMAND)
{
- register int n = b_command(0,com,&shp->bltindata);
+ register int n;
+ shp->bltindata.pwdfd = shp->pwdfd;
+ n = b_command(0,com,&shp->bltindata);
if(n==0)
break;
command += n;
@@ -3270,6 +3272,7 @@
opt_info.index = opt_info.offset = 0;
error_info.errors = 0;
shp->st.loopcnt = 0;
+ shp->bltindata.pwdfd = shp->pwdfd;
b_dot_cmd(argn+1,argv-1,&shp->bltindata);
shp->st.loopcnt = loopcnt;
argv[-1] = save;
@@ -3335,6 +3338,7 @@
int jmpval;
struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt));
Shbltin_t *bp = &shp->bltindata;
+ shp->bltindata.pwdfd = shp->pwdfd;
sh_pushcontext(shp,buffp,SH_JMPCMD);
jmpval = sigsetjmp(buffp->buff,1);
if(jmpval == 0)
@@ -4087,6 +4091,7 @@
Opt_t *op, *np = optctx(0, 0);
Shbltin_t bltindata;
bltindata = shp->bltindata;
+ shp->bltindata.pwdfd = shp->pwdfd;
op = optctx(np, 0);
memset(t, 0, sizeof(struct comnod));
dp = (struct dolnod*)stkalloc(shp->stk,(unsigned)sizeof(struct dolnod) + ARG_SPARE*sizeof(char*) + argn*sizeof(char*));
diff -r -u original/src/lib/libast/include/shcmd.h build_errormap/src/lib/libast/include/shcmd.h
--- src/lib/libast/include/shcmd.h 2012-03-05 16:48:49.000000000 +0100
+++ src/lib/libast/include/shcmd.h 2012-08-15 19:23:26.627487076 +0200
@@ -75,6 +75,11 @@
char* (*shgetenv)(const char*);
char* (*shsetenv)(const char*);
int invariant;
+ /*
+ * pwdfd - dir fd to cwd, guranteed if platform has
+ * O_SEARCH/O_PATH, otherwise _may_ be -1
+ */
+ int pwdfd;
};

#if defined(SH_VERSION) || defined(_SH_PRIVATE)
Cedric Blancher
2013-06-17 14:55:42 UTC
Permalink
Post by ольга крыжановская
Glenn, I have attached a patch which makes the directory fd to the
current working directory available as Shbltin_t* context->pwdfd, so
that builtins like ls, grep, find, mv, cp and so on can use it in the
future for openat().
lost patch which never made it

Seriously, is there a more reliable way to submit patches?

Ced
--
Cedric Blancher <cedric.blancher at googlemail.com>
Institute Pasteur
-------------- next part --------------
diff -r -u original/src/cmd/ksh93/bltins/typeset.c build_errormap/src/cmd/ksh93/bltins/typeset.c
--- src/cmd/ksh93/bltins/typeset.c 2012-08-03 21:58:29.000000000 +0200
+++ src/cmd/ksh93/bltins/typeset.c 2012-08-15 19:23:51.687699342 +0200
@@ -906,6 +906,7 @@
Shbltin_t *sp = &shp->bltindata;

sp->nosfio = 0;
+ sp->pwdfd = shp->pwdfd;
for (n = r = 0; n < nlib; n++)
{
if (r)
diff -r -u original/src/cmd/ksh93/sh/init.c build_errormap/src/cmd/ksh93/sh/init.c
--- src/cmd/ksh93/sh/init.c 2012-08-10 23:18:24.000000000 +0200
+++ src/cmd/ksh93/sh/init.c 2012-08-15 19:26:19.966884367 +0200
@@ -1406,6 +1406,7 @@
break;
nopt = optctx(0, 0);
oopt = optctx(nopt, 0);
+ shp->bltindata.pwdfd=shp->pwdfd;
b___regress__(2, regress, &shp->bltindata);
optctx(oopt, nopt);
}
@@ -1621,6 +1622,7 @@
shp->gd->login_files = login_files;
shp->bltindata.version = SH_VERSION;
shp->bltindata.shp = shp;
+ shp->bltindata.pwdfd = -1;
#if 1
# undef sh_run
# undef sh_trap
diff -r -u original/src/cmd/ksh93/sh/macro.c build_errormap/src/cmd/ksh93/sh/macro.c
--- src/cmd/ksh93/sh/macro.c 2012-08-10 20:07:28.000000000 +0200
+++ src/cmd/ksh93/sh/macro.c 2012-08-15 19:31:05.670724431 +0200
@@ -2627,7 +2627,10 @@
if(np)
sh_fun(shp,np, (Namval_t*)0, av);
else
+ {
+ shp->bltindata.pwdfd = shp->pwdfd;
sh_btilde(2, av, &shp->bltindata);
+ }
sfstdout = save;
stkset(shp->stk,ptr, offset);
sfseek(iop,(Sfoff_t)0,SEEK_SET);
diff -r -u original/src/cmd/ksh93/sh/xec.c build_errormap/src/cmd/ksh93/sh/xec.c
--- src/cmd/ksh93/sh/xec.c 2012-08-07 22:13:08.000000000 +0200
+++ src/cmd/ksh93/sh/xec.c 2012-08-15 19:29:57.095402357 +0200
@@ -994,7 +994,9 @@
shp->xargexit = 0;
while(np==SYSCOMMAND)
{
- register int n = b_command(0,com,&shp->bltindata);
+ register int n;
+ shp->bltindata.pwdfd = shp->pwdfd;
+ n = b_command(0,com,&shp->bltindata);
if(n==0)
break;
command += n;
@@ -3270,6 +3272,7 @@
opt_info.index = opt_info.offset = 0;
error_info.errors = 0;
shp->st.loopcnt = 0;
+ shp->bltindata.pwdfd = shp->pwdfd;
b_dot_cmd(argn+1,argv-1,&shp->bltindata);
shp->st.loopcnt = loopcnt;
argv[-1] = save;
@@ -3335,6 +3338,7 @@
int jmpval;
struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt));
Shbltin_t *bp = &shp->bltindata;
+ shp->bltindata.pwdfd = shp->pwdfd;
sh_pushcontext(shp,buffp,SH_JMPCMD);
jmpval = sigsetjmp(buffp->buff,1);
if(jmpval == 0)
@@ -4087,6 +4091,7 @@
Opt_t *op, *np = optctx(0, 0);
Shbltin_t bltindata;
bltindata = shp->bltindata;
+ shp->bltindata.pwdfd = shp->pwdfd;
op = optctx(np, 0);
memset(t, 0, sizeof(struct comnod));
dp = (struct dolnod*)stkalloc(shp->stk,(unsigned)sizeof(struct dolnod) + ARG_SPARE*sizeof(char*) + argn*sizeof(char*));
diff -r -u original/src/lib/libast/include/shcmd.h build_errormap/src/lib/libast/include/shcmd.h
--- src/lib/libast/include/shcmd.h 2012-03-05 16:48:49.000000000 +0100
+++ src/lib/libast/include/shcmd.h 2012-08-15 19:23:26.627487076 +0200
@@ -75,6 +75,11 @@
char* (*shgetenv)(const char*);
char* (*shsetenv)(const char*);
int invariant;
+ /*
+ * pwdfd - dir fd to cwd, guranteed if platform has
+ * O_SEARCH/O_PATH, otherwise _may_ be -1
+ */
+ int pwdfd;
};

#if defined(SH_VERSION) || defined(_SH_PRIVATE)
Cedric Blancher
2013-06-17 14:58:33 UTC
Permalink
Post by Cedric Blancher
Post by ольга крыжановская
Glenn, I have attached a patch which makes the directory fd to the
current working directory available as Shbltin_t* context->pwdfd, so
that builtins like ls, grep, find, mv, cp and so on can use it in the
future for openat().
lost patch which never made it
Seriously, is there a more reliable way to submit patches?
forgot to comment on the purpose: I agree with Lionel (per comment in
http://lists.research.att.com/pipermail/ast-developers/2013q2/002702.html)
that builtins (grep, find, ...) which do directory traversal should be
able to benefit from the directory fd maintained by ksh93 internally.
Post by Cedric Blancher
Ced
--
Cedric Blancher <cedric.blancher at googlemail.com>
Institute Pasteur
Ced
--
Cedric Blancher <cedric.blancher at googlemail.com>
Institute Pasteur
-------------- next part --------------
diff -r -u original/src/cmd/ksh93/bltins/typeset.c build_errormap/src/cmd/ksh93/bltins/typeset.c
--- src/cmd/ksh93/bltins/typeset.c 2012-08-03 21:58:29.000000000 +0200
+++ src/cmd/ksh93/bltins/typeset.c 2012-08-15 19:23:51.687699342 +0200
@@ -906,6 +906,7 @@
Shbltin_t *sp = &shp->bltindata;

sp->nosfio = 0;
+ sp->pwdfd = shp->pwdfd;
for (n = r = 0; n < nlib; n++)
{
if (r)
diff -r -u original/src/cmd/ksh93/sh/init.c build_errormap/src/cmd/ksh93/sh/init.c
--- src/cmd/ksh93/sh/init.c 2012-08-10 23:18:24.000000000 +0200
+++ src/cmd/ksh93/sh/init.c 2012-08-15 19:26:19.966884367 +0200
@@ -1406,6 +1406,7 @@
break;
nopt = optctx(0, 0);
oopt = optctx(nopt, 0);
+ shp->bltindata.pwdfd=shp->pwdfd;
b___regress__(2, regress, &shp->bltindata);
optctx(oopt, nopt);
}
@@ -1621,6 +1622,7 @@
shp->gd->login_files = login_files;
shp->bltindata.version = SH_VERSION;
shp->bltindata.shp = shp;
+ shp->bltindata.pwdfd = -1;
#if 1
# undef sh_run
# undef sh_trap
diff -r -u original/src/cmd/ksh93/sh/macro.c build_errormap/src/cmd/ksh93/sh/macro.c
--- src/cmd/ksh93/sh/macro.c 2012-08-10 20:07:28.000000000 +0200
+++ src/cmd/ksh93/sh/macro.c 2012-08-15 19:31:05.670724431 +0200
@@ -2627,7 +2627,10 @@
if(np)
sh_fun(shp,np, (Namval_t*)0, av);
else
+ {
+ shp->bltindata.pwdfd = shp->pwdfd;
sh_btilde(2, av, &shp->bltindata);
+ }
sfstdout = save;
stkset(shp->stk,ptr, offset);
sfseek(iop,(Sfoff_t)0,SEEK_SET);
diff -r -u original/src/cmd/ksh93/sh/xec.c build_errormap/src/cmd/ksh93/sh/xec.c
--- src/cmd/ksh93/sh/xec.c 2012-08-07 22:13:08.000000000 +0200
+++ src/cmd/ksh93/sh/xec.c 2012-08-15 19:29:57.095402357 +0200
@@ -994,7 +994,9 @@
shp->xargexit = 0;
while(np==SYSCOMMAND)
{
- register int n = b_command(0,com,&shp->bltindata);
+ register int n;
+ shp->bltindata.pwdfd = shp->pwdfd;
+ n = b_command(0,com,&shp->bltindata);
if(n==0)
break;
command += n;
@@ -3270,6 +3272,7 @@
opt_info.index = opt_info.offset = 0;
error_info.errors = 0;
shp->st.loopcnt = 0;
+ shp->bltindata.pwdfd = shp->pwdfd;
b_dot_cmd(argn+1,argv-1,&shp->bltindata);
shp->st.loopcnt = loopcnt;
argv[-1] = save;
@@ -3335,6 +3338,7 @@
int jmpval;
struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt));
Shbltin_t *bp = &shp->bltindata;
+ shp->bltindata.pwdfd = shp->pwdfd;
sh_pushcontext(shp,buffp,SH_JMPCMD);
jmpval = sigsetjmp(buffp->buff,1);
if(jmpval == 0)
@@ -4087,6 +4091,7 @@
Opt_t *op, *np = optctx(0, 0);
Shbltin_t bltindata;
bltindata = shp->bltindata;
+ shp->bltindata.pwdfd = shp->pwdfd;
op = optctx(np, 0);
memset(t, 0, sizeof(struct comnod));
dp = (struct dolnod*)stkalloc(shp->stk,(unsigned)sizeof(struct dolnod) + ARG_SPARE*sizeof(char*) + argn*sizeof(char*));
diff -r -u original/src/lib/libast/include/shcmd.h build_errormap/src/lib/libast/include/shcmd.h
--- src/lib/libast/include/shcmd.h 2012-03-05 16:48:49.000000000 +0100
+++ src/lib/libast/include/shcmd.h 2012-08-15 19:23:26.627487076 +0200
@@ -75,6 +75,11 @@
char* (*shgetenv)(const char*);
char* (*shsetenv)(const char*);
int invariant;
+ /*
+ * pwdfd - dir fd to cwd, guranteed if platform has
+ * O_SEARCH/O_PATH, otherwise _may_ be -1
+ */
+ int pwdfd;
};

#if defined(SH_VERSION) || defined(_SH_PRIVATE)
Cedric Blancher
2013-07-04 14:18:28 UTC
Permalink
Post by Cedric Blancher
Post by Cedric Blancher
Post by ольга крыжановская
Glenn, I have attached a patch which makes the directory fd to the
current working directory available as Shbltin_t* context->pwdfd, so
that builtins like ls, grep, find, mv, cp and so on can use it in the
future for openat().
lost patch which never made it
Seriously, is there a more reliable way to submit patches?
forgot to comment on the purpose: I agree with Lionel (per comment in
http://lists.research.att.com/pipermail/ast-developers/2013q2/002702.html)
that builtins (grep, find, ...) which do directory traversal should be
able to benefit from the directory fd maintained by ksh93 internally.
Can this patch - now that ast-@(ksh|open).2013-06-28 has an at API
emulation integrated - be merged with AST/UWIN trunk, please? Or at
least state a justification for its rejection.

Its rotting since a year now. A whole year!

Ced
--
Cedric Blancher <cedric.blancher at googlemail.com>
Institute Pasteur
Roland Mainz
2013-07-06 00:53:13 UTC
Permalink
On Thu, Jul 4, 2013 at 4:18 PM, Cedric Blancher
Post by Cedric Blancher
Post by Cedric Blancher
Post by Cedric Blancher
Post by ольга крыжановская
Glenn, I have attached a patch which makes the directory fd to the
current working directory available as Shbltin_t* context->pwdfd, so
that builtins like ls, grep, find, mv, cp and so on can use it in the
future for openat().
lost patch which never made it
Seriously, is there a more reliable way to submit patches?
forgot to comment on the purpose: I agree with Lionel (per comment in
http://lists.research.att.com/pipermail/ast-developers/2013q2/002702.html)
that builtins (grep, find, ...) which do directory traversal should be
able to benefit from the directory fd maintained by ksh93 internally.
emulation integrated - be merged with AST/UWIN trunk, please? Or at
least state a justification for its rejection.
Its rotting since a year now. A whole year!
;-((

Erm... grumpf... ;-((
... I'll talk to David...

----

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...