From ef5f1b7ed256bdaae7db7de4d547ac269aec3a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A1roly=20Balogh?= Date: Sat, 30 Aug 2014 00:58:42 +0000 Subject: [PATCH] amicommon: fixed sysdir.inc/do_chdir() to actually work on AROS - fixed all Amiga-like system units to not leak the last directory lock while changing back to the original dir in System_exit; (a bug found by Marcus Sackrow, thanks!) * renamed AOS_origDir to ASYS_origDir git-svn-id: trunk@28537 - --- rtl/amicommon/sysdir.inc | 6 +++--- rtl/amiga/system.pp | 13 +++++++++---- rtl/aros/system.pp | 13 ++++++++----- rtl/morphos/system.pp | 13 +++++++++---- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/rtl/amicommon/sysdir.inc b/rtl/amicommon/sysdir.inc index 9e4e43ddac..1665fe3641 100644 --- a/rtl/amicommon/sysdir.inc +++ b/rtl/amicommon/sysdir.inc @@ -69,10 +69,10 @@ begin FIB:=nil; new(FIB); - if (Examine(tmpLock,FIB)>0) and (FIB^.fib_DirEntryType>0) then begin + if (Examine(tmpLock,FIB)<>0) and (FIB^.fib_DirEntryType>0) then begin tmpLock:=CurrentDir(tmpLock); - if AOS_OrigDir=0 then begin - AOS_OrigDir:=tmpLock; + if ASYS_OrigDir=0 then begin + ASYS_OrigDir:=tmpLock; tmpLock:=0; end; end else begin diff --git a/rtl/amiga/system.pp b/rtl/amiga/system.pp index 0773b7be4e..ffcc5c556c 100644 --- a/rtl/amiga/system.pp +++ b/rtl/amiga/system.pp @@ -78,7 +78,7 @@ var {$ENDIF} ASYS_heapPool : Pointer; { pointer for the OS pool for growing the heap } - AOS_origDir : LongInt; { original directory on startup } + ASYS_origDir : LongInt; { original directory on startup } AOS_wbMsg : Pointer; public name '_WBenchMsg'; { the "public" part is amunits compatibility kludge } _WBenchMsg : Pointer; external name '_WBenchMsg'; { amunits compatibility kludge } AOS_ConName : PChar ='CON:10/30/620/100/FPC Console Output/AUTO/CLOSE/WAIT'; @@ -132,6 +132,8 @@ implementation procedure haltproc(e:longint);cdecl;external name '_haltproc'; procedure System_exit; +var + oldDirLock: LongInt; begin { We must remove the CTRL-C FLAG here because halt } { may call I/O routines, which in turn might call } @@ -145,8 +147,11 @@ begin CloseList(ASYS_fileList); { Changing back to original directory if changed } - if AOS_origDir<>0 then begin - CurrentDir(AOS_origDir); + if ASYS_origDir<>0 then begin + oldDirLock:=CurrentDir(ASYS_origDir); + { unlock our lock if its safe, so we won't leak the lock } + if (oldDirLock<>0) and (oldDirLock<>ASYS_origDir) then + Unlock(oldDirLock); end; {$IFDEF AMIGAOS4} @@ -393,7 +398,7 @@ begin StackBottom := Sptr - StackLength; { OS specific startup } AOS_wbMsg:=nil; - AOS_origDir:=0; + ASYS_origDir:=0; ASYS_fileList:=nil; envp:=nil; SysInitAmigaOS; diff --git a/rtl/aros/system.pp b/rtl/aros/system.pp index ede8502794..ef57cbeefc 100644 --- a/rtl/aros/system.pp +++ b/rtl/aros/system.pp @@ -66,7 +66,7 @@ var ASYS_heapPool : Pointer; { pointer for the OS pool for growing the heap } - AOS_origDir : LongInt; { original directory on startup } + ASYS_origDir : LongInt; { original directory on startup } AOS_wbMsg : Pointer; AOS_ConName : PChar ='CON:10/30/620/100/FPC Console Output/AUTO/CLOSE/WAIT'; AOS_ConHandle: THandle; @@ -114,7 +114,7 @@ procedure haltproc(e:longint); cdecl; external name '_haltproc'; procedure System_exit; var - a: LongInt; + oldDirLock: LongInt; begin if Killed then Exit; @@ -125,8 +125,11 @@ begin if AOS_wbMsg <> nil then ReplyMsg(AOS_wbMsg); { Changing back to original directory if changed } - if AOS_OrigDir <> 0 then begin - CurrentDir(AOS_origDir); + if ASYS_OrigDir <> 0 then begin + oldDirLock:=CurrentDir(ASYS_origDir); + { unlock our lock if its safe, so we won't leak the lock } + if (oldDirLock<>0) and (oldDirLock<>ASYS_origDir) then + Unlock(oldDirLock); end; if AOS_UtilityBase <> nil then CloseLibrary(AOS_UtilityBase); @@ -448,7 +451,7 @@ begin StackBottom := Sptr - StackLength; { OS specific startup } AOS_wbMsg := nil; - AOS_origDir := 0; + ASYS_origDir := 0; ASYS_fileList := nil; envp := nil; SysInitAmigaOS; diff --git a/rtl/morphos/system.pp b/rtl/morphos/system.pp index 88dcba44ff..896fd863d6 100644 --- a/rtl/morphos/system.pp +++ b/rtl/morphos/system.pp @@ -63,7 +63,7 @@ var MOS_UtilityBase: Pointer; ASYS_heapPool : Pointer; { pointer for the OS pool for growing the heap } - AOS_origDir : LongInt; { original directory on startup } + ASYS_origDir : LongInt; { original directory on startup } MOS_ambMsg : Pointer; MOS_ConName : PChar ='CON:10/30/620/100/FPC Console Output/AUTO/CLOSE/WAIT'; MOS_ConHandle: LongInt; @@ -93,6 +93,8 @@ implementation procedure haltproc(e:longint);cdecl;external name '_haltproc'; procedure System_exit; +var + oldDirLock: LongInt; begin { We must remove the CTRL-C FLAG here because halt } { may call I/O routines, which in turn might call } @@ -106,8 +108,11 @@ begin CloseList(ASYS_fileList); { Changing back to original directory if changed } - if AOS_origDir<>0 then begin - CurrentDir(AOS_origDir); + if ASYS_origDir<>0 then begin + oldDirLock:=CurrentDir(ASYS_origDir); + { unlock our lock if its safe, so we won't leak the lock } + if (oldDirLock<>0) and (oldDirLock<>ASYS_origDir) then + Unlock(oldDirLock); end; { Closing CON: when in Ambient mode } @@ -405,7 +410,7 @@ begin StackBottom := Sptr - StackLength; { OS specific startup } MOS_ambMsg:=nil; - AOS_origDir:=0; + ASYS_origDir:=0; ASYS_fileList:=nil; envp:=nil; SysInitMorphOS;