Recent

Author Topic: [RESOLVED] bug in FpWait?  (Read 1775 times)

robert rozee

  • Full Member
  • ***
  • Posts: 153
[RESOLVED] bug in FpWait?
« on: June 05, 2023, 05:59:20 pm »
does the below behavior seem odd?

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. uses SysUtils, BaseUnix;
  4.  
  5. var L:longint;
  6.  
  7. begin
  8.   if FpFork=0 then begin               // *** child process ***
  9.                      L:=90;
  10.                      writeln('child process sent ', IntToHex(L, 4));
  11.                      halt(L)
  12.                    end
  13.               else begin               // *** parent process ***
  14.                      FpWait(L);
  15.                      writeln('parent process got ', IntToHex(L, 4))
  16.                    end
  17. end.

Code: Text  [Select][+][-]
  1. user@DH61BE:~/pascal/tests/test 209 (FpFork)$ ./project1
  2. child process sent 005A
  3. parent process got 5A00
  4. user@DH61BE:~/pascal/tests/test 209 (FpFork)$

FpWait seems to return the exit code shifted left by 8 bits. linux mint 21.1, kernel: 5.19.0-43-generic, although this shouldn't matter.


cheers,
rob   :-)
« Last Edit: June 06, 2023, 01:23:14 pm by robert rozee »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: bug in FpWait?
« Reply #1 on: June 05, 2023, 06:28:46 pm »
This is afaik normal behaviour for wait(2). IRC there is a wrapper called (fp)waitprocess()

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: bug in FpWait?
« Reply #2 on: June 05, 2023, 09:30:19 pm »
FpWait seems to return the exit code shifted left by 8 bits. linux mint 21.1, kernel: 5.19.0-43-generic, although this shouldn't matter.

FpWait() is simply a wrapper around POSIX wait(), so it's documentation applies, thus you need to use the wexitstatus() function from the BaseUnix unit.

robert rozee

  • Full Member
  • ***
  • Posts: 153
[RESOLVED] Re: bug in FpWait?
« Reply #3 on: June 06, 2023, 01:22:35 pm »
you need to use the wexitstatus() function from the BaseUnix unit

aha... you are right! the following modification produces the desired result:
Code: Pascal  [Select][+][-]
  1.               else begin               // *** parent process ***
  2.                      FpWait(L);
  3.                      L:=wexitStatus(L);
  4.                      writeln('parent process got ', IntToHex(L, 4))
  5.                    end

with the prototype "Function  wexitStatus  (Status : cInt): cInt;" given in /usr/share/fpcsrc/3.2.2/rtl/unix/bunxovlh.inc and the function's source in /usr/share/fpcsrc/3.2.2/rtl/linux/osmacro.inc:
Code: Pascal  [Select][+][-]
  1. function wexitstatus(status : cint): cint;
  2. begin
  3.  wexitstatus:=(status and $FF00) shr 8;
  4. end;

it would be handy if the help for FpWait made reference to using wexitStatus to decode the stat_loc parameter passed back. is there any place to suggest changes/additions like this to the FPC documentation?


cheers,
rob   :-)

dsiders

  • Hero Member
  • *****
  • Posts: 1045
Re: [RESOLVED] Re: bug in FpWait?
« Reply #4 on: June 06, 2023, 05:21:21 pm »

it would be handy if the help for FpWait made reference to using wexitStatus to decode the stat_loc parameter passed back. is there any place to suggest changes/additions like this to the FPC documentation?

https://gitlab.com/freepascal.org/fpc/documentation/-/issues
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: [RESOLVED] Re: bug in FpWait?
« Reply #5 on: June 06, 2023, 09:50:06 pm »
it would be handy if the help for FpWait made reference to using wexitStatus to decode the stat_loc parameter passed back. is there any place to suggest changes/additions like this to the FPC documentation?

We don't document operating system functions. Our modus operandi for these is to refer you (outside of our own documentation) to the documentation of the operating system. That's why I linked a man page above.

robert rozee

  • Full Member
  • ***
  • Posts: 153
Re: [RESOLVED] Re: bug in FpWait?
« Reply #6 on: June 08, 2023, 10:10:38 am »
We don't document operating system functions. Our modus operandi for these is to refer you (outside of our own documentation) to the documentation of the operating system. That's why I linked a man page above.

while that is cetainly a noble and pure philosophical stance to take, the practicality is that for many users of FPC they will fail to discover the link between FpWait and wexitStatus. instead, they will assume that something in FPC is broken, or worse still fail to notice that the value of stat_loc (for linux) is the exitcode multiplied by 0x100.

for the cost of but a ha'porth of tar, one could add to the help page for FpWait the single sentence:
"if wifexited(stat_loc) returns true then wexitStatus(stat_loc) extracts the child's exitcode from stat_loc."

sometimes pragmatism should override philosophical purity.


cheers,
rob   :-)
« Last Edit: June 08, 2023, 10:13:58 am by robert rozee »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: [RESOLVED] bug in FpWait?
« Reply #7 on: June 08, 2023, 12:34:27 pm »
I just saw that we do have documentation for FpWait, so feel free to file a bug against the documentation to have that improved.

robert rozee

  • Full Member
  • ***
  • Posts: 153
Re: [RESOLVED] bug in FpWait?
« Reply #8 on: June 08, 2023, 01:04:36 pm »
tried creating a gitlab account, it emailed me a 'verification' number but there is nowhere to enter it. refused to let me log in using the details i'd supplied, and refuses to let me redo the registration from start. a fail.

if anyone else wants to submit a 'bug against the documentation' of FpWait, to add the one line of text i suggested, please feel free to do so.


cheers,
rob   :-)

 

TinyPortal © 2005-2018