Recent

Author Topic: [SOLVED] Improvement of function TProcess.Terminate  (Read 851 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 407
[SOLVED] Improvement of function TProcess.Terminate
« on: July 19, 2023, 12:14:34 pm »
packages/fcl-process/src/unix/process.inc has the following function:
Code: Pascal  [Select][+][-]
  1. Function TProcess.Terminate(AExitCode : Integer) : Boolean;
  2.  
  3. begin
  4.   Result:=False;
  5.   Result:=fpkill(Handle,SIGTERM)=0;
  6.   If Result then
  7.     begin
  8.     If Running then
  9.       Result:=fpkill(Handle,SIGKILL)=0;
  10.     end;
  11.   { the fact that the signal has been sent does not
  12.     mean that the process has already handled the
  13.     signal -> wait instead of calling getexitstatus }
  14.   if Result then
  15.     WaitOnExit;
  16. end;
The initial Result:=False; line has been removed.
After that, the code has been changed so that the condition to call WaitOnExit is executed depending on If Running then Result:=fpkill(Handle,SIGKILL)=0;
The code becomes:
Code: Pascal  [Select][+][-]
  1. Function TProcess.Terminate(AExitCode : Integer) : Boolean;
  2.  
  3. begin
  4.   Result:=fpkill(Handle,SIGTERM)=0;
  5.   If Result then
  6.     begin
  7.       If Running then
  8.         begin
  9.           Result:=fpkill(Handle,SIGKILL)=0;
  10.           if not Result then exit;
  11.         end;
  12.       { the fact that the signal has been sent does not
  13.       mean that the process has already handled the
  14.       signal -> wait instead of calling getexitstatus }
  15.       WaitOnExit;
  16.     end;
  17. end;

Here is the patch
Code: Pascal  [Select][+][-]
  1. diff --git a/packages/fcl-process/src/unix/process.inc b/packages/fcl-process/src/unix/process.inc
  2. index 54c00ef8ea..7099ca8339 100644
  3. --- a/packages/fcl-process/src/unix/process.inc
  4. +++ b/packages/fcl-process/src/unix/process.inc
  5. @@ -530,18 +530,19 @@ procedure TProcess.CloseProcessHandles;
  6.  Function TProcess.Terminate(AExitCode : Integer) : Boolean;
  7.  
  8.  begin
  9. -  Result:=False;
  10.    Result:=fpkill(Handle,SIGTERM)=0;
  11.    If Result then
  12.      begin
  13. -    If Running then
  14. -      Result:=fpkill(Handle,SIGKILL)=0;
  15. +      If Running then
  16. +        begin
  17. +          Result:=fpkill(Handle,SIGKILL)=0;
  18. +          if not Result then exit;
  19. +        end;
  20. +      { the fact that the signal has been sent does not
  21. +      mean that the process has already handled the
  22. +      signal -> wait instead of calling getexitstatus }
  23. +      WaitOnExit;
  24.      end;
  25. -  { the fact that the signal has been sent does not
  26. -    mean that the process has already handled the
  27. -    signal -> wait instead of calling getexitstatus }
  28. -  if Result then
  29. -    WaitOnExit;
  30.  end;
  31.  
  32.  Procedure TProcess.SetShowWindow (Value : TShowWindowOptions);
« Last Edit: July 19, 2023, 01:31:51 pm by lagprogramming »


 

TinyPortal © 2005-2018