bitwiseworks / libcx

kLIBC Extension Library
GNU Lesser General Public License v2.1
11 stars 1 forks source link

Implement P_SESSION support in spawn2 #63

Open dmik opened 5 years ago

dmik commented 5 years ago

This task originates from here: http://trac.netlabs.org/qt4/ticket/85. Although we could add P_SESSION support right in kLIBC within our fork, I don't think it makes sense given that we have spawn2 in LIBCx (which we'd have to use anyway for thread safety).

We should take Qt requirements in mind when doing so (regarding I/O redirection which should be still provided for P_SESSION processes).

There is also https://github.com/bitwiseworks/qtbase-os2/issues/63 which is related.

dmik commented 5 years ago

The P_SESSION support is there. It includes the P_UNRELATED flag support as well as this is what we need for Qt in the first place.

Note also the previous commit where I had to do quite an important change related to PIDs returned by spawn2 in P_2_THREADSAFE mode. They used to be intermediate wrapper PIDs, not the wrapped child PIDs. This confused Qt and would confuse many other apps because of the difference between the actual child PID (seen by the child itself) and the one received by the spawn2 caller (the PID of the wrapper).

Note that the above improvement allowed us to implement a really cool thing in P_SESSION which is not available even in the native DosStartSession API. When you start an unrelated child (using SSF_RELATED_INDEPENDENT), the PID of the started process is not available to the caller. As I guess, this was done because such a PID is quite useless in terms of parent-child interaction: it cannot be waited on, its priority cannot be changed etc. However, there are many cases when this is desired (and sharing memory is one of them, not to mention the Qt QProcess::startDetached API requirement). If P_UNRELATED and P_2_THREADSAFE are used together in our spawn2 call, it's the wrapper process that gets started as an unrelated child. However, it still maintains a connection to the parent via a shared memory block which we use to pass information about the target child process the wrapper is about to start. And once the wrapper starts the child, it passes its PID back to the parent. This way, we overcome the OS/2 DosStartSession limitation and make Qt happy. (I'm sure there might be other uses for that).

dmik commented 5 years ago

Before closing this, I want to add other flags for P_SESSION, such as P_DEFAULT, P_FULLSCREEN, P_WINDOWED, P_MNIMIZE, P_MAXIMIZE, P_BACKGROUND, P_FOREGROUND and P_NOCLOSE. All of these have straight mappings to the respective DosStartSession flags.

I also need to document this new functionality in the README and cover it in tst-spawn2.c.

dmik commented 5 years ago

Note that starting PM applications through the wrapper seems to be broken now. This needs a look. Should be trivial to fix.

dmik commented 5 years ago

Regarding starting PM applications through the wrapper. I've created #66 for that as it's actually bigger than I initially thought, it needs a different wrapper.

dmik commented 5 years ago

No reason for this to stay open. P_SESSION will be covered by tests within #65.