Hello everyone.
I have some code that launches a child process and then reads its output. It's working fine on OS3, but on OS4, both the m68k and PPC builds crash when I call IDOS->Read(). I've written below a simplified version (with error checking removed) of the code. Can anyone spot anything silly that I'm doing wrong that would cause this crash?
BPTR stdInRead = Open("Console:", MODE_OLDFILE); BPTR stdOutWrite = Open("PIPE:RADRunner", MODE_NEWFILE); BPTR stdOutRead = Open("PIPE:RADRunner", MODE_OLDFILE); BPTR segList = LoadSeg("my_app"); struct Process *process = CreateNewProcTags(NP_Seglist, (ULONG) segList, NP_Input, stdInRead, NP_Output, stdOutWrite, NP_ExitCode, (ULONG) ExitFunction, NP_ExitData, (ULONG) &exitCode, NP_Cli, TRUE, NP_StackSize, stackSize, TAG_DONE); do { // The crash happens here, but it works perfectly on OS3 if ((bytesRead = Read(stdOutRead, buffer, (STDOUT_BUFFER_SIZE - 1))) > 0) { buffer[bytesRead] = '\0'; printf("%s", buffer); m_socket->write(buffer, bytesRead); } } while (bytesRead > 0);
Does anyone have any ideas?
What's the crash code (guru number)?
Hi Colin,
First of all: check whether an action was successfull whenever possible. That is considered 'good coding pratice'.
I added some checks:
Try and see what happens.
Regards
OldFart
(Copy of hyperion list reply here...)
Where is the child process exit arbitration code ?
Who is handling the allocated resources ?
You can't just create a new distinct child process and have it
go hurtling into code that was loaded and unloaded by another
process at any time without some sort of exit or resource arbitration.
The exitcode() for example is INSIDE the loaded segment for the parent
process that is calling createnewproc(), not the child segment itself,
what will happen if the parent exits and unloads before the child process. ?
The exitcode() code will be running in someone elses freed memory.
Also, who's closing the streams and unloading the seglist - and when ?
I can't see any of that, so I can't comment on this aspect.
You need a propper exit arbitration method at least.
There are examples in the CreateNewProc() autodoc.
This low level function requires a lot of care and understanding about
process context, ie. which process is doing what and when.
The puzzling question is; why are you not just using a propper shell-handler
process to take care of all the semantics and resources ?
Just use Systemtags(), that's what it's for.