Browse Source

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 -

Károly Balogh 11 years ago
parent
commit
ef5f1b7ed2
4 changed files with 29 additions and 16 deletions
  1. 3 3
      rtl/amicommon/sysdir.inc
  2. 9 4
      rtl/amiga/system.pp
  3. 8 5
      rtl/aros/system.pp
  4. 9 4
      rtl/morphos/system.pp

+ 3 - 3
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

+ 9 - 4
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;

+ 8 - 5
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;

+ 9 - 4
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;