Comments (6)
Thanks for the report.
Using a normal command substitution instead of a shared-state command substitution to invoke tput seems to be an effective workaround for the bug. So there must still be some bug involving command -p
and/or shared-state command substitutions somewhere, but about an hour of searching got me nowhere so far.
diff --git a/src/cmd/ksh93/edit/edit.c b/src/cmd/ksh93/edit/edit.c
index ce21a8f07..1dac5391b 100644
--- a/src/cmd/ksh93/edit/edit.c
+++ b/src/cmd/ksh93/edit/edit.c
@@ -413,7 +413,7 @@ static void get_tput(char *tp, char **cpp)
sh_offoption(SH_RESTRICTED);
sh_offoption(SH_VERBOSE);
sh_offoption(SH_XTRACE);
- sfprintf(sh.strbuf,".sh.value=${ \\command -p tput %s 2>/dev/null;}",tp);
+ sfprintf(sh.strbuf,".sh.value=$(\\command -p tput %s 2>/dev/null)",tp);
sh_trap(sfstruse(sh.strbuf),0);
if((cp = nv_getval(SH_VALNOD)) && (!*cpp || strcmp(cp,*cpp)!=0))
{
from ksh.
I found a third workaround: add sh_offstate(SH_DEFPATH)
after restoring the shell options.
diff --git a/src/cmd/ksh93/edit/edit.c b/src/cmd/ksh93/edit/edit.c
index ce21a8f0..cb07c670 100644
--- a/src/cmd/ksh93/edit/edit.c
+++ b/src/cmd/ksh93/edit/edit.c
@@ -429,6 +429,7 @@ static void get_tput(char *tp, char **cpp)
}
nv_unset(SH_VALNOD);
sh.options = o;
+ sh_offstate(SH_DEFPATH);
sigrelease(SIGINT);
}
EDIT: Is this something that should be handled in whence.c
?
from ksh.
Of course SH_DEFPATH is the problem. I need more caffeine...
EDIT: Is this something that should be handled in
whence.c
?
No, the actual running of commands via command
is handled in sh_exec(); whence.c handles command -v
and command -V
.
I tried this patch (click triangle) that turns off SH_DEFPATH at the end of every sh_exec() invocation and in sh_exit() instead of at the beginning of sh_exec(), but that causes a few regression test failures as sh_exec() heavily uses recursion.
diff --git a/src/cmd/ksh93/sh/fault.c b/src/cmd/ksh93/sh/fault.c
index f024f6520..b26b9c11f 100644
--- a/src/cmd/ksh93/sh/fault.c
+++ b/src/cmd/ksh93/sh/fault.c
@@ -564,6 +564,7 @@ void sh_exit(int xno)
struct checkpt *pp = (struct checkpt*)sh.jmplist;
int sig=0;
Sfio_t *pool;
+ sh_offstate(SH_DEFPATH);
/* POSIX requires exit status >= 2 for error in 'test'/'[' */
if(xno==1 && sh.bltinfun==b_test)
sh.exitval = 2;
diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c
index 6fb0b9371..b8f474853 100644
--- a/src/cmd/ksh93/sh/xec.c
+++ b/src/cmd/ksh93/sh/xec.c
@@ -893,7 +893,6 @@ int sh_exec(const Shnode_t *t, int flags)
job.curjobid = 0;
flags &= ~sh_state(SH_INTERACTIVE);
}
- sh_offstate(SH_DEFPATH);
if(!(flags & sh_state(SH_ERREXIT)))
sh_offstate(SH_ERREXIT);
sh.exitval=0;
@@ -1443,6 +1442,7 @@ int sh_exec(const Shnode_t *t, int flags)
#endif
if(sh.topfd > topfd && !(sh.subshell && (np==SYSEXEC || np==SYSREDIR)))
sh_iorestore(topfd,jmpval); /* avoid leaking unused file descriptors */
+ sh_offstate(SH_DEFPATH);
exitset();
break;
}
So I think the following is probably the best we can do: when turning on the command completion state (SH_COMPLETE), make sure SH_DEFPATH is off.
diff --git a/src/cmd/ksh93/edit/completion.c b/src/cmd/ksh93/edit/completion.c
index bc6ae9c4c..ffb898793 100644
--- a/src/cmd/ksh93/edit/completion.c
+++ b/src/cmd/ksh93/edit/completion.c
@@ -385,6 +385,7 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count)
{
cmd_completion=1;
sh_onstate(SH_COMPLETE);
+ sh_offstate(SH_DEFPATH);
}
if(ep->e_nlist)
{
from ksh.
Another workaround: execute a dummy command (:
) after the shared-state comsub.
diff --git a/src/cmd/ksh93/edit/edit.c b/src/cmd/ksh93/edit/edit.c
index ce21a8f07..9aed564ac 100644
--- a/src/cmd/ksh93/edit/edit.c
+++ b/src/cmd/ksh93/edit/edit.c
@@ -413,7 +413,7 @@ static void get_tput(char *tp, char **cpp)
sh_offoption(SH_RESTRICTED);
sh_offoption(SH_VERBOSE);
sh_offoption(SH_XTRACE);
- sfprintf(sh.strbuf,".sh.value=${ \\command -p tput %s 2>/dev/null;}",tp);
+ sfprintf(sh.strbuf,".sh.value=${ \\command -p tput %s 2>/dev/null;};:",tp);
sh_trap(sfstruse(sh.strbuf),0);
if((cp = nv_getval(SH_VALNOD)) && (!*cpp || strcmp(cp,*cpp)!=0))
{
from ksh.
I suppose that means a command -p
bug per se can be ruled out, since the SH_DEFPATH
state doesn't do any damage with ordinary command substitution.
from ksh.
Cool, that seems to work. Thank you!
FWIW: Adding the two sh_offstate
in the first patch but not removing the one at the beginning of sh_exec()
doesn't fail the path tests.
from ksh.
Related Issues (20)
- open file descriptors of the shell aren't inherited by processes launched by the shell, unlike bash or zsh HOT 5
- `sleep 10 | read` hangs interactive shell after ^Z HOT 3
- document shell option behavior wrt functions HOT 3
- showme doesn't print redirects properly HOT 1
- e8b45cc8 Broke FreeBSD Build HOT 5
- Cygwin //server/path paths do not work HOT 3
- ksh93 1.0.9 build crashes on Cygwin 3.5.3 HOT 20
- RFE: Add build option to run mamake/mamprobe/iffe under valgrind control HOT 2
- [portability] Make AST code aliasing clean and use -fstrict-aliasing with ISO C17 aliasing rules HOT 2
- support HISTCONTROL as in bash HOT 3
- ksh93's printf(1) builtin somehow turns "\x20" (space character in UTF-8) into garbage HOT 10
- Syntax error in arithmetic command crashes ksh HOT 11
- ksh dev@3b33b438 fails signal regression test on macOS 13.6.7 Intel and ARM HOT 3
- [question] should "printf -v%s x" print "-vx" ? HOT 1
- Division by negative numbers returns "division by zero" HOT 10
- Shell arithmetic is broken for integer values beyond the system's maximum float precision HOT 5
- ksh dev@4467eaff does not build on macOS Intel/ARM 13.6.8 HOT 8
- command substitution here-doc syntax error not entered in history
- Issue with ksh93 on OpenBSD HOT 12
- Migrate code to C99 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ksh.