Pārlūkot izejas kodu

FIX: Bug [0002607] Named pipes creation error in FreeBSD

Alexander Koblov 4 gadi atpakaļ
vecāks
revīzija
cc5a23df0f

+ 8 - 2
src/platform/unix/darwin/umydarwin.pas

@@ -3,7 +3,7 @@
    -------------------------------------------------------------------------
    -------------------------------------------------------------------------
    This unit contains specific DARWIN functions.
    This unit contains specific DARWIN functions.
 
 
-   Copyright (C) 2016-2017 Alexander Koblov ([email protected])
+   Copyright (C) 2016-2021 Alexander Koblov ([email protected])
 
 
    This library is free software; you can redistribute it and/or
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    modify it under the terms of the GNU Lesser General Public
@@ -30,6 +30,8 @@ interface
 uses
 uses
   Classes, SysUtils, MacOSAll, CocoaAll;
   Classes, SysUtils, MacOSAll, CocoaAll;
 
 
+function NSGetTempPath: String;
+
 function StringToNSString(const S: String): NSString;
 function StringToNSString(const S: String): NSString;
 function StringToCFStringRef(const S: String): CFStringRef;
 function StringToCFStringRef(const S: String): CFStringRef;
 
 
@@ -46,6 +48,11 @@ implementation
 uses
 uses
   DynLibs;
   DynLibs;
 
 
+function NSGetTempPath: String;
+begin
+  Result:= IncludeTrailingBackslash(NSTemporaryDirectory.UTF8String);
+end;
+
 function StringToNSString(const S: String): NSString;
 function StringToNSString(const S: String): NSString;
 begin
 begin
   Result:= NSString(NSString.stringWithUTF8String(PAnsiChar(S)));
   Result:= NSString(NSString.stringWithUTF8String(PAnsiChar(S)));
@@ -137,4 +144,3 @@ finalization
   Finalize;
   Finalize;
 
 
 end.
 end.
-

+ 7 - 26
src/platform/unix/upipeserver.pas

@@ -3,7 +3,7 @@
    -------------------------------------------------------------------------
    -------------------------------------------------------------------------
    Unix implementation of one-way IPC between 2 processes
    Unix implementation of one-way IPC between 2 processes
 
 
-   Copyright (C) 2015-2019 Alexander Koblov ([email protected])
+   Copyright (C) 2015-2021 Alexander Koblov ([email protected])
 
 
    Based on simpleipc.inc from Free Component Library.
    Based on simpleipc.inc from Free Component Library.
    Copyright (c) 2005 by Michael Van Canneyt, member of
    Copyright (c) 2005 by Michael Van Canneyt, member of
@@ -32,7 +32,9 @@ implementation
 
 
 uses
 uses
   SimpleIPC, BaseUnix, uPollThread
   SimpleIPC, BaseUnix, uPollThread
-{$IF DEFINED(LINUX)}
+{$IF DEFINED(DARWIN)}
+  , uMyDarwin
+{$ELSE}
   , uXdg
   , uXdg
 {$ENDIF}
 {$ENDIF}
   ;
   ;
@@ -65,10 +67,10 @@ Type
 
 
 function GetPipeFileName(const FileName: String; Global : Boolean): String;
 function GetPipeFileName(const FileName: String; Global : Boolean): String;
 begin
 begin
-{$IF DEFINED(LINUX)}
-  Result:= IncludeTrailingBackslash(GetUserRuntimeDir) + FileName;
+{$IF DEFINED(DARWIN)}
+  Result:= NSGetTempPath + FileName;
 {$ELSE}
 {$ELSE}
-  Result:= GetTempDir(Global) + ApplicationName + '-' + IntToStr(fpGetUID) + PathDelim + FileName;
+  Result:= IncludeTrailingBackslash(GetUserRuntimeDir) + FileName;
 {$ENDIF}
 {$ENDIF}
   Result:= Result + '.pipe'
   Result:= Result + '.pipe'
 end;
 end;
@@ -89,11 +91,6 @@ begin
 end;
 end;
 
 
 constructor TPipeServerComm.Create(AOWner: TSimpleIPCServer);
 constructor TPipeServerComm.Create(AOWner: TSimpleIPCServer);
-{$IF NOT DEFINED(LINUX)}
-var
-  Info: TStat;
-  Directory: String;
-{$ENDIF}
 begin
 begin
   inherited Create(AOWner);
   inherited Create(AOWner);
   FFileName:= Owner.ServerID;
   FFileName:= Owner.ServerID;
@@ -101,21 +98,6 @@ begin
     FFileName:= FFileName + '-' + IntToStr(fpGetPID);
     FFileName:= FFileName + '-' + IntToStr(fpGetPID);
   if FFileName[1] <> '/' then
   if FFileName[1] <> '/' then
     FFileName:= GetPipeFileName(FFileName, Owner.Global);
     FFileName:= GetPipeFileName(FFileName, Owner.Global);
-{$IF NOT DEFINED(LINUX)}
-  // Verify directory owner
-  Directory:= ExtractFileDir(FFileName);
-  if not DirectoryExists(Directory) then
-  begin
-    if fpMkDir(Directory, &700) <> 0 then
-      raise EIPCError.Create(SysErrorMessage(GetLastOSError));
-  end
-  else begin
-    if fpStat(Directory, Info) <> 0 then
-      raise EIPCError.Create(SysErrorMessage(GetLastOSError));
-    if (Info.st_uid <> fpGetUID) or (Info.st_gid <> fpGetGID) then
-      DoError(SErrFailedToCreatePipe, [FFileName]);
-  end;
-{$ENDIF}
 end;
 end;
 
 
 procedure TPipeServerComm.StartServer;
 procedure TPipeServerComm.StartServer;
@@ -169,4 +151,3 @@ initialization
   DefaultIPCServerClass:= TPipeServerComm;
   DefaultIPCServerClass:= TPipeServerComm;
 
 
 end.
 end.
-