[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MiNT] Pfork() & SLB



Hi,

I have written a new version of my shutdown.app, this time in C. When it
gets completed, it will be released together with the source
code. Anyways, I got an idea of adding a feature for that, namely, when
the user selects reboot or halt, the program should first terminate the
AES. Seemed easy.

I must say that the version I am speaking of loads an SLB, but I am not
sure if the problem I am gonna describe is related.

The first problem was, that it turned over that N.AES does not want to
terminate before all its children exit. To ensure they do, N.AES sends
SIGTERM. The signal is also sent to the process which told the N.AES to
terminate itself, so it obviously cannot do anything after the AES
termination (because it is killed earlier).

When I blocked SIGTERM, the N.AES didn't terminate.

So I got an idea, that I split the program into two processes. One, being
a GEM application, will tell the AES to terminate, and then exit
immediately. The other, a child, not being a direct child of the AESSYS,
will be after its parent exited, adopted by the process 000, and thus will
not prevent AESSYS from exiting. When this occurs (i.e. when AESSYS is
gone), the child will survive and do the stuff (i.e. call Shutdown()).

Everything worked ok, except the system crashed once entering the
Shutdown(). Endless memory violation inside the kernel, no option but a
reboot.

Since I created the child with Pexec(104), I though there was a problem
with it. I changed the code to use Pexec(204), finally Pfork(). I also
forced the program to explicitly close the SLB and leave GEM (with
appl_exit()) before forking it. All the same result.

The only way I got this to work was, when the program forks before opening
GEM with appl_init(), which is done by the child, also the child loads
SLB, and does all the GEM stuff, while the parent remains a "normal" non
GEM process. After the child closed all the applications, told the AES to
terminate, closed everything and exited, the parent entered Shutdown() and
the system rebooted as expected. However, this lacks sense, because it
only works if the entire program is started from text shell (because
otherwise both are AESSYS children, and AESSYS does not exit before
killing all the children ... etc.).

Resume: apparently for a reason, calling Shutdown() from within child
process, created by Pfork(), crashes the system.

I had an impression that the problem is cause by the memory regions which
are inherited by the child, and in fact belong to the SLB opened by the
parent. When the parent releases (closes) the library, the memory gets
released and marked invalid, however, these regions are still marked in
the child's memory map as owned. This does not have sense, however,
because in this case forking the program after the SLB has been closed
should fix the problem. It doesn't.

I am speaking about MiNT kernel 1.15.10.

Any clue?

--
Konrad M.Kokoszkiewicz
mail: draco@atari.org
http://draco.atari.org

** Ea natura multitudinis est,
** aut servit humiliter, aut superbe dominatur (Liv. XXIV,25)
*************************************************************
** Taka to juz natura pospolstwa, ze albo sluzy ono unizenie,
** albo bezczelnie sie panoszy.