mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-11 18:25:58 +02:00
* SimpleIPC, avoid stale server state files (Unix). Patch by Andrew, Mantis #21289
git-svn-id: trunk@20385 -
This commit is contained in:
parent
48d780b920
commit
99892a7e45
@ -155,8 +155,27 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TPipeClientComm.ServerRunning: Boolean;
|
function TPipeClientComm.ServerRunning: Boolean;
|
||||||
|
var
|
||||||
|
fd: cint;
|
||||||
begin
|
begin
|
||||||
Result:=FileExists(FFileName);
|
Result:=FileExists(FFileName);
|
||||||
|
// it's possible to have a stale file that is not open for reading which will
|
||||||
|
// cause fpOpen to hang/block later when .Active is set to true while it
|
||||||
|
// wait's for the pipe to be opened on the other end
|
||||||
|
if Result then
|
||||||
|
begin
|
||||||
|
// O_WRONLY | O_NONBLOCK causes fpOpen to return -1 if the file is not open for reading
|
||||||
|
// so in fact the 'server' is not running
|
||||||
|
fd := FpOpen(FFileName, O_WRONLY or O_NONBLOCK);
|
||||||
|
if fd = -1 then
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
// delete the named pipe since it's orphaned
|
||||||
|
FpUnlink(FFileName);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
FpClose(fd);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -282,4 +301,4 @@ initialization
|
|||||||
Finalization
|
Finalization
|
||||||
IPCDone;
|
IPCDone;
|
||||||
end.
|
end.
|
||||||
{$endif}
|
{$endif}
|
||||||
|
Loading…
Reference in New Issue
Block a user