From c0380c3a73ac254207c17f27560b855e93d640f3 Mon Sep 17 00:00:00 2001 From: Chris Jefferson Date: Sat, 4 Nov 2017 08:45:43 +0000 Subject: [PATCH] xAdd function for libraries to inform GAP of dying child processes --- src/iostream.c | 25 +++++++++++++++++++++++++ src/iostream.h | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/src/iostream.c b/src/iostream.c index bd910c1608f..2b43141e3da 100644 --- a/src/iostream.c +++ b/src/iostream.c @@ -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; diff --git a/src/iostream.h b/src/iostream.h index 2138b6f7c3c..d4f8a35edfc 100644 --- a/src/iostream.h +++ b/src/iostream.h @@ -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 * * * * * * * * * * * * * * * */