On Tue, Jul 29, 2025 at 01:00:58PM +0200, Patrice Dumas wrote: > Hello, > > The CI at github for the mingw on cygwin leads to failing link of info > with: > /usr/lib/gcc/i686-w64-mingw32/13/../../../../i686-w64-mingw32/bin/ld: > run-external.o: in function `get_output_from_program': > /cygdrive/d/a/ci-check/ci-check/texinfo-7.2.20250729dev/build/info/../../info/run-external.c:119:(.text+0x1b9): > undefined reference to `WEXITSTATUS' > > configure does not find <sys/wait.h>. > > So, there may be a need for some portability for the case of missing > <sys/wait.h> (and no definition of WEXITSTATUS).
I split this code out of info/man.c to try to reuse code for running an external process for the hook programs. Before, nothing was done with the return value of wait or pclose. It appears that 'pclose' (and 'system') return the same kind of value as set by 'wait'. However what happens on MinGW where there is no 'wait'? There is Microsoft documentation on these functions: system - https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/277bwbdz(v=vs.100) _pclose - https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/25xdhsd2(v=vs.100) "Returns the exit status of the terminating command processor, or –1 if an error occurs. The format of the return value is the same as that for _cwait, except the low-order and high-order bytes are swapped. If stream is NULL, _pclose sets errno to EINVAL and returns -1." Presumably _pclose is the same function as pclose. _cwait - https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/zb9ehy71(v=vs.100) "When the specified process has successfully completed, returns the handle of the specified process and sets termstat to the result code returned by the specified process. Otherwise, returns –1 and sets errno as follows..." "...For more information about the value passed back through termstat, see GetExitCodeProcess." The link to GetExitCodeProcess is broken on that page. As long as pclose still returns 0 on success, we shouldn't need to worry about interpreting the exit statuses too closely. I'll try to adjust the code only to use WIFEXITED and WEXITSTATUS within HAVE_SYS_WAIT_H. > Maybe minor, and I may have missed something as I am a beginner here, > but I read the man pages for WEXITSTATUS and pclose, and the code does > not seem to follow my understanding of the documentation (maybe on > purpose). > > * on line 119 there is > return WEXITSTATUS(exit_status); > without checking first that WIFEXITED(exit_status) returned true, ie > that there was a proper exiting > > Again I may be totally off. Yes, I believe you are correct here. > > * on line 111 > exit_status = pclose (fpipe); > Upon my reading of the pclose man page it seems to me that before > considering > exit_status as an exit status, it should be checked if not < 0, and if > < 0 check errno / give an error message or keep errno somewhere. It seems unlikely but we should check for -1 as a return value as you say. According to POSIX (*) the only possible value of errno in this situation is ECHILD so it is probably not worth trying to check errno. (*) https://pubs.opengroup.org/onlinepubs/9699919799/functions/pclose.html)