Code Monkey home page Code Monkey logo

Comments (6)

McDutchie avatar McDutchie commented on August 18, 2024 1

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.

pghvlaans avatar pghvlaans commented on August 18, 2024 1

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.

McDutchie avatar McDutchie commented on August 18, 2024 1

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.

McDutchie avatar McDutchie commented on August 18, 2024

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.

pghvlaans avatar pghvlaans commented on August 18, 2024

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.

pghvlaans avatar pghvlaans commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.