Skip to content

Commit

Permalink
HPCC-33031 Add the option to terminate a child process gracefully
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
  • Loading branch information
ghalliday committed Jan 7, 2025
1 parent 3f7492d commit ed79fd5
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion deployment/deploy/DeployTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ class CDeployTask : public CInterface, implements IDeployTask
{
retcode = 5;
errbuf.clear().append("Invalid or missing key passphrase. ");
pipe->abort();
pipe->abort(false);
return retcode;
}

Expand Down
4 changes: 2 additions & 2 deletions ecl/eclccserver/eclccserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class AbortWaiter : public Thread
ForEachItemIn(idx, pipes)
{
IPipeProcess *pipe = pipes.item(idx);
pipe->abort();
pipe->abort(true);
}
break;
}
Expand All @@ -187,7 +187,7 @@ class AbortWaiter : public Thread
CriticalBlock b(crit);
pipes.append(LINK(pipe));
if (timedOut)
pipe->abort();
pipe->abort(true);
}
void removePipe(IPipeProcess *pipe)
{
Expand Down
9 changes: 5 additions & 4 deletions system/jlib/jthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ class CWindowsPipeProcess: implements IPipeProcess, public CInterface
doCloseError();
}

void abort()
virtual void abort(bool gracefull) override
{
CriticalBlock block(sect);
if (pipeProcess != (HANDLE)-1) {
Expand Down Expand Up @@ -2416,7 +2416,7 @@ protected: friend class PipeWriterThread;
}
}

void abort()
virtual void abort(bool graceful) override
{
CriticalBlock block(sect);
aborted = true;
Expand All @@ -2432,10 +2432,11 @@ protected: friend class PipeWriterThread;
if (pipeProcess != (HANDLE)-1) {
if (title.length())
PROGLOG("%s: Forcibly killing pipe process %d",title.get(),pipeProcess);
int signalToSend = graceful ? SIGTERM : SIGKILL;
if (newProcessGroup)
::kill(-pipeProcess,SIGKILL);
::kill(-pipeProcess,signalToSend);
else
::kill(pipeProcess,SIGKILL); // if this doesn't kill it we are in trouble
::kill(pipeProcess,signalToSend); // if this doesn't kill it we are in trouble
CriticalUnblock unblock(sect);
wait();
}
Expand Down
2 changes: 1 addition & 1 deletion system/jlib/jthread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ interface IPipeProcess: extends IInterface
virtual void closeInput() = 0; // indicate finished input to pipe
virtual void closeOutput() = 0; // indicate finished reading from pipe (generally called automatically)
virtual void closeError() = 0; // indicate finished reading from pipe stderr
virtual void abort() = 0;
virtual void abort(bool gracefull) = 0; // graceful=true allows the child process to clean up.
virtual void notifyTerminated(HANDLE pid,unsigned retcode) = 0; // internal
virtual HANDLE getProcessHandle() = 0; // used to auto kill
virtual void setenv(const char *var, const char *value) = 0; // Set a value to be passed in the called process environment
Expand Down
2 changes: 1 addition & 1 deletion thorlcr/activities/piperead/thprslave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class CPipeSlaveBase : public CSlaveActivity
void abortPipe()
{
unregisterSelfDestructChildProcess(pipe->getProcessHandle());
pipe->abort();
pipe->abort(false);
}

public:
Expand Down
2 changes: 1 addition & 1 deletion thorlcr/activities/pipewrite/thpwslave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CPipeWriteSlaveActivity : public ProcessSlaveActivity
if (pipeOpen)
{
unregisterSelfDestructChildProcess(pipe->getProcessHandle());
pipe->abort();
pipe->abort(false);
}
ProcessSlaveActivity::abort();
}
Expand Down

0 comments on commit ed79fd5

Please sign in to comment.