Menu

#4 Call to Pwait() in ldg_load is wrong

v1.0 (example)
open
nobody
None
5
2019-08-20
2019-08-19
No

There is an extra call to Pwait() in https://sourceforge.net/p/ldg/code/HEAD/tree/trunk/ldg/src/devel/ldgload.c#l158 after calling Pexec(4). This seems to be wrong: Pexec(4) already waits for the process to terminate. The problem with this is, if you have loaded some other libraries before with Slbopen(), that Pwait() will instead wait for those libraries to terminate, which they never do, causing Pwait() to wait forever. Even without Slbopen(), Pwait() will wait for any process to terminate, so there is no guarantee that it returns because the just loaded library has trminated. For that, you need to use Pwaitpid().

Discussion

  • Olivier Landemarre

    It's not clear for me what Pwait do exactly, looks like it is as Pwait3(2, NULL) but we wait Pexec(4,..) quit, so child for me is stopped and Pwait should report something, if I remember it is to not have zombie process, perhaps should more use Pwait3(3,NULL) in all case it will not wait, I have load several ldg in same time without this issue, does SLB are separate thread ?

     
  • Thorsten Otto

    Thorsten Otto - 2019-08-19

    Yes, Pwait() is identical to Pwait3(2, NULL), or Pwaitpid(-1, 2, NULL, NULL),as you can see here

    Pwait should report something,

    The module you started with Pexec(4) already has exited, so there is nothing to report... unless you have loaded other libraries before with Slbopen(). They are handled a bit strange by MiNT: they are started also with Pexec(), but then they get a SIGSTOP signal sent once their init function has been called. That is why Pwait() hangs: it waits for them to exit or change their status, but they never do that. I think this is actually not handled quite right by MiNT, but i have currently no idea how to fix that, a similar Pwait() call is also done by MiNT itself to wait for the signal to arrive.

    perhaps should more use Pwait3(3,NULL)

    That might work too, haven't tried yet. But i think it should not be neccessary, at least not with recent MiNT kernels.

    does SLB are separate thread

    Yes, they are actually loaded similar to LDGs, with Pexec(3), then Pexec(106)

     
  • Olivier Landemarre

    Ok, I will do the change this week using Pwait3(3,NULL) in case of need on old Mint Kernel, but I agree I should not need anything. Thanks for the help

     
  • Thorsten Otto

    Thorsten Otto - 2019-08-19

    Another idea (also not tried yet): you could use Pexec(104) instead of Pexec(4). That call does not wait, and should give you also the pid of the started Process, which you can use for Pwaitpid(pid, 2, NULL, NULL)

     
  • Olivier Landemarre

    Yes possible but it not help to do faster
    but use Pexec(104) is impossible for one reason: it doesn't work under single TOS. LDG work on any system

     
  • Thorsten Otto

    Thorsten Otto - 2019-08-20

    Yes, you are right, almost forgot that. But you could still do something like

    if ((pid = Pexec(104), ...)) == -32)
         Pexec(4,...);
    else if (pid <0)
        /* maybe handle other errors here */
    else
         Pwaitpid(pid, 2, NULL, NULL);
    
     

    Last edit: Thorsten Otto 2019-08-20
  • Olivier Landemarre

    Yes but I not see any interest, it is just more complex

     
  • Thorsten Otto

    Thorsten Otto - 2019-08-20

    Thats up to you of course, but a single "if" does not look very complex ;)

    Anyway, i'm fine with any solution that works. In the meantime, i try to fix that also in MiNT.

     

Log in to post a comment.

MongoDB Logo MongoDB