From ecf260c28262412ce1c999dca8719fcf26026f48 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Thu, 8 Apr 2021 16:46:47 +0100 Subject: [PATCH] SHOPT_SPAWN: Fix 'not found' error message inconsistency There's an annoying inconsistency in error messages if ksh is compiled with SHOPT_SPAWN. One way to trigger it: $ /usr/local/bin/ksh -c '/tmp/nonexistent' /usr/local/bin/ksh: /tmp/nonexistent: not found $ /usr/local/bin/ksh -c '/tmp/nonexistent; :' /usr/local/bin/ksh: /tmp/nonexistent: not found [No such file or directory] In the first variant, as an optimisation, ksh went straight to exec'ing the command without forking first. In the second variant, sh_ntfork() was used. The first variant is done in path_exec(), path.c, line 1049: errormsg(SH_DICT,ERROR_exit(ERROR_NOENT),e_found,arg0); The second one is in sh_ntfork(), xec.c, line 3654: errormsg(SH_DICT,ERROR_system(ERROR_NOENT),e_found+4); In both cases, the e_found message is only used if errno==ENOENT, so the extra '[No such file or directory]' message generated by ERROR_system() is pointless as that will never change for that message. src/cmd/ksh93/sh/xec.c: sh_ntfork(): - Use ERROR_exit() instead of ERROR_system() for the e_found message to avoid the superfluous addition. --- src/cmd/ksh93/sh/xec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index ce4bbb0f6..6ad4e324b 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -3631,7 +3631,7 @@ static pid_t sh_ntfork(Shell_t *shp,const Shnode_t *t,char *argv[],int *jobid,in if(spawnpid < 0) switch(errno=shp->path_err) { case ENOENT: - errormsg(SH_DICT,ERROR_system(ERROR_NOENT),e_found+4); + errormsg(SH_DICT,ERROR_exit(ERROR_NOENT),e_found+4); UNREACHABLE(); default: errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_exec+4);