Forum > FPC development

[SOLVED] Improvement of function TProcess.Terminate

(1/1)

lagprogramming:
packages/fcl-process/src/unix/process.inc has the following function:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Function TProcess.Terminate(AExitCode : Integer) : Boolean; begin  Result:=False;  Result:=fpkill(Handle,SIGTERM)=0;  If Result then    begin    If Running then      Result:=fpkill(Handle,SIGKILL)=0;    end;  { the fact that the signal has been sent does not    mean that the process has already handled the    signal -> wait instead of calling getexitstatus }  if Result then    WaitOnExit;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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Function TProcess.Terminate(AExitCode : Integer) : Boolean; begin  Result:=fpkill(Handle,SIGTERM)=0;  If Result then    begin      If Running then        begin          Result:=fpkill(Handle,SIGKILL)=0;          if not Result then exit;        end;      { the fact that the signal has been sent does not      mean that the process has already handled the      signal -> wait instead of calling getexitstatus }      WaitOnExit;    end;end;
Here is the patch

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---diff --git a/packages/fcl-process/src/unix/process.inc b/packages/fcl-process/src/unix/process.incindex 54c00ef8ea..7099ca8339 100644--- a/packages/fcl-process/src/unix/process.inc+++ b/packages/fcl-process/src/unix/process.inc@@ -530,18 +530,19 @@ procedure TProcess.CloseProcessHandles; Function TProcess.Terminate(AExitCode : Integer) : Boolean;  begin-  Result:=False;   Result:=fpkill(Handle,SIGTERM)=0;   If Result then     begin-    If Running then-      Result:=fpkill(Handle,SIGKILL)=0;+      If Running then+        begin+          Result:=fpkill(Handle,SIGKILL)=0;+          if not Result then exit;+        end;+      { the fact that the signal has been sent does not+      mean that the process has already handled the+      signal -> wait instead of calling getexitstatus }+      WaitOnExit;     end;-  { the fact that the signal has been sent does not-    mean that the process has already handled the-    signal -> wait instead of calling getexitstatus }-  if Result then-    WaitOnExit; end;  Procedure TProcess.SetShowWindow (Value : TShowWindowOptions);

AlexTP:
Posted to https://gitlab.com/freepascal.org/fpc/source/-/issues/40356

Navigation

[0] Message Index

Go to full version