Skip to content

Commit

Permalink
kernel: add #define to disable subprocess code
Browse files Browse the repository at this point in the history
This helps debug whether the Julia replacements for GAP's subprocess
code are fully in place, and ensure we don't forget anything. More
importantly, it disables the SIGCHLD handler in the GAP kernel.

In the future we could also add configure flag to set it.
  • Loading branch information
fingolfin committed Mar 3, 2022
1 parent a06b32c commit f9e5fcd
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
65 changes: 62 additions & 3 deletions src/iostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

#include "config.h"

#ifndef GAP_DISABLE_SUBPROCESS_CODE

#include <errno.h>
#include <fcntl.h>
#include <signal.h>
Expand Down Expand Up @@ -804,6 +806,60 @@ static Obj FuncFD_OF_IOSTREAM(Obj self, Obj stream)
return result;
}

#else // !defined(GAP_DISABLE_SUBPROCESS_CODE)

int CheckChildStatusChanged(int childPID, int status)
{
return 0;
}

static Obj FuncCREATE_PTY_IOSTREAM(Obj self, Obj dir, Obj prog, Obj args)
{
return Fail;
}

static Obj FuncWRITE_IOSTREAM(Obj self, Obj stream, Obj string, Obj len)
{
return Fail;
}

static Obj FuncREAD_IOSTREAM(Obj self, Obj stream, Obj len)
{
return Fail;
}

static Obj FuncREAD_IOSTREAM_NOWAIT(Obj self, Obj stream, Obj len)
{
return Fail;
}

static Obj FuncKILL_CHILD_IOSTREAM(Obj self, Obj stream)
{
return 0;
}

static Obj FuncSIGNAL_CHILD_IOSTREAM(Obj self, Obj stream, Obj sig)
{
return 0;
}

static Obj FuncCLOSE_PTY_IOSTREAM(Obj self, Obj stream)
{
return 0;
}

static Obj FuncIS_BLOCKED_IOSTREAM(Obj self, Obj stream)
{
return Fail;
}

static Obj FuncFD_OF_IOSTREAM(Obj self, Obj stream)
{
return Fail;
}

#endif


/****************************************************************************
**
Expand Down Expand Up @@ -841,6 +897,7 @@ static StructGVarFunc GVarFuncs[] = {
*/
static Int InitKernel(StructInitInfo * module)
{
#ifndef GAP_DISABLE_SUBPROCESS_CODE
UInt i;
PtyIOStreams[0].childPID = -1;
for (i = 1; i < MAX_PTYS; i++) {
Expand All @@ -849,14 +906,16 @@ static Int InitKernel(StructInitInfo * module)
}
FreePtyIOStreams = MAX_PTYS - 1;

/* init filters and functions */
InitHdlrFuncsFromTable(GVarFuncs);

#if !defined(HPCGAP)
/* Set up the trap to detect future dying children */
signal(SIGCHLD, ChildStatusChanged);
#endif

#endif

/* init filters and functions */
InitHdlrFuncsFromTable(GVarFuncs);

return 0;
}

Expand Down
15 changes: 15 additions & 0 deletions src/sysfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,20 @@ void SySetErrorNo ( void )
*F * * * * * * * * * * * * * file and execution * * * * * * * * * * * * * * *
*/

#ifdef GAP_DISABLE_SUBPROCESS_CODE

UInt SyExecuteProcess (
Char * dir,
Char * prg,
Int in,
Int out,
Char * args[] )
{
return 255;
}

#else

/****************************************************************************
**
*F SyExecuteProcess( <dir>, <prg>, <in>, <out>, <args> ) . . . . new process
Expand Down Expand Up @@ -3027,6 +3041,7 @@ UInt SyExecuteProcess (

#endif

#endif // !GAP_DISABLE_SUBPROCESS_CODE

/****************************************************************************
**
Expand Down

0 comments on commit f9e5fcd

Please sign in to comment.