Re: [PATCH] return status 126 on failure to execute

2019-07-03 Thread Thorsten Glaser
Hi Martijn,

> Currently, when a utility fails to execute due to something like E2BIG, mksh
> sets the exit status to 1. That is not satisfactory because there is no way to

agreed; thanks for the patch, it’s consistent, will apply.

bye,
//mirabilos
-- 
21:12⎜ sogar bei opensolaris haben die von der community so
ziemlich jeden mist eingebaut │ man sollte unices nich so machen das
desktopuser zuviel intresse kriegen │ das macht die code base kaputt
21:13⎜ linux war früher auch mal besser :D


[PATCH] return status 126 on failure to execute

2019-07-03 Thread Martijn Dekker
Currently, when a utility fails to execute due to something like E2BIG, 
mksh sets the exit status to 1. That is not satisfactory because there 
is no way to distinguish this error by exit status from a normal 1 for 
false/no match/etc. from utilities such as grep.


Generally accepted convention is to return status 126 in such cases, as 
done by ksh93, bash, yash, dash (current git), FreeBSD sh, and NetBSD 
sh. The attached patch makes that happen.


Test script:

v=foo_bar_baz_quux_lorem_ipsum_dolor_sit_amet
while :; do
v=$v$v
sh -c ":" -- "$v" || { echo "status $?"; exit; }
done

Current output:

longargs.sh[8]: /bin/sh: Argument list too long
status 1

Expected output:

longargs.sh[8]: /bin/sh: Argument list too long
status 126

Thanks,

- M.

--
modernish -- harness the shell
https://github.com/modernish/modernish
diff --git a/exec.c b/exec.c
index 8231b54..01135c4 100644
--- a/exec.c
+++ b/exec.c
@@ -446,7 +446,7 @@ execute(struct op * volatile t,
if (rv == ENOEXEC)
scriptexec(t, (const char **)up);
else
-   errorf(Tf_sD_s, t->str, cstrerror(rv));
+   errorfx(126, Tf_sD_s, t->str, cstrerror(rv));
}
  Break:
exstat = rv & 0xFF;