On 7/18/25 2:19 PM, andy pugh wrote:
That is interesting. So, why/how does mb2hal exit...
I think that halrun -f always exits once the HAL file is parsed unless
the -I (interactive) flag is set:
https://linuxcnc.org/docs/stable/html/man/man1/halrun.1.html
"If a filename is specified and neither the -I nor the -T option
... After processing, the realtime environment
will be torn down."
The question is then when exactly and how it is torn down.
If it happens immediately after hal_ready is detected, then there is yet
another race condition.
In mb2hal.c:
hal_ready(gbl.hal_mod_id);
OK(gbl.init_dbg, "HAL components created OK");
gbl.quit_flag = 0;
signal(SIGINT, quit_signal);
signal(SIGTERM, quit_signal);
The quit_flag will be set in the signal handler, which are installed
/after/ the program indicates it is ready. There is a non-zero chance
that it will get killed before the signal handler(s) are installed and
can therefore terminate with the default handler in place.
This can be fixed by placing the hal_ready() call after installing the
signal handlers.
But this does not resolve the race. For that you need to be sure that
mb2hal exited /before/ you run the checkresult diff. Maybe it should
simply test whether it is still alive
I was wondering about something along those lines, but was actually
(after some web searching) looking at using lsof to wait for the
"result" file to be closed.
The same race condition is still present because the 'result' file is
closed (in runtests by the shell) when halrun exists. But we know that
halrun's exit is not enough to prevent the race because halrun must have
exited or 'checkresult' will not be executed.
It might be possible to use lsof to see if the mb2hal executable is
still mapped. It has terminated when that vanishes.
But I am also wondering if that check should be in the "runtests"
script rather than in specific "checkresults" scripts.
That depends on finding a common denominator for _all_ tests that must
be satisfied. The program name to wait for is not available in runtests.
Only the test- or verification-script will know the whole story. Using
the 'result' file is inadequate.
--
Greetings Bertho
(disclaimers are disclaimed)
_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers