* FCL now compiles for FreeBSD with new 1.1. Now Linux.

This commit is contained in:
marco 2003-09-20 12:38:29 +00:00
parent f704b06638
commit 688866ff4f
14 changed files with 125 additions and 59 deletions

View File

@ -35,7 +35,7 @@ uses
{$ifdef ver1_0}
linux
{$else}
unix
baseunix,unix
{$endif}
;
@ -55,7 +55,10 @@ finalization
end.
{
$Log$
Revision 1.5 2002-09-07 15:15:24 peter
Revision 1.6 2003-09-20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.5 2002/09/07 15:15:24 peter
* old logs removed and tabs fixed
}

View File

@ -53,7 +53,11 @@ end;
//function SIGCHLDHandler(Sig: longint): longint; cdecl;//this is std linux C declaration as function
procedure SIGCHLDHandler(Sig: longint); cdecl;
begin
{$ifdef ver1_0}
waitpid(-1, nil, WNOHANG);
{$else}
fpwaitpid(-1, nil, WNOHANG);
{$endif}
end;
const zeroset :sigset = (0,0,0,0);
@ -66,6 +70,7 @@ begin
ThreadsInited:=true;
// This will install SIGCHLD signal handler
// signal() installs "one-shot" handler,
// so it is better to install and set up handler with sigaction()
@ -83,7 +88,11 @@ begin
Act^.sa_flags := SA_NOCLDSTOP {or SA_NOMASK or SA_RESTART};
//Do not block all signals ??. Don't need if SA_NOMASK in flags
SigAction(SIGCHLD, Act, OldAct);
{$ifdef ver1_0}
SigAction(SIGCHLD, @Act, @OldAct);
{$else}
fpsigaction(SIGCHLD, @Act, @OldAct);
{$endif}
FreeMem(Act, SizeOf(SigActionRec));
FreeMem(OldAct, SizeOf(SigActionRec));
@ -162,7 +171,7 @@ begin
Thread.DoTerminate;
if FreeThread then
Thread.Free;
ExitProcess(Result);
fpExit(Result);
end;
@ -195,7 +204,7 @@ begin
WaitFor;
end;
if FHandle <> -1 then
Kill(FHandle, SIGKILL);
{$ifdef ver1_0}kill({$else}fpkill({$endif}FHandle, SIGKILL);
dec(FStackPointer,FStackSize);
Freemem(pointer(FStackPointer),FStackSize);
inherited Destroy;
@ -226,7 +235,11 @@ var
P: Integer;
I: TThreadPriority;
begin
P := {$ifdef ver1_0}Linux{$else}Unix{$endif}.GetPriority(Prio_Process,FHandle);
P := {$ifdef ver1_0}
Linux.getpriority
{$else}
Unix.fpGetPriority
{$endif} (Prio_Process,FHandle);
Result := tpNormal;
for I := Low(TThreadPriority) to High(TThreadPriority) do
if Priorities[I] = P then
@ -236,7 +249,11 @@ end;
procedure TThread.SetPriority(Value: TThreadPriority);
begin
{$ifdef ver1_0}Linux{$else}Unix{$endif}.SetPriority(Prio_Process,FHandle, Priorities[Value]);
{$ifdef ver1_0}
Linux.Setpriority
{$else}
Unix.fpSetPriority
{$endif} (Prio_Process,FHandle, Priorities[Value]);
end;
@ -262,14 +279,14 @@ end;
procedure TThread.Suspend;
begin
Kill(FHandle, SIGSTOP);
{$ifdef ver1_0}kill({$else}fpkill({$endif}FHandle, SIGSTOP);
FSuspended := true;
end;
procedure TThread.Resume;
begin
Kill(FHandle, SIGCONT);
{$ifdef ver1_0}kill({$else}fpkill({$endif}FHandle, SIGCONT);
FSuspended := False;
end;
@ -283,16 +300,26 @@ function TThread.WaitFor: Integer;
var
status : longint;
begin
{$ifdef ver1_0}
if FThreadID = MainThreadID then
WaitPid(0,@status,0)
else
WaitPid(FHandle,@status,0);
{$else}
if FThreadID = MainThreadID then
fpWaitPid(0,@status,0)
else
fpWaitPid(FHandle,@status,0);
{$endif}
Result:=status;
end;
{
$Log$
Revision 1.9 2003-01-17 19:01:07 marco
Revision 1.10 2003-09-20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.9 2003/01/17 19:01:07 marco
* small fix
Revision 1.8 2002/11/17 21:09:44 marco

View File

@ -24,7 +24,7 @@ Uses Classes,
{$ifdef ver1_0}
Linux,
{$else}
unix,
Baseunix,unix,
{$endif}
{$else}
Windows,
@ -324,7 +324,7 @@ end;
Function TProcess.PeekLinuxExitStatus : Boolean;
begin
Result:=WaitPID(Handle,@FExitCode,WNOHANG)=Handle;
Result:={$ifdef VER1_0}WaitPID{$else}fpWaitPid{$endif}(Handle,@FExitCode,WNOHANG)=Handle;
If Result then
FExitCode:=wexitstatus(FExitCode)
else
@ -616,8 +616,8 @@ begin
Result:=True;
Argv:=MakeCommand(Pname,PCommandLine,StartupOptions,ProcessOptions,FStartupInfo);
if (pos('/',PName)<>1) then
PName:=FileSearch(Pname,GetEnv('PATH'));
Pid:=fork;
PName:=FileSearch(Pname,{$ifdef ver1_0}GetEnv{$else}fpgetenv{$endif}('PATH'));
Pid:={$ifdef ver1_0}fork;{$else}fpfork;{$endif}
if Pid=0 then
begin
{ We're in the child }
@ -625,23 +625,23 @@ begin
ChDir(PDir);
if PoUsePipes in ProcessOptions then
begin
dup2(FStartupInfo.hStdInput,0);
dup2(FStartupInfo.hStdOutput,1);
dup2(FStartupInfo.hStdError,2);
{$ifdef ver1_0}dup2{$else}fpdup2{$endif}(FStartupInfo.hStdInput,0);
{$ifdef ver1_0}dup2{$else}fpdup2{$endif}(FStartupInfo.hStdOutput,1);
{$ifdef ver1_0}dup2{$else}fpdup2{$endif}(FStartupInfo.hStdError,2);
end
else if poNoConsole in ProcessOptions then
begin
fd:=FileOpen('/dev/null',fmOpenReadWrite);
dup2(fd,0);
dup2(fd,1);
dup2(fd,2);
{$ifdef ver1_0}dup2{$else}fpdup2{$endif}(fd,0);
{$ifdef ver1_0}dup2{$else}fpdup2{$endif}(fd,1);
{$ifdef ver1_0}dup2{$else}fpdup2{$endif}(fd,2);
end;
if (poRunSuspended in ProcessOptions) then
sigraise(SIGSTOP);
if FEnv<>Nil then
Execve(PChar(PName),Argv,Fenv)
{$ifdef ver1_0}execve{$else}fpexecve{$endif}(PChar(PName),Argv,Fenv)
else
Execv(Pchar(PName),argv);
{$ifdef ver1_0}execv{$else}fpexecv{$endif}(Pchar(PName),argv);
Halt(127);
end
else
@ -728,7 +728,7 @@ Function TProcess.WaitOnExit : Dword;
begin
{$ifdef unix}
Result:=Dword(WaitPid(Handle,@FExitCode,0));
Result:=Dword({$ifdef ver1_0}WaitPid{$else}fpWaitPid{$endif}(Handle,@FExitCode,0));
If Result=Handle then
FExitCode:=WexitStatus(FExitCode);
{$else}
@ -743,7 +743,7 @@ Function TProcess.Suspend : Longint;
begin
{$ifdef unix}
If kill(Handle,SIGSTOP)<>0 then
If {$ifdef ver1_0}kill{$else}fpkill{$endif}(Handle,SIGSTOP)<>0 then
Result:=-1
else
Result:=1;
@ -756,7 +756,7 @@ Function TProcess.Resume : LongInt;
begin
{$ifdef unix}
If kill(Handle,SIGCONT)<>0 then
If {$ifdef ver1_0}kill{$else}fpkill{$endif}(Handle,SIGCONT)<>0 then
Result:=-1
else
Result:=0;
@ -770,11 +770,11 @@ Function TProcess.Terminate(AExitCode : Integer) : Boolean;
begin
Result:=False;
{$ifdef unix}
Result:=kill(Handle,SIGTERM)=0;
Result:={$ifdef ver1_0}kill{$else}fpkill{$endif}(Handle,SIGTERM)=0;
If Result then
begin
If Running then
Result:=Kill(Handle,SIGKILL)=0;
Result:={$ifdef ver1_0}kill{$else}fpkill{$endif}(Handle,SIGKILL)=0;
end;
GetExitStatus;
{$else}
@ -919,7 +919,10 @@ end;
end.
{
$Log$
Revision 1.16 2003-08-12 13:49:42 michael
Revision 1.17 2003-09-20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.16 2003/08/12 13:49:42 michael
+ Freed streams were not closed correctly
Revision 1.15 2003/05/08 20:04:16 armin

View File

@ -167,7 +167,7 @@ uses
{$ifdef ver1_0}
Linux,
{$else}
Unix,
BaseUnix, Unix,
{$endif}
{$endif}
resolve
@ -370,7 +370,7 @@ Procedure TSocketServer.SetNonBlocking;
begin
{$ifndef notUnix}
fcntl(FSocket,F_SETFL,OPEN_NONBLOCK);
{$ifdef ver1_0}fcntl{$else}fpfcntl{$endif}(FSocket,F_SETFL,{$ifdef ver1_0}OPEN_NONBLOCK{$else}O_NONBLOCK{$endif});
{$endif}
FNonBlocking:=True;
end;
@ -568,7 +568,10 @@ end.
{
$Log$
Revision 1.19 2003-03-25 17:47:06 armin
Revision 1.20 2003-09-20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.19 2003/03/25 17:47:06 armin
* use closesocket and not fdClose for netware
Revision 1.18 2003/03/21 23:10:24 armin

View File

@ -17,7 +17,7 @@ Uses
{$ifdef ver1_0}
Linux
{$else}
Unix
baseUnix
{$endif}
;
@ -29,7 +29,7 @@ Var P : Pchar;
begin
// Linux version returns pchar.
p:={$ifdef ver1_0}Linux{$else}Unix{$endif}.getenv(EnvVar);
p:={$ifdef ver1_0}Linux{$else}BaseUnix{$endif}.fpgetenv(EnvVar);
if P<>nil then
getenv:=strpas(p)
else
@ -38,7 +38,10 @@ end;
{
$Log$
Revision 1.5 2002-09-07 15:15:29 peter
Revision 1.6 2003-09-20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.5 2002/09/07 15:15:29 peter
* old logs removed and tabs fixed
}

View File

@ -47,7 +47,7 @@
function Fpfstat(fd : cint; var sb : stat): cint; cdecl; external name 'fstat';
function Fpfork : pid_t; cdecl; external name 'fork';
function Fpexecve(const path : pchar; const argv : ppchar; const envp: ppchar): cint; cdecl; external name 'execve';
function Fpwaitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; cdecl; external name 'waitpid';
function Fpwaitpid(pid : pid_t; tat_loc : pcint; options: cint): pid_t; cdecl; external name 'waitpid';
function Fpaccess(const pathname : pchar; amode : cint): cint; cdecl; external name 'access';
function Fpuname(var name: utsname): cint; cdecl; external name 'uname';
@ -403,7 +403,7 @@ Begin
do_syscall(syscall_nr_Execve,TSysParam(path),TSysParam(Argv),TSysParam(envp));
End;
}
function Fpwaitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; [public, alias : 'FPC_SYSC_WAITPID'];
function Fpwaitpid(pid : pid_t; stat_loc : pcint; options: cint): pid_t; [public, alias : 'FPC_SYSC_WAITPID'];
{
Waits until a child with PID Pid exits, or returns if it is exited already.
Any resources used by the child are freed.
@ -412,7 +412,7 @@ function Fpwaitpid(pid : pid_t; var stat_loc : cint; options: cint): pid_t; [pub
}
begin // actually a wait4() call with 4th arg 0.
FpWaitPID:=do_syscall(syscall_nr_WaitPID,PID,TSysParam(@Stat_loc),options,0);
FpWaitPID:=do_syscall(syscall_nr_WaitPID,PID,TSysParam(Stat_loc),options,0);
end;
function Fpaccess(const pathname : pchar; amode : cint): cint; [public, alias : 'FPC_SYSC_ACCESS'];
@ -598,7 +598,10 @@ end;
{
$Log$
Revision 1.9 2003-09-17 16:02:31 marco
Revision 1.10 2003-09-20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.9 2003/09/17 16:02:31 marco
* ostype include moved to top
Revision 1.8 2003/09/16 12:45:49 marco

View File

@ -15,14 +15,14 @@
****************************************************************************
}
Function Fpmmap(start:pointer;len:size_t;prot:cint;flags:cint;fd:cint;offst:off_t):pointer; external name 'FPC_SYSC_MMAP';
//Function Fpmmap(adr,len,prot,flags,fdes,off:longint):longint; external name 'FPC_SYSC_MMAP';
Function Fpmunmap(start:pointer;len:size_t):cint; external name 'FPC_SYSC_MUNMAP';
//Function Fpmmap(start:pointer;len:size_t;prot:cint;flags:cint;fd:cint;offst:off_t):pointer; external name 'FPC_SYSC_MMAP';
//Function Fpmunmap(start:pointer;len:size_t):cint; external name 'FPC_SYSC_MUNMAP';
//function fpgettimeofday(tp: ptimeval;tzp:ptimezone):cint; external name 'FPC_SYSC_GETTIMEOFDAY';
Function FpIOCtl(Handle:cint;Ndx: culong;Data: Pointer):cint; external name 'FPC_SYSC_IOCTL';
Function FpGetPid:LongInt; external name 'FPC_SYSC_GETPID';
//Function FpReadLink(name,linkname:pchar;maxlen:longint):longint; external name 'FPC_SYSC_READLINK';
function fpgettimeofday(tp: ptimeval;tzp:ptimezone):cint; external name 'FPC_SYSC_GETTIMEOFDAY';
{ Needed in both POSIX (for implementation of sleep()) as POSIX realtime extensions or Unix/freebsd}
Function FpNanoSleep (const req : timespec;var rem : timespec) : longint; external name 'FPC_SYSC_NANOSLEEP';
@ -31,7 +31,10 @@ Function Fpgetcwd (path:pchar; siz:size_t):pchar; external name 'FPC_SYSC_GETCWD
{
$Log$
Revision 1.4 2003-09-16 12:45:49 marco
Revision 1.5 2003-09-20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.4 2003/09/16 12:45:49 marco
* mmap typing fixes
Revision 1.3 2003/09/15 20:08:49 marco

View File

@ -6,4 +6,7 @@ Function fpLstat(path:pchar;Info:pstat):cint;
Function fpLstat(Filename: PathStr;Info:pstat):cint;
Function fpSymlink(oldname,newname:pchar):cint;
Function fpReadLink(name,linkname:pchar;maxlen:cint):cint;
Function Fpmmap(start:pointer;len:size_t;prot:cint;flags:cint;fd:cint;offst:off_t):pointer; external name 'FPC_SYSC_MMAP';
Function Fpmunmap(start:pointer;len:size_t):cint; external name 'FPC_SYSC_MUNMAP';
function fpgettimeofday(tp: ptimeval;tzp:ptimezone):cint; external name 'FPC_SYSC_GETTIMEOFDAY';

View File

@ -144,7 +144,7 @@ begin
do_syscall(syscall_nr_close,Textrec(F).Handle);
{ closed our side, Now wait for the other - this appears to be needed ?? }
pl:=@(textrec(f).userdata[2]);
fpwaitpid(pl^,res,0);
fpwaitpid(pl^,@res,0);
pclose:=res shr 8;
end;
@ -157,7 +157,7 @@ begin
do_syscall(syscall_nr_close,filerec(F).Handle);
{ closed our side, Now wait for the other - this appears to be needed ?? }
pl:=@(filerec(f).userdata[2]);
fpwaitpid(pl^,res,0);
fpwaitpid(pl^,@res,0);
pclose:=res shr 8;
end;
@ -214,7 +214,10 @@ end;
{
$Log$
Revision 1.10 2003-09-15 20:08:49 marco
Revision 1.11 2003-09-20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.10 2003/09/15 20:08:49 marco
* small fixes. FreeBSD now cycles
Revision 1.9 2003/09/15 07:09:58 marco

View File

@ -71,7 +71,7 @@ Type TGrpArr = Array [0..0] of TGid; { C style array workarounds}
Function FpFork : TPid;
Function FpExecve (path : pChar; argv : ppChar; envp: ppChar): cInt;
Function FpExecv (path : pChar; argv : ppChar): cInt;
Function FpWaitpid (pid : TPid; var stat_loc : cInt; options: cInt): TPid;
Function FpWaitpid (pid : TPid; stat_loc : pcInt; options: cInt): TPid;
Function FpWait (var stat_loc : cInt): TPid;
Procedure FpExit (Status : cInt);
Function FpKill (pid : TPid; sig: cInt): cInt;
@ -122,7 +122,10 @@ Type TGrpArr = Array [0..0] of TGid; { C style array workarounds}
{
$Log$
Revision 1.7 2003-09-17 11:24:46 marco
Revision 1.8 2003-09-20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.7 2003/09/17 11:24:46 marco
* fixes for new macro's
Revision 1.6 2003/09/17 11:14:25 marco

View File

@ -109,7 +109,7 @@ begin
else
begin
{ We're in the parent. }
fpwaitpid (i,j,0);
fpwaitpid (i,@j,0);
if j<>0 then
exit;
{ Erase the file }
@ -254,7 +254,10 @@ end.
{
$Log$
Revision 1.5 2003-09-14 20:15:01 marco
Revision 1.6 2003-09-20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.5 2003/09/14 20:15:01 marco
* Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
Revision 1.4 2002/09/07 16:01:27 peter

View File

@ -36,7 +36,7 @@ function fpftruncate (fd : cint; flength : TOff): cint; external name 'FPC_SYSC_
function fpfstat (fd : cint; var sb : stat): cint; external name 'FPC_SYSC_FSTAT';
function fpfork : pid_t; external name 'FPC_SYSC_FORK';
// function fpexecve (path : pchar; argv : ppchar;envp: ppchar): cint; external name 'FPC_SYSC_EXECVE';
function fpwaitpid (pid : pid_t; var stat_loc : cint; options: cint): pid_t; external name 'FPC_SYSC_WAITPID';
function fpwaitpid (pid : pid_t; stat_loc : pcint; options: cint): pid_t; external name 'FPC_SYSC_WAITPID';
function fpaccess (pathname : pchar; amode : cint): cint;external name 'FPC_SYSC_ACCESS';
function fpDup (fildes:cint):cint; external name 'FPC_SYSC_DUP';
function fpDup2 (fildes:cint;fildes2:cint):cint; external name 'FPC_SYSC_DUP2';
@ -45,7 +45,10 @@ procedure seterrno (i:cint); external name 'FPC_SYS_SETERRNO';
{
$Log$
Revision 1.1 2003-06-01 15:25:14 marco
Revision 1.2 2003-09-20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.1 2003/06/01 15:25:14 marco
* now generic

View File

@ -45,14 +45,13 @@ interface
implementation
Uses BaseUnix;
Uses BaseUnix,unix;
{*****************************************************************************
Generic overloaded
*****************************************************************************}
{$i ostypes.inc}
{$i ossysch.inc}
{ Include generic overloaded routines }
{$i thread.inc}
@ -385,7 +384,10 @@ initialization
end.
{
$Log$
Revision 1.12 2003-09-16 13:17:03 marco
Revision 1.13 2003-09-20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.12 2003/09/16 13:17:03 marco
* Wat cleanup, ouwe syscalls nu via baseunix e.d.
Revision 1.11 2003/09/16 13:00:02 marco

View File

@ -259,7 +259,7 @@ Function Glob(Const path:pathstr):pglob;
Procedure Globfree(var p:pglob);
{Filedescriptorsets}
{Stat.Mode Types}
procedure SigRaise(sig:integer);
{******************************************************************************
Implementation
******************************************************************************}
@ -271,9 +271,10 @@ Implementation
Uses Strings;
{$i syscallh.inc}
{$i unxsysc.inc}
{$i ossysch.inc}
{$i unxsysc.inc}
{ Get the definitions of textrec and filerec }
{$i textrec.inc}
{$i filerec.inc}
@ -296,7 +297,7 @@ var r,s : LongInt;
begin
repeat
s:=$7F00;
r:=fpWaitPid(Pid,s,0);
r:=fpWaitPid(Pid,@s,0);
until (r<>-1) or (LinuxError<>ESysEINTR);
if (r=-1) or (r=0) then // 0 is not a valid return and should never occur (it means status invalid when using WNOHANG)
WaitProcess:=-1 // return -1 to indicate an error
@ -1713,7 +1714,10 @@ End.
{
$Log$
Revision 1.37 2003-09-17 19:07:44 marco
Revision 1.38 2003-09-20 12:38:29 marco
* FCL now compiles for FreeBSD with new 1.1. Now Linux.
Revision 1.37 2003/09/17 19:07:44 marco
* more fixes for Unix<->unixutil
Revision 1.36 2003/09/17 17:30:46 marco