In the long night of porting Camlp5 to Windows, I’ve encountered a couple of pretty weird and deep bugs. The first, I have a pretty clean repro for, though it needs to be cleaned-up a little more to submit a bugreport. So before I do the extra work, I thought I’d ask:
Suppose
(1) a shell
(2) invokes program#1
(3) which does Unix.execvp
to program #2.
(4) which exits with a nonzero exit-code
Will the shell in #1 receive that exit-code ? Instead of a shell in #1, it could be “make” – in which case getting that exit-code is actually crucial.
B/c I have a clean repro where the exit-code is -not- returned.
I also have a version of program #1 that uses Unix.system
instead of Unix.execvp
, reaps the exit-code, and Unix.exit
with it, so I know that the return-code is bona-fide, etc.
==========
Concretely, in a Makefile I have:
test::
../../src/LAUNCH2 -- false || touch FAILED
if [ ! -f FAILED ] ; then false; fi
rm -f FAILED
“false” is the program that exits with code=1 (not zero). LAUNCH2
invokes its argument with Unix.execvp
. And if you follow the shell logic, if the file FAILED
is created, that means
the first arm of the disjunction did not return nonzero – it returned zero. So the target fails if LAUNCH2 doesn’t properly ensure that the return-code of false
is properly received by make
.
Let me try that again: if FAILED
is created, then the first arm of the first line exited nonzero. And on the next line, if FAILED does not exit, then we fail. So: that second line fails exactly when the first arm of the first line DOES NOT fail.
OK, so that’s the situation. It’s a pretty trivial program, but searching the issue database for ocaml/ocaml doesn’t show that anybody’s found this?
Again, only on Windows.
ETA: just in case, I do understand that it isn’t program #1 that “passes along” the return-code from program #2. Rather, the kernel does the job. But I don’t know how else to describe it. When OCaml program#1 execs over itself with (some arbitrary) program#2, does that mean that the invoker of program#1 gets the exit-code of program#2? that’s the question I’m asking.
ETA2: and here’s a repro in a git repo with a CI that repros on windows: GitHub - chetmurthy/ocaml-exec-bug: Sysadmin scripts written in OCaml (and Perl precursors)
And of course, it works on other platforms, and there’s a CI that demonstrates that too.