Skip to content

Commit

Permalink
xAdd function for libraries to inform GAP of dying child processes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Nov 9, 2017
1 parent 0d6c64e commit c0380c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/iostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,31 @@ static UInt OpenPty(int * master, int * slave)
** Start a subprocess using ptys. Returns the stream number of the IOStream
** that is connected to the new processs
*/


// Clean up a signalled or exited child process
// CheckChildStatusChanged must be called by libraries which replace GAP's
// signal handler, or call 'waitpid'.
// The function should be passed a PID, and the return value of waitpid.
// Returns 1 if that PID was a child owned by GAP, or 0 otherwise.
int CheckChildStatusChanged(int childPID, int status)
{
GAP_ASSERT(childPID > 0);
GAP_ASSERT((WIFEXITED(status) || WIFSIGNALED(status)));
HashLock(PtyIOStreams);
for (UInt i = 0; i < MAX_PTYS; i++) {
if (PtyIOStreams[i].inuse && PtyIOStreams[i].childPID == childPID) {
PtyIOStreams[i].changed = 1;
PtyIOStreams[i].status = status;
PtyIOStreams[i].blocked = 0;
HashUnlock(PtyIOStreams);
return 1;
}
}
HashUnlock(PtyIOStreams);
return 0;
}

static void ChildStatusChanged(int whichsig)
{
UInt i;
Expand Down
4 changes: 4 additions & 0 deletions src/iostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
#ifndef GAP_IOSTREAM_H
#define GAP_IOSTREAM_H

// Provide a feature macro to let libraries check if GAP supports
// CheckChildStatusChanged.
#define GAP_HasCheckChildStatusChanged

int CheckChildStatusChanged(int childPID, int status);

/*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *
*/
Expand Down

0 comments on commit c0380c3

Please sign in to comment.