I have a rather vexing problem with the POSIX wait(&retcode) function, and I'm not sure how to zero in on it. I've defined a test for the libbu process wrappers to verify that I can detect a non-zero child exit code:
https://github.com/BRL-CAD/brlcad/blob/facetize/src/libbu/tests/process.c#L96
https://github.com/BRL-CAD/brlcad/blob/facetize/src/libbu/tests/subprocess.cpp#L62
It should return 2, but on Linux when I run this via bu_test I get a "0" return code. However, if I run the subprocess exec directly, "echo $?" does indeed report "2" for an exit code.
Even more vexing, if I put the bu_test call into gdb and break on bu_process_wait, the program behavior changes and it DOES end up with 2 as the return code.
Am I setting this up incorrectly somehow?
OK, some progress - closing the stdout and stderr of the child process before waiting was an issue, from the looks of things.
Perhaps not the issue, but you should only use WEXITSTATUS on a return code that passes the WIFEXITED() macro test
And when a program behaves differently when launched in gdb than standalone, what I usually do is to put a sleep() at the top of main(), launch it standalone and attach gdb to it before the sleep() finishes
It's looking like there are multiple issues at play... it never fails.
I'm commencing to think it's time to dissect CTest and identify the subset of their capabilities that we need for libbu process control - a cursory inspection suggests that they're leveraging libuv and put quite a bit of work into this, so trying to custom roll our own solution without reusing their code is probably going to be both a lot of work and error prone. The core of what CTest does is almost exactly what we need bu_process to do - launch processes, support timeouts and tracking return codes, and collect output.
Hmm. Looks like there are also a few small libraries for doing similar things. Experiment time
starseeker said:
Hmm. Looks like there are also a few small libraries for doing similar things. Experiment time
I think I'm running into something similar.. Did anything come of your experiments?
Yes, actually. One of them worked in the facetize branch.
The subprocess bit is here: https://github.com/BRL-CAD/brlcad/commit/c3eefb86430b7bb85e586412d0a26bf3e1dd585c
https://github.com/sheredom/subprocess.h
I was focused on facetize, so I haven't audited whether it can straight up replace libbu's process bits completely
Gotcha. I'll see if that helps the errors I'm seeing in rtweight.
starseeker said:
I was focused on facetize, so I haven't audited whether it can straight up replace libbu's process bits completely
Should probably set up a test suite for the process stuff's eventually
There is this: https://github.com/BRL-CAD/brlcad/blob/main/src/libbu/tests/process.c
Last updated: Jan 09 2025 at 00:46 UTC